From 6731df766c00b5c81146fc38fa19142da27f5371 Mon Sep 17 00:00:00 2001 From: rookiiie Date: Wed, 16 Oct 2024 22:26:03 +0800 Subject: [PATCH] =?UTF-8?q?UIExtension=E6=8F=90=E4=BE=9B=E6=96=B9=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E8=AE=BE=E7=BD=AE=E7=BB=84=E4=BB=B6=E6=88=96=E8=80=85?= =?UTF-8?q?=E7=AA=97=E5=8F=A3=E6=88=AA=E5=9B=BE=E9=9A=90=E7=A7=81=E4=BF=9D?= =?UTF-8?q?=E6=8A=A4=E7=9A=84=E8=83=BD=E5=8A=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: rookiiie --- interfaces/innerkits/wm/extension_window.h | 2 + interfaces/innerkits/wm/window.h | 11 +++++ .../napi/extension_window/extension_window.js | 4 ++ .../extension_window/js_extension_window.cpp | 47 +++++++++++++++++++ .../extension_window/js_extension_window.h | 3 ++ wm/include/extension_window_impl.h | 1 + wm/include/window_extension_session_impl.h | 6 +++ wm/src/extension_window_impl.cpp | 7 +++ wm/src/window_extension_session_impl.cpp | 26 ++++++++++ .../window_extension_session_impl_test.cpp | 10 ++++ 10 files changed, 117 insertions(+) diff --git a/interfaces/innerkits/wm/extension_window.h b/interfaces/innerkits/wm/extension_window.h index 31e9df126d..c3a9f51e93 100644 --- a/interfaces/innerkits/wm/extension_window.h +++ b/interfaces/innerkits/wm/extension_window.h @@ -35,6 +35,8 @@ public: virtual WMError HideNonSecureWindows(bool shouldHide) = 0; virtual WMError SetWaterMarkFlag(bool isEnable) = 0; + + virtual WMError HidePrivacyContentForHost(bool needHide) = 0; }; } // namespace Rosen } // namespace OHOS diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index 66192e95aa..17c13533fa 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -2069,6 +2069,17 @@ public: return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; } + /** + * @brief Hide the display content when snapshot. + * + * @param needHide bool. + * @return WMError + */ + virtual WMError HidePrivacyContentForHost(bool needHide) + { + return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; + } + /** * @brief Set the modality of window. * diff --git a/interfaces/kits/napi/extension_window/extension_window.js b/interfaces/kits/napi/extension_window/extension_window.js index 9ccce07ab5..843e2e3053 100644 --- a/interfaces/kits/napi/extension_window/extension_window.js +++ b/interfaces/kits/napi/extension_window/extension_window.js @@ -48,6 +48,10 @@ class ExtensionWindow { setWaterMarkFlag(type, callback) { return this.__extension_window__.setWaterMarkFlag(type, callback); } + + hidePrivacyContentForHost(type, callback) { + return this.__extension_window__.hidePrivacyContentForHost(type, callback); + } } export default ExtensionWindow; diff --git a/interfaces/kits/napi/extension_window/js_extension_window.cpp b/interfaces/kits/napi/extension_window/js_extension_window.cpp index d2879b3b13..cd50a4d4ff 100644 --- a/interfaces/kits/napi/extension_window/js_extension_window.cpp +++ b/interfaces/kits/napi/extension_window/js_extension_window.cpp @@ -76,6 +76,8 @@ napi_value JsExtensionWindow::CreateJsExtensionWindow(napi_env env, sptrOnSetWaterMarkFlag(env, info) : nullptr; } +napi_value JsExtensionWindow::HidePrivacyContentForHost(napi_env env, napi_callback_info info) +{ + TLOGI(WmsLogTag::WMS_UIEXT, "enter"); + JsExtensionWindow* me = CheckParamsAndGetThis(env, info); + return (me != nullptr) ? me->OnHidePrivacyContentForHost(env, info) : nullptr; +} + napi_value JsExtensionWindow::LoadContent(napi_env env, napi_callback_info info) { TLOGI(WmsLogTag::WMS_UIEXT, "LoadContent is called"); @@ -837,6 +846,44 @@ napi_value JsExtensionWindow::OnSetWaterMarkFlag(napi_env env, napi_callback_inf return NapiGetUndefined(env); } +napi_value JsExtensionWindow::OnHidePrivacyContentForHost(napi_env env, napi_callback_info info) +{ + if (extensionWindow_ == nullptr) { + TLOGE(WmsLogTag::WMS_UIEXT, "extension window is nullptr"); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + } + + sptr windowImpl = extensionWindow_->GetWindow(); + if (windowImpl == nullptr) { + TLOGE(WmsLogTag::WMS_UIEXT, "windowImpl is nullptr"); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + } + + size_t argc = 4; + napi_value argv[4] = {nullptr}; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + if (argc < 1) { + TLOGE(WmsLogTag::WMS_UIEXT, "Argc is invalid: %{public}zu", argc); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + } + + bool needHide = false; + if (!ConvertFromJsValue(env, argv[0], needHide)) { + TLOGE(WmsLogTag::WMS_UIEXT, "Failed to convert parameter to bool"); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + } + + auto ret = WM_JS_TO_ERROR_CODE_MAP.at(extensionWindow_->HidePrivacyContentForHost(needHide)); + if (ret != WmErrorCode::WM_OK) { + return NapiThrowError(env, ret); + } + + TLOGI(WmsLogTag::WMS_UIEXT, "finished, window [%{public}u, %{public}s], needHide:%{public}u.", + windowImpl->GetWindowId(), windowImpl->GetWindowName().c_str(), needHide); + + return NapiGetUndefined(env); +} + napi_value JsExtensionWindow::GetProperties(napi_env env, napi_callback_info info) { TLOGI(WmsLogTag::WMS_UIEXT, "GetProperties is called"); diff --git a/interfaces/kits/napi/extension_window/js_extension_window.h b/interfaces/kits/napi/extension_window/js_extension_window.h index 25cc1a7ed1..06226561a4 100644 --- a/interfaces/kits/napi/extension_window/js_extension_window.h +++ b/interfaces/kits/napi/extension_window/js_extension_window.h @@ -59,6 +59,8 @@ public: static napi_value SetWindowKeepScreenOn(napi_env env, napi_callback_info info); static napi_value CreateSubWindowWithOptions(napi_env env, napi_callback_info info); static napi_value SetWaterMarkFlag(napi_env env, napi_callback_info info); + static napi_value HidePrivacyContentForHost(napi_env env, napi_callback_info info); + private: napi_value OnGetWindowAvoidArea(napi_env env, napi_callback_info info); napi_value OnRegisterExtensionWindowCallback(napi_env env, napi_callback_info info); @@ -80,6 +82,7 @@ private: napi_value OnSetWindowBrightness(napi_env env, napi_callback_info info); napi_value OnSetWindowKeepScreenOn(napi_env env, napi_callback_info info); napi_value OnSetWaterMarkFlag(napi_env env, napi_callback_info info); + napi_value OnHidePrivacyContentForHost(napi_env env, napi_callback_info info); napi_value OnCreateSubWindowWithOptions(napi_env env, napi_callback_info info); diff --git a/wm/include/extension_window_impl.h b/wm/include/extension_window_impl.h index bce4a145ac..99ff521711 100644 --- a/wm/include/extension_window_impl.h +++ b/wm/include/extension_window_impl.h @@ -32,6 +32,7 @@ public: sptr GetWindow() override; WMError HideNonSecureWindows(bool shouldHide) override; WMError SetWaterMarkFlag(bool isEnable) override; + WMError HidePrivacyContentForHost(bool needHide) override; private: sptr windowExtensionSessionImpl_; diff --git a/wm/include/window_extension_session_impl.h b/wm/include/window_extension_session_impl.h index 992f717281..0adf087e20 100644 --- a/wm/include/window_extension_session_impl.h +++ b/wm/include/window_extension_session_impl.h @@ -48,7 +48,13 @@ public: void RegisterTransferComponentDataForResultListener( const NotifyTransferComponentDataForResultFunc& func) override; void TriggerBindModalUIExtension() override; + + /* + * Window Privacy + */ WMError SetPrivacyMode(bool isPrivacyMode) override; + WMError HidePrivacyContentForHost(bool needHide) override; + WMError NapiSetUIContent(const std::string& contentInfo, napi_env env, napi_value storage, BackupAndRestoreType type, sptr token, AppExecFwk::Ability* ability) override; void SetUniqueVirtualPixelRatio(bool useUniqueDensity, float virtualPixelRatio) override {} diff --git a/wm/src/extension_window_impl.cpp b/wm/src/extension_window_impl.cpp index 70428a5c3e..6ee097b96b 100644 --- a/wm/src/extension_window_impl.cpp +++ b/wm/src/extension_window_impl.cpp @@ -51,5 +51,12 @@ WMError ExtensionWindowImpl::SetWaterMarkFlag(bool isEnable) TLOGI(WmsLogTag::WMS_UIEXT, "SetWaterMarkFlag is called"); return windowExtensionSessionImpl_->SetWaterMarkFlag(isEnable); } + +WMError ExtensionWindowImpl::HidePrivacyContentForHost(bool needHide) +{ + TLOGI(WmsLogTag::WMS_UIEXT, "enter"); + return windowExtensionSessionImpl_->HidePrivacyContentForHost(needHide); +} + } // namespace Rosen } // namespace OHOS diff --git a/wm/src/window_extension_session_impl.cpp b/wm/src/window_extension_session_impl.cpp index 93f4e0372f..767f00a417 100644 --- a/wm/src/window_extension_session_impl.cpp +++ b/wm/src/window_extension_session_impl.cpp @@ -338,6 +338,32 @@ WMError WindowExtensionSessionImpl::SetPrivacyMode(bool isPrivacyMode) return ret; } +WMError WindowExtensionSessionImpl::HidePrivacyContentForHost(bool needHide) +{ + auto persistentId = GetPersistentId(); + std::stringstream ss; + ss << "ID: " << persistentId << ", needHide: " << needHide; + + if (surfaceNode_ == nullptr) { + TLOGI(WmsLogTag::WMS_UIEXT, "surfaceNode is null, %{public}s", ss.str().c_str()); + return WMError::WM_ERROR_NULLPTR; + } + + // Let rs guarantee the security and permissions of the interface + auto errCode = surfaceNode_->SetHidePrivacyContent(needHide); + TLOGI(WmsLogTag::WMS_UIEXT, "Notify Render Service client finished, %{public}s, err: %{public}u", ss.str().c_str(), + errCode); + if (errCode == RSInterfaceErrorCode::NONSYSTEM_CALLING) { // not system app calling + return WMError::WM_ERROR_NOT_SYSTEM_APP; + } else if (errCode != RSInterfaceErrorCode::NO_ERROR) { // other error + return WMError::WM_ERROR_SYSTEM_ABNORMALLY; + } else { // notify Render Service ok + TLOGI(WmsLogTag::WMS_UIEXT, "finished, %{public}s", ss.str().c_str()); + } + + return WMError::WM_OK; +} + void WindowExtensionSessionImpl::NotifyFocusStateEvent(bool focusState) { if (auto uiContent = GetUIContentSharedPtr()) { diff --git a/wm/test/unittest/window_extension_session_impl_test.cpp b/wm/test/unittest/window_extension_session_impl_test.cpp index f70db7b5b2..59fc5f7d58 100644 --- a/wm/test/unittest/window_extension_session_impl_test.cpp +++ b/wm/test/unittest/window_extension_session_impl_test.cpp @@ -592,6 +592,16 @@ HWTEST_F(WindowExtensionSessionImplTest, SetPrivacyMod05, Function | SmallTest | ASSERT_NE(WMError::WM_OK, window_->SetPrivacyMode(true)); } +HWTEST_F(WindowExtensionSessionImplTest, HidePrivacyContentForHost, Function | SmallTest | Level3) +{ + struct RSSurfaceNodeConfig config; + window_->surfaceNode_ = RSSurfaceNode::Create(config); + SessionInfo sessionInfo; + window_->hostSession_ = new (std::nothrow) SessionMocker(sessionInfo); + ASSERT_NE(nullptr, window_->hostSession_); + ASSERT_NE(WMError::WM_OK, window_->HidePrivacyContentForHost(true)); +} + /** * @tc.name: NotifyFocusStateEvent01 * @tc.desc: NotifyFocusStateEvent Test -- Gitee