diff --git a/BUILD.gn b/BUILD.gn index f2f0f0befcebec4bbf9bcadac510a212e03e2508..455086d1637f31292256a417b1a455d6531ac7c8 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -24,6 +24,7 @@ group("accesstoken_build_module_test") { "//base/security/access_token/interfaces/innerkits/privacy/test:unittest", "//base/security/access_token/interfaces/innerkits/token_setproc/test:unittest", "//base/security/access_token/services/accesstokenmanager/test:unittest", + "//base/security/access_token/services/privacymanager/test:unittest", ] } if (token_sync_enable == true) { diff --git a/frameworks/privacy/BUILD.gn b/frameworks/privacy/BUILD.gn index e0106a79d2849a5394bd962dd8c177b0bba4b6f4..0104023ca9147968e715a6af1f95ccc4a6d7d3f1 100644 --- a/frameworks/privacy/BUILD.gn +++ b/frameworks/privacy/BUILD.gn @@ -34,6 +34,4 @@ ohos_shared_library("privacy_communication_adapter_cxx") { ] deps = [ "//utils/native/base:utils" ] - - external_deps = [ "ipc:ipc_core" ] } diff --git a/services/privacymanager/BUILD.gn b/services/privacymanager/BUILD.gn index 5d00d6c6548f26200e0d992ec0c9d823725763ab..ce8afb375a3083536a1c344fe32c5922d56caa27 100644 --- a/services/privacymanager/BUILD.gn +++ b/services/privacymanager/BUILD.gn @@ -29,6 +29,7 @@ if (is_standard_system) { "include/common", "include/database", "include/record", + "include/sensitive", "include/service", "//base/security/access_token/frameworks/privacy/include", "//base/security/access_token/frameworks/common/include", @@ -51,6 +52,7 @@ if (is_standard_system) { "src/record/permission_record_repository.cpp", "src/record/permission_visitor.cpp", "src/record/permission_visitor_repository.cpp", + "src/sensitive/global_switch_manager.cpp", "src/service/privacy_manager_service.cpp", "src/service/privacy_manager_stub.cpp", ] @@ -63,11 +65,17 @@ if (is_standard_system) { "//base/security/access_token/interfaces/innerkits/accesstoken:libaccesstoken_sdk", "//base/security/access_token/services/common/database:accesstoken_database_cxx", "//base/security/access_token/services/privacymanager:privacy.rc", + "//base/security/access_token/services/privacymanager/dialog_ui:dialog_js_files_etc", + "//foundation/arkui/ace_engine/interfaces/inner_api/ui_service_manager:ui_service_mgr", "//third_party/sqlite:sqlite", "//utils/native/base:utils", ] external_deps = [ + "ability_base:want", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "hiviewdfx_hilog_native:libhilog", "hiviewdfx_hilog_native:libhilog", "init:libbegetutil", "ipc:ipc_core", diff --git a/services/privacymanager/dialog_ui/BUILD.gn b/services/privacymanager/dialog_ui/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..0668d56455dd3c0396f2c221bf796e063591cb22 --- /dev/null +++ b/services/privacymanager/dialog_ui/BUILD.gn @@ -0,0 +1,27 @@ +# 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. + +import("//base/notification/distributed_notification_service/notification.gni") +import("//foundation/arkui/ace_engine/build/ace_gen_sa_dialog_js.gni") + +gen_sa_dialog_js("dialog_js_files_etc") { + project_path = "//base/security/access_token/services/privacymanager/dialog_ui/" + i18n_files = [ + "i18n/en-US.json", + "i18n/zh-CN.json", + ] + common_files = [] + dialog_name = "global_switch_dialog" + subsystem_name = "security" + part_name = "access_token" +} diff --git a/services/privacymanager/dialog_ui/common/.gitkeep b/services/privacymanager/dialog_ui/common/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/services/privacymanager/dialog_ui/i18n/en-US.json b/services/privacymanager/dialog_ui/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..c5ec0165bab1fe1081e50b8f68a95fb123f725b2 --- /dev/null +++ b/services/privacymanager/dialog_ui/i18n/en-US.json @@ -0,0 +1,7 @@ +{ + "message":{ + "request": "Allowed to send notification?", + "allowButton": "Allow", + "cancelButton": "Cancel" + } +} diff --git a/services/privacymanager/dialog_ui/i18n/zh-CN.json b/services/privacymanager/dialog_ui/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..e0d70632552bddbbfa8dda5dffb111e63841b4a1 --- /dev/null +++ b/services/privacymanager/dialog_ui/i18n/zh-CN.json @@ -0,0 +1,7 @@ +{ + "message": { + "request": "正在申请开启本机摄像头功能", + "allowButton": "开启", + "cancelButton": "拒绝" + } +} diff --git a/services/privacymanager/dialog_ui/pages/index/index.css b/services/privacymanager/dialog_ui/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..727c1ea7124c62f566b86c2d1d7db1f0ee210464 --- /dev/null +++ b/services/privacymanager/dialog_ui/pages/index/index.css @@ -0,0 +1,86 @@ +/* + * 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. + */ + + .container { + height: 100%; + width: 100%; + position: relative; + display: flex; + justify-content: center; + align-items: center; +} + +.global-dialog { + width: 397vp; + height: 117vp; + border-radius: 32vp; + align-items: center; + background-color: rgba(255, 255, 255, 1); + display: flex; + flex-direction: column; + box-shadow: 2vp 2vp 2vp #888888; +} + +.title-bar { + width: 100%; + height: 34vp; + font-size: 14fp; + font-weight: 400; + word-break: break-word; + text-color: #182431; + opacity: 1; + text-align: center; + margin-top: 24vp; + font-family: 'HarmonyHeiTi'; +} + +.btn-group { + align-items: center; + flex-direction: row; + display: flex; + justify-content: center; +} + +.btn-inner { + width: 116vp; + height: 40vp; + margin: 16vp 4vp 16vp 4.5vp; + align-items: center; +} + +.btn { + width: 100vp; + height: 22vp; + font-size: 16fp; + background-color: rgba(255, 255, 255, 1); + text-color: #0d81f2; + line-height: 22vp; + font-weight: 500; + margin: 9vp 8vp; +} + +.split { + width: 0.5vp; + height: 24vp; + background-color: rgba(0, 0, 0, 0.2); + align-self: center; +} + +.center { + position: relative; + display: flex; + justify-content: center; + align-items: center; +} diff --git a/services/privacymanager/dialog_ui/pages/index/index.hml b/services/privacymanager/dialog_ui/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..c0d544e8cce0fc6f68ac8646af90efcba52c7ce4 --- /dev/null +++ b/services/privacymanager/dialog_ui/pages/index/index.hml @@ -0,0 +1,43 @@ + + +
+ + + + {{ prompt }} + + + + +
+ +
+
+ +
+
+ +
+ +
+
+
+
+
diff --git a/services/privacymanager/dialog_ui/pages/index/index.js b/services/privacymanager/dialog_ui/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..e5983709c5aa5ca7882d81679abccd4f9bb6d39f --- /dev/null +++ b/services/privacymanager/dialog_ui/pages/index/index.js @@ -0,0 +1,38 @@ +/* + * 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. + */ + +import router from '@ohos.router' + +export default { + data: { + prompt: '', + allowButton: '', + cancelButton: '', + }, + onInit() { + console.info('getParams: ' + JSON.stringify(router.getParams())); + this.prompt = router.getParams()['bundleName'] + this.$t("message.request") + '?' + this.allowButton = this.$t('message.allowButton'); + this.cancelButton = this.$t('message.cancelButton'); + }, + onAllow() { + console.info('clicked allow'); + callNativeHandler("EVENT_ALLOW", "allow"); + }, + onCancel() { + console.info('clicked cancel'); + callNativeHandler("EVENT_CANCEL", "cancel"); + }, +} diff --git a/services/privacymanager/include/sensitive/application_status_change_callback.h b/services/privacymanager/include/sensitive/application_status_change_callback.h new file mode 100644 index 0000000000000000000000000000000000000000..b8d0be5713d6f592c6637d0afaff5d4f16b84e12 --- /dev/null +++ b/services/privacymanager/include/sensitive/application_status_change_callback.h @@ -0,0 +1,34 @@ +/* + * 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 APPLICATION_STATUS_CHANGE_CALLBACK_H +#define APPLICATION_STATUS_CHANGE_CALLBACK_H + +#include "iapplication_state_observer.h" + +namespace OHOS { +namespace Security { +namespace AccessToken { +class ApplicationStatusChangeCallback : public IApplicationStateObserver { +public: + void OnForegroundApplicationChange(const AppStateData& appStateData) override; + void OnProcessDied(const ProcesData& processData) override; + uint32_t tokenId_ = 0; + int32_t state = 0; +}; +} // namespace AccessToken +} // namespace Security +} // namespace OHOS +#endif // APPLICATION_STATUS_CHANGE_CALLBACK_H diff --git a/services/privacymanager/include/sensitive/camera_float_window_change_callback.h b/services/privacymanager/include/sensitive/camera_float_window_change_callback.h new file mode 100644 index 0000000000000000000000000000000000000000..54ff119c01fb1571d0b6eb6c16f987948cc48c40 --- /dev/null +++ b/services/privacymanager/include/sensitive/camera_float_window_change_callback.h @@ -0,0 +1,33 @@ +/* + * 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 CAMERA_FLOAT_WINDOW_CALLBACK_H +#define CAMERA_FLOAT_WINDOW_CALLBACK_H + +#include "window_manager.h" + +namespace OHOS { +namespace Security { +namespace AccessToken { +class CameraFloatWindowChangeCallback : public Rosen::ICameraFloatWindowChangedListener { +public: + void OnCameraFloatWindowChange(uint32_t accessTokenId, bool isShowing) override; + uint32_t tokenId_ = 0; + bool isShow_ = false; +}; +} // namespace AccessToken +} // namespace Security +} // namespace OHOS +#endif // CAMERA_FLOAT_WINDOW_CALLBACK_H 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..c4f4343aaec9d624e0fe9d5e95e3839c1db4b0e9 --- /dev/null +++ b/services/privacymanager/include/sensitive/global_switch_change_callback.h @@ -0,0 +1,34 @@ +/* + * 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 { +class CameraSwitchChangeCallback { +public: + +}; + +class AudioSwitchChangeCallback { +public: + +}; +} // namespace AccessToken +} // namespace Security +} // namespace OHOS +#endif // GLOBAL_SWITCH_CHANGE_CALLBACK_H diff --git a/services/privacymanager/include/sensitive/resource_manager.h b/services/privacymanager/include/sensitive/resource_manager.h new file mode 100644 index 0000000000000000000000000000000000000000..30cb861bc3d8f20e9464eab334c10181d2d8f5fc --- /dev/null +++ b/services/privacymanager/include/sensitive/resource_manager.h @@ -0,0 +1,78 @@ +/* + * 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 RESOURCE_MANAGER_H +#define RESOURCE_MANAGER_H + +#include +#include +#include +#include "camera_float_window_change_callback.h" + +namespace OHOS { +namespace Security { +namespace AccessToken { +enum AppStatus { + APP_CREATE = 0, + APP_DIE, + APP_FOREGROUND, + APP_BACKGROUND, +}; +enum ResourceType { + CAMERA = 0, + MICROPHONE, +}; +typedef void (*OnAppStatusChangeCallback)(uint32_t tokenId, AppStatus status); +typedef void (*OnCameraFloatWindowChangeCallback)(uint32_t tokenId, bool isShowing); +using CameraFloatWindowChangeCallbackMap = + std::map>; +class ResourceManager final { +public: + static ResourceManager& GetInstance(); + virtual ~ResourceManager(); + + void Init(); + bool GetGlobalSwitch(const ResourceType& type); + bool IsAllowedRequest(uint32_t tokenId, const ResourceType& type); + + // 前后台监听 + void RegisterAppStatusChangeCallback(uint32_t tokenId, OnAppStatusChangeCallback callback); + void UnRegisterAppStatusChangeCallback(uint32_t tokenId, OnAppStatusChangeCallback callback); + + // camera float window + void RegisterCameraFloatWindowChangeCallback(OnCameraFloatWindowChangeCallback callback); + void UnRegisterCameraFloatWindowChangeCallback(OnCameraFloatWindowChangeCallback callback); + + bool ShowDialog(const ResourceType& type); +public: + void NotifyAppStatusChange(uint32_t tokenId, AppStatus status); + void NotifyFloatWindowChange(uint32_t tokenId, bool isShowing); + void NotifyGlobalSwitchChange(const ResourceType& type, bool status); + +private: + std::mutex switchStatusMutex_; + std::map switchStatusMap_; + + std::mutex appStatusMutex_; + std::map appStatusCallbackMap_; + + std::mutex cameraFloatWindowMutex_; + CameraFloatWindowChangeCallbackMap cameraFloatWindowCallbacks_; + int32_t dialogId_ = -1; +}; +} // namespace AccessToken +} // namespace Security +} // namespace OHOS +#endif // RESOURCE_MANAGER_H diff --git a/services/privacymanager/src/sensitive/application_status_change_callback.cpp b/services/privacymanager/src/sensitive/application_status_change_callback.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c58f894b00f1d14c258deb6a7866786364ee1c70 --- /dev/null +++ b/services/privacymanager/src/sensitive/application_status_change_callback.cpp @@ -0,0 +1,52 @@ +/* + * 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 "application_status_change_callback.h" +#include "accesstoken_log.h" +#include "resource_manager.h" + +namespace OHOS { +namespace Security { +namespace AccessToken { +namespace { +static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { + LOG_CORE, SECURITY_DOMAIN_PRIVACY, "ApplicationStatusChangeCallback" +}; +} + +AppStatus ApplicationStatusChangeCallback::GetAppStatue(int state) +{ + // TODOҪstate + return APP_FOREGROUND; +} + +void ApplicationStatusChangeCallback::OnForegroundApplicationChange(const AppStateData& appStateData) + ACCESSTOKEN_LOG_INFO(LABEL, "OnChange(bundleName=%{public}s, uid=%{public}d, state=%{public}d)", + appStateData.bundleName.c_str(), appStateData.uid, appStateData.state); + + uint32_t tokenId = 0; // TODOݱȡtokenId + ResourceManager::GetInstance().NotifyAppStatusChange(tokenId, GetAppStatue(appStateData.state)); +} + +void ApplicationStatusChangeCallback::OnProcessDied(const ProcesData& processData) + ACCESSTOKEN_LOG_INFO(LABEL, "OnChange(bundleName=%{public}s, uid=%{public}d, pid=%{public}d)", + processData.bundleName.c_str(), processData.uid, processData.pid); + + uint32_t tokenId = 0; // TODOݱȡtokenId + ResourceManager::GetInstance().NotifyAppStatusChange(tokenId, APP_DIE); +} +} // namespace AccessToken +} // namespace Security +} // namespace OHOS \ No newline at end of file diff --git a/services/privacymanager/src/sensitive/camera_float_window_change_callback.cpp b/services/privacymanager/src/sensitive/camera_float_window_change_callback.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c8a915bce8a81c448465c5c215bb8d64aa0cd0e1 --- /dev/null +++ b/services/privacymanager/src/sensitive/camera_float_window_change_callback.cpp @@ -0,0 +1,37 @@ +/* + * 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 "camera_float_window_change_callback.h" +#include "accesstoken_log.h" +#include "resource_manager.h" + +namespace OHOS { +namespace Security { +namespace AccessToken { +namespace { +static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { + LOG_CORE, SECURITY_DOMAIN_PRIVACY, "CameraFloatWindowChangeCallback" +}; +} + +void CameraFloatWindowChangeCallback::OnCameraFloatWindowChange(uint32_t accessTokenId, bool isShowing) +{ + ACCESSTOKEN_LOG_INFO(LABEL, "OnChange(tokenId=%{public}d, isShow=%{public}d)", accessTokenId, isShowing); + + ResourceManager::GetInstance().NotifyFloatWindowChange(accessTokenId, isShowing); +} +} // namespace AccessToken +} // namespace Security +} // namespace OHOS \ No newline at end of file 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..833f4f639c4e2ec307527d517fa3fe6c93f18318 --- /dev/null +++ b/services/privacymanager/src/sensitive/global_switch_change_callback.cpp @@ -0,0 +1,30 @@ +/* + * 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, "AudioSwitchChangeCallback" +}; +} + +} // namespace AccessToken +} // namespace Security +} // namespace OHOS \ No newline at end of file diff --git a/services/privacymanager/src/sensitive/resource_manager.cpp b/services/privacymanager/src/sensitive/resource_manager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f57dcbf37fddd22718de127ba9916628fc54b1b3 --- /dev/null +++ b/services/privacymanager/src/sensitive/resource_manager.cpp @@ -0,0 +1,167 @@ +/* + * 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 "resource_manager.h" +#include "accesstoken_log.h" +#include "ui_service_mgr_client.h" +#include "window_manager.h" + +namespace OHOS { +namespace Security { +namespace AccessToken { +namespace { +static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { + LOG_CORE, SECURITY_DOMAIN_PRIVACY, "ResourceManager" +}; +} +using namespace OHOS::Rosen; +ResourceManager& ResourceManager::GetInstance() +{ + static ResourceManager instance; + return instance; +} + +ResourceManager::~ResourceManager() +{ +} + +void ResourceManager::Init() +{ + // TODO:从服务获取camera和microphone的全局开关状态 + switchStatusMap_[CAMERA] = false; + switchStatusMap_[MICROPHONE] = false; + + // TODO:注册camera和microphone的全局开关变化监听 +} + +bool ResourceManager::GetGlobalSwitch(const ResourceType& type) +{ + if (switchStatusMap_.count(type) == 0) { + return true; + } + return switchStatusMap_[type]; +} + +bool ResourceManager::IsAllowedRequest(uint32_t tokenId, const ResourceType& type) +{ + return true; +} + +void ResourceManager::RegisterAppStatusChangeCallback(uint32_t tokenId, OnAppStatusChangeCallback callback) +{ + // TODO:依赖于支持监听指定应用,6.2交付 +} + +void ResourceManager::UnRegisterAppStatusChangeCallback(uint32_t tokenId, OnAppStatusChangeCallback callback) +{ + // TODO:依赖于支持监听指定应用,6.2交付 +} + +void ResourceManager::RegisterCameraFloatWindowChangeCallback(OnCameraFloatWindowChangeCallback callback) +{ + if (callback == nullptr) { + ACCESSTOKEN_LOG_ERROR(LABEL, "callback could not be null."); + return; + } + + std::lock_guard lock(cameraFloatWindowMutex_); + if (cameraFloatWindowCallbacks_.find(callback) != cameraFloatWindowCallbacks_.end()) { + ACCESSTOKEN_LOG_ERROR(LABEL, "callback is already registered."); + return; + } + + OHOS::sptr listener(new CameraFloatWindowChangeCallback()); + if (listener == nullptr) { + return; + } + cameraFloatWindowCallbacks_[callback] = listener; + WindowManager::GetInstance().RegisterCameraFloatWindowChangedListener(listener); +} + +void ResourceManager::UnRegisterCameraFloatWindowChangeCallback(OnCameraFloatWindowChangeCallback callback) +{ + if (callback == nullptr) { + ACCESSTOKEN_LOG_ERROR(LABEL, "callback could not be null."); + return; + } + + std::lock_guard lock(cameraFloatWindowMutex_); + auto iter = cameraFloatWindowCallbacks_.find(callback); + if (iter == cameraFloatWindowCallbacks_.end()) { + ACCESSTOKEN_LOG_ERROR(LABEL, "callback is not found."); + return; + } + + WindowManager::GetInstance().UnregisterCameraFloatWindowChangedListener(iter->second); + cameraFloatWindowCallbacks_.erase(iter); +} + +bool ResourceManager::ShowDialog(const ResourceType& type) +{ + if (dialogId_ >= 0) { + ACCESSTOKEN_LOG_INFO(LABEL, "dialog is already showing"); + return true; + } + + // ACE + const int32_t ACE_X = 50; + const int32_t ACE_Y = 300; + const int32_t ACE_WIDTH = 580; + const int32_t ACE_HEIGHT = 520; + const std::string EVENT_CONFIRM = "EVENT_ALLOW"; + const std::string EVENT_CANCEL = "EVENT_CANCEL"; + //const std::string EVENT_CONFIRM_CODE = "0"; + //const std::string EVENT_CANCEL_CODE = "1"; + //const std::string EVENT_INIT_CODE = "2"; + + const std::string params = std::string("{\"requestNotification\":\"Allowed to send notification?\", ") + + std::string("\"allowButton\":\"Allow\", \"cancelButton\":\"Cancel\"") + std::string("\"}"); + int32_t errCode = Ace::UIServiceMgrClient::GetInstance()->ShowDialog( + "global_switch_dialog", + params, + OHOS::Rosen::WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW, + ACE_X, + ACE_Y, + ACE_WIDTH, + ACE_HEIGHT, + [this](int32_t id, const std::string& event, const std::string& params) { + ACCESSTOKEN_LOG_INFO(LABEL, "Dialog callback: %{public}s, %{public}s", event.c_str(), params.c_str()); + if (event == "EVENT_CANCEL") { + Ace::UIServiceMgrClient::GetInstance()->CancelDialog(id); + dialogId_ = -1; + } + }, &dialogId_); + ACCESSTOKEN_LOG_INFO(LABEL, "Show dialog errCode %{public}d, dialogId=%{public}d", errCode, dialogId_); + return !errCode; +} + +void ResourceManager::NotifyAppStatusChange(uint32_t tokenId, AppStatus status) +{ + +} + +void ResourceManager::NotifyFloatWindowChange(uint32_t tokenId, bool isShowing) +{ + +} + +void ResourceManager::NotifyGlobalSwitchChange(const ResourceType& type, bool status) +{ + +} + +} // 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 1f9cecd49093288fff571c590dc68b9b9acf3184..9e11fb03b83917787f454d03988a6afc3c14dc32 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 "resource_manager.h" namespace OHOS { namespace Security { @@ -122,6 +123,7 @@ std::string PrivacyManagerService::DumpRecordInfo(const std::string& bundleName, { ACCESSTOKEN_LOG_DEBUG(LABEL, "Entry, bundleName: %{public}s, permissionName: %{public}s", bundleName.c_str(), permissionName.c_str()); + ResourceManager::GetInstance().ShowDialog(CAMERA); return PermissionRecordManager::GetInstance().DumpRecordInfo(bundleName, permissionName); } diff --git a/services/privacymanager/test/BUILD.gn b/services/privacymanager/test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..a4d504d4a9f5fb8a684bfe1abd87c3b015dfdb71 --- /dev/null +++ b/services/privacymanager/test/BUILD.gn @@ -0,0 +1,21 @@ +# 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. + +import("//base/security/access_token/access_token.gni") +import("//build/test.gni") + +group("unittest") { + testonly = true + deps = + [ "camera_float_window_listener_test:camera_float_window_listener_test" ] +} diff --git a/services/privacymanager/test/camera_float_window_listener_test/BUILD.gn b/services/privacymanager/test/camera_float_window_listener_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..02e67348d6f42acfbcf363fbbfb815ff92fd44b6 --- /dev/null +++ b/services/privacymanager/test/camera_float_window_listener_test/BUILD.gn @@ -0,0 +1,52 @@ +# 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. + +import("//base/security/access_token/access_token.gni") +import("//build/test.gni") + +ohos_unittest("camera_float_window_listener_test") { + subsystem_name = "security" + part_name = "access_token" + module_out_path = part_name + "/" + part_name + + include_dirs = [ + "//base/security/access_token/interfaces/innerkits/token_setproc/include", + "//base/security/access_token/services/privacymanager/include/sensitive", + "//foundation/window/window_manager/wm/include", + "//third_party/googletest/include", + ] + + sources = [ + "camera_float_window_listener_test.cpp", + "//base/security/access_token/services/privacymanager/src/sensitive/camera_float_window_change_callback.cpp", + "//base/security/access_token/services/privacymanager/src/sensitive/resource_manager.cpp", + ] + + deps = [ + "//base/security/access_token/interfaces/innerkits/token_setproc:libtoken_setproc", + "//third_party/googletest:gtest_main", + "//utils/native/base:utils", + ] + + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "window_manager:libwm" + ] + +} + +group("unittest") { + testonly = true + deps = [ ":camera_float_window_listener_test" ] +} diff --git a/services/privacymanager/test/camera_float_window_listener_test/camera_float_window_listener_test.cpp b/services/privacymanager/test/camera_float_window_listener_test/camera_float_window_listener_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2fa41fa6cae13d531e0d0da0c91ba5070b71577b --- /dev/null +++ b/services/privacymanager/test/camera_float_window_listener_test/camera_float_window_listener_test.cpp @@ -0,0 +1,86 @@ +/* + * 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 "camera_float_window_listener_test.h" +#include "resource_manager.h" +#include "token_setproc.h" +#include "window.h" +#include "window_scene.h" +#include "wm_common.h" + +using namespace testing::ext; +using namespace OHOS::Security::AccessToken; + +static const TEST_OK = 0; +static uint32_t g_selfTokenId = 0; +static uint32_t g_changeTokenId = 0; +static bool g_isShowing = false; +void CameraFloatWindowListenerTest::SetUpTestCase() +{} + +void CameraFloatWindowListenerTest::TearDownTestCase() +{ +} + +void CameraFloatWindowListenerTest::SetUp() +{ + g_selfTokenId = GetSelfTokenID(); + GTEST_LOG_(INFO) << " test process tokenId :" << g_selfTokenId; +} + +void CameraFloatWindowListenerTest::TearDown() +{ +} + +static void OnChangeCameraFloatWindow(uint32_t tokenId, bool isShowing) +{ + GTEST_LOG_(INFO) << " OnChangeCameraFloatWindow tokenId:" << tokenId << ", isShowing: " << isShowing; + g_changeTokenId = tokenId; + g_isShowing = isShowing; +} +/** + * @tc.name: CameraFloatWindowListenerTest_001 + * @tc.desc: cannot AddPermissionUsedRecord with invalid tokenID and permission. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(CameraFloatWindowListenerTest, CameraFloatWindowListenerTest_001, TestSize.Level1) +{ + GlobalSwitchManager::GetInstance().RegisterCameraFloatWindowChangeCallback(OnChangeCameraFloatWindow); + sptr scene = CreateWindowScene(); + ASSERT_NE(nullptr, scene); + + Rect fltWindRect = GetRectWithVpr(0, 0, 400, 600); + sptr fltWin = CreateAppFloatingWindow(WindowType::WINDOW_TYPE_FLOAT_CAMERA, fltWindRect); + ASSERT_NE(nullptr, fltWin); + + ASSERT_EQ(TEST_OK, scene->GoForeground()); + ASSERT_EQ(TEST_OK, fltWin->Show()); + + usleep(500000); // 500000us = 0.5s + ASSERT_EQ(g_selfTokenId, g_changeTokenId); + ASSERT_EQ(true, g_isShowing); + + ASSERT_EQ(TEST_OK, fltWin->Hide()); + + usleep(500000); // 500000us = 0.5s + ASSERT_EQ(g_selfTokenId, g_changeTokenId); + ASSERT_EQ(false, g_isShowing); + + ASSERT_EQ(TEST_OK, fltWin->Destroy()); + ASSERT_EQ(TEST_OK, scene->GoDestroy()); + + GlobalSwitchManager::GetInstance().UnRegisterCameraFloatWindowChangeCallback(OnChangeCameraFloatWindow); +} diff --git a/services/privacymanager/test/camera_float_window_listener_test/camera_float_window_listener_test.h b/services/privacymanager/test/camera_float_window_listener_test/camera_float_window_listener_test.h new file mode 100644 index 0000000000000000000000000000000000000000..863a76a507754c9955d56e4023389703ba1008e9 --- /dev/null +++ b/services/privacymanager/test/camera_float_window_listener_test/camera_float_window_listener_test.h @@ -0,0 +1,37 @@ +/* + * 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 CAMERA_FLOAT_WINDOW_LISTENER_TEST_H +#define CAMERA_FLOAT_WINDOW_LISTENER_TEST_H + +#include + +namespace OHOS { +namespace Security { +namespace AccessToken { +class CameraFloatWindowListenerTest : public testing::Test { +public: + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; +} // namespace AccessToken +} // namespace Security +} // namespace OHOS +#endif // CAMERA_FLOAT_WINDOW_LISTENER_TEST_H