diff --git a/frameworks/privacy/include/i_privacy_manager.h b/frameworks/privacy/include/i_privacy_manager.h index c375649469372c9b62afe98c69c163fdff72102a..a3780ce84e5ebbee891fa0dd8ac6cb2ad733109c 100644 --- a/frameworks/privacy/include/i_privacy_manager.h +++ b/frameworks/privacy/include/i_privacy_manager.h @@ -47,6 +47,7 @@ public: virtual int32_t RegisterPermActiveStatusCallback( std::vector& permList, const sptr& callback) = 0; virtual int32_t UnRegisterPermActiveStatusCallback(const sptr& callback) = 0; + virtual void StartPopupWindows() = 0; enum class InterfaceCode { ADD_PERMISSION_USED_RECORD = 0xf001, START_USING_PERMISSION, @@ -56,6 +57,7 @@ public: GET_PERMISSION_USED_RECORDS_ASYNC, REGISTER_PERM_ACTIVE_STATUS_CHANGE_CALLBACK, UNREGISTER_PERM_ACTIVE_STATUS_CHANGE_CALLBACK, + START_POPUP_WINDOWS, }; }; } // namespace AccessToken diff --git a/interfaces/innerkits/privacy/include/privacy_kit.h b/interfaces/innerkits/privacy/include/privacy_kit.h index 832a77b3abe3ebb53dca24d098b7c220f34b6675..635a92b16ba9450908d59dc1ccaa8a5fbf85a795 100644 --- a/interfaces/innerkits/privacy/include/privacy_kit.h +++ b/interfaces/innerkits/privacy/include/privacy_kit.h @@ -39,6 +39,7 @@ public: const PermissionUsedRequest& request, const sptr& callback); static int32_t RegisterPermActiveStatusCallback(const std::shared_ptr& callback); static int32_t UnRegisterPermActiveStatusCallback(const std::shared_ptr& callback); + static void StartPopupWindows(); }; } // namespace AccessToken } // namespace Security diff --git a/interfaces/innerkits/privacy/src/privacy_kit.cpp b/interfaces/innerkits/privacy/src/privacy_kit.cpp index 2d26151f6108367401ba56c324e87992c9626d0d..79e46611ebeaadbf6d8713369d27b5289f00d1ca 100644 --- a/interfaces/innerkits/privacy/src/privacy_kit.cpp +++ b/interfaces/innerkits/privacy/src/privacy_kit.cpp @@ -79,6 +79,11 @@ int32_t PrivacyKit::UnRegisterPermActiveStatusCallback(const std::shared_ptrStartPopupWindows(); +} + void PrivacyManagerClient::InitProxy() { std::lock_guard lock(proxyMutex_); diff --git a/interfaces/innerkits/privacy/src/privacy_manager_client.h b/interfaces/innerkits/privacy/src/privacy_manager_client.h index ce1dcfbd61dc8b071af55922acc4776dabb86f44..bfe8b40e695ad53c744b227a9fcffe459f9446c2 100644 --- a/interfaces/innerkits/privacy/src/privacy_manager_client.h +++ b/interfaces/innerkits/privacy/src/privacy_manager_client.h @@ -45,6 +45,7 @@ public: const PermissionUsedRequest& request, const sptr& callback); int32_t RegisterPermActiveStatusCallback(const std::shared_ptr& callback); int32_t UnRegisterPermActiveStatusCallback(const std::shared_ptr& callback); + void StartPopupWindows(); int32_t CreateActiveStatusChangeCbk( const std::shared_ptr& callback, sptr& callbackWrap); diff --git a/interfaces/innerkits/privacy/src/privacy_manager_proxy.cpp b/interfaces/innerkits/privacy/src/privacy_manager_proxy.cpp index 6e7f1125f328c50406790953cf1d59a3fe810065..6216d9e630ee0b91e1aa38f740463bf9f425efe9 100644 --- a/interfaces/innerkits/privacy/src/privacy_manager_proxy.cpp +++ b/interfaces/innerkits/privacy/src/privacy_manager_proxy.cpp @@ -273,6 +273,20 @@ int32_t PrivacyManagerProxy::UnRegisterPermActiveStatusCallback(const sptr& permList, const sptr& callback) override; int32_t UnRegisterPermActiveStatusCallback(const sptr& callback) override; + void StartPopupWindows() override; private: bool SendRequest(IPrivacyManager::InterfaceCode code, MessageParcel& data, MessageParcel& reply); diff --git a/services/privacymanager/include/sensitive/global_switch_change_callback.h b/services/privacymanager/include/sensitive/global_switch_change_callback.h new file mode 100644 index 0000000000000000000000000000000000000000..6c3976eb78114cab0b62211f02793b780e2bbaee --- /dev/null +++ b/services/privacymanager/include/sensitive/global_switch_change_callback.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef GLOBAL_SWITCH_CHANGE_CALLBACK_H +#define GLOBAL_SWITCH_CHANGE_CALLBACK_H + +namespace OHOS { +namespace Security { +namespace AccessToken { +typedef void (*OnGlobalSwitchChangeCallback)(const ResourceType& type, bool switchStatus); +class GlobalSwitchChangeCallback { +public: + static GlobalSwitchChangeCallback& GetInstance(); + GlobalSwitchChangeCallback(); + virtual ~GlobalSwitchChangeCallback(); + void OnGlobalSwitchChange(const ResourceType& type, bool switchStatus) override; + void SetCallback(OnGlobalSwitchChangeCallback callback); + OnGlobalSwitchChangeCallback GetCallback() const; + ResourceType GetType() const; +private: + OnGlobalSwitchChangeCallback callback_ = nullptr; + ResourceType type_ = INVALID; + bool switchStatus_ = false; +}; +} // namespace AccessToken +} // namespace Security +} // namespace OHOS +#endif // GLOBAL_SWITCH_CHANGE_CALLBACK_H \ No newline at end of file diff --git a/services/privacymanager/include/sensitive/sensitive_resource_manager.h b/services/privacymanager/include/sensitive/sensitive_resource_manager.h index 80f91eb57ec6caf95169690173b7eb38a717e42a..2cdacce535ac2440f8c5ddede1979b7a03cb38da 100644 --- a/services/privacymanager/include/sensitive/sensitive_resource_manager.h +++ b/services/privacymanager/include/sensitive/sensitive_resource_manager.h @@ -44,7 +44,7 @@ public: // register and unregister app status change callback bool RegisterAppStatusChangeCallback(uint32_t tokenId, OnAppStatusChangeCallback callback); bool UnRegisterAppStatusChangeCallback(uint32_t tokenId, OnAppStatusChangeCallback callback); - + void StartPopupWindows(); private: bool InitProxy(); OHOS::sptr GetAppManagerProxy(); diff --git a/services/privacymanager/include/service/privacy_manager_service.h b/services/privacymanager/include/service/privacy_manager_service.h index ddbbe7ac2ca896cf62befe06156b2777c7420974..1a9a8399496d8c92a2f985de26e836969438f688 100644 --- a/services/privacymanager/include/service/privacy_manager_service.h +++ b/services/privacymanager/include/service/privacy_manager_service.h @@ -48,7 +48,7 @@ public: int32_t RegisterPermActiveStatusCallback( std::vector& permList, const sptr& callback) override; int32_t UnRegisterPermActiveStatusCallback(const sptr& callback) override; - + void StartPopupWindows() override; private: bool Initialize() const; diff --git a/services/privacymanager/include/service/privacy_manager_stub.h b/services/privacymanager/include/service/privacy_manager_stub.h index 0151ca494e37133ed55acc26f43a6526d9f447b3..af57abcc89b05d10b2e83b4b66aaae1e79c4fb6a 100644 --- a/services/privacymanager/include/service/privacy_manager_stub.h +++ b/services/privacymanager/include/service/privacy_manager_stub.h @@ -40,6 +40,7 @@ private: void GetPermissionUsedRecordsAsyncInner(MessageParcel& data, MessageParcel& reply); void RegisterPermActiveStatusCallbackInner(MessageParcel& data, MessageParcel& reply); void UnRegisterPermActiveStatusCallbackInner(MessageParcel& data, MessageParcel& reply); + void StartPopupWindowsInner(MessageParcel& data, MessageParcel& reply); bool IsAccessTokenCalling() const; bool VerifyPermission(const std::string& permission) const; static const int32_t ACCESSTOKEN_UID = 3020; diff --git a/services/privacymanager/src/sensitive/global_switch_change_callback.cpp b/services/privacymanager/src/sensitive/global_switch_change_callback.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c4e637c758a402ed1770348c53a99fc0b1fc2b22 --- /dev/null +++ b/services/privacymanager/src/sensitive/global_switch_change_callback.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "global_switch_change_callback.h" +#include "accesstoken_log.h" + +namespace OHOS { +namespace Security { +namespace AccessToken { +namespace { +static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { + LOG_CORE, SECURITY_DOMAIN_PRIVACY, "GlobalSwitchChangeCallback" +}; +} + +GlobalSwitchChangeCallback& GlobalSwitchChangeCallback::GetInstance() +{ + static GlobalSwitchChangeCallback instance; + return instance; +} + +GlobalSwitchChangeCallback::GlobalSwitchChangeCallback() +{ +} + +GlobalSwitchChangeCallback::~GlobalSwitchChangeCallback() +{ +} + +void GlobalSwitchChangeCallback::OnGlobalSwitchChange(const ResourceType& type, bool switchStatus) +{ + ACCESSTOKEN_LOG_INFO(LABEL, "OnChange(type=%{public}d, switchStatus=%{public}d)", type, switchStatus); + + if (callback_ != nullptr) { + callback_(type, switchStatus); + } +} + +void GlobalSwitchChangeCallback::SetCallback(OnGlobalSwitchChangeCallback callback) +{ + callback_ = callback; +} + +OnGlobalSwitchChangeCallback GlobalSwitchChangeCallback::GetCallback() const +{ + return callback_; +} + +ResourceType GlobalSwitchChangeCallback::GetType() const +{ + return type_; +} +} // namespace AccessToken +} // namespace Security +} // namespace OHOS \ No newline at end of file diff --git a/services/privacymanager/src/sensitive/sensitive_resource_manager.cpp b/services/privacymanager/src/sensitive/sensitive_resource_manager.cpp index b53b061ab72628d779ca72517dfccaa3bfdbb233..e0a92ff9fd4421da0de88ed0f39b4d7c6602495d 100644 --- a/services/privacymanager/src/sensitive/sensitive_resource_manager.cpp +++ b/services/privacymanager/src/sensitive/sensitive_resource_manager.cpp @@ -15,10 +15,13 @@ #include "sensitive_resource_manager.h" #include +#include "ability_manager_client.h" #include "accesstoken_log.h" #include "active_change_response_info.h" -#include "iservice_registry.h" +#include "iservice_registry.h" #include "system_ability_definition.h" +#include "window_manager.h" +#include "global_switch_change_callback.h" namespace OHOS { namespace Security { @@ -182,6 +185,23 @@ bool SensitiveResourceManager::UnRegisterAppStatusChangeCallback(uint32_t tokenI return true; } + +void SensitiveResourceManager::StartPopupWindows() +{ + ResourceType type = GlobalSwitchChangeCallback::GetInstance().GetType(); + AAFwk::Want want; + want.SetElementName(PERMISSION_MANAGER_BUNDLE_NAME, PERMISSION_MANAGER_DIALOG_ABILITY); + std::vector bundleName; + bundleName.emplace_back("test"); + want.SetParam(CALLER_BUNDLE_NAME_KEY, bundleName); + want.SetParam(RESOURCE_KEY, type); + ErrCode err = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want, nullptr); + if (err != ERR_OK) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Fail to StartAbility, err:%{public}d", err); + return; + } + return; +} } // namespace AccessToken } // namespace Security } // namespace OHOS \ No newline at end of file diff --git a/services/privacymanager/src/service/privacy_manager_service.cpp b/services/privacymanager/src/service/privacy_manager_service.cpp index c8bef113b040e43a5d24d8485adbd65158fc481b..d30834ba8377789d312981f379af47de7a1b5c06 100644 --- a/services/privacymanager/src/service/privacy_manager_service.cpp +++ b/services/privacymanager/src/service/privacy_manager_service.cpp @@ -20,6 +20,7 @@ #include "constant.h" #include "ipc_skeleton.h" #include "permission_record_manager.h" +#include "sensitive_resource_manager.h" namespace OHOS { namespace Security { @@ -118,6 +119,11 @@ int32_t PrivacyManagerService::UnRegisterPermActiveStatusCallback(const sptr(IPrivacyManager::InterfaceCode::UNREGISTER_PERM_ACTIVE_STATUS_CHANGE_CALLBACK): UnRegisterPermActiveStatusCallbackInner(data, reply); break; + case static_cast(IPrivacyManager::InterfaceCode::START_POPUP_WINDOWS): + StartPopupWindowsInner(data, reply); + break; default: return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } @@ -203,6 +206,15 @@ void PrivacyManagerStub::UnRegisterPermActiveStatusCallbackInner(MessageParcel& reply.WriteInt32(result); } +void PrivacyManagerStub::StartPopupWindowsInner(MessageParcel& data, MessageParcel& reply) +{ + if (!VerifyPermission(PERMISSION_USED_STATS)) { + reply.WriteInt32(RET_FAILED); + return; + } + this->StartPopupWindows(); +} + bool PrivacyManagerStub::IsAccessTokenCalling() const { int32_t callingUid = IPCSkeleton::GetCallingUid();