From 88e823052a0164ff0d856a3992b67f1e1e37393c Mon Sep 17 00:00:00 2001 From: wangzilin Date: Tue, 5 Nov 2024 09:48:48 +0800 Subject: [PATCH] =?UTF-8?q?C++=E4=BE=A7=E6=B2=89=E6=B5=B8=E5=BC=8F?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96=EF=BC=8C=201=E3=80=81Avoid?= =?UTF-8?q?AreaType=E6=B7=BB=E5=8A=A0TYPE=5FSTART=E5=92=8CTYPE=5FEND?= =?UTF-8?q?=E6=9E=9A=E4=B8=BE=E5=80=BC=E7=94=A8=E4=BB=A5=E6=A0=87=E8=AE=B0?= =?UTF-8?q?=E9=81=BF=E8=AE=A9=E5=8C=BA=E5=9F=9F=E5=A4=B4=E5=B0=BE=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=EF=BC=8C=E4=BE=BF=E4=BA=8E=E6=9D=A1=E4=BB=B6=E5=BE=AA?= =?UTF-8?q?=E7=8E=AF=EF=BC=8C=E6=B6=88=E9=99=A4=E4=BB=A3=E7=A0=81=E9=AD=94?= =?UTF-8?q?=E6=9C=AF=E5=80=BC=E3=80=82=202=E3=80=81SceneSessionManager?= =?UTF-8?q?=E4=B8=AD=EF=BC=8CUpdateSessionAvoidAreaListener=E3=80=81Update?= =?UTF-8?q?SessionAvoidAreaIfNeed=E3=80=81UpdateNormalSessionAvoidArea?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E5=8F=82=E6=95=B0=E6=B6=88=E9=99=A4=E6=95=B0?= =?UTF-8?q?=E5=80=BC=E5=BC=95=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangzilin --- interfaces/innerkits/wm/wm_common.h | 2 ++ interfaces/kits/cj/window_runtime/window_impl.cpp | 2 +- .../napi/extension_window/js_extension_window.cpp | 4 ++-- .../napi/window_runtime/window_napi/js_window.cpp | 6 +++--- previewer/include/wm_common.h | 2 ++ .../container/src/zidl/session_stage_stub.cpp | 6 ++++-- window_scene/session/host/src/scene_session.cpp | 2 +- window_scene/session/host/src/zidl/session_stub.cpp | 4 ++-- .../session_manager/src/scene_session_manager.cpp | 12 +++++++----- wmserver/src/zidl/window_manager_stub.cpp | 4 ++-- 10 files changed, 26 insertions(+), 18 deletions(-) diff --git a/interfaces/innerkits/wm/wm_common.h b/interfaces/innerkits/wm/wm_common.h index 670ba19b65..0866af54f7 100644 --- a/interfaces/innerkits/wm/wm_common.h +++ b/interfaces/innerkits/wm/wm_common.h @@ -796,11 +796,13 @@ struct KeyboardPanelInfo : public Parcelable { * @brief Enumerates avoid area type. */ enum class AvoidAreaType : uint32_t { + TYPE_START = -1, TYPE_SYSTEM, // area of SystemUI TYPE_CUTOUT, // cutout of screen TYPE_SYSTEM_GESTURE, // area for system gesture TYPE_KEYBOARD, // area for soft input keyboard TYPE_NAVIGATION_INDICATOR, // area for navigation indicator + TYPE_END, }; /** diff --git a/interfaces/kits/cj/window_runtime/window_impl.cpp b/interfaces/kits/cj/window_runtime/window_impl.cpp index 7a73d65aca..2032219207 100644 --- a/interfaces/kits/cj/window_runtime/window_impl.cpp +++ b/interfaces/kits/cj/window_runtime/window_impl.cpp @@ -402,7 +402,7 @@ int32_t CJWindowImpl::GetWindowAvoidArea(uint32_t areaType, CAvoidArea* retPtr) return static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY); } AvoidAreaType avoidAreaType = static_cast(areaType); - if ((avoidAreaType > AvoidAreaType::TYPE_NAVIGATION_INDICATOR) || (avoidAreaType < AvoidAreaType::TYPE_SYSTEM)) { + if ((avoidAreaType >= AvoidAreaType::TYPE_END) || (avoidAreaType <= AvoidAreaType::TYPE_START)) { return static_cast(WmErrorCode::WM_ERROR_INVALID_PARAM); } AvoidArea avoidArea; diff --git a/interfaces/kits/napi/extension_window/js_extension_window.cpp b/interfaces/kits/napi/extension_window/js_extension_window.cpp index 9c0b19a18c..4fd802e454 100644 --- a/interfaces/kits/napi/extension_window/js_extension_window.cpp +++ b/interfaces/kits/napi/extension_window/js_extension_window.cpp @@ -668,8 +668,8 @@ napi_value JsExtensionWindow::OnGetWindowAvoidArea(napi_env env, napi_callback_i uint32_t resultValue = 0; napi_get_value_uint32(env, nativeMode, &resultValue); avoidAreaType = static_cast(resultValue); - errCode = ((avoidAreaType > AvoidAreaType::TYPE_NAVIGATION_INDICATOR) || - (avoidAreaType < AvoidAreaType::TYPE_SYSTEM)) ? + errCode = ((avoidAreaType >= AvoidAreaType::TYPE_END) || + (avoidAreaType <= AvoidAreaType::TYPE_START)) ? WmErrorCode::WM_ERROR_INVALID_PARAM : WmErrorCode::WM_OK; } if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) { diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp b/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp index 5052578fcf..1018a0083e 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp @@ -3145,7 +3145,7 @@ static void ParseAvoidAreaParam(napi_env env, napi_callback_info info, WMError& napi_get_value_uint32(env, nativeMode, &resultValue)); avoidAreaType = static_cast(resultValue); errCode = ((avoidAreaType > AvoidAreaType::TYPE_KEYBOARD) || - (avoidAreaType < AvoidAreaType::TYPE_SYSTEM)) ? WMError::WM_ERROR_INVALID_PARAM : WMError::WM_OK; + (avoidAreaType <= AvoidAreaType::TYPE_START)) ? WMError::WM_ERROR_INVALID_PARAM : WMError::WM_OK; } } } @@ -3218,8 +3218,8 @@ napi_value JsWindow::OnGetWindowAvoidAreaSync(napi_env env, napi_callback_info i CHECK_NAPI_RETCODE(errCode, WmErrorCode::WM_ERROR_INVALID_PARAM, napi_get_value_uint32(env, nativeMode, &resultValue)); avoidAreaType = static_cast(resultValue); - errCode = ((avoidAreaType > AvoidAreaType::TYPE_NAVIGATION_INDICATOR) || - (avoidAreaType < AvoidAreaType::TYPE_SYSTEM)) ? + errCode = ((avoidAreaType >= AvoidAreaType::TYPE_END) || + (avoidAreaType <= AvoidAreaType::TYPE_START)) ? WmErrorCode::WM_ERROR_INVALID_PARAM : WmErrorCode::WM_OK; } if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) { diff --git a/previewer/include/wm_common.h b/previewer/include/wm_common.h index 068833929a..a46f79fa51 100644 --- a/previewer/include/wm_common.h +++ b/previewer/include/wm_common.h @@ -547,11 +547,13 @@ struct SystemBarProperty { * @brief Enumerates avoid area type. */ enum class AvoidAreaType : uint32_t { + TYPE_START = -1, TYPE_SYSTEM, // area of SystemUI TYPE_CUTOUT, // cutout of screen TYPE_SYSTEM_GESTURE, // area for system gesture TYPE_KEYBOARD, // area for soft input keyboard TYPE_NAVIGATION_INDICATOR, // area for navigation indicator + TYPE_END, }; /** diff --git a/window_scene/session/container/src/zidl/session_stage_stub.cpp b/window_scene/session/container/src/zidl/session_stage_stub.cpp index e7869afff5..29bc29564f 100644 --- a/window_scene/session/container/src/zidl/session_stage_stub.cpp +++ b/window_scene/session/container/src/zidl/session_stage_stub.cpp @@ -312,8 +312,10 @@ int SessionStageStub::HandleUpdateAvoidArea(MessageParcel& data, MessageParcel& if (!avoidArea) { return ERR_INVALID_VALUE; } - uint32_t type; - if (!data.ReadUint32(type)) { + uint32_t type = 0; + if (!data.ReadUint32(type) && + type <= static_cast(AvoidAreaType::TYPE_START) && + type >= static_cast(AvoidAreaType::TYPE_END)) { return ERR_INVALID_VALUE; } UpdateAvoidArea(avoidArea, static_cast(type)); diff --git a/window_scene/session/host/src/scene_session.cpp b/window_scene/session/host/src/scene_session.cpp index ce35154f73..eaac3b9044 100644 --- a/window_scene/session/host/src/scene_session.cpp +++ b/window_scene/session/host/src/scene_session.cpp @@ -1867,7 +1867,7 @@ WSError SceneSession::GetAllAvoidAreas(std::map& avoid using T = std::underlying_type_t; for (T avoidType = static_cast(AvoidAreaType::TYPE_SYSTEM); - avoidType <= static_cast(AvoidAreaType::TYPE_NAVIGATION_INDICATOR); avoidType++) { + avoidType < static_cast(AvoidAreaType::TYPE_END; avoidType++) { auto type = static_cast(avoidType); avoidAreas[type] = session->GetAvoidAreaByTypeInner(type); } diff --git a/window_scene/session/host/src/zidl/session_stub.cpp b/window_scene/session/host/src/zidl/session_stub.cpp index 9d2eb69e90..e784813c8a 100644 --- a/window_scene/session/host/src/zidl/session_stub.cpp +++ b/window_scene/session/host/src/zidl/session_stub.cpp @@ -806,8 +806,8 @@ int SessionStub::HandleGetAvoidAreaByType(MessageParcel& data, MessageParcel& re { uint32_t typeId = 0; if (!data.ReadUint32(typeId) || - typeId < static_cast(AvoidAreaType::TYPE_SYSTEM) || - typeId > static_cast(AvoidAreaType::TYPE_NAVIGATION_INDICATOR)) { + typeId <= static_cast(AvoidAreaType::TYPE_START) || + typeId >= static_cast(AvoidAreaType::TYPE_END)) { return ERR_INVALID_DATA; } AvoidAreaType type = static_cast(typeId); diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index 980dec377f..05a760df7c 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -8044,7 +8044,7 @@ WSError SceneSessionManager::GetFocusSessionElement(AppExecFwk::ElementName& ele return taskScheduler_->PostSyncTask(task, "GetFocusSessionElement"); } -WSError SceneSessionManager::UpdateSessionAvoidAreaListener(int32_t& persistentId, bool haveListener) +WSError SceneSessionManager::UpdateSessionAvoidAreaListener(int32_t& persistentId, bool& haveListener) { const auto callingPid = IPCSkeleton::GetCallingRealPid(); auto task = [this, persistentId, haveListener, callingPid]() { @@ -8073,7 +8073,7 @@ WSError SceneSessionManager::UpdateSessionAvoidAreaListener(int32_t& persistentI } bool SceneSessionManager::UpdateSessionAvoidAreaIfNeed(const int32_t& persistentId, - const sptr& sceneSession, const AvoidArea& avoidArea, AvoidAreaType avoidAreaType) + const sptr& sceneSession, const AvoidArea& avoidArea, AvoidAreaType& avoidAreaType) { if (sceneSession == nullptr) { TLOGI(WmsLogTag::WMS_IMMS, "scene session null no need update avoid area"); @@ -8085,7 +8085,9 @@ bool SceneSessionManager::UpdateSessionAvoidAreaIfNeed(const int32_t& persistent bool needUpdate = true; if (auto iter = lastUpdatedAvoidArea_[persistentId].find(avoidAreaType); - iter != lastUpdatedAvoidArea_[persistentId].end()) { + iter != lastUpdatedAvoidArea_[persistentId].end() && + iter != AvoidAreaType::TYPE_START && + iter != AvoidAreaType::TYPE_END) { needUpdate = iter->second != avoidArea; } else { if (avoidArea.isEmptyAvoidArea()) { @@ -8153,8 +8155,8 @@ void SceneSessionManager::UpdateNormalSessionAvoidArea( return; } uint32_t start = static_cast(AvoidAreaType::TYPE_SYSTEM); - uint32_t end = static_cast(AvoidAreaType::TYPE_NAVIGATION_INDICATOR); - for (uint32_t avoidType = start; avoidType <= end; avoidType++) { + uint32_t end = static_cast(AvoidAreaType::TYPE_END); + for (uint32_t avoidType = start; avoidType < end; avoidType++) { AvoidArea avoidArea = sceneSession->GetAvoidAreaByType(static_cast(avoidType)); if (avoidType == static_cast(AvoidAreaType::TYPE_NAVIGATION_INDICATOR) && !CheckAvoidAreaForAINavigationBar(isAINavigationBarVisible_, avoidArea, diff --git a/wmserver/src/zidl/window_manager_stub.cpp b/wmserver/src/zidl/window_manager_stub.cpp index 74d3e50a68..a4a8bc96c3 100644 --- a/wmserver/src/zidl/window_manager_stub.cpp +++ b/wmserver/src/zidl/window_manager_stub.cpp @@ -103,8 +103,8 @@ int32_t WindowManagerStub::OnRemoteRequest(uint32_t code, MessageParcel& data, M uint32_t windowId = data.ReadUint32(); uint32_t avoidAreaTypeId = 0; if (!data.ReadUint32(avoidAreaTypeId) || - avoidAreaTypeId < static_cast(AvoidAreaType::TYPE_SYSTEM) || - avoidAreaTypeId > static_cast(AvoidAreaType::TYPE_NAVIGATION_INDICATOR)) { + avoidAreaTypeId <= static_cast(AvoidAreaType::TYPE_START) || + avoidAreaTypeId >= static_cast(AvoidAreaType::TYPE_END)) { return ERR_INVALID_DATA; } auto avoidAreaType = static_cast(avoidAreaTypeId);