From 3af4a8ec51e77b51f2799b71e783d89ab8f75d05 Mon Sep 17 00:00:00 2001 From: j21p3 Date: Thu, 18 Jul 2024 10:11:29 +0800 Subject: [PATCH] code review advice fix Change-Id: I299fb56ada55fb79ce62696cae8e8dee00dd1d16 Signed-off-by: j21p3 --- security_component.gni | 7 ++++++ .../security_component_service/sa/BUILD.gn | 9 ++++++++ .../sa/sa_main/sec_comp_entity.cpp | 22 ++++++++++++++----- .../sa/sa_main/sec_comp_entity.h | 2 ++ .../sa/test/BUILD.gn | 10 +++++++++ .../service/security_component_fuzz.gni | 8 +++++++ 6 files changed, 52 insertions(+), 6 deletions(-) diff --git a/security_component.gni b/security_component.gni index c8d6f9a..b02db06 100644 --- a/security_component.gni +++ b/security_component.gni @@ -19,3 +19,10 @@ if (!defined(global_parts_info) || } else { security_component_enhance_enable = false } + +if (!defined(global_parts_info) || + defined(global_parts_info.distributeddatamgr_data_share)) { + distributeddatamgr_data_share_enable = true +} else { + distributeddatamgr_data_share_enable = false +} diff --git a/services/security_component_service/sa/BUILD.gn b/services/security_component_service/sa/BUILD.gn index d0b279b..35bd07b 100644 --- a/services/security_component_service/sa/BUILD.gn +++ b/services/security_component_service/sa/BUILD.gn @@ -12,6 +12,7 @@ # limitations under the License. import("//build/ohos.gni") +import("../../../security_component.gni") sec_comp_root_dir = "../../.." @@ -104,6 +105,14 @@ ohos_source_set("security_component_service_src_set") { "window_manager:libdm", "window_manager:libwm", ] + + if (distributeddatamgr_data_share_enable == true) { + cflags += [ "-DDATA_SHARE_ENABLE" ] + external_deps += [ + "ability_base:zuri", + "data_share:datashare_consumer", + ] + } } ohos_shared_library("security_component_service") { diff --git a/services/security_component_service/sa/sa_main/sec_comp_entity.cpp b/services/security_component_service/sa/sa_main/sec_comp_entity.cpp index c8df011..d5f6978 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_entity.cpp +++ b/services/security_component_service/sa/sa_main/sec_comp_entity.cpp @@ -15,7 +15,9 @@ #include "sec_comp_entity.h" #include +#ifdef DATA_SHARE_ENABLE #include "datashare_helper.h" +#endif // DATA_SHARE_ENABLE #include "hisysevent.h" #include "ipc_skeleton.h" #include "iservice_registry.h" @@ -33,6 +35,7 @@ namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_SECURITY_COMPONENT, "SecCompEntity"}; static constexpr uint64_t MAX_TOUCH_INTERVAL = 1000000L; // 1000ms static constexpr uint64_t TIME_CONVERSION_UNIT = 1000; +#ifdef DATA_SHARE_ENABLE constexpr const char *SETTINGS_DATA_EXT_URI = "datashare:///com.ohos.settingsdata.DataAbility"; constexpr const char *SETTINGS_DATASHARE_URI = "datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true"; @@ -41,6 +44,7 @@ constexpr const char *SETTINGS_DATASHARE_SEARCH_URI = "Proxy=true&key=accessibility_screenreader_enabled"; constexpr const char *ADVANCED_DATA_COLUMN_KEYWORD = "KEYWORD"; constexpr const char *ADVANCED_DATA_COLUMN_VALUE = "VALUE"; +#endif // DATA_SHARE_ENABLE } int32_t SecCompEntity::GrantTempPermission() @@ -99,12 +103,15 @@ int32_t SecCompEntity::CheckClickInfo(const SecCompClickEvent& clickInfo) const } int32_t res = SC_SERVICE_ERROR_CLICK_EVENT_INVALID; - bool isScreenReadMode = IsScreenReadMode(); - if (clickInfo.type == ClickEventType::POINT_EVENT_TYPE && !isScreenReadMode) { - res = CheckPointEvent(clickInfo); - } else if (clickInfo.type == ClickEventType::POINT_EVENT_TYPE && isScreenReadMode) { - SC_LOG_WARN(LABEL, "Device is in screen read mode, skip event check."); - return SC_OK; + if (clickInfo.type == ClickEventType::POINT_EVENT_TYPE) { +#ifdef DATA_SHARE_ENABLE + if (IsScreenReadMode()) { + // if in screen read mode, return ok to skip normal check. + SC_LOG_WARN(LABEL, "Device is in screen read mode, skip event check."); + return SC_OK; + } +#endif // DATA_SHARE_ENABLE + res = CheckPointEvent(clickInfo); } else if (clickInfo.type == ClickEventType::KEY_EVENT_TYPE) { res = CheckKeyEvent(clickInfo); } @@ -128,6 +135,7 @@ int32_t SecCompEntity::CheckClickInfo(const SecCompClickEvent& clickInfo) const return SC_OK; } +#ifdef DATA_SHARE_ENABLE bool SecCompEntity::IsScreenReadMode() const { auto saManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); @@ -168,8 +176,10 @@ bool SecCompEntity::IsScreenReadMode() const result->GetString(columnIndex, value); result->Close(); dataShareHelper->Release(); + // '1'-enable; '0'-disable return value == "1"; } +#endif // DATA_SHARE_ENABLE } // namespace SecurityComponent } // namespace Security } // namespace OHOS diff --git a/services/security_component_service/sa/sa_main/sec_comp_entity.h b/services/security_component_service/sa/sa_main/sec_comp_entity.h index 1c76b1f..d950c4b 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_entity.h +++ b/services/security_component_service/sa/sa_main/sec_comp_entity.h @@ -57,7 +57,9 @@ public: private: int32_t CheckKeyEvent(const SecCompClickEvent& clickInfo) const; int32_t CheckPointEvent(const SecCompClickEvent& clickInfo) const; +#ifdef DATA_SHARE_ENABLE bool IsScreenReadMode() const; +#endif // DATA_SHARE_ENABLE bool isGrant_ = false; }; } // namespace SecurityComponent diff --git a/services/security_component_service/sa/test/BUILD.gn b/services/security_component_service/sa/test/BUILD.gn index 8133c97..ae3982b 100644 --- a/services/security_component_service/sa/test/BUILD.gn +++ b/services/security_component_service/sa/test/BUILD.gn @@ -90,6 +90,11 @@ ohos_unittest("sec_comp_service_test") { "json:nlohmann_json_static", "window_manager:libdm", ] + + if (distributeddatamgr_data_share_enable == true) { + cflags_cc += [ "-DDATA_SHARE_ENABLE" ] + external_deps += [ "ability_base:zuri" ] + } } ohos_unittest("sec_comp_service_mock_test") { @@ -163,6 +168,11 @@ ohos_unittest("sec_comp_service_mock_test") { "json:nlohmann_json_static", "window_manager:libdm", ] + + if (distributeddatamgr_data_share_enable == true) { + cflags_cc += [ "-DDATA_SHARE_ENABLE" ] + external_deps += [ "ability_base:zuri" ] + } } group("unittest") { diff --git a/test/fuzztest/security_component/service/security_component_fuzz.gni b/test/fuzztest/security_component/service/security_component_fuzz.gni index 259571c..3f1e559 100644 --- a/test/fuzztest/security_component/service/security_component_fuzz.gni +++ b/test/fuzztest/security_component/service/security_component_fuzz.gni @@ -81,3 +81,11 @@ sc_mock_sources = [ "${sec_comp_dir}/services/security_component_service/sa/test/mock/src/sec_comp_enhance_adapter.cpp", "${sec_comp_dir}/test/fuzztest/security_component/common/fuzz_common.cpp", ] + +if (distributeddatamgr_data_share_enable == true) { + sc_cflags_cc += [ "-DDATA_SHARE_ENABLE" ] + sc_external_deps += [ + "ability_base:zuri", + "data_share:datashare_consumer", + ] + } -- Gitee