diff --git a/interfaces/innerkits/wm/extension_window.h b/interfaces/innerkits/wm/extension_window.h index 31e9df126dec7a788aff298cad67a8b8f3a37d7f..c3a9f51e93df597f350c78c840a2e1b3fb3ddaa8 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 66192e95aac0776cd9a4e5e5e8e9c9abec3f724e..17c13533fac1d157309d247b35debf56a08319a6 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 9ccce07ab5ebcb1f465f78b39b52034e4a1e48f3..843e2e3053352d0ff413721678ad55ca16e87009 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 d2879b3b138742bd218306c88c381985ca6f2a33..cd50a4d4ff6def00a0e803f87baf14af659454c2 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 25cc1a7ed1028046fd480afa8e03b962130dffb3..06226561a4f4dd647d15b830240dfab8c243d61d 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 bce4a145ac87eb3274196b5af2c800d5a6f4263d..99ff521711f7841d3bc88cf04d7863d68251a4b1 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 992f717281773f6bfef7ff0f748e19b441782ac8..0adf087e203c2be5becdda59f8f6b2cbd7009a73 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 70428a5c3e189fa03e6c451dd6ab49d152882ec7..6ee097b96b68255f805b3249bee6a7156d9684e8 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 93f4e0372f02c7ebc479d634b04ce2c701500749..767f00a41752b70b15ecf9d94805f947408bd5ce 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 f70db7b5b2becbffa951f6ab888fe485cdf6a1e9..59fc5f7d5852088aca40db70497aad8c195251f9 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