diff --git a/services/abilitymgr/include/extension_config.h b/services/abilitymgr/include/extension_config.h index 9ff64501601f7c0061882caa94760c271f70c9a4..27e520b2091a0a9a0213b2ae7fd7ec0dab3c82b5 100644 --- a/services/abilitymgr/include/extension_config.h +++ b/services/abilitymgr/include/extension_config.h @@ -52,6 +52,7 @@ struct ExtensionConfigItem { AbilityAccessItem abilityAccess; bool hasAbilityAccess = false; bool screenUnlockIntercept = false; + bool screenUnlockInterceptExcludeSystemApp = false; }; class ExtensionConfig : public DelayedSingleton { @@ -71,7 +72,7 @@ public: bool IsExtensionStartDefaultEnable(const std::string &extensionTypeName, const std::string &targetUri); bool IsExtensionNetworkEnable(const std::string &extensionTypeName); bool IsExtensionSAEnable(const std::string &extensionTypeName); - bool IsScreenUnlockIntercept(const std::string &extensionTypeName); + bool IsScreenUnlockIntercept(const std::string &extensionTypeName, bool isSystemApp); private: void LoadExtensionConfig(const nlohmann::json &object); bool ReadFileInfoJson(const std::string &filePath, nlohmann::json &jsonBuf); diff --git a/services/abilitymgr/src/extension_config.cpp b/services/abilitymgr/src/extension_config.cpp index e23882820f7cfd1ead18c3a9c49f1c3cc369c90d..a515e7c42e1019583f83d146fdc0dec34cb49ab5 100644 --- a/services/abilitymgr/src/extension_config.cpp +++ b/services/abilitymgr/src/extension_config.cpp @@ -46,6 +46,7 @@ constexpr const char* ALLOW_LIST = "allowlist"; constexpr const char* NETWORK_ACCESS_ENABLE_FLAG = "network_access_enable_flag"; constexpr const char* SA_ACCESS_ENABLE_FLAG = "sa_access_enable_flag"; constexpr const char* SCREEN_UNLOCK_INTERCEPT = "screen_unlock_intercept"; +constexpr const char* SCREEN_UNLOCK_INTERCEPT_EXCLUDE_SYSTEM_APP = "screen_unlock_intercept_exclude_system_app"; } std::string ExtensionConfig::GetExtensionConfigPath() const @@ -289,13 +290,24 @@ void ExtensionConfig::LoadScreenUnlockIntercept(const nlohmann::json &object, { TAG_LOGD(AAFwkTag::ABILITYMGR, "LoadScreenUnlockIntercept call"); if (!object.contains(SCREEN_UNLOCK_INTERCEPT) || !object.at(SCREEN_UNLOCK_INTERCEPT).is_boolean()) { - TAG_LOGI(AAFwkTag::ABILITYMGR, "screen_unlock_intercept null"); + TAG_LOGD(AAFwkTag::ABILITYMGR, "screen_unlock_intercept null"); return; } bool flag = object.at(SCREEN_UNLOCK_INTERCEPT).get(); configMap_[extensionTypeName].screenUnlockIntercept = flag; TAG_LOGD(AAFwkTag::ABILITYMGR, "The %{public}s extension's screen_unlock_intercept is %{public}d", extensionTypeName.c_str(), flag); + + if (!object.contains(SCREEN_UNLOCK_INTERCEPT_EXCLUDE_SYSTEM_APP) || + !object.at(SCREEN_UNLOCK_INTERCEPT_EXCLUDE_SYSTEM_APP).is_boolean()) { + TAG_LOGD(AAFwkTag::ABILITYMGR, "screen_unlock_intercept_exclude_system_app null"); + return; + } + flag = object.at(SCREEN_UNLOCK_INTERCEPT_EXCLUDE_SYSTEM_APP).get(); + configMap_[extensionTypeName].screenUnlockInterceptExcludeSystemApp = flag; + TAG_LOGD(AAFwkTag::ABILITYMGR, + "The %{public}s extension's screen_unlock_intercept_exclude_system_app is %{public}d", + extensionTypeName.c_str(), flag); } bool ExtensionConfig::HasAbilityAccess(const std::string &extensionTypeName) @@ -424,13 +436,21 @@ bool ExtensionConfig::IsExtensionSAEnable(const std::string &extensionTypeName) return EXTENSION_SA_ENABLE_FLAG_DEFAULT; } -bool ExtensionConfig::IsScreenUnlockIntercept(const std::string &extensionTypeName) +bool ExtensionConfig::IsScreenUnlockIntercept(const std::string &extensionTypeName, bool isSystemApp) { std::lock_guard lock(configMapMutex_); - if (configMap_.find(extensionTypeName) != configMap_.end()) { - return configMap_[extensionTypeName].screenUnlockIntercept; + auto iter = configMap_.find(extensionTypeName); + if (iter == configMap_.end()) { + return false; + } + const auto &config = iter->second; + if (!config.screenUnlockIntercept) { + return false; + } + if (!isSystemApp) { + return true; } - return false; + return !config.screenUnlockInterceptExcludeSystemApp; } bool ExtensionConfig::ReadFileInfoJson(const std::string &filePath, nlohmann::json &jsonBuf) diff --git a/services/abilitymgr/src/interceptor/screen_unlock_interceptor.cpp b/services/abilitymgr/src/interceptor/screen_unlock_interceptor.cpp index 17a92bd5111b216eb5f368347ce68731153a01c2..6cc2b1aff875990f7bb56a1925bcaea895e21522 100644 --- a/services/abilitymgr/src/interceptor/screen_unlock_interceptor.cpp +++ b/services/abilitymgr/src/interceptor/screen_unlock_interceptor.cpp @@ -64,7 +64,7 @@ ErrCode ScreenUnlockInterceptor::DoProcess(AbilityInterceptorParam param) } if (targetAbilityInfo.type == AppExecFwk::AbilityType::EXTENSION && !DelayedSingleton::GetInstance()->IsScreenUnlockIntercept( - targetAbilityInfo.extensionTypeName)) { + targetAbilityInfo.extensionTypeName, targetAbilityInfo.applicationInfo.isSystemApp)) { return ERR_OK; } TAG_LOGE(AAFwkTag::ABILITYMGR, "no startup before device first unlock"); diff --git a/test/unittest/ability_extension_config_test/ability_extension_config_test.cpp b/test/unittest/ability_extension_config_test/ability_extension_config_test.cpp index 24abceec8320a8443a1741c07cbdb0ed157a7196..f39df1ec370aaccb6b7269551e850cde3352e21e 100644 --- a/test/unittest/ability_extension_config_test/ability_extension_config_test.cpp +++ b/test/unittest/ability_extension_config_test/ability_extension_config_test.cpp @@ -1339,7 +1339,7 @@ HWTEST_F(AbilityExtensionConfigTest, IsScreenUnlockIntercept_001, TestSize.Level })"; ASSERT_NE(extensionConfig_, nullptr); LoadTestConfig(configStr); - bool flag = extensionConfig_->IsScreenUnlockIntercept("form"); + bool flag = extensionConfig_->IsScreenUnlockIntercept("form", false); EXPECT_TRUE(flag); TAG_LOGI(AAFwkTag::TEST, "IsScreenUnlockIntercept_001 end."); } @@ -1361,7 +1361,7 @@ HWTEST_F(AbilityExtensionConfigTest, IsScreenUnlockIntercept_002, TestSize.Level })"; ASSERT_NE(extensionConfig_, nullptr); LoadTestConfig(configStr); - bool flag = extensionConfig_->IsScreenUnlockIntercept("form"); + bool flag = extensionConfig_->IsScreenUnlockIntercept("form", false); EXPECT_FALSE(flag); TAG_LOGI(AAFwkTag::TEST, "IsScreenUnlockIntercept_002 end."); } @@ -1382,7 +1382,7 @@ HWTEST_F(AbilityExtensionConfigTest, IsScreenUnlockIntercept_003, TestSize.Level })"; ASSERT_NE(extensionConfig_, nullptr); LoadTestConfig(configStr); - bool flag = extensionConfig_->IsScreenUnlockIntercept("form"); + bool flag = extensionConfig_->IsScreenUnlockIntercept("form", false); EXPECT_FALSE(flag); TAG_LOGI(AAFwkTag::TEST, "IsScreenUnlockIntercept_003 end."); } @@ -1404,9 +1404,100 @@ HWTEST_F(AbilityExtensionConfigTest, IsScreenUnlockIntercept_004, TestSize.Level })"; ASSERT_NE(extensionConfig_, nullptr); LoadTestConfig(configStr); - bool flag = extensionConfig_->IsScreenUnlockIntercept("push"); + bool flag = extensionConfig_->IsScreenUnlockIntercept("push", false); EXPECT_FALSE(flag); TAG_LOGI(AAFwkTag::TEST, "IsScreenUnlockIntercept_004 end."); } + +/* + * @tc.number : IsScreenUnlockIntercept_005 + * @tc.name : AbilityExtensionConfigTest + * @tc.desc : Test Function IsScreenUnlockIntercept + */ +HWTEST_F(AbilityExtensionConfigTest, IsScreenUnlockIntercept_005, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "IsScreenUnlockIntercept_005 start."); + const std::string configStr = R"({ + "ams_extension_config": [{ + "name": "FormExtension", + "extension_type_name": "form", + "screen_unlock_intercept": true, + "screen_unlock_intercept_exclude_system_app": true + }] + })"; + ASSERT_NE(extensionConfig_, nullptr); + LoadTestConfig(configStr); + bool flag = extensionConfig_->IsScreenUnlockIntercept("form", true); + EXPECT_FALSE(flag); + TAG_LOGI(AAFwkTag::TEST, "IsScreenUnlockIntercept_005 end."); +} + +/* + * @tc.number : IsScreenUnlockIntercept_006 + * @tc.name : AbilityExtensionConfigTest + * @tc.desc : Test Function IsScreenUnlockIntercept + */ +HWTEST_F(AbilityExtensionConfigTest, IsScreenUnlockIntercept_006, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "IsScreenUnlockInterceIsScreenUnlockIntercept_006 start."); + const std::string configStr = R"({ + "ams_extension_config": [{ + "name": "FormExtension", + "extension_type_name": "form", + "screen_unlock_intercept": true, + "screen_unlock_intercept_exclude_system_app": false + }] + })"; + ASSERT_NE(extensionConfig_, nullptr); + LoadTestConfig(configStr); + bool flag = extensionConfig_->IsScreenUnlockIntercept("form", true); + EXPECT_TRUE(flag); + TAG_LOGI(AAFwkTag::TEST, "IsScreenUnlockIntercept_006 end."); +} + +/* + * @tc.number : IsScreenUnlockIntercept_007 + * @tc.name : AbilityExtensionConfigTest + * @tc.desc : Test Function IsScreenUnlockIntercept + */ +HWTEST_F(AbilityExtensionConfigTest, IsScreenUnlockIntercept_007, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "IsScreenUnlockIntercept_007 start."); + const std::string configStr = R"({ + "ams_extension_config": [{ + "name": "FormExtension", + "extension_type_name": "form", + "screen_unlock_intercept": true + }] + })"; + ASSERT_NE(extensionConfig_, nullptr); + LoadTestConfig(configStr); + bool flag = extensionConfig_->IsScreenUnlockIntercept("form", true); + EXPECT_TRUE(flag); + TAG_LOGI(AAFwkTag::TEST, "IsScreenUnlockIntercept_007 end."); +} + +/* + * @tc.number : IsScreenUnlockIntercept_008 + * @tc.name : AbilityExtensionConfigTest + * @tc.desc : Test Function IsScreenUnlockIntercept + */ +HWTEST_F(AbilityExtensionConfigTest, IsScreenUnlockIntercept_008, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "IsScreenUnlockIntercept_008 start."); + const std::string configStr = R"({ + "ams_extension_config": [{ + "name": "FormExtension", + "extension_type_name": "form", + "screen_unlock_intercept": true, + "screen_unlock_intercept_exclude_system_app": "invalid value" + }] + })"; + ASSERT_NE(extensionConfig_, nullptr); + LoadTestConfig(configStr); + bool flag = extensionConfig_->IsScreenUnlockIntercept("form", true); + EXPECT_TRUE(flag); + TAG_LOGI(AAFwkTag::TEST, "IsScreenUnlockIntercept_008 end."); +} } }