diff --git a/frameworks/native/ability/native/ability_business_error/ability_business_error.cpp b/frameworks/native/ability/native/ability_business_error/ability_business_error.cpp index 1df63993d6..18129bc45f 100644 --- a/frameworks/native/ability/native/ability_business_error/ability_business_error.cpp +++ b/frameworks/native/ability/native/ability_business_error/ability_business_error.cpp @@ -75,7 +75,6 @@ constexpr const char* ERROR_MSG_NOT_SUPPORT_CROSS_APP_START = "The application is not allow jumping to other applications when api version is above 11."; constexpr const char* ERROR_MSG_CANNOT_MATCH_ANY_COMPONENT = "Can not match any component."; constexpr const char* ERROR_MSG_TARGET_BUNDLE_NOT_EXIST = "The target bundle does not exist."; -constexpr const char* ERROR_MSG_SET_SUPPORTED_PROCESS_CACHE_AGAIN = "Can not set process cache state more than once."; constexpr const char* ERROR_MSG_NO_RESIDENT_PERMISSION = "The caller application can only set the resident status of the configured process."; constexpr const char* ERROR_MSG_MULTI_APP_NOT_SUPPORTED = "App clone or multi-instance is not supported."; @@ -137,7 +136,6 @@ static std::unordered_map ERR_CODE_MAP = { { AbilityErrorCode::ERROR_CODE_NOT_SUPPORT_CROSS_APP_START, ERROR_MSG_NOT_SUPPORT_CROSS_APP_START }, { AbilityErrorCode::ERROR_CODE_CANNOT_MATCH_ANY_COMPONENT, ERROR_MSG_CANNOT_MATCH_ANY_COMPONENT }, { AbilityErrorCode::ERROR_CODE_TARGET_BUNDLE_NOT_EXIST, ERROR_MSG_TARGET_BUNDLE_NOT_EXIST }, - { AbilityErrorCode::ERROR_CODE_SET_SUPPORTED_PROCESS_CACHE_AGAIN, ERROR_MSG_SET_SUPPORTED_PROCESS_CACHE_AGAIN }, { AbilityErrorCode::ERROR_CODE_NO_RESIDENT_PERMISSION, ERROR_MSG_NO_RESIDENT_PERMISSION }, { AbilityErrorCode::ERROR_CODE_MULTI_APP_NOT_SUPPORTED, ERROR_MSG_MULTI_APP_NOT_SUPPORTED }, { AbilityErrorCode::ERROR_APP_CLONE_INDEX_INVALID, ERROR_MSG_APP_CLONE_INDEX_INVALID }, @@ -201,7 +199,6 @@ static std::unordered_map INNER_TO_JS_ERROR_CODE_MAP {ERR_IMPLICIT_START_ABILITY_FAIL, AbilityErrorCode::ERROR_CODE_CANNOT_MATCH_ANY_COMPONENT}, {ERR_START_OTHER_APP_FAILED, AbilityErrorCode::ERROR_CODE_NOT_SUPPORT_CROSS_APP_START}, {ERR_TARGET_BUNDLE_NOT_EXIST, AbilityErrorCode::ERROR_CODE_TARGET_BUNDLE_NOT_EXIST}, - {ERR_SET_SUPPORTED_PROCESS_CACHE_AGAIN, AbilityErrorCode::ERROR_CODE_SET_SUPPORTED_PROCESS_CACHE_AGAIN}, {ERR_NO_RESIDENT_PERMISSION, AbilityErrorCode::ERROR_CODE_NO_RESIDENT_PERMISSION}, {ERR_MULTI_APP_NOT_SUPPORTED, AbilityErrorCode::ERROR_CODE_MULTI_APP_NOT_SUPPORTED}, {ERR_APP_CLONE_INDEX_INVALID, AbilityErrorCode::ERROR_APP_CLONE_INDEX_INVALID}, diff --git a/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp b/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp index 1ff04aac1d..c2ebdb917f 100644 --- a/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp +++ b/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp @@ -1483,11 +1483,6 @@ napi_value JsApplicationContextUtils::OnSetSupportedProcessCacheSelf(napi_env en { TAG_LOGD(AAFwkTag::APPKIT, "called"); - if (!CheckCallerIsSystemApp()) { - TAG_LOGE(AAFwkTag::APPKIT, "This application is not system-app, can not use system-api."); - AbilityRuntimeErrorUtil::Throw(env, ERR_ABILITY_RUNTIME_NOT_SYSTEM_APP); - return CreateJsUndefined(env); - } // only support one params if (info.argc == ARGC_ZERO) { TAG_LOGE(AAFwkTag::APPKIT, "Not enough params"); @@ -1510,12 +1505,9 @@ napi_value JsApplicationContextUtils::OnSetSupportedProcessCacheSelf(napi_env en } int32_t errCode = applicationContext->SetSupportedProcessCacheSelf(isSupport); - if (errCode == AAFwk::CHECK_PERMISSION_FAILED) { - TAG_LOGE(AAFwkTag::APPKIT, "check permission failed"); - AbilityRuntimeErrorUtil::Throw(env, ERR_ABILITY_RUNTIME_EXTERNAL_NO_ACCESS_PERMISSION); - } else if (errCode == AAFwk::ERR_SET_SUPPORTED_PROCESS_CACHE_AGAIN) { - TAG_LOGE(AAFwkTag::APPKIT, "cannot set more than once"); - AbilityRuntimeErrorUtil::Throw(env, ERR_ABILITY_RUNTIME_SET_SUPPORTED_PROCESS_CACHE_AGAIN); + if (errCode == AAFwk::ERR_CAPABILITY_NOT_SUPPORT) { + TAG_LOGE(AAFwkTag::APPKIT, "process cache feature is disabled."); + AbilityRuntimeErrorUtil::Throw(env, ERR_ABILITY_RUNTIME_EXTERNAL_NO_SUCH_SYSCAP); } else if (errCode != ERR_OK) { TAG_LOGE(AAFwkTag::APPKIT, "set failed"); AbilityRuntimeErrorUtil::Throw(env, ERR_ABILITY_RUNTIME_EXTERNAL_INTERNAL_ERROR); diff --git a/interfaces/inner_api/error_utils/include/ability_runtime_error_util.h b/interfaces/inner_api/error_utils/include/ability_runtime_error_util.h index 1c621573e5..aaf07eb4fe 100644 --- a/interfaces/inner_api/error_utils/include/ability_runtime_error_util.h +++ b/interfaces/inner_api/error_utils/include/ability_runtime_error_util.h @@ -59,7 +59,6 @@ enum { ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_WANTAGENT = 16000151, ERR_ABILITY_RUNTIME_EXTERNAL_WANTAGENT_NOT_FOUND = 16000152, ERR_ABILITY_RUNTIME_EXTERNAL_WANTAGENT_CANCELED = 16000153, - ERR_ABILITY_RUNTIME_SET_SUPPORTED_PROCESS_CACHE_AGAIN = 16000200, ERR_ABILITY_RUNTIME_EXTERNAL_NO_SUCH_URI_ABILITY = 16100001, ERR_ABILITY_RUNTIME_EXTERNAL_FA_NOT_SUPPORT_OPERATION = 16100002, diff --git a/interfaces/inner_api/error_utils/src/ability_runtime_error_util.cpp b/interfaces/inner_api/error_utils/src/ability_runtime_error_util.cpp index 4e9d131e6d..6e28350599 100644 --- a/interfaces/inner_api/error_utils/src/ability_runtime_error_util.cpp +++ b/interfaces/inner_api/error_utils/src/ability_runtime_error_util.cpp @@ -149,8 +149,6 @@ const std::map ERROR_MSG_MAP = { "Restart too frequently. Try again at least 10s later." }, { ERR_ABILITY_RUNTIME_EXTERNAL_NOT_SYSTEM_HSP, "The input bundleName and moduleName is not system HSP" }, - { ERR_ABILITY_RUNTIME_SET_SUPPORTED_PROCESS_CACHE_AGAIN, - "The supported process cache state cannot be set more than once" }, }; } diff --git a/interfaces/kits/native/ability/native/ability_business_error/ability_business_error.h b/interfaces/kits/native/ability/native/ability_business_error/ability_business_error.h index 424f861a83..c26ead4973 100644 --- a/interfaces/kits/native/ability/native/ability_business_error/ability_business_error.h +++ b/interfaces/kits/native/ability/native/ability_business_error/ability_business_error.h @@ -177,8 +177,6 @@ enum class AbilityErrorCode { // target bundle not exist. ERROR_CODE_TARGET_BUNDLE_NOT_EXIST = 16300005, - ERROR_CODE_SET_SUPPORTED_PROCESS_CACHE_AGAIN = 16300006, - // target free install task does not exist. ERROR_CODE_FREE_INSTALL_TASK_NOT_EXIST = 16300007, diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index fd41e9331a..6616095786 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -1477,8 +1477,6 @@ private: const HapModuleInfo &hapModuleInfo, std::shared_ptr want, bool appExistFlag, bool isPreload, sptr token = nullptr); - int32_t CheckSetProcessCachePermission() const; - int32_t CreatNewStartMsg(const Want &want, const AbilityInfo &abilityInfo, const std::shared_ptr &appInfo, const std::string &processName, AppSpawnStartMsg &startMsg); diff --git a/services/appmgr/include/cache_process_manager.h b/services/appmgr/include/cache_process_manager.h index 7e766df29e..a4546cc15a 100644 --- a/services/appmgr/include/cache_process_manager.h +++ b/services/appmgr/include/cache_process_manager.h @@ -54,11 +54,14 @@ private: void AddToApplicationSet(const std::shared_ptr &appRecord); void RemoveFromApplicationSet(const std::shared_ptr &appRecord); bool CheckAndNotifyCachedState(const std::shared_ptr &appRecord); + bool IsAppSupportProcessCacheInnerFirst(const std::shared_ptr &appRecord); int32_t maxProcCacheNum_ = 0; std::deque> cachedAppRecordQueue_; ffrt::recursive_mutex cacheQueueMtx; std::weak_ptr appMgr_; bool shouldCheckApi = true; + // whether the feature should check setSupportedProcessCache value or not + bool shouldCheckSupport = true; // bundleName->uid->record std::map>>> sameAppSet; // stores records that are servcie extension diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 211633d56f..c05a0441f6 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -6871,11 +6871,6 @@ int32_t AppMgrServiceInner::SetSupportedProcessCacheSelf(bool isSupport) TAG_LOGE(AAFwkTag::APPMGR, "appRunningManager_ is nullptr"); return ERR_NO_INIT; } - auto result = CheckSetProcessCachePermission(); - if (result != ERR_OK) { - TAG_LOGE(AAFwkTag::APPMGR, "Permission verification failed."); - return result; - } auto callerPid = IPCSkeleton::GetCallingPid(); auto appRecord = GetAppRunningRecordByPid(callerPid); @@ -6883,21 +6878,13 @@ int32_t AppMgrServiceInner::SetSupportedProcessCacheSelf(bool isSupport) TAG_LOGE(AAFwkTag::APPMGR, "no such appRecord, callerPid:%{public}d", callerPid); return ERR_INVALID_VALUE; } - if (!appRecord->SetSupportedProcessCache(isSupport)) { - TAG_LOGE(AAFwkTag::APPMGR, "SetSupportedProcessCache more than once"); - return AAFwk::ERR_SET_SUPPORTED_PROCESS_CACHE_AGAIN; - } - return ERR_OK; -} -int32_t AppMgrServiceInner::CheckSetProcessCachePermission() const -{ - TAG_LOGI(AAFwkTag::APPMGR, "Called."); - HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); - CHECK_CALLER_IS_SYSTEM_APP; - auto isCallingPerm = AAFwk::PermissionVerification::GetInstance()->VerifySetProcessCachePermission(); - TAG_LOGI(AAFwkTag::APPMGR, "ProcessCache permission: %{public}d", isCallingPerm); - return isCallingPerm ? ERR_OK : AAFwk::CHECK_PERMISSION_FAILED; + if (!DelayedSingleton::GetInstance()->QueryEnableProcessCache()) { + TAG_LOGE(AAFwkTag::APPMGR, "process cache feature is disabled."); + return AAFwk::ERR_CAPABILITY_NOT_SUPPORT; + } + appRecord->SetSupportedProcessCache(isSupport); + return ERR_OK; } void AppMgrServiceInner::OnAppCacheStateChanged(const std::shared_ptr &appRecord, diff --git a/services/appmgr/src/app_running_record.cpp b/services/appmgr/src/app_running_record.cpp index fd929bc26a..e968e73de1 100644 --- a/services/appmgr/src/app_running_record.cpp +++ b/services/appmgr/src/app_running_record.cpp @@ -2261,10 +2261,6 @@ int AppRunningRecord::DumpFfrt(std::string& result) bool AppRunningRecord::SetSupportedProcessCache(bool isSupport) { TAG_LOGI(AAFwkTag::APPMGR, "Called"); - if (procCacheSupportState_ != SupportProcessCacheState::UNSPECIFIED) { - TAG_LOGI(AAFwkTag::APPMGR, "Process cache not support set more than once."); - return false; - } procCacheSupportState_ = isSupport ? SupportProcessCacheState::SUPPORT : SupportProcessCacheState::NOT_SUPPORT; return true; } diff --git a/services/appmgr/src/cache_process_manager.cpp b/services/appmgr/src/cache_process_manager.cpp index 0f6d8cef57..6b83e68b12 100644 --- a/services/appmgr/src/cache_process_manager.cpp +++ b/services/appmgr/src/cache_process_manager.cpp @@ -25,6 +25,7 @@ namespace { const std::string MAX_PROC_CACHE_NUM = "persist.sys.abilityms.maxProcessCacheNum"; const std::string PROCESS_CACHE_API_CHECK_CONFIG = "persist.sys.abilityms.processCacheApiCheck"; +const std::string PROCESS_CACHE_SET_SUPPORT_CHECK_CONFIG = "persist.sys.abilityms.processCacheSetSupportCheck"; const std::string SHELL_ASSISTANT_BUNDLENAME = "com.huawei.shell_assistant"; constexpr int32_t API12 = 12; constexpr int32_t API_VERSION_MOD = 100; @@ -37,6 +38,7 @@ CacheProcessManager::CacheProcessManager() { maxProcCacheNum_ = OHOS::system::GetIntParameter(MAX_PROC_CACHE_NUM, 0); shouldCheckApi = OHOS::system::GetBoolParameter(PROCESS_CACHE_API_CHECK_CONFIG, true); + shouldCheckSupport = OHOS::system::GetBoolParameter(PROCESS_CACHE_SET_SUPPORT_CHECK_CONFIG, true); TAG_LOGW(AAFwkTag::APPMGR, "maxProcCacheNum is =%{public}d", maxProcCacheNum_); } @@ -255,16 +257,30 @@ bool CacheProcessManager::IsAppSupportProcessCache(const std::shared_ptr &appRecord) +{ + if (appRecord == nullptr) { + TAG_LOGI(AAFwkTag::APPMGR, "appRecord nullptr precheck failed"); + return false; + } auto supportState = appRecord->GetSupportProcessCacheState(); switch (supportState) { case SupportProcessCacheState::UNSPECIFIED: - return true; + TAG_LOGD(AAFwkTag::APPMGR, "App %{public}s has not defined support state.", + appRecord->GetBundleName().c_str()); + return shouldCheckSupport ? false : true; case SupportProcessCacheState::SUPPORT: return true; case SupportProcessCacheState::NOT_SUPPORT: + TAG_LOGD(AAFwkTag::APPMGR, "App %{public}s defines not support.", + appRecord->GetBundleName().c_str()); return false; default: - return true; + TAG_LOGD(AAFwkTag::APPMGR, "Invalid support state."); + return false; } } diff --git a/services/common/include/permission_verification.h b/services/common/include/permission_verification.h index b38bf5a2c6..ed12d8b189 100644 --- a/services/common/include/permission_verification.h +++ b/services/common/include/permission_verification.h @@ -99,8 +99,6 @@ struct VerificationInfo { bool VerifyPreloadApplicationPermission() const; - bool VerifySetProcessCachePermission() const; - bool VerifyPreStartAtomicServicePermission() const; private: diff --git a/services/common/src/permission_verification.cpp b/services/common/src/permission_verification.cpp index fa35280a3c..f07d0c73f2 100644 --- a/services/common/src/permission_verification.cpp +++ b/services/common/src/permission_verification.cpp @@ -476,16 +476,6 @@ bool PermissionVerification::VerifyPreloadApplicationPermission() const return false; } -bool PermissionVerification::VerifySetProcessCachePermission() const -{ - if (VerifyCallingPermission(PermissionConstants::PERMISSION_SET_PROCESS_CACHE_STATE)) { - TAG_LOGD(AAFwkTag::APPMGR, "Permission verification succeeded."); - return true; - } - TAG_LOGW(AAFwkTag::APPMGR, "Permission verification failed"); - return false; -} - bool PermissionVerification::VerifyPreStartAtomicServicePermission() const { if (VerifyCallingPermission(PermissionConstants::PERMISSION_PRE_START_ATOMIC_SERVICE)) { diff --git a/test/unittest/app_mgr_service_inner_test/BUILD.gn b/test/unittest/app_mgr_service_inner_test/BUILD.gn index f4ab66da66..b70803417d 100644 --- a/test/unittest/app_mgr_service_inner_test/BUILD.gn +++ b/test/unittest/app_mgr_service_inner_test/BUILD.gn @@ -63,6 +63,7 @@ ohos_unittest("AppMgrServiceInnerTest") { "c_utils:utils", "ffrt:libffrt", "hilog:libhilog", + "hitrace:hitrace_meter", "image_framework:image_native", "init:libbeget_proxy", "init:libbegetutil", diff --git a/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp b/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp index fa4eab5ec3..3d8c2b95de 100644 --- a/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp +++ b/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp @@ -4302,7 +4302,7 @@ HWTEST_F(AppMgrServiceInnerTest, SetSupportedProcessCacheSelf_001, TestSize.Leve EXPECT_NE(appMgrServiceInner, nullptr); bool isSupported = false; - EXPECT_EQ(appMgrServiceInner->SetSupportedProcessCacheSelf(isSupported), CHECK_PERMISSION_FAILED); + EXPECT_EQ(appMgrServiceInner->SetSupportedProcessCacheSelf(isSupported), ERR_INVALID_VALUE); appMgrServiceInner->appRunningManager_ = nullptr; EXPECT_EQ(appMgrServiceInner->SetSupportedProcessCacheSelf(isSupported), ERR_NO_INIT); diff --git a/test/unittest/app_mgr_service_test/BUILD.gn b/test/unittest/app_mgr_service_test/BUILD.gn index e5b06178f1..861ad9df91 100644 --- a/test/unittest/app_mgr_service_test/BUILD.gn +++ b/test/unittest/app_mgr_service_test/BUILD.gn @@ -61,6 +61,7 @@ ohos_unittest("app_mgr_service_test") { "c_utils:utils", "ffrt:libffrt", "hilog:libhilog", + "hitrace:hitrace_meter", "init:libbeget_proxy", "init:libbegetutil", "ipc:ipc_core", diff --git a/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp b/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp index e8eb6aeca6..c6fa4bdcae 100644 --- a/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp +++ b/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp @@ -1715,7 +1715,7 @@ HWTEST_F(AppMgrServiceTest, SetSupportedProcessCacheSelf_002, TestSize.Level0) // permission check failed int32_t res = appMgrService->SetSupportedProcessCacheSelf(false); - EXPECT_EQ(res, AAFwk::CHECK_PERMISSION_FAILED); + EXPECT_EQ(res, ERR_INVALID_VALUE); // appRecord not in AppRunningManager AAFwk::IsMockSaCall::IsMockProcessCachePermission(); @@ -1749,10 +1749,7 @@ HWTEST_F(AppMgrServiceTest, SetSupportedProcessCacheSelf_002, TestSize.Level0) recordMap.insert({IPCSkeleton::GetCallingPid(), appRecord}); } res = appMgrService->SetSupportedProcessCacheSelf(false); - EXPECT_EQ(res, ERR_OK); - - res = appMgrService->SetSupportedProcessCacheSelf(false); - EXPECT_EQ(res, AAFwk::ERR_SET_SUPPORTED_PROCESS_CACHE_AGAIN); + EXPECT_EQ(res, AAFwk::ERR_CAPABILITY_NOT_SUPPORT); } /** diff --git a/test/unittest/app_running_manager_test/app_running_manager_test.cpp b/test/unittest/app_running_manager_test/app_running_manager_test.cpp index e9c888c6ef..a0ce428d13 100644 --- a/test/unittest/app_running_manager_test/app_running_manager_test.cpp +++ b/test/unittest/app_running_manager_test/app_running_manager_test.cpp @@ -674,8 +674,10 @@ HWTEST_F(AppRunningManagerTest, IsAppProcessesAllCached_0100, TestSize.Level1) std::string processName = "com.tdd.cacheprocesstest"; auto appRunningRecord1 = std::make_shared(appInfo, recordId1, processName); appRunningRecord1->SetUid(appInfo->uid); + appRunningRecord1->SetSupportedProcessCache(true); auto appRunningRecord2 = std::make_shared(appInfo, recordId2, processName); appRunningRecord2->SetUid(appInfo->uid); + appRunningRecord2->SetSupportedProcessCache(true); appRunningManager->appRunningRecordMap_.insert(make_pair(recordId1, appRunningRecord1)); std::set> cachedSet; diff --git a/test/unittest/cache_process_manager_test/cache_process_manager_test.cpp b/test/unittest/cache_process_manager_test/cache_process_manager_test.cpp index 80b09876a9..cfad79654a 100644 --- a/test/unittest/cache_process_manager_test/cache_process_manager_test.cpp +++ b/test/unittest/cache_process_manager_test/cache_process_manager_test.cpp @@ -266,7 +266,7 @@ HWTEST_F(CacheProcessManagerTest, CacheProcessManager_IsAppSupportProcessCache_0 // different supportState auto appRecord3 = MockAppRecord(12); EXPECT_NE(appRecord3, nullptr); - EXPECT_EQ(cacheProcMgr->IsAppSupportProcessCache(appRecord3), true); + EXPECT_EQ(cacheProcMgr->IsAppSupportProcessCache(appRecord3), false); appRecord3->SetSupportedProcessCache(true); EXPECT_EQ(cacheProcMgr->IsAppSupportProcessCache(appRecord3), true); appRecord3->procCacheSupportState_ = SupportProcessCacheState::NOT_SUPPORT;