diff --git a/security_component.gni b/security_component.gni index c8d6f9a0411565df13fdb3ffebd824c7f4731ae9..b02db06b48c20cd03fa3a7dd62be60fd9bde5778 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 d0b279b0a291ebfe616d22195541451f50c8f206..35bd07bded9badbdc9ab676601d04072029728f4 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 c8df0118d2c0363409894c05dafcc0d44dcb9125..d5f69786332db553da5e0a3d9131d26c0cf054c2 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 1c76b1fdd57c1f9a7f38651fef8b885178d548cf..d950c4b8f6bd881841877e313b8c2d2e4c1f3e92 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 8133c971c19674014871686ddf27cb5195d39e81..ae3982b4217f5e2c6b8cb83214e9aa583e735845 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 259571ca1af167b6a23209f3ab8779f7f044e398..3f1e5599ecdf588ad877077468afb593e3dea2e1 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", + ] + }