From 8be1cab8a810b67f7018e4c696f0720226b9ba2b Mon Sep 17 00:00:00 2001 From: y1585740638 Date: Wed, 21 Sep 2022 14:31:24 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E7=9B=B8=E6=9C=BA=E5=85=A8=E5=B1=80?= =?UTF-8?q?=E5=BC=80=E5=85=B3=E7=9B=91=E5=90=AC=E6=B5=8B=E8=AF=95=E7=94=A8?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: y1585740638 Change-Id: I9d63f8c144a1d9f8a9da1e622ac762f2231482e6 --- interfaces/innerkits/privacy/BUILD.gn | 2 +- .../src/service/privacy_manager_stub.cpp | 2 +- services/privacymanager/test/BUILD.gn | 85 +++++++++++ .../sensitive_resource_manager_test.cpp | 136 ++++++++++++++++++ 4 files changed, 223 insertions(+), 2 deletions(-) create mode 100644 services/privacymanager/test/BUILD.gn create mode 100644 services/privacymanager/test/unittest/sensitive_resource_manager_test.cpp diff --git a/interfaces/innerkits/privacy/BUILD.gn b/interfaces/innerkits/privacy/BUILD.gn index cfbb6a9c0..683797d07 100644 --- a/interfaces/innerkits/privacy/BUILD.gn +++ b/interfaces/innerkits/privacy/BUILD.gn @@ -42,7 +42,7 @@ if (is_standard_system) { "src/perm_active_status_change_callback.cpp", "src/perm_active_status_change_callback_stub.cpp", "src/perm_active_status_customized_cbk.cpp", - "src/privacy_death_recipient.cpp", + "src/privacy_death_recipient.cpp", "src/privacy_kit.cpp", "src/privacy_manager_client.cpp", "src/privacy_manager_proxy.cpp", diff --git a/services/privacymanager/src/service/privacy_manager_stub.cpp b/services/privacymanager/src/service/privacy_manager_stub.cpp index d3bda6b3b..230608350 100644 --- a/services/privacymanager/src/service/privacy_manager_stub.cpp +++ b/services/privacymanager/src/service/privacy_manager_stub.cpp @@ -33,7 +33,7 @@ static const int32_t ERROR = -1; static const std::string PERMISSION_USED_STATS = "ohos.permission.PERMISSION_USED_STATS"; } -int32_t PrivacyManagerStub::OnRemoteRequest( +int32_t PrivacyManagerStub:: ( uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) { std::u16string descriptor = data.ReadInterfaceToken(); diff --git a/services/privacymanager/test/BUILD.gn b/services/privacymanager/test/BUILD.gn new file mode 100644 index 000000000..46ff47f55 --- /dev/null +++ b/services/privacymanager/test/BUILD.gn @@ -0,0 +1,85 @@ +# 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("sensitive_resource_manager_test") { + subsystem_name = "security" + part_name = "access_token" + module_out_path = part_name + "/" + part_name + + include_dirs = [ + "//base/security/access_token/frameworks/privacy/include", + "//base/security/access_token/frameworks/common/include", + "//base/security/access_token/interfaces/innerkits/accesstoken/include", + "//base/security/access_token/interfaces/innerkits/privacy/include", + "//base/security/access_token/services/common/database/include", + "//base/global/resource_management/interfaces/inner_api/include", + "//base/security/access_token/services/privacymanager/include/sensitive", + "//base/security/access_token/frameworks/common/include", + "//base/security/access_token/interfaces/innerkits/token_setproc/include", + "//foundation/ability/ability_runtime/interfaces/kits/native/ability/ability_runtime", + "//foundation/arkui/napi", + "//foundation/multimedia/audio_framework/interfaces/inner_api/native/audiomanager/include", + "//foundation/window/window_manager/wm/include", + "//third_party/googletest/include", + ] + + sources = [ + "//base/security/access_token/services/privacymanager/src/sensitive/application_status_change_callback.cpp", + "//base/security/access_token/services/privacymanager/src/sensitive/camera_global_switch_change_callback.cpp", + "//base/security/access_token/services/privacymanager/src/sensitive/sensitive_resource_manager.cpp", + "unittest/sensitive_resource_manager_test.cpp", + ] + + cflags_cc = [ "-DHILOG_ENABLE" ] + + if (dlp_permission_enable == true) { + cflags_cc += [ "-DSUPPORT_SANDBOX_APP" ] + } + + configs = [ "//base/security/access_token/config:coverage_flags" ] + + deps = [ + "//base/security/access_token/interfaces/innerkits/token_setproc:libtoken_setproc", + "//base/security/access_token/services/privacymanager:privacymanager", + "//foundation/ability/ability_runtime/interfaces/inner_api/ability_manager:ability_manager", + "//foundation/ability/ability_runtime/services/abilitymgr:abilityms_target", + "//foundation/arkui/ace_engine/interfaces/inner_api/ui_service_manager:ui_service_mgr", + "//third_party/googletest:gtest_main", + "//third_party/libuv:uv", + "//utils/native/base:utils", + ] + + external_deps = [ + "ability_base:base", + "ability_base:want", + "ability_runtime:ability_context_native", + "ability_runtime:ability_manager", + "ability_runtime:app_manager", + "access_token:libaccesstoken_sdk", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "multimedia_audio_framework:audio_client", + "samgr:samgr_proxy", + "window_manager:libwm", + ] +} + +group("unittest") { + testonly = true + deps = [ ":sensitive_resource_manager_test" ] +} diff --git a/services/privacymanager/test/unittest/sensitive_resource_manager_test.cpp b/services/privacymanager/test/unittest/sensitive_resource_manager_test.cpp new file mode 100644 index 000000000..efc790925 --- /dev/null +++ b/services/privacymanager/test/unittest/sensitive_resource_manager_test.cpp @@ -0,0 +1,136 @@ +/* + * 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 +#include "ability_context_impl.h" +#include "accesstoken_kit.h" +#include "audio_system_manager.h" +#include "sensitive_resource_manager.h" +#include "token_setproc.h" +#include "window.h" +#include "window_scene.h" +#include "wm_common.h" + +using namespace testing; +using namespace testing::ext; +using namespace OHOS; +using namespace OHOS::Rosen; + +class SensitiveResourceManagerTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void SensitiveResourceManagerTest::SetUpTestCase() +{ +} + +void SensitiveResourceManagerTest::TearDownTestCase() +{ +} + +void SensitiveResourceManagerTest::SetUp() +{ + SensitiveResourceManager::GetInstance().Init(); +} + +void SensitiveResourceManagerTest::TearDown() +{ +} + +static bool camera_isShowing = false; +static void OnChangeCameraGlobalSwitch(bool isShowing) +{ + GTEST_LOG_(INFO) << " OnChangeCameraGlobalSwitch isShowing: " << camera_isShowing; + camera_isShowing = isShowing; + GTEST_LOG_(INFO) << " camera_isShowing: " << camera_isShowing; +} + +static void ResetEnv() +{ + camera_isShowing = false; +} + +/** + * @tc.name: RegisterCameraGlobalSwitchChangeCallbackTest_001 + * @tc.desc: call RegisterCameraGlobalSwitchChangeCallback with vaild callback. + * @tc.type: FUNC + * @tc.require: issueI5RWXA + */ +HWTEST_F(SensitiveResourceManagerTest, RegisterCameraGlobalSwitchChangeCallbackTest_001, TestSize.Level1) +{ + SensitiveResourceManager::GetInstance().RegisterCameraGlobalSwitchChangeCallback(OnChangeCameraGlobalSwitch); + + ASSERT_EQ(false, camera_isShowing); + + ResetEnv(); + + CameraStandard::CameraManager::GetInstance()->SetCameraMute(true); + usleep(500000); // 500000us = 0.5s + ASSERT_EQ(true, camera_isShowing); + + ResetEnv(); + + CameraStandard::CameraManager::GetInstance()->SetCameraMute(false); + usleep(500000); // 500000us = 0.5s + ASSERT_EQ(false, camera_isShowing); + + ResetEnv(); + SensitiveResourceManager::GetInstance().UnRegisterMicGlobalSwitchChangeCallback(OnChangeCameraGlobalSwitch); +} + + +/** + * @tc.name: RegisterCameraGlobalSwitchChangeCallbackTest_002 + * @tc.desc: Verify the RegisterCameraGlobalSwitchChangeCallback abnormal branch callback is invalid. + * @tc.type: FUNC + * @tc.require: issueI5RWXA + */ +HWTEST_F(SensitiveResourceManagerTest, RegisterCameraGlobalSwitchChangeCallbackTest_002, TestSize.Level1) +{ + ASSERT_EQ(false, SensitiveResourceManager::GetInstance().RegisterCameraGlobalSwitchChangeCallback(nullptr)); + + ASSERT_EQ(true, SensitiveResourceManager::GetInstance().RegisterCameraGlobalSwitchChangeCallback(OnChangeCameraGlobalSwitch)); + ASSERT_EQ(true, SensitiveResourceManager::GetInstance().RegisterCameraGlobalSwitchChangeCallback(OnChangeCameraGlobalSwitch)); + + SensitiveResourceManager::GetInstance().UnRegisterCameraGlobalSwitchChangeCallback(OnChangeCameraGlobalSwitch); +} + +/** + * @tc.name: UnRegisterCameraGlobalSwitchChangeCallbackTest_001 + * @tc.desc: Verify the UnRegisterCameraGlobalSwitchChangeCallback with vaild callback. + * @tc.type: FUNC + * @tc.require: issueI5RWXA + */ +HWTEST_F(SensitiveResourceManagerTest, UnRegisterCameraGlobalSwitchChangeCallbackTest_001, TestSize.Level1) +{ + ASSERT_EQ(true, SensitiveResourceManager::GetInstance().RegisterCameraGlobalSwitchChangeCallback(OnChangeCameraGlobalSwitch)); + ASSERT_EQ(true, SensitiveResourceManager::GetInstance().UnRegisterCameraGlobalSwitchChangeCallback(OnChangeCameraGlobalSwitch)); +} + +/** + * @tc.name: UnRegisterCameraGlobalSwitchChangeCallbackTest_002 + * @tc.desc: Verify the UnRegisterCameraGlobalSwitchChangeCallback abnormal branch callback is invalid. + * @tc.type: FUNC + * @tc.require: issueI5RWXA + */ +HWTEST_F(SensitiveResourceManagerTest, UnRegisterCameraGlobalSwitchChangeCallbackTest_002, TestSize.Level1) +{ + ASSERT_EQ(false, SensitiveResourceManager::GetInstance().UnRegisterCameraGlobalSwitchChangeCallback(nullptr)); + ASSERT_EQ(false, SensitiveResourceManager::GetInstance().UnRegisterCameraGlobalSwitchChangeCallback(OnChangeCameraGlobalSwitch)); +} \ No newline at end of file -- Gitee From 94b9dcf5a5873256f153b35010616a973c14ae40 Mon Sep 17 00:00:00 2001 From: y1585740638 Date: Wed, 21 Sep 2022 14:34:06 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E7=9B=B8=E6=9C=BA=E5=85=A8=E5=B1=80?= =?UTF-8?q?=E5=BC=80=E5=85=B3=E7=9B=91=E5=90=AC=E6=B5=8B=E8=AF=95=E7=94=A8?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: y1585740638 Change-Id: Idf9d68b17b13aa70bc36e920e70470b888880e09 --- interfaces/innerkits/privacy/BUILD.gn | 2 +- services/privacymanager/BUILD.gn | 3 +++ services/privacymanager/src/service/privacy_manager_stub.cpp | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/interfaces/innerkits/privacy/BUILD.gn b/interfaces/innerkits/privacy/BUILD.gn index 683797d07..cfbb6a9c0 100644 --- a/interfaces/innerkits/privacy/BUILD.gn +++ b/interfaces/innerkits/privacy/BUILD.gn @@ -42,7 +42,7 @@ if (is_standard_system) { "src/perm_active_status_change_callback.cpp", "src/perm_active_status_change_callback_stub.cpp", "src/perm_active_status_customized_cbk.cpp", - "src/privacy_death_recipient.cpp", + "src/privacy_death_recipient.cpp", "src/privacy_kit.cpp", "src/privacy_manager_client.cpp", "src/privacy_manager_proxy.cpp", diff --git a/services/privacymanager/BUILD.gn b/services/privacymanager/BUILD.gn index 4f5321129..c9b5125a2 100644 --- a/services/privacymanager/BUILD.gn +++ b/services/privacymanager/BUILD.gn @@ -67,6 +67,9 @@ if (is_standard_system && ability_base_enable == true) { "src/record/permission_record_repository.cpp", "src/record/permission_used_record_cache.cpp", "src/sensitive/application_status_change_callback.cpp", + "src/sensitive/camera_float_window_change_callback.cpp", + "src/sensitive/camera_global_switch_change_callback.cpp", + "src/sensitive/mic_global_switch_change_callback.cpp", "src/sensitive/sensitive_resource_manager.cpp", "src/service/privacy_manager_service.cpp", "src/service/privacy_manager_stub.cpp", diff --git a/services/privacymanager/src/service/privacy_manager_stub.cpp b/services/privacymanager/src/service/privacy_manager_stub.cpp index 230608350..d3bda6b3b 100644 --- a/services/privacymanager/src/service/privacy_manager_stub.cpp +++ b/services/privacymanager/src/service/privacy_manager_stub.cpp @@ -33,7 +33,7 @@ static const int32_t ERROR = -1; static const std::string PERMISSION_USED_STATS = "ohos.permission.PERMISSION_USED_STATS"; } -int32_t PrivacyManagerStub:: ( +int32_t PrivacyManagerStub::OnRemoteRequest( uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) { std::u16string descriptor = data.ReadInterfaceToken(); -- Gitee