From 7d01d0b4f90a2466b46d9e6ea43f62b84784b9dc Mon Sep 17 00:00:00 2001 From: rookiiie Date: Mon, 18 Nov 2024 11:04:57 +0000 Subject: [PATCH 1/2] =?UTF-8?q?UIExtension=E9=94=81=E5=B1=8F=E4=B8=8A?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E6=9D=83=E9=99=90=E7=AE=A1=E6=8E=A7=E6=9C=BA?= =?UTF-8?q?=E5=88=B6=E6=A3=80=E8=A7=86=E6=84=8F=E8=A7=81=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=20Signed-off-by:=20rookiiie=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../js_scene_session_manager.cpp | 16 +-- .../session/host/include/scene_session.h | 24 ++-- .../session/host/src/scene_session.cpp | 61 ++++------ window_scene/session/host/src/session.cpp | 5 +- .../session/host/src/zidl/session_proxy.cpp | 8 +- .../session/host/src/zidl/session_stub.cpp | 2 +- .../include/scene_session_manager.h | 7 +- .../include/scene_session_manager_lite.h | 4 +- .../zidl/scene_session_manager_lite_proxy.h | 4 +- .../src/scene_session_manager.cpp | 104 ++++++++---------- .../src/scene_session_manager_lite.cpp | 4 +- .../zidl/scene_session_manager_lite_proxy.cpp | 11 +- .../scene_session_manager_lite_stub_test.cpp | 4 +- .../zidl/window_manager_lite_interface.h | 4 +- 14 files changed, 109 insertions(+), 149 deletions(-) diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp index 6936ac5513..273fcde515 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp @@ -224,7 +224,7 @@ napi_value JsSceneSessionManager::Init(napi_env env, napi_value exportObj) JsSceneSessionManager::ResetPcFoldScreenArrangeRule); BindNativeFunction(env, exportObj, "setIsWindowRectAutoSave", moduleName, JsSceneSessionManager::SetIsWindowRectAutoSave); - BindNativeFunction(env, exportObj, "NotifyAboveLockScreen", moduleName, + BindNativeFunction(env, exportObj, "notifyAboveLockScreen", moduleName, JsSceneSessionManager::NotifyAboveLockScreen); return NapiGetUndefined(env); } @@ -3423,7 +3423,7 @@ napi_value JsSceneSessionManager::OnIsScbCoreEnabled(napi_env env, napi_callback napi_value JsSceneSessionManager::OnNotifyAboveLockScreen(napi_env env, napi_callback_info info) { size_t argc = ARGC_FOUR; - napi_value argv[ARGC_FOUR] = {nullptr}; + napi_value argv[ARGC_FOUR] = { nullptr }; napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); if (argc != ARGC_ONE) { TLOGE(WmsLogTag::WMS_UIEXT, "[NAPI]Argc is invalid: %{public}zu", argc); @@ -3440,17 +3440,7 @@ napi_value JsSceneSessionManager::OnNotifyAboveLockScreen(napi_env env, napi_cal return NapiGetUndefined(env); } - std::string windowIdListStr = "none"; - if (!windowIds.empty()) { - windowIdListStr = std::accumulate(windowIds.begin() + 1, - windowIds.end(), - std::to_string(windowIds[0]), - [](const std::string &str, int32_t windowId) { return str + "," + std::to_string(windowId); }); - } - - TLOGI(WmsLogTag::WMS_UIEXT, - "UIExtOnLock: OnNotifyAboveLockScreen, window list: %{public}s", - windowIdListStr.c_str()); + TLOGI(WmsLogTag::WMS_UIEXT, "UIExtOnLock: window list size: %{public}zu", windowIds.size()); SceneSessionManager::GetInstance().OnNotifyAboveLockScreen(windowIds); return NapiGetUndefined(env); } diff --git a/window_scene/session/host/include/scene_session.h b/window_scene/session/host/include/scene_session.h index c943ad256a..ac670847f3 100644 --- a/window_scene/session/host/include/scene_session.h +++ b/window_scene/session/host/include/scene_session.h @@ -96,14 +96,14 @@ using NotifyVisibleChangeFunc = std::function; using IsLastFrameLayoutFinishedFunc = std::function; using NotifySetWindowRectAutoSaveFunc = std::function; +struct UIExtensionTokenInfo { + bool canShowOnLockScreen { false }; + uint32_t callingTokenId { 0 }; + sptr abilityToken; +}; + class SceneSession : public Session { public: - struct UIExtensionTokenInfo { - bool canShowOnLockScreen{false}; - uint32_t callingTokenId{0}; - sptr abilityToken; - }; - friend class HidumpController; // callback for notify SceneSessionManager struct SpecificSessionCallback : public RefBase { @@ -417,10 +417,6 @@ public: * Window Visibility */ void SetNotifyVisibleChangeFunc(const NotifyVisibleChangeFunc& func); - virtual WSError HideSync() - { - return WSError::WS_DO_NOTHING; - }; /** * Window Lifecycle @@ -430,6 +426,7 @@ public: void RegisterShowWhenLockedCallback(NotifyShowWhenLockedFunc&& callback); void RegisterForceHideChangeCallback(NotifyForceHideChangeFunc&& callback); void RegisterClearCallbackMapCallback(ClearCallbackMapFunc&& callback); + virtual WSError HideSync() { return WSError::WS_DO_NOTHING; } void SendPointerEventToUI(std::shared_ptr pointerEvent); bool SendKeyEventToUI(std::shared_ptr keyEvent, bool isPreImeEvent = false); @@ -476,10 +473,10 @@ public: * UIExtension */ bool IsShowOnLockScreen(uint32_t lockScreenZOrder); - void AddExtensionTokenInfo(const SceneSession::UIExtensionTokenInfo &tokenInfo); - void RemoveExtensionTokenInfo(sptr abilityToken); + void AddExtensionTokenInfo(const UIExtensionTokenInfo& tokenInfo); + void RemoveExtensionTokenInfo(const sptr& abilityToken); void CheckExtensionOnLockScreenToClose(); - void CloseExtensionSync(const SceneSession::UIExtensionTokenInfo& tokenInfo); + void CloseExtensionSync(const UIExtensionTokenInfo& tokenInfo); void OnNotifyAboveLockScreen(); void AddModalUIExtension(const ExtensionWindowEventInfo& extensionInfo); void RemoveModalUIExtension(int32_t persistentId); @@ -796,7 +793,6 @@ private: std::shared_mutex combinedExtWindowFlagsMutex_; ExtensionWindowFlags combinedExtWindowFlags_ { 0 }; std::map extWindowFlagsMap_; - mutable std::recursive_mutex extensionTokenInfosMutex_; std::vector extensionTokenInfos_; /** diff --git a/window_scene/session/host/src/scene_session.cpp b/window_scene/session/host/src/scene_session.cpp index 2291975ca1..a26b3655f3 100644 --- a/window_scene/session/host/src/scene_session.cpp +++ b/window_scene/session/host/src/scene_session.cpp @@ -201,9 +201,7 @@ WSError SceneSession::ReconnectInner(sptr property) bool SceneSession::IsShowOnLockScreen(uint32_t lockScreenZorder) { - TLOGD(WmsLogTag::WMS_UIEXT, - "UIExtOnLock: lockScreenZorder: %{public}d, zOrder_: %{public}d", - lockScreenZorder, + TLOGD(WmsLogTag::WMS_UIEXT, "UIExtOnLock: lockScreenZorder: %{public}d, zOrder_: %{public}d", lockScreenZorder, zOrder_); // must be default screen @@ -228,29 +226,20 @@ bool SceneSession::IsShowOnLockScreen(uint32_t lockScreenZorder) return false; } -void SceneSession::AddExtensionTokenInfo(const SceneSession::UIExtensionTokenInfo &tokenInfo) +void SceneSession::AddExtensionTokenInfo(const UIExtensionTokenInfo& tokenInfo) { - { - std::lock_guard lock(extensionTokenInfosMutex_); - extensionTokenInfos_.push_back(tokenInfo); - } - - TLOGI(WmsLogTag::WMS_UIEXT, - "UIExtOnLock: canShowOnLockScreen: %{public}u, persistentId: %{public}u", - tokenInfo.canShowOnLockScreen, - GetPersistentId()); + extensionTokenInfos_.push_back(tokenInfo); + TLOGI(WmsLogTag::WMS_UIEXT, "UIExtOnLock: canShowOnLockScreen: %{public}u, persistentId: %{public}d", + tokenInfo.canShowOnLockScreen, GetPersistentId()); } -void SceneSession::RemoveExtensionTokenInfo(sptr abilityToken) +void SceneSession::RemoveExtensionTokenInfo(const sptr& abilityToken) { - std::lock_guard lock(extensionTokenInfosMutex_); auto persistentId = GetPersistentId(); auto itr = std::remove_if( - extensionTokenInfos_.begin(), extensionTokenInfos_.end(), [&abilityToken, persistentId](const auto &tokenInfo) { - TLOGI(WmsLogTag::WMS_UIEXT, - "UIExtOnLock: need remove, calling token: %{public}u, persistentId: %{public}u", - tokenInfo.callingTokenId, - persistentId); + extensionTokenInfos_.begin(), extensionTokenInfos_.end(), [&abilityToken, persistentId](const auto& tokenInfo) { + TLOGNI(WmsLogTag::WMS_UIEXT, "UIExtOnLock: need remove, token: %{public}u, persistentId: %{public}d", + tokenInfo.callingTokenId, persistentId); return tokenInfo.abilityToken == abilityToken; }); @@ -264,10 +253,10 @@ void SceneSession::OnNotifyAboveLockScreen() void SceneSession::CheckExtensionOnLockScreenToClose() { - TLOGD(WmsLogTag::WMS_UIEXT, "UIExtOnLock: %{public}u", GetPersistentId()); + TLOGD(WmsLogTag::WMS_UIEXT, "UIExtOnLock: %{public}d", GetPersistentId()); // 1. check sub session - for (auto session : GetSubSession()) { + for (auto& session : GetSubSession()) { if (!session) { TLOGE(WmsLogTag::WMS_UIEXT, "UIExtOnLock: session is null"); continue; @@ -276,30 +265,26 @@ void SceneSession::CheckExtensionOnLockScreenToClose() } // 2. check self permission - std::vector tokenInfosToClose; - { - std::lock_guard lock(extensionTokenInfosMutex_); - for (auto &tokenInfo : extensionTokenInfos_) { - if (tokenInfo.canShowOnLockScreen) { - continue; - } - tokenInfosToClose.push_back(tokenInfo); + std::vector tokenInfosToClose; + for (auto& tokenInfo : extensionTokenInfos_) { + if (tokenInfo.canShowOnLockScreen) { + continue; } + tokenInfosToClose.push_back(tokenInfo); } // 3. close ui extension without lock screen permisson - std::for_each(tokenInfosToClose.rbegin(), - tokenInfosToClose.rend(), - [this](SceneSession::UIExtensionTokenInfo &tokenInfo) { CloseExtensionSync(tokenInfo); }); + std::for_each(tokenInfosToClose.rbegin(), tokenInfosToClose.rend(), + [this](const UIExtensionTokenInfo& tokenInfo) { CloseExtensionSync(tokenInfo); }); } -void SceneSession::CloseExtensionSync(const SceneSession::UIExtensionTokenInfo &tokenInfo) +void SceneSession::CloseExtensionSync(const UIExtensionTokenInfo& tokenInfo) { TLOGD(WmsLogTag::WMS_UIEXT, "UIExtOnLock"); // hide sub window auto subSceneSessions = GetSubSession(); - for (auto session : subSceneSessions) { + for (auto& session : subSceneSessions) { if (!session) { TLOGE(WmsLogTag::WMS_UIEXT, "UIExtOnLock: session is null"); continue; @@ -311,10 +296,8 @@ void SceneSession::CloseExtensionSync(const SceneSession::UIExtensionTokenInfo & } } - TLOGI(WmsLogTag::WMS_UIEXT, - "UIExtOnLock: close ui extension, callerToken: %{public}u, persistent id %{public}u", - tokenInfo.callingTokenId, - GetPersistentId()); + TLOGI(WmsLogTag::WMS_UIEXT, "UIExtOnLock: close ui extension, callerToken: %{public}u, persistent id %{public}d", + tokenInfo.callingTokenId, GetPersistentId()); // kill ui extension ability AAFwk::AbilityManagerClient::GetInstance()->CloseUIExtensionAbilityBySCB(tokenInfo.abilityToken); diff --git a/window_scene/session/host/src/session.cpp b/window_scene/session/host/src/session.cpp index e9137f86a6..fea04ef238 100644 --- a/window_scene/session/host/src/session.cpp +++ b/window_scene/session/host/src/session.cpp @@ -473,19 +473,18 @@ void Session::NotifyTransferAccessibilityEvent(const Accessibility::Accessibilit void Session::NotifyExtensionDetachToDisplay() { + TLOGI(WmsLogTag::WMS_UIEXT, "called"); if (!SessionPermission::IsSystemCalling()) { TLOGE(WmsLogTag::WMS_UIEXT, "permission denied!"); return; } auto lifecycleListeners = GetListeners(); - for (auto &listener : lifecycleListeners) { + for (auto& listener : lifecycleListeners) { if (auto listenerPtr = listener.lock()) { listenerPtr->OnExtensionDetachToDisplay(); } } - - TLOGI(WmsLogTag::WMS_UIEXT, "called"); } float Session::GetAspectRatio() const diff --git a/window_scene/session/host/src/zidl/session_proxy.cpp b/window_scene/session/host/src/zidl/session_proxy.cpp index 934c33b8f4..7112e38051 100644 --- a/window_scene/session/host/src/zidl/session_proxy.cpp +++ b/window_scene/session/host/src/zidl/session_proxy.cpp @@ -2016,7 +2016,6 @@ void SessionProxy::NotifyExtensionEventAsync(uint32_t notifyEvent) void SessionProxy::NotifyExtensionDetachToDisplay() { TLOGD(WmsLogTag::WMS_UIEXT, "UIExtOnLock: UIExtcalled"); - MessageParcel data; MessageParcel reply; MessageOption option(MessageOption::TF_SYNC); @@ -2027,10 +2026,15 @@ void SessionProxy::NotifyExtensionDetachToDisplay() } sptr remote = Remote(); + if (!remote) { + TLOGE(WmsLogTag::WMS_UIEXT, "UIExtOnLock: remote is null"); + return; + } + auto ret = remote->SendRequest( static_cast(SessionInterfaceCode::TRANS_ID_NOTIFY_EXTENSION_DETACH_TO_DISPLAY), data, reply, option); if (ret != ERR_NONE) { - TLOGE(WmsLogTag::WMS_UIEXT, "UIExtOnLock: SendRequest failed"); + TLOGE(WmsLogTag::WMS_UIEXT, "UIExtOnLock: SendRequest failed, ret code: %{public}u", ret); } } diff --git a/window_scene/session/host/src/zidl/session_stub.cpp b/window_scene/session/host/src/zidl/session_stub.cpp index 2f86a896e8..09d8ff8c33 100644 --- a/window_scene/session/host/src/zidl/session_stub.cpp +++ b/window_scene/session/host/src/zidl/session_stub.cpp @@ -1213,7 +1213,7 @@ int SessionStub::HandleSetDialogSessionBackGestureEnabled(MessageParcel& data, M return ERR_NONE; } -int SessionStub::HandleNotifyExtensionDetachToDisplay(MessageParcel &data, MessageParcel &reply) +int SessionStub::HandleNotifyExtensionDetachToDisplay(MessageParcel& data, MessageParcel& reply) { TLOGD(WmsLogTag::WMS_UIEXT, "in"); NotifyExtensionDetachToDisplay(); diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index ff97e44baf..46056a95d4 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -351,6 +351,7 @@ public: void SetEnableInputEvent(bool enabled); void UpdateRecoveredSessionInfo(const std::vector& recoveredPersistentIds); void SetAlivePersistentIds(const std::vector& alivePersistentIds); + void NotifyRecoveringFinished(); WMError CheckWindowId(int32_t windowId, int32_t& pid) override; void GetSceneSessionPrivacyModeBundles(DisplayId displayId, std::unordered_set& privacyBundles); @@ -407,10 +408,8 @@ public: * UIExtension */ uint32_t GetLockScreenZorder(); - WMError CheckUIExtensionCreation(int32_t windowId, - uint32_t tokenId, - const AppExecFwk::ElementName& element, - int32_t& pid); + WMError CheckUIExtensionCreation(int32_t windowId, uint32_t tokenId, const AppExecFwk::ElementName& element, + int32_t& pid); void OnNotifyAboveLockScreen(const std::vector& windowIds); void AddExtensionWindowStageToSCB(const sptr& sessionStage, const sptr& token, uint64_t surfaceNodeId) override; diff --git a/window_scene/session_manager/include/scene_session_manager_lite.h b/window_scene/session_manager/include/scene_session_manager_lite.h index ebf5fb2183..7515b9e1f8 100644 --- a/window_scene/session_manager/include/scene_session_manager_lite.h +++ b/window_scene/session_manager/include/scene_session_manager_lite.h @@ -58,8 +58,8 @@ public: WMError UnregisterWindowManagerAgent(WindowManagerAgentType type, const sptr& windowManagerAgent) override; WMError CheckWindowId(int32_t windowId, int32_t& pid) override; - WMError CheckUIExtensionCreation( - int32_t windowId, uint32_t tokenId, const AppExecFwk::ElementName &element, int32_t &pid) override; + WMError CheckUIExtensionCreation(int32_t windowId, uint32_t tokenId, const AppExecFwk::ElementName& element, + int32_t& pid) override; WMError GetVisibilityWindowInfo(std::vector>& infos) override; WSError UpdateWindowMode(int32_t persistentId, int32_t windowMode); WMError GetWindowModeType(WindowModeType& windowModeType) override; diff --git a/window_scene/session_manager/include/zidl/scene_session_manager_lite_proxy.h b/window_scene/session_manager/include/zidl/scene_session_manager_lite_proxy.h index 7530c72496..ee06f7575d 100644 --- a/window_scene/session_manager/include/zidl/scene_session_manager_lite_proxy.h +++ b/window_scene/session_manager/include/zidl/scene_session_manager_lite_proxy.h @@ -69,8 +69,8 @@ public: WMError UnregisterWindowManagerAgent(WindowManagerAgentType type, const sptr& windowManagerAgent) override; WMError CheckWindowId(int32_t windowId, int32_t& pid) override; - WMError CheckUIExtensionCreation( - int32_t windowId, uint32_t tokenId, const AppExecFwk::ElementName &element, int32_t &pid) override; + WMError CheckUIExtensionCreation(int32_t windowId, uint32_t tokenId, const AppExecFwk::ElementName& element, + int32_t& pid) override; WMError GetVisibilityWindowInfo(std::vector>& infos) override; WMError GetWindowModeType(WindowModeType& windowModeType) override; WMError GetMainWindowInfos(int32_t topNum, std::vector& topNInfo) override; diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index 4fac373de4..09bd81bca5 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -183,15 +183,12 @@ bool GetEnableRemoveStartingWindowFromBMS(const std::shared_ptr> whitelist = { + static const std::vector> whitelist = { std::make_tuple("com.huawei.hmos.settings", "AccessibilityReConfirmDialog", "phone_settings"), std::make_tuple("com.huawei.hmos.settings", "AccessibilityShortKeyDialog", "phone_settings"), std::make_tuple("com.huawei.hmos.settings", "DefaultIntentUiExtensionAbility", "phone_settings"), @@ -199,28 +196,18 @@ bool IsUIExtCanShowOnLockScreen(const AppExecFwk::ElementName &element, uint32_t std::make_tuple("com.huawei.hmos.motiongesture", "IntentUIExtensionAbility", "entry"), }; - auto itr = std::find_if(whitelist.begin(), whitelist.end(), [element](const auto &item) { - auto [bundleName, abilityName, moduleName] = item; - if (element.GetBundleName() != bundleName) { - return false; - } - if (element.GetAbilityName() != abilityName) { - return false; - } - return true; + auto it = std::find_if(whitelist.begin(), whitelist.end(), [&element](const auto& item) { + auto& [bundleName, abilityName, moduleName] = item; + return (element.GetBundleName() == bundleName && element.GetAbilityName() == abilityName); }); - if (itr != whitelist.end()) { + if (it != whitelist.end()) { return true; } TLOGI(WmsLogTag::WMS_UIEXT, "UIExtOnLock: not in white list"); - if (SessionPermission::VerifyPermissionByCallerToken( - callingTokenId, PermissionConstants::PERMISSION_CALLED_EXTENSION_ON_LOCK_SCREEN)) { - return true; - } - - return false; + return SessionPermission::VerifyPermissionByCallerToken(callingTokenId, + PermissionConstants::PERMISSION_CALLED_EXTENSION_ON_LOCK_SCREEN); } class BundleStatusCallback : public IRemoteStub { @@ -1462,9 +1449,9 @@ WMError SceneSessionManager::CheckWindowId(int32_t windowId, int32_t& pid) uint32_t SceneSessionManager::GetLockScreenZorder() { std::shared_lock lock(sceneSessionMapMutex_); - for (auto &[sessionId, session] : sceneSessionMap_) { - if (session->GetWindowType() == WindowType::WINDOW_TYPE_KEYGUARD) { - TLOGI(WmsLogTag::WMS_UIEXT, "UIExtOnLock: found window %{public}d: ", sessionId); + for (auto& [persistentId, session] : sceneSessionMap_) { + if (persistentId && (session->GetWindowType() == WindowType::WINDOW_TYPE_KEYGUARD)) { + TLOGI(WmsLogTag::WMS_UIEXT, "UIExtOnLock: found window %{public}d", persistentId); return session->GetZOrder(); } } @@ -1472,56 +1459,58 @@ uint32_t SceneSessionManager::GetLockScreenZorder() return 0; } -WMError SceneSessionManager::CheckUIExtensionCreation( - int32_t windowId, uint32_t callingTokenId, const AppExecFwk::ElementName &element, int32_t &pid) +WMError SceneSessionManager::CheckUIExtensionCreation(int32_t windowId, uint32_t callingTokenId, + const AppExecFwk::ElementName& element, int32_t& pid) { - auto task = [this, windowId, &pid, &callingTokenId, element]() -> WMError { + auto task = [this, windowId, &callingTokenId, &element, &pid]() -> WMError { pid = INVALID_PID; auto sceneSession = GetSceneSession(windowId); if (sceneSession == nullptr) { - TLOGE(WmsLogTag::WMS_UIEXT, "UIExtOnLock: sceneSession(%{public}d) is nullptr", windowId); + TLOGNE(WmsLogTag::WMS_UIEXT, "UIExtOnLock: sceneSession(%{public}d) is nullptr", windowId); return WMError::WM_ERROR_INVALID_WINDOW; } pid = sceneSession->GetCallingPid(); // 1. check window whether can show on main window if (!sceneSession->IsShowOnLockScreen(GetLockScreenZorder())) { - TLOGI(WmsLogTag::WMS_UIEXT, "UIExtOnLock: not called on lock screen"); + TLOGNI(WmsLogTag::WMS_UIEXT, "UIExtOnLock: not called on lock screen"); return WMError::WM_OK; } // 2. check permission if (!IsUIExtCanShowOnLockScreen(element, callingTokenId)) { - TLOGE(WmsLogTag::WMS_UIEXT, - "UIExtOnLock: no permisson, window id %{public}d, %{public}d", - windowId, + TLOGNE(WmsLogTag::WMS_UIEXT, "UIExtOnLock: no permisson, window id %{public}d, %{public}d", windowId, callingTokenId); return WMError::WM_ERROR_INVALID_PERMISSION; } - TLOGI(WmsLogTag::WMS_UIEXT, "UIExtOnLock: IsShowOnLockScreen: The caller permission has granted"); + TLOGNI(WmsLogTag::WMS_UIEXT, "UIExtOnLock: IsShowOnLockScreen: The caller permission has granted"); return WMError::WM_OK; }; - std::stringstream ss; + std::ostringstream ss; ss << "UIExtOnLockCheck" << "_" << windowId << "_" << callingTokenId; return taskScheduler_->PostSyncTask(task, ss.str()); } // windowIds are all main window -void SceneSessionManager::OnNotifyAboveLockScreen(const std::vector &windowIds) -{ - // check every window - for (auto windowId : windowIds) { - auto sceneSession = GetSceneSession(windowId); - if (!sceneSession) { - TLOGE(WmsLogTag::WMS_UIEXT, "UIExtOnLock: sesssion is null for %{public}d", windowId); - continue; +void SceneSessionManager::OnNotifyAboveLockScreen(const std::vector& windowIds) +{ + auto task = [this, &windowIds]() -> WMError { + // check every window + for (auto windowId : windowIds) { + auto sceneSession = GetSceneSession(windowId); + if (!sceneSession) { + TLOGNE(WmsLogTag::WMS_UIEXT, "UIExtOnLock: sesssion is null for %{public}d", windowId); + continue; + } + TLOGNI(WmsLogTag::WMS_UIEXT, "UIExtOnLock: check for %{public}d", windowId); + sceneSession->OnNotifyAboveLockScreen(); } - TLOGI(WmsLogTag::WMS_UIEXT, "UIExtOnLock: check for %{public}d", windowId); - sceneSession->OnNotifyAboveLockScreen(); - } + return WMError::WM_OK; + }; + taskScheduler_->PostSyncTask(task, "OnNotifyAboveLockScreen"); } void SceneSessionManager::CreateKeyboardPanelSession(sptr keyboardSession) @@ -10104,7 +10093,6 @@ void SceneSessionManager::AddExtensionWindowStageToSCB(const sptr { auto pid = IPCSkeleton::GetCallingRealPid(); auto callingTokenId = IPCSkeleton::GetCallingTokenID(); - auto task = [this, sessionStage, token, surfaceNodeId, pid, callingTokenId]() { if (sessionStage == nullptr || token == nullptr) { TLOGE(WmsLogTag::WMS_UIEXT, "input is nullptr"); @@ -10142,22 +10130,24 @@ void SceneSessionManager::AddExtensionWindowStageToSCB(const sptr extSessionInfoMap_.insert(std::make_pair(token, ExtensionWindowAbilityInfo{ persistentId, parentId, usage })); auto parentSession = GetSceneSession(parentId); - if (parentSession) { - parentSession->AddUIExtSurfaceNodeId(surfaceNodeId, persistentId); + if (!parentSession) { + TLOGNI(WmsLogTag::WMS_UIEXT, "no parent session for %{public}d", persistentId); + return; } - if (usage == UIExtensionUsage::MODAL && parentSession && parentSession->GetCallingPid() != GetPid()) { + + UIExtensionTokenInfo tokenInfo; + tokenInfo.abilityToken = token; + tokenInfo.callingTokenId = callingTokenId; + tokenInfo.canShowOnLockScreen = IsUIExtCanShowOnLockScreen(info.elementName, callingTokenId); + parentSession->AddExtensionTokenInfo(tokenInfo); + parentSession->AddUIExtSurfaceNodeId(surfaceNodeId, persistentId); + if (usage == UIExtensionUsage::MODAL && parentSession->GetCallingPid() != GetPid()) { ExtensionWindowEventInfo extensionInfo { .persistentId = persistentId, .pid = pid, }; parentSession->AddModalUIExtension(extensionInfo); } - - SceneSession::UIExtensionTokenInfo tokenInfo; - tokenInfo.abilityToken = token; - tokenInfo.callingTokenId = callingTokenId; - tokenInfo.canShowOnLockScreen = IsUIExtCanShowOnLockScreen(info.elementName, callingTokenId); - parentSession->AddExtensionTokenInfo(tokenInfo); }; taskScheduler_->PostAsyncTask(task, "AddExtensionWindowStageToSCB"); } diff --git a/window_scene/session_manager/src/scene_session_manager_lite.cpp b/window_scene/session_manager/src/scene_session_manager_lite.cpp index 1992e85bc2..1ce73f2b48 100644 --- a/window_scene/session_manager/src/scene_session_manager_lite.cpp +++ b/window_scene/session_manager/src/scene_session_manager_lite.cpp @@ -190,8 +190,8 @@ WMError SceneSessionManagerLite::CheckWindowId(int32_t windowId, int32_t& pid) return SceneSessionManager::GetInstance().CheckWindowId(windowId, pid); } -WMError SceneSessionManagerLite::CheckUIExtensionCreation( - int32_t windowId, uint32_t tokenId, const AppExecFwk::ElementName &element, int32_t &pid) +WMError SceneSessionManagerLite::CheckUIExtensionCreation(int32_t windowId, uint32_t tokenId, + const AppExecFwk::ElementName& element, int32_t& pid) { return SceneSessionManager::GetInstance().CheckUIExtensionCreation(windowId, tokenId, element, pid); } diff --git a/window_scene/session_manager/src/zidl/scene_session_manager_lite_proxy.cpp b/window_scene/session_manager/src/zidl/scene_session_manager_lite_proxy.cpp index 27c1a76251..0f84c7ffc0 100644 --- a/window_scene/session_manager/src/zidl/scene_session_manager_lite_proxy.cpp +++ b/window_scene/session_manager/src/zidl/scene_session_manager_lite_proxy.cpp @@ -890,8 +890,8 @@ WMError SceneSessionManagerLiteProxy::CheckWindowId(int32_t windowId, int32_t& p return WMError::WM_OK; } -WMError SceneSessionManagerLiteProxy::CheckUIExtensionCreation( - int32_t windowId, uint32_t tokenId, const AppExecFwk::ElementName &element, int32_t &pid) +WMError SceneSessionManagerLiteProxy::CheckUIExtensionCreation(int32_t windowId, uint32_t tokenId, + const AppExecFwk::ElementName& element, int32_t& pid) { MessageParcel data; MessageParcel reply; @@ -900,6 +900,7 @@ WMError SceneSessionManagerLiteProxy::CheckUIExtensionCreation( TLOGE(WmsLogTag::WMS_UIEXT, "UIExtOnLock: Failed to write interfaceToken"); return WMError::WM_ERROR_IPC_FAILED; } + if (!data.WriteInt32(windowId)) { TLOGE(WmsLogTag::WMS_UIEXT, "UIExtOnLock: Failed to write windowId"); return WMError::WM_ERROR_IPC_FAILED; @@ -914,15 +915,13 @@ WMError SceneSessionManagerLiteProxy::CheckUIExtensionCreation( sptr remote = Remote(); if (remote == nullptr) { - TLOGE(WmsLogTag::WMS_UIEXT, "UIExtOnLock: Failed to write tokenId"); + TLOGE(WmsLogTag::WMS_UIEXT, "remote is null"); return WMError::WM_ERROR_NULLPTR; } int32_t ret = remote->SendRequest(static_cast(SceneSessionManagerLiteMessage::TRANS_ID_UI_EXTENSION_CREATION_CHECK), - data, - reply, - option); + data, reply, option); if (ret != ERR_NONE) { TLOGE(WmsLogTag::WMS_UIEXT, "UIExtOnLock: Send request failed, ret:%{public}d", ret); return WMError::WM_ERROR_IPC_FAILED; diff --git a/window_scene/test/unittest/scene_session_manager_lite_stub_test.cpp b/window_scene/test/unittest/scene_session_manager_lite_stub_test.cpp index 70b71b72f0..40c712e561 100644 --- a/window_scene/test/unittest/scene_session_manager_lite_stub_test.cpp +++ b/window_scene/test/unittest/scene_session_manager_lite_stub_test.cpp @@ -198,8 +198,8 @@ class MockSceneSessionManagerLiteStub : public SceneSessionManagerLiteStub { { return nullptr; } - WMError CheckUIExtensionCreation(int32_t windowId, uint32_t tokenId, - const AppExecFwk::ElementName& element, int32_t& pid) override + WMError CheckUIExtensionCreation(int32_t windowId, uint32_t tokenId, const AppExecFwk::ElementName& element, + int32_t& pid) override { return WMError::WM_OK; } diff --git a/wmserver/include/zidl/window_manager_lite_interface.h b/wmserver/include/zidl/window_manager_lite_interface.h index f6ddbe0ce8..9b002b5a2b 100644 --- a/wmserver/include/zidl/window_manager_lite_interface.h +++ b/wmserver/include/zidl/window_manager_lite_interface.h @@ -40,8 +40,8 @@ public: virtual WMError GetVisibilityWindowInfo(std::vector>& infos) { return WMError::WM_OK; }; virtual void GetFocusWindowInfo(FocusChangeInfo& focusInfo) = 0; virtual WMError CheckWindowId(int32_t windowId, int32_t& pid) = 0; - virtual WMError CheckUIExtensionCreation( - int32_t windowId, uint32_t tokenId, const AppExecFwk::ElementName &element, int32_t &pid) = 0; + virtual WMError CheckUIExtensionCreation(int32_t windowId, uint32_t tokenId, const AppExecFwk::ElementName& element, + int32_t& pid) = 0; virtual WMError GetWindowModeType(WindowModeType& windowModeType) { return WMError::WM_OK; } virtual WMError GetMainWindowInfos(int32_t topNum, std::vector& topNInfo) = 0; virtual WMError GetAllMainWindowInfos(std::vector& infos) = 0; -- Gitee From 4370ee95b764e3eb25a735fe5d7d6ca3b1117fda Mon Sep 17 00:00:00 2001 From: rookiiie Date: Mon, 18 Nov 2024 11:43:37 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=E6=A3=80=E8=A7=86=E6=84=8F=E8=A7=81?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: rookiiie --- window_scene/session_manager/src/scene_session_manager.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index 09bd81bca5..1026efe885 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -197,10 +197,9 @@ bool IsUIExtCanShowOnLockScreen(const AppExecFwk::ElementName& element, uint32_t }; auto it = std::find_if(whitelist.begin(), whitelist.end(), [&element](const auto& item) { - auto& [bundleName, abilityName, moduleName] = item; + auto& [bundleName, abilityName, _] = item; return (element.GetBundleName() == bundleName && element.GetAbilityName() == abilityName); }); - if (it != whitelist.end()) { return true; } @@ -1450,7 +1449,7 @@ uint32_t SceneSessionManager::GetLockScreenZorder() { std::shared_lock lock(sceneSessionMapMutex_); for (auto& [persistentId, session] : sceneSessionMap_) { - if (persistentId && (session->GetWindowType() == WindowType::WINDOW_TYPE_KEYGUARD)) { + if (session && (session->GetWindowType() == WindowType::WINDOW_TYPE_KEYGUARD)) { TLOGI(WmsLogTag::WMS_UIEXT, "UIExtOnLock: found window %{public}d", persistentId); return session->GetZOrder(); } -- Gitee