!9305 【应用热启需求】开启策略改为应用接口确认后才开启

Merge pull request !9305 from 胡泽善/disableByDefault
This commit is contained in:
openharmony_ci
2024-07-11 09:20:09 +00:00
committed by Gitee
18 changed files with 38 additions and 65 deletions
@@ -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<AbilityErrorCode, const char*> 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<int32_t, AbilityErrorCode> 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},
@@ -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);
@@ -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,
@@ -149,8 +149,6 @@ const std::map<int32_t, std::string> 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" },
};
}
@@ -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,
@@ -1477,8 +1477,6 @@ private:
const HapModuleInfo &hapModuleInfo, std::shared_ptr<AAFwk::Want> want,
bool appExistFlag, bool isPreload, sptr<IRemoteObject> token = nullptr);
int32_t CheckSetProcessCachePermission() const;
int32_t CreatNewStartMsg(const Want &want, const AbilityInfo &abilityInfo,
const std::shared_ptr<ApplicationInfo> &appInfo, const std::string &processName,
AppSpawnStartMsg &startMsg);
@@ -54,11 +54,14 @@ private:
void AddToApplicationSet(const std::shared_ptr<AppRunningRecord> &appRecord);
void RemoveFromApplicationSet(const std::shared_ptr<AppRunningRecord> &appRecord);
bool CheckAndNotifyCachedState(const std::shared_ptr<AppRunningRecord> &appRecord);
bool IsAppSupportProcessCacheInnerFirst(const std::shared_ptr<AppRunningRecord> &appRecord);
int32_t maxProcCacheNum_ = 0;
std::deque<std::shared_ptr<AppRunningRecord>> cachedAppRecordQueue_;
ffrt::recursive_mutex cacheQueueMtx;
std::weak_ptr<AppMgrServiceInner> appMgr_;
bool shouldCheckApi = true;
// whether the feature should check setSupportedProcessCache value or not
bool shouldCheckSupport = true;
// bundleName->uid->record
std::map<std::string, std::map<int32_t, std::set<std::shared_ptr<AppRunningRecord>>>> sameAppSet;
// stores records that are servcie extension
+6 -19
View File
@@ -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<CacheProcessManager>::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<AppRunningRecord> &appRecord,
@@ -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;
}
+18 -2
View File
@@ -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<int>(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<AppRunn
TAG_LOGD(AAFwkTag::APPMGR, "shell assistant, not support.");
return false;
}
return IsAppSupportProcessCacheInnerFirst(appRecord);
}
bool CacheProcessManager::IsAppSupportProcessCacheInnerFirst(const std::shared_ptr<AppRunningRecord> &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;
}
}
@@ -99,8 +99,6 @@ struct VerificationInfo {
bool VerifyPreloadApplicationPermission() const;
bool VerifySetProcessCachePermission() const;
bool VerifyPreStartAtomicServicePermission() const;
private:
@@ -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)) {
@@ -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",
@@ -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);
@@ -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",
@@ -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);
}
/**
@@ -674,8 +674,10 @@ HWTEST_F(AppRunningManagerTest, IsAppProcessesAllCached_0100, TestSize.Level1)
std::string processName = "com.tdd.cacheprocesstest";
auto appRunningRecord1 = std::make_shared<AppRunningRecord>(appInfo, recordId1, processName);
appRunningRecord1->SetUid(appInfo->uid);
appRunningRecord1->SetSupportedProcessCache(true);
auto appRunningRecord2 = std::make_shared<AppRunningRecord>(appInfo, recordId2, processName);
appRunningRecord2->SetUid(appInfo->uid);
appRunningRecord2->SetSupportedProcessCache(true);
appRunningManager->appRunningRecordMap_.insert(make_pair(recordId1, appRunningRecord1));
std::set<std::shared_ptr<AppRunningRecord>> cachedSet;
@@ -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;