!11400 支持三方应用保活

Merge pull request !11400 from 杨旭光/feat/keep-alive-new
This commit is contained in:
openharmony_ci 2024-11-10 12:18:23 +00:00 committed by Gitee
commit 151c895818
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
92 changed files with 1810 additions and 471 deletions

View File

@ -184,6 +184,16 @@ public:
{
GET_CB_INFO_AND_CALL(env, info, JsAppManager, OnGetSupportedProcessCachePids);
}
static napi_value SetKeepAliveForBundle(napi_env env, napi_callback_info info)
{
GET_CB_INFO_AND_CALL(env, info, JsAppManager, OnSetKeepAliveForBundle);
}
static napi_value GetKeepAliveBundles(napi_env env, napi_callback_info info)
{
GET_CB_INFO_AND_CALL(env, info, JsAppManager, OnGetKeepAliveBundles);
}
#ifdef SUPPORT_SCREEN
static bool CheckCallerIsSystemApp()
{
@ -1457,6 +1467,138 @@ private:
return result;
}
napi_value OnSetKeepAliveForBundleInner(napi_env env, const std::string &bundleName,
int32_t userId, bool flag)
{
auto innerErrCode = std::make_shared<ErrCode>(ERR_OK);
NapiAsyncTask::ExecuteCallback execute = [bundleName, userId, flag,
abilityManager = abilityManager_, innerErrCode]() {
if (innerErrCode == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "inner code null");
return;
}
if (abilityManager == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "abilityManager nullptr");
*innerErrCode = static_cast<int>(AbilityErrorCode::ERROR_CODE_INNER);
return;
}
*innerErrCode = abilityManager->SetApplicationKeepAlive(bundleName, userId, flag);
};
NapiAsyncTask::CompleteCallback complete = [innerErrCode](napi_env env, NapiAsyncTask& task, int32_t status) {
if (innerErrCode == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "inner code null");
task.Reject(env, CreateJsErrorByNativeErr(env,
static_cast<int>(AbilityErrorCode::ERROR_CODE_INNER)));
return;
}
if (*innerErrCode == ERR_OK) {
TAG_LOGI(AAFwkTag::APPMGR, "SetApplicationKeepAlive succeeded.");
task.ResolveWithNoError(env, CreateJsUndefined(env));
return;
}
TAG_LOGE(AAFwkTag::APPMGR, "SetApplicationKeepAlive failed:%{public}d", *innerErrCode);
task.Reject(env, CreateJsErrorByNativeErr(env, *innerErrCode));
};
napi_value result = nullptr;
NapiAsyncTask::ScheduleHighQos("OnSetKeepAliveForBundle", env,
CreateAsyncTaskWithLastParam(env, nullptr, std::move(execute), std::move(complete), &result));
return result;
}
napi_value OnSetKeepAliveForBundle(napi_env env, size_t argc, napi_value *argv)
{
if (argc < ARGC_THREE) {
TAG_LOGE(AAFwkTag::APPMGR, "Params not enough.");
ThrowTooFewParametersError(env);
return CreateJsUndefined(env);
}
std::string bundleName;
if (!ConvertFromJsValue(env, argv[INDEX_ZERO], bundleName)) {
TAG_LOGE(AAFwkTag::APPMGR, "get bundleName wrong.");
ThrowInvalidParamError(env, "Parse param bundleName failed, must be a string.");
return CreateJsUndefined(env);
}
int32_t userId = -1;
if (!ConvertFromJsValue(env, argv[INDEX_ONE], userId)) {
TAG_LOGE(AAFwkTag::APPMGR, "get userId wrong.");
ThrowInvalidParamError(env, "Parse param userId failed, must be a number.");
return CreateJsUndefined(env);
}
bool flag = false;
if (!ConvertFromJsValue(env, argv[INDEX_TWO], flag)) {
TAG_LOGE(AAFwkTag::APPMGR, "get flag wrong.");
ThrowInvalidParamError(env, "Parse param flag failed, must be a boolean.");
return CreateJsUndefined(env);
}
return OnSetKeepAliveForBundleInner(env, bundleName, userId, flag);
}
napi_value OnGetKeepAliveBundlesInner(napi_env env, int32_t appType, int32_t userId)
{
auto innerErrCode = std::make_shared<ErrCode>(ERR_OK);
auto infoList = std::make_shared<std::vector<KeepAliveInfo>>();
NapiAsyncTask::ExecuteCallback execute = [appType, userId, abilityManager = abilityManager_,
infoList, innerErrCode]() {
if (infoList == nullptr || innerErrCode == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "infoList or inner code null");
return;
}
if (abilityManager == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "abilityManager nullptr");
*innerErrCode = static_cast<int>(AbilityErrorCode::ERROR_CODE_INNER);
return;
}
*innerErrCode = abilityManager->QueryKeepAliveApplications(appType, userId, *infoList);
};
NapiAsyncTask::CompleteCallback complete = [infoList, innerErrCode](
napi_env env, NapiAsyncTask& task, int32_t status) {
if (infoList == nullptr || innerErrCode == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "infoList or inner code null");
task.Reject(env, CreateJsErrorByNativeErr(env,
static_cast<int>(AbilityErrorCode::ERROR_CODE_INNER)));
return;
}
if (*innerErrCode == ERR_OK) {
TAG_LOGI(AAFwkTag::APPMGR, "QueryKeepAliveApplications succeeded.");
task.ResolveWithNoError(env, CreateJsKeepAliveBundleInfoArray(env, *infoList));
return;
}
TAG_LOGE(AAFwkTag::APPMGR, "QueryKeepAliveApplications failed:%{public}d", *innerErrCode);
task.Reject(env, CreateJsErrorByNativeErr(env, *innerErrCode));
};
napi_value result = nullptr;
NapiAsyncTask::ScheduleHighQos("OnSetKeepAliveForBundle", env,
CreateAsyncTaskWithLastParam(env, nullptr, std::move(execute), std::move(complete), &result));
return result;
}
napi_value OnGetKeepAliveBundles(napi_env env, size_t argc, napi_value *argv)
{
TAG_LOGD(AAFwkTag::APPMGR, "called");
if (argc < ARGC_ONE) {
TAG_LOGE(AAFwkTag::APPMGR, "Params not enough.");
ThrowTooFewParametersError(env);
return CreateJsUndefined(env);
}
int32_t appType = 0;
if (!ConvertFromJsValue(env, argv[INDEX_ZERO], appType)) {
TAG_LOGE(AAFwkTag::APPMGR, "get appType wrong.");
ThrowInvalidParamError(env, "Parse param appType failed, must be a number.");
return CreateJsUndefined(env);
}
int32_t userId = -1;
if (argc > ARGC_ONE && !ConvertFromJsValue(env, argv[INDEX_ONE], userId)) {
TAG_LOGE(AAFwkTag::APPMGR, "get userId wrong.");
ThrowInvalidParamError(env, "Parse param userId failed, must be a number.");
return CreateJsUndefined(env);
}
return OnGetKeepAliveBundlesInner(env, appType, userId);
}
bool CheckOnOffType(napi_env env, size_t argc, napi_value* argv)
{
if (argc < ARGC_ONE) {
@ -1524,6 +1666,8 @@ napi_value JsAppManagerInit(napi_env env, napi_value exportObj)
napi_set_named_property(env, exportObj, "ApplicationState", ApplicationStateInit(env));
napi_set_named_property(env, exportObj, "ProcessState", ProcessStateInit(env));
napi_set_named_property(env, exportObj, "PreloadMode", PreloadModeInit(env));
napi_set_named_property(env, exportObj, "KeepAliveAppType", KeepAliveAppTypeInit(env));
napi_set_named_property(env, exportObj, "KeepAliveSetter", KeepAliveSetterInit(env));
const char *moduleName = "AppManager";
BindNativeFunction(env, exportObj, "on", moduleName, JsAppManager::On);
@ -1534,8 +1678,7 @@ napi_value JsAppManagerInit(napi_env env, napi_value exportObj)
JsAppManager::GetRunningProcessInformation);
BindNativeFunction(env, exportObj, "getRunningProcessInformation", moduleName,
JsAppManager::GetRunningProcessInformation);
BindNativeFunction(env, exportObj, "isRunningInStabilityTest", moduleName,
JsAppManager::IsRunningInStabilityTest);
BindNativeFunction(env, exportObj, "isRunningInStabilityTest", moduleName, JsAppManager::IsRunningInStabilityTest);
BindNativeFunction(env, exportObj, "killProcessWithAccount", moduleName, JsAppManager::KillProcessWithAccount);
BindNativeFunction(env, exportObj, "killProcessesByBundleName", moduleName,
JsAppManager::KillProcessesByBundleName);
@ -1550,13 +1693,14 @@ napi_value JsAppManagerInit(napi_env env, napi_value exportObj)
JsAppManager::GetRunningProcessInfoByBundleName);
BindNativeFunction(env, exportObj, "getRunningMultiAppInfo", moduleName, JsAppManager::GetRunningMultiAppInfo);
BindNativeFunction(env, exportObj, "isApplicationRunning", moduleName, JsAppManager::IsApplicationRunning);
BindNativeFunction(env, exportObj, "isAppRunning", moduleName,
JsAppManager::IsAppRunning);
BindNativeFunction(env, exportObj, "isAppRunning", moduleName, JsAppManager::IsAppRunning);
BindNativeFunction(env, exportObj, "preloadApplication", moduleName, JsAppManager::PreloadApplication);
BindNativeFunction(env, exportObj, "getRunningProcessInformationByBundleType", moduleName,
JsAppManager::GetRunningProcessInformationByBundleType);
BindNativeFunction(env, exportObj, "getSupportedProcessCachePids", moduleName,
JsAppManager::GetSupportedProcessCachePids);
BindNativeFunction(env, exportObj, "setKeepAliveForBundle", moduleName, JsAppManager::SetKeepAliveForBundle);
BindNativeFunction(env, exportObj, "getKeepAliveBundles", moduleName, JsAppManager::GetKeepAliveBundles);
TAG_LOGD(AAFwkTag::APPMGR, "end");
return CreateJsUndefined(env);
}

View File

@ -299,6 +299,48 @@ napi_value PreloadModeInit(napi_env env)
return objValue;
}
napi_value KeepAliveAppTypeInit(napi_env env)
{
if (env == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "null env");
return nullptr;
}
napi_value object = nullptr;
napi_create_object(env, &object);
if (object == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "null obj");
return nullptr;
}
napi_set_named_property(env, object, "ALL", CreateJsValue(env,
static_cast<int32_t>(KeepAliveAppType::UNSPECIFIED)));
napi_set_named_property(env, object, "THIRD_PARTY",
CreateJsValue(env, static_cast<int32_t>(KeepAliveAppType::THIRD_PARTY)));
napi_set_named_property(env, object, "SYSTEM",
CreateJsValue(env, static_cast<int32_t>(KeepAliveAppType::SYSTEM)));
return object;
}
napi_value KeepAliveSetterInit(napi_env env)
{
if (env == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "null env");
return nullptr;
}
napi_value object = nullptr;
napi_create_object(env, &object);
if (object == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "null obj");
return nullptr;
}
napi_set_named_property(env, object, "SYSTEM",
CreateJsValue(env, static_cast<int32_t>(KeepAliveSetter::SYSTEM)));
napi_set_named_property(env, object, "USER",
CreateJsValue(env, static_cast<int32_t>(KeepAliveSetter::USER)));
return object;
}
bool ConvertPreloadApplicationParam(napi_env env, size_t argc, napi_value *argv, PreloadApplicationParam &param,
std::string &errorMsg)
{
@ -352,5 +394,30 @@ JsAppProcessState ConvertToJsAppProcessState(
}
return processState;
}
napi_value CreateJsKeepAliveBundleInfo(napi_env env, const KeepAliveInfo &info)
{
napi_value object = nullptr;
napi_create_object(env, &object);
if (object == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "null obj");
return nullptr;
}
napi_set_named_property(env, object, "bundleName", CreateJsValue(env, info.bundleName));
napi_set_named_property(env, object, "type", CreateJsValue(env, static_cast<int32_t>(info.appType)));
napi_set_named_property(env, object, "setter", CreateJsValue(env, static_cast<int32_t>(info.setter)));
return object;
}
napi_value CreateJsKeepAliveBundleInfoArray(napi_env env, const std::vector<KeepAliveInfo>& data)
{
napi_value arrayValue = nullptr;
napi_create_array_with_length(env, data.size(), &arrayValue);
uint32_t index = 0;
for (const auto &item : data) {
napi_set_element(env, arrayValue, index++, CreateJsKeepAliveBundleInfo(env, item));
}
return arrayValue;
}
} // namespace AbilityRuntime
} // namespace OHOS

View File

@ -17,6 +17,7 @@
#define OHOS_ABILITY_RUNTIME_JS_APP_MANAGER_UTILS_H
#include "application_state_observer_stub.h"
#include "keep_alive_info.h"
#include "native_engine/native_engine.h"
#include "running_process_info.h"
#include "running_multi_info.h"
@ -63,6 +64,8 @@ napi_value CreateJsRunningProcessInfo(napi_env env, const RunningProcessInfo &in
napi_value ApplicationStateInit(napi_env env);
napi_value ProcessStateInit(napi_env env);
napi_value PreloadModeInit(napi_env env);
napi_value KeepAliveAppTypeInit(napi_env env);
napi_value KeepAliveSetterInit(napi_env env);
bool ConvertPreloadApplicationParam(napi_env env, size_t argc, napi_value *argv, PreloadApplicationParam &param,
std::string &errorMsg);
JsAppProcessState ConvertToJsAppProcessState(
@ -72,6 +75,8 @@ napi_value CreateJsRunningAppCloneArray(napi_env env, const std::vector<RunningA
napi_value CreateJsRunningAppClone(napi_env env, const RunningAppClone &info);
napi_value CreateJsRunningMultiInstanceInfosArray(napi_env env, const std::vector<RunningMultiInstanceInfo>& data);
napi_value CreateJsRunningMultiInstanceInfo(napi_env env, const RunningMultiInstanceInfo &info);
napi_value CreateJsKeepAliveBundleInfo(napi_env env, const KeepAliveInfo &info);
napi_value CreateJsKeepAliveBundleInfoArray(napi_env env, const std::vector<KeepAliveInfo>& data);
} // namespace AbilityRuntime
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_JS_APP_MANAGER_UTILS_H

View File

@ -77,6 +77,9 @@ constexpr const char* ERROR_MSG_NOT_SUPPORT_CROSS_APP_START =
"Redirection to a third-party application is not allowed in API version 11 or later.";
constexpr const char* ERROR_MSG_CANNOT_MATCH_ANY_COMPONENT = "No matching ability is found.";
constexpr const char* ERROR_MSG_TARGET_BUNDLE_NOT_EXIST = "The bundle does not exist or no patch has been applied.";
constexpr const char* ERROR_MSG_NO_MAIN_ABILITY = "The target bundle has no main ability.";
constexpr const char* ERROR_MSG_NO_STATUS_BAR_ABILITY = "The target app has no status-bar ability.";
constexpr const char* ERROR_MSG_NOT_ATTACHED_TO_STATUS_BAR = "The target app is not attached to a status bar.";
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.";
@ -148,6 +151,9 @@ 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_NO_MAIN_ABILITY, ERROR_MSG_NO_MAIN_ABILITY },
{ AbilityErrorCode::ERROR_CODE_NO_STATUS_BAR_ABILITY, ERROR_MSG_NO_STATUS_BAR_ABILITY },
{ AbilityErrorCode::ERROR_CODE_NOT_ATTACHED_TO_STATUS_BAR, ERROR_MSG_NOT_ATTACHED_TO_STATUS_BAR },
{ 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_NOT_APP_CLONE, ERROR_MSG_NOT_APP_CLONE },
@ -219,6 +225,9 @@ static std::unordered_map<int32_t, AbilityErrorCode> INNER_TO_JS_ERROR_CODE_MAP
{ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST, AbilityErrorCode::ERROR_CODE_INVALID_ID},
{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_NO_MAIN_ABILITY, AbilityErrorCode::ERROR_CODE_NO_MAIN_ABILITY},
{ERR_NO_STATUS_BAR_ABILITY, AbilityErrorCode::ERROR_CODE_NO_STATUS_BAR_ABILITY},
{ERR_NOT_ATTACHED_TO_STATUS_BAR, AbilityErrorCode::ERROR_CODE_NOT_ATTACHED_TO_STATUS_BAR},
{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},

View File

@ -85,6 +85,7 @@ ohos_shared_library("ability_manager") {
"${ability_runtime_services_path}/abilitymgr/src/insight_intent_execute_callback_stub.cpp",
"${ability_runtime_services_path}/abilitymgr/src/insight_intent_execute_param.cpp",
"${ability_runtime_services_path}/abilitymgr/src/insight_intent_execute_result.cpp",
"${ability_runtime_services_path}/abilitymgr/src/keep_alive/keep_alive_info.cpp",
"${ability_runtime_services_path}/abilitymgr/src/launch_param.cpp",
"${ability_runtime_services_path}/abilitymgr/src/lifecycle_state_info.cpp",
"${ability_runtime_services_path}/abilitymgr/src/mission/mission_listener_stub.cpp",

View File

@ -807,6 +807,21 @@ enum NativeFreeInstallError {
*/
INVALID_REMOTE_PARAMETERS_ERR = 29360131,
/**
* Native error(29360135) for target bundle has no main ability.
*/
ERR_NO_MAIN_ABILITY = 29360135,
/**
* Native error(29360136) for target app has no status-bar ability.
*/
ERR_NO_STATUS_BAR_ABILITY = 29360136,
/**
* Native error(29360137) for target app is not attached to a status bar.
*/
ERR_NOT_ATTACHED_TO_STATUS_BAR = 29360137,
/*
* Result(29360205) for continue freeinstall failed.
*/

View File

@ -40,6 +40,7 @@
#include "insight_intent_execute_param.h"
#include "insight_intent_execute_result.h"
#include "iprepare_terminate_callback_interface.h"
#include "keep_alive_info.h"
#include "mission_info.h"
#include "mission_listener_interface.h"
#include "mission_snapshot.h"
@ -73,6 +74,7 @@ class IStatusBarDelegate;
}
namespace AAFwk {
using KeepAliveInfo = AbilityRuntime::KeepAliveInfo;
using AutoStartupInfo = AbilityRuntime::AutoStartupInfo;
using InsightIntentExecuteParam = AppExecFwk::InsightIntentExecuteParam;
using InsightIntentExecuteResult = AppExecFwk::InsightIntentExecuteResult;
@ -1895,6 +1897,54 @@ public:
{
return 0;
}
/**
* Set keep-alive flag for application under a specific user.
* @param bundleName Bundle name.
* @param userId User Id.
* @param flag Keep-alive flag.
* @return Returns ERR_OK on success, others on failure.
*/
virtual int32_t SetApplicationKeepAlive(const std::string &bundleName, int32_t userId, bool flag)
{
return 0;
}
/**
* Get keep-alive applications.
* @param appType Application type.
* @param userId User Id.
* @param list List of Keep-alive information.
* @return Returns ERR_OK on success, others on failure.
*/
virtual int32_t QueryKeepAliveApplications(int32_t appType, int32_t userId, std::vector<KeepAliveInfo> &list)
{
return 0;
}
/**
* Set keep-alive flag for application under a specific user by EDM.
* @param bundleName Bundle name.
* @param userId User Id.
* @param flag Keep-alive flag.
* @return Returns ERR_OK on success, others on failure.
*/
virtual int32_t SetApplicationKeepAliveByEDM(const std::string &bundleName, int32_t userId, bool flag)
{
return 0;
}
/**
* Get keep-alive applications by EDM.
* @param appType Application type.
* @param userId User Id.
* @param list List of Keep-alive information.
* @return Returns ERR_OK on success, others on failure.
*/
virtual int32_t QueryKeepAliveApplicationsByEDM(int32_t appType, int32_t userId, std::vector<KeepAliveInfo> &list)
{
return 0;
}
};
} // namespace AAFwk
} // namespace OHOS

View File

@ -561,6 +561,18 @@ enum class AbilityManagerInterfaceCode {
// update associate config list
UPDATE_ASSOCIATE_CONFIG_LIST = 6120,
// set application keep alive
SET_APPLICATION_KEEP_ALLIVE = 6121,
// get keep-alive applications
GET_APPLICATIONS_KEEP_ALIVE = 6122,
// set application keep alive by EDM
SET_APPLICATION_KEEP_ALLIVE_BY_EDM = 6123,
// get keep-alive applications by EDM
GET_APPLICATIONS_KEEP_ALIVE_BY_EDM = 6124,
};
} // namespace AAFwk
} // namespace OHOS

View File

@ -38,7 +38,7 @@ enum class KeepAliveSetter : int32_t {
*/
enum class KeepAliveAppType : int32_t {
UNSPECIFIED = 0,
APP = 1,
THIRD_PARTY = 1,
SYSTEM = 2,
};
@ -60,7 +60,7 @@ public:
struct KeepAliveStatus {
int32_t code;
bool isKeepAlive;
KeepAliveSetter setter;
};
} // namespace AbilityRuntime
} // namespace OHOS

View File

@ -56,6 +56,7 @@ public:
ProcessMode processMode = ProcessMode::UNSPECIFIED;
StartupVisibility startupVisibility = StartupVisibility::UNSPECIFIED;
std::string processName;
bool isRestartKeepAlive = false;
};
} // namespace AAFwk
} // namespace OHOS

View File

@ -375,6 +375,14 @@ public:
*/
virtual void SetKeepAliveEnableState(const std::string &bundleName, bool enable, int32_t uid) {};
/**
* @brief Set non-resident keep-alive process status.
* @param bundleName The application bundle name.
* @param enable The current updated enable status.
* @param uid indicates user, 0 for all users
*/
virtual void SetKeepAliveDkv(const std::string &bundleName, bool enable, int32_t uid) {};
/**
* To clear the process by ability token.
*
@ -502,6 +510,7 @@ public:
IS_APP_KILLING,
ENABLE_START_PROCESS_FLAG_BY_USER_ID,
SET_APP_EXCEPTION_CALLBACK,
SET_KEEP_ALIVE_DKV,
// Add enumeration values above
END
};

View File

@ -338,6 +338,14 @@ public:
*/
void SetKeepAliveEnableState(const std::string &bundleName, bool enable, int32_t uid) override;
/**
* @brief Set non-resident keep-alive process status.
* @param bundleName The application bundle name.
* @param enable The current updated enable status.
* @param uid indicates user, 0 for all users
*/
void SetKeepAliveDkv(const std::string &bundleName, bool enable, int32_t uid) override;
/**
* To clear the process by ability token.
*

View File

@ -85,6 +85,7 @@ private:
int32_t HandleClearProcessByToken(MessageParcel &data, MessageParcel &reply);
int32_t HandleIsMemorySizeSufficent(MessageParcel &data, MessageParcel &reply);
int32_t HandleSetKeepAliveEnableState(MessageParcel &data, MessageParcel &reply);
int32_t HandleSetKeepAliveDkv(MessageParcel &data, MessageParcel &reply);
int32_t HandleAttachedToStatusBar(MessageParcel &data, MessageParcel &reply);
int32_t OnRemoteRequestInner(uint32_t code, MessageParcel &data,
MessageParcel &reply, MessageOption &option);

View File

@ -675,6 +675,14 @@ public:
*/
void SetKeepAliveEnableState(const std::string &bundleName, bool enable, int32_t uid);
/**
* @brief Set non-resident keep-alive process status.
* @param bundleName The application bundle name.
* @param enable The current updated enable status.
* @param uid indicates user, 0 for all users
*/
void SetKeepAliveDkv(const std::string &bundleName, bool enable, int32_t uid);
/**
* Register application or process state observer.
* @param observer, ability token.
@ -893,6 +901,17 @@ public:
bool IsAppKilling(sptr<IRemoteObject> token) const;
/**
* Check whether the bundle is running.
*
* @param bundleName Indicates the bundle name of the bundle.
* @param appCloneIndex the appindex of the bundle.
* @param isRunning Obtain the running status of the application, the result is true if running, false otherwise.
* @return Return ERR_OK if success, others fail.
*/
virtual AppMgrResultCode IsAppRunning(const std::string &bundleName, int32_t appCloneIndex,
bool &isRunning);
private:
void SetServiceManager(std::unique_ptr<AppServiceManager> serviceMgr);
/**

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -62,7 +62,13 @@ public:
* @param bundleInfos resident process bundle infos.
*/
virtual void NotifyStartResidentProcess(std::vector<AppExecFwk::BundleInfo> &bundleInfos) override;
/**
* @brief Notify abilityms start keep-alive process.
* @param bundleInfos resident process bundle infos.
*/
virtual void NotifyStartKeepAliveProcess(std::vector<AppExecFwk::BundleInfo> &bundleInfos) override;
/**
* @brief Notify abilityms app process OnRemoteDied
* @param abilityTokens abilities in died process.
@ -81,6 +87,7 @@ private:
int32_t HandleOnAbilityRequestDone(MessageParcel &data, MessageParcel &reply);
int32_t HandleNotifyConfigurationChange(MessageParcel &data, MessageParcel &reply);
int32_t HandleNotifyStartResidentProcess(MessageParcel &data, MessageParcel &reply);
int32_t HandleNotifyStartKeepAliveProcess(MessageParcel &data, MessageParcel &reply);
int32_t HandleOnAppRemoteDied(MessageParcel &data, MessageParcel &reply);
int32_t HandleNotifyAppPreCache(MessageParcel &data, MessageParcel &reply);

View File

@ -57,6 +57,12 @@ public:
*/
virtual void NotifyStartResidentProcess(std::vector<AppExecFwk::BundleInfo> &bundleInfos) override;
/**
* @brief Notify abilityms start keep-alive process.
* @param bundleInfos resident process bundle infos.
*/
virtual void NotifyStartKeepAliveProcess(std::vector<AppExecFwk::BundleInfo> &bundleInfos) override;
/**
* @brief Notify abilityms app process OnRemoteDied
* @param abilityTokens abilities in died process.

View File

@ -63,6 +63,12 @@ public:
*/
virtual void NotifyStartResidentProcess(std::vector<AppExecFwk::BundleInfo> &bundleInfos) {}
/**
* @brief Notify abilityms start keep-alive process.
* @param bundleInfos resident process bundle infos.
*/
virtual void NotifyStartKeepAliveProcess(std::vector<AppExecFwk::BundleInfo> &bundleInfos) {}
/**
* @brief Notify abilityms app process OnRemoteDied
* @param abilityTokens abilities in died process.
@ -82,7 +88,8 @@ public:
TRANSACT_ON_NOTIFY_CONFIG_CHANGE,
TRANSACT_ON_NOTIFY_START_RESIDENT_PROCESS,
TRANSACT_ON_APP_REMOTE_DIED,
TRANSACT_ON_APP_PRE_CACHE
TRANSACT_ON_APP_PRE_CACHE,
TRANSACT_ON_NOTIFY_START_KEEP_ALIVE_PROCESS
};
};
} // namespace AppExecFwk

View File

@ -972,6 +972,31 @@ void AmsMgrProxy::SetKeepAliveEnableState(const std::string &bundleName, bool en
}
}
void AmsMgrProxy::SetKeepAliveDkv(const std::string &bundleName, bool enable, int32_t uid)
{
TAG_LOGD(AAFwkTag::APPMGR, "called");
MessageParcel data;
if (!WriteInterfaceToken(data)) {
TAG_LOGE(AAFwkTag::APPMGR, "Write token failed");
return;
}
if (bundleName.empty() || !data.WriteString(bundleName)) {
TAG_LOGE(AAFwkTag::APPMGR, "Write bundleName fail");
return;
}
if (!data.WriteBool(enable) || !data.WriteInt32(uid)) {
TAG_LOGE(AAFwkTag::APPMGR, "Write flag or uid fail");
return;
}
MessageParcel reply;
MessageOption option;
auto ret = SendTransactCmd(static_cast<uint32_t>(IAmsMgr::Message::SET_KEEP_ALIVE_DKV),
data, reply, option);
if (ret != NO_ERROR) {
TAG_LOGE(AAFwkTag::APPMGR, "Send request err: %{public}d", ret);
}
}
int32_t AmsMgrProxy::SetAppWaitingDebug(const std::string &bundleName, bool isPersist)
{
TAG_LOGD(AAFwkTag::APPMGR, "called");

View File

@ -215,6 +215,8 @@ int32_t AmsMgrStub::OnRemoteRequestInnerFourth(uint32_t code, MessageParcel &dat
return HandleIsProcessAttached(data, reply);
case static_cast<uint32_t>(IAmsMgr::Message::IS_APP_KILLING):
return HandleIsAppKilling(data, reply);
case static_cast<uint32_t>(IAmsMgr::Message::SET_KEEP_ALIVE_DKV):
return HandleSetKeepAliveDkv(data, reply);
}
return AAFwk::ERR_CODE_NOT_EXIST;
}
@ -714,6 +716,16 @@ int32_t AmsMgrStub::HandleSetKeepAliveEnableState(MessageParcel &data, MessagePa
return NO_ERROR;
}
int32_t AmsMgrStub::HandleSetKeepAliveDkv(MessageParcel &data, MessageParcel &reply)
{
TAG_LOGD(AAFwkTag::APPMGR, "called");
auto bundleName = data.ReadString();
auto enable = data.ReadBool();
auto uid = data.ReadInt32();
SetKeepAliveDkv(bundleName, enable, uid);
return NO_ERROR;
}
int32_t AmsMgrStub::HandleClearNonPersistWaitingDebugFlag(MessageParcel &data, MessageParcel &reply)
{
TAG_LOGD(AAFwkTag::APPMGR, "called");

View File

@ -688,6 +688,14 @@ void AppMgrClient::SetKeepAliveEnableState(const std::string &bundleName, bool e
amsService_->SetKeepAliveEnableState(bundleName, enable, uid);
}
void AppMgrClient::SetKeepAliveDkv(const std::string &bundleName, bool enable, int32_t uid)
{
if (!IsAmsServiceReady()) {
return;
}
amsService_->SetKeepAliveDkv(bundleName, enable, uid);
}
void AppMgrClient::StartSpecifiedProcess(const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo,
int32_t requestId)
{
@ -1403,5 +1411,15 @@ bool AppMgrClient::IsAppKilling(sptr<IRemoteObject> token) const
}
return amsService->IsAppKilling(token);
}
AppMgrResultCode AppMgrClient::IsAppRunning(const std::string &bundleName, int32_t appCloneIndex,
bool &isRunning)
{
sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
if (service != nullptr) {
return AppMgrResultCode(service->IsAppRunning(bundleName, appCloneIndex, isRunning));
}
return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
}
} // namespace AppExecFwk
} // namespace OHOS

View File

@ -56,6 +56,8 @@ int AppStateCallbackHost::OnRemoteRequest(
return HandleOnAppRemoteDied(data, reply);
case static_cast<uint32_t>(IAppStateCallback::Message::TRANSACT_ON_APP_PRE_CACHE):
return HandleNotifyAppPreCache(data, reply);
case static_cast<uint32_t>(IAppStateCallback::Message::TRANSACT_ON_NOTIFY_START_KEEP_ALIVE_PROCESS):
return HandleNotifyStartKeepAliveProcess(data, reply);
}
TAG_LOGD(AAFwkTag::APPMGR, "AppStateCallbackHost::OnRemoteRequest end");
@ -86,6 +88,11 @@ void AppStateCallbackHost::NotifyStartResidentProcess(std::vector<AppExecFwk::Bu
TAG_LOGD(AAFwkTag::APPMGR, "called");
}
void AppStateCallbackHost::NotifyStartKeepAliveProcess(std::vector<AppExecFwk::BundleInfo> &bundleInfos)
{
TAG_LOGD(AAFwkTag::APPMGR, "called");
}
void AppStateCallbackHost::OnAppRemoteDied(const std::vector<sptr<IRemoteObject>> &abilityTokens)
{
TAG_LOGD(AAFwkTag::APPMGR, "called");
@ -148,6 +155,26 @@ int32_t AppStateCallbackHost::HandleNotifyStartResidentProcess(MessageParcel &da
return NO_ERROR;
}
int32_t AppStateCallbackHost::HandleNotifyStartKeepAliveProcess(MessageParcel &data, MessageParcel &reply)
{
std::vector<AppExecFwk::BundleInfo> bundleInfos;
int32_t infoSize = data.ReadInt32();
if (infoSize > CYCLE_LIMIT) {
TAG_LOGE(AAFwkTag::APPMGR, "infoSize is too large");
return ERR_INVALID_VALUE;
}
for (int32_t i = 0; i < infoSize; i++) {
std::unique_ptr<AppExecFwk::BundleInfo> bundleInfo(data.ReadParcelable<AppExecFwk::BundleInfo>());
if (!bundleInfo) {
TAG_LOGE(AAFwkTag::APPMGR, "Read Parcelable infos failed.");
return ERR_INVALID_VALUE;
}
bundleInfos.emplace_back(*bundleInfo);
}
NotifyStartKeepAliveProcess(bundleInfos);
return NO_ERROR;
}
int32_t AppStateCallbackHost::HandleOnAppRemoteDied(MessageParcel &data, MessageParcel &reply)
{
std::vector<sptr<IRemoteObject>> abilityTokens;

View File

@ -137,6 +137,35 @@ void AppStateCallbackProxy::NotifyStartResidentProcess(std::vector<AppExecFwk::B
}
}
void AppStateCallbackProxy::NotifyStartKeepAliveProcess(std::vector<AppExecFwk::BundleInfo> &bundleInfos)
{
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_ASYNC);
if (!WriteInterfaceToken(data)) {
TAG_LOGE(AAFwkTag::APPMGR, "WriteInterfaceToken failed");
return;
}
if (!data.WriteInt32(bundleInfos.size())) {
TAG_LOGE(AAFwkTag::APPMGR, "write bundle info size failed.");
return;
}
for (auto &bundleInfo : bundleInfos) {
if (!data.WriteParcelable(&bundleInfo)) {
TAG_LOGE(AAFwkTag::APPMGR, "write bundle info failed");
return;
}
}
auto ret = SendTransactCmd(
static_cast<uint32_t>(IAppStateCallback::Message::TRANSACT_ON_NOTIFY_START_KEEP_ALIVE_PROCESS),
data, reply, option);
if (ret != NO_ERROR) {
TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
}
}
void AppStateCallbackProxy::OnAppRemoteDied(const std::vector<sptr<IRemoteObject>> &abilityTokens)
{
MessageParcel data;

View File

@ -204,6 +204,15 @@ enum class AbilityErrorCode {
// target free install task does not exist.
ERROR_CODE_FREE_INSTALL_TASK_NOT_EXIST = 16300007,
// target bundle has no main ability.
ERROR_CODE_NO_MAIN_ABILITY = 16300008,
// target application has no status-bar ability.
ERROR_CODE_NO_STATUS_BAR_ABILITY = 16300009,
// target application is not attached to a status bar.
ERROR_CODE_NOT_ATTACHED_TO_STATUS_BAR = 16300010,
ERROR_CODE_BUNDLE_NAME_INVALID = 18500001,
};

View File

@ -36,6 +36,7 @@ config("abilityms_config") {
"include/mission/",
"include/rdb/",
"include/resident_process/",
"include/keep_alive/",
"include/screen_lock/",
"include/utils/",
"${ability_runtime_innerkits_path}/ability_manager/include",

View File

@ -126,6 +126,11 @@ abilityms_files = [
"src/insight_intent_execute_manager.cpp",
"src/insight_intent_execute_result.cpp",
# keep alive
"src/keep_alive/ability_keep_alive_data_manager.cpp",
"src/keep_alive/ability_keep_alive_service.cpp",
"src/keep_alive/keep_alive_process_manager.cpp",
"src/ability_manager_event_subscriber.cpp",
#utils
@ -135,6 +140,7 @@ abilityms_files = [
"src/utils/dump_utils.cpp",
"src/utils/extension_permissions_util.cpp",
"src/utils/insight_intent_utils.cpp",
"src/utils/keep_alive_utils.cpp",
"src/utils/main_element_utils.cpp",
"src/utils/modal_system_dialog_util.cpp",
"src/utils/multi_app_utils.cpp",

View File

@ -56,9 +56,6 @@ private:
DistributedKv::Key ConvertAutoStartupDataToKey(const AutoStartupInfo &info);
AutoStartupInfo ConvertAutoStartupInfoFromKeyAndValue(
const DistributedKv::Key &key, const DistributedKv::Value &value);
bool IsEqual(nlohmann::json &jsonObject, const std::string &key,
const std::string &value, bool checkEmpty = false);
bool IsEqual(nlohmann::json &jsonObject, const std::string &key, int32_t value);
bool IsEqual(const DistributedKv::Key &key, const AutoStartupInfo &info);
bool IsEqual(const DistributedKv::Key &key, const std::string &accessTokenId);
bool IsEqual(const DistributedKv::Key &key, int32_t userId);

View File

@ -1499,6 +1499,44 @@ public:
virtual int32_t UpdateAssociateConfigList(const std::map<std::string, std::list<std::string>>& configs,
const std::list<std::string>& exportConfigs, int32_t flag) override;
/**
* Set keep-alive flag for application under a specific user.
* @param bundleName Bundle name.
* @param userId User Id.
* @param flag Keep-alive flag.
* @return Returns ERR_OK on success, others on failure.
*/
virtual int32_t SetApplicationKeepAlive(const std::string &bundleName, int32_t userId, bool flag) override;
/**
* Get keep-alive applications.
* @param appType Application type.
* @param userId User Id.
* @param list List of Keep-alive information.
* @return Returns ERR_OK on success, others on failure.
*/
virtual int32_t QueryKeepAliveApplications(int32_t appType, int32_t userId,
std::vector<KeepAliveInfo> &list) override;
/**
* Set keep-alive flag for application under a specific user by EDM.
* @param bundleName Bundle name.
* @param userId User Id.
* @param flag Keep-alive flag.
* @return Returns ERR_OK on success, others on failure.
*/
virtual int32_t SetApplicationKeepAliveByEDM(const std::string &bundleName, int32_t userId, bool flag) override;
/**
* Get keep-alive applications by EDM.
* @param appType Application type.
* @param userId User Id.
* @param list List of Keep-alive information.
* @return Returns ERR_OK on success, others on failure.
*/
virtual int32_t QueryKeepAliveApplicationsByEDM(int32_t appType, int32_t userId,
std::vector<KeepAliveInfo> &list) override;
private:
template <typename T>
int GetParcelableInfos(MessageParcel &reply, std::vector<T> &parcelableInfos);

View File

@ -34,6 +34,7 @@
#include "ability_info.h"
#include "ability_manager_event_subscriber.h"
#include "ability_manager_stub.h"
#include "ability_keep_alive_service.h"
#include "ams_configuration_parameter.h"
#include "app_debug_listener_interface.h"
#include "app_exit_reason_helper.h"
@ -1819,6 +1820,46 @@ public:
int32_t UpdateKeepAliveEnableState(const std::string &bundleName, const std::string &moduleName,
const std::string &mainElement, bool updateEnable, int32_t userId);
bool IsInStatusBar(uint32_t accessTokenId);
/**
* Set keep-alive flag for application under a specific user.
* @param bundleName Bundle name.
* @param userId User Id.
* @param flag Keep-alive flag.
* @return Returns ERR_OK on success, others on failure.
*/
virtual int32_t SetApplicationKeepAlive(const std::string &bundleName, int32_t userId, bool flag) override;
/**
* Get keep-alive applications by EDM.
* @param appType Application type.
* @param userId User Id.
* @param list List of Keep-alive information.
* @return Returns ERR_OK on success, others on failure.
*/
virtual int32_t QueryKeepAliveApplications(int32_t appType, int32_t userId,
std::vector<KeepAliveInfo> &list) override;
/**
* Set keep-alive flag for application under a specific user by EDM.
* @param bundleName Bundle name.
* @param userId User Id.
* @param flag Keep-alive flag.
* @return Returns ERR_OK on success, others on failure.
*/
virtual int32_t SetApplicationKeepAliveByEDM(const std::string &bundleName, int32_t userId, bool flag) override;
/**
* Get keep-alive applications by EDM.
* @param appType Application type.
* @param userId User Id.
* @param list List of Keep-alive information.
* @return Returns ERR_OK on success, others on failure.
*/
virtual int32_t QueryKeepAliveApplicationsByEDM(int32_t appType, int32_t userId,
std::vector<KeepAliveInfo> &list) override;
// MSG 0 - 20 represents timeout message
static constexpr uint32_t LOAD_TIMEOUT_MSG = 0;
static constexpr uint32_t ACTIVE_TIMEOUT_MSG = 1;
@ -1852,6 +1893,8 @@ protected:
void NotifyStartResidentProcess(std::vector<AppExecFwk::BundleInfo> &bundleInfos) override;
void NotifyStartKeepAliveProcess(std::vector<AppExecFwk::BundleInfo> &bundleInfos) override;
/**
* @brief Notify abilityms app process pre cache
* @param pid process pid.
@ -2027,6 +2070,8 @@ private:
void StartResidentApps(int32_t userId);
void StartKeepAliveApps(int32_t userId);
void StartAutoStartupApps();
void RetryStartAutoStartupApps(const std::vector<AutoStartupInfo> &infoList, int32_t retryCount);
void SubscribeScreenUnlockedEvent();

View File

@ -303,6 +303,10 @@ private:
int32_t NotifyFrozenProcessByRSSInner(MessageParcel &data, MessageParcel &reply);
int32_t CleanUIAbilityBySCBInner(MessageParcel &data, MessageParcel &reply);
int32_t PreStartMissionInner(MessageParcel &data, MessageParcel &reply);
int32_t SetApplicationKeepAliveInner(MessageParcel &data, MessageParcel &reply);
int32_t QueryKeepAliveApplicationsInner(MessageParcel &data, MessageParcel &reply);
int32_t SetApplicationKeepAliveByEDMInner(MessageParcel &data, MessageParcel &reply);
int32_t QueryKeepAliveApplicationsByEDMInner(MessageParcel &data, MessageParcel &reply);
int OnRemoteRequestInnerFirst(uint32_t code, MessageParcel &data,
MessageParcel &reply, MessageOption &option);
int OnRemoteRequestInnerSecond(uint32_t code, MessageParcel &data,
@ -343,6 +347,8 @@ private:
MessageParcel &reply, MessageOption &option);
int OnRemoteRequestInnerNineteenth(uint32_t code, MessageParcel &data,
MessageParcel &reply, MessageOption &option);
int OnRemoteRequestInnerTwentieth(uint32_t code, MessageParcel &data,
MessageParcel &reply, MessageOption &option);
int HandleOnRemoteRequestInnerFirst(uint32_t code, MessageParcel &data,
MessageParcel &reply, MessageOption &option);
int HandleOnRemoteRequestInnerSecond(uint32_t code, MessageParcel &data,

View File

@ -100,6 +100,8 @@ public:
virtual void NotifyStartResidentProcess(std::vector<AppExecFwk::BundleInfo> &bundleInfos) {}
virtual void NotifyStartKeepAliveProcess(std::vector<AppExecFwk::BundleInfo> &bundleInfos) {}
/**
* @brief Notify abilityms app process pre cache
* @param pid process pid.
@ -597,6 +599,12 @@ protected:
*/
virtual void NotifyStartResidentProcess(std::vector<AppExecFwk::BundleInfo> &bundleInfos) override;
/**
* @brief Notify abilityms start keep-alive process.
* @param bundleInfos resident process bundle infos.
*/
virtual void NotifyStartKeepAliveProcess(std::vector<AppExecFwk::BundleInfo> &bundleInfos) override;
/**
* @brief Notify abilityms app process OnRemoteDied
* @param abilityTokens abilities in died process.

View File

@ -43,8 +43,8 @@ private:
~AbilityKeepAliveDataManager();
DistributedKv::Status GetKvStore();
bool CheckKvStore();
DistributedKv::Value ConvertKeepAliveStatusToValue(bool isKeepAlive);
void ConvertKeepAliveStatusFromValue(const DistributedKv::Value &value, bool &isKeepAlive);
DistributedKv::Value ConvertKeepAliveStatusToValue(KeepAliveSetter setter);
void ConvertKeepAliveStatusFromValue(const DistributedKv::Value &value, KeepAliveSetter &setter);
DistributedKv::Key ConvertKeepAliveDataToKey(const KeepAliveInfo &info);
KeepAliveInfo ConvertKeepAliveInfoFromKey(const DistributedKv::Key &key);
bool IsEqual(const DistributedKv::Key &key, const KeepAliveInfo &info);

View File

@ -26,12 +26,9 @@
namespace OHOS {
namespace AbilityRuntime {
class AbilityKeepAliveService : public std::enable_shared_from_this<AbilityKeepAliveService> {
class AbilityKeepAliveService {
public:
explicit AbilityKeepAliveService();
virtual ~AbilityKeepAliveService();
static AbilityKeepAliveService &GetInstance();
/**
* @brief Set every application keep alive state.
* @param info The keep-alive info,include bundle name, module name, ability name.
@ -49,31 +46,13 @@ public:
*/
int32_t QueryKeepAliveApplications(int32_t userId, int32_t appType, std::vector<KeepAliveInfo> &infoList);
/**
* @brief Set application keep alive state by EDM.
* @param info The keep-alive info, include bundle name, module name, ability name.
* @param flag Indicates whether to keep alive for application.
* @return Returns ERR_OK on success, others on failure.
*/
int32_t SetApplicationKeepAliveByEDM(KeepAliveInfo &info, bool flag);
/**
* @brief Query keep-alive applications by EDM.
* @param userId User id.
* @param appType App type.
* @param infoList Output parameters, return keep-alive info list.
* @return Returns ERR_OK on success, others on failure.
*/
int32_t QueryKeepAliveApplicationsByEDM(int32_t userId, int32_t appType, std::vector<KeepAliveInfo> &infoList);
/**
* @brief Query if bundle is keep-alive.
* @param bundleName The bundle name.
* @param userId User id.
* @param isKeepAlive The return flag indicates whether the bundle is keep-alive.
* @return Returns ERR_OK on success, others on failure.
* @return Returns true on app keep alive, false otherwise.
*/
int32_t GetKeepAliveProcessEnable(const std::string &bundleName, int32_t userId, bool &isKeepAlive);
bool IsKeepAliveApp(const std::string &bundleName, int32_t userId);
/**
* @brief Get keep-alive applications without permissions.
@ -83,12 +62,24 @@ public:
*/
int32_t GetKeepAliveApplications(int32_t userId, std::vector<KeepAliveInfo> &infoList);
/**
* @brief Query if bundle is keep-alive.
* @param bundleName The bundle name.
* @param userId User id.
* @param isByEDM The flag indicates whether it's user or system who sets the flag.
* @param isKeepAlive The return flag indicates whether the bundle is keep-alive.
* @return Returns ERR_OK on success, others on failure.
*/
bool CanSetKeepAlive(const std::string &bundleName, int32_t userId, bool isByEDM, bool &isKeepAlive);
private:
int32_t CheckPermission();
int32_t CheckPermissionForEDM();
AbilityKeepAliveService();
~AbilityKeepAliveService();
void GetValidUserId(int32_t &userId);
int32_t SetKeepAliveTrue(const KeepAliveInfo &info);
int32_t CancelKeepAlive(const KeepAliveInfo &info);
DISALLOW_COPY_AND_MOVE(AbilityKeepAliveService);
};
} // namespace AbilityRuntime
} // namespace OHOS

View File

@ -40,9 +40,15 @@ struct KeepAliveAbilityInfo {
* @class KeepAliveProcessManager
* KeepAliveProcessManager
*/
class KeepAliveProcessManager : public std::enable_shared_from_this<KeepAliveProcessManager> {
DECLARE_DELAYED_SINGLETON(KeepAliveProcessManager)
class KeepAliveProcessManager {
public:
/**
* Get the instance of KeepAliveProcessManager.
*
* @return Returns the instance of KeepAliveProcessManager.
*/
static KeepAliveProcessManager &GetInstance();
/**
* Set the enable flag for keep-alive processes.
*
@ -102,8 +108,11 @@ public:
void StartFailedKeepAliveAbilities();
private:
void UpdateKeepAliveProcessesStatus(const AppExecFwk::BundleInfo &bundleInfo, int32_t userId,
bool localEnable, bool updateEnable);
KeepAliveProcessManager();
~KeepAliveProcessManager();
int32_t CheckPermission();
int32_t CheckPermissionForEDM();
void AddFailedKeepAliveAbility(const std::string &bundleName, const std::string &moduleName,
const std::string &abilityName, int32_t userId);
void StartKeepAliveProcessWithMainElementPerBundle(const AppExecFwk::BundleInfo &bundleInfo,
@ -115,11 +124,10 @@ private:
bool IsRunningAppInStatusBar(std::shared_ptr<AbilityManagerService> abilityMgr,
const AppExecFwk::BundleInfo &bundleInfo);
std::shared_ptr<AbilityKeepAliveService> abilityKeepAliveService_;
std::mutex failedKeepAliveAbilityInfoMutex_;
std::list<KeepAliveAbilityInfo> failedKeepAliveAbilityInfos_;
std::atomic_bool unlockedAfterBoot_ = false;
DISALLOW_COPY_AND_MOVE(KeepAliveProcessManager);
};
} // namespace AAFwk
} // namespace OHOS

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -98,7 +98,10 @@ public:
private:
void UpdateResidentProcessesStatus(const std::string &bundleName, bool localEnable, bool updateEnable);
void AddFailedResidentAbility(const std::string &bundleName, const std::string &abilityName, int32_t userId);
void NotifyDisableResidentProcess(const std::vector<AppExecFwk::BundleInfo> &bundleInfos, int32_t userId);
void StartResidentProcessWithMainElementPerBundle(const AppExecFwk::BundleInfo &bundleInfo,
size_t index, std::set<uint32_t> &needEraseIndexSet, int32_t userId);
void StartResidentProcessWithMainElementPerBundleHap(const AppExecFwk::HapModuleInfo &hapModuleInfo,
const std::string &processName, size_t index, std::set<uint32_t> &needEraseIndexSet, int32_t userId);
std::mutex residentAbilityInfoMutex_;
std::list<ResidentAbilityInfo> residentAbilityInfos_;

View File

@ -30,6 +30,7 @@ public:
int32_t RegisterStatusBarDelegate(sptr<AbilityRuntime::IStatusBarDelegate> delegate);
bool IsCallerInStatusBar();
bool IsInStatusBar(uint32_t accessTokenId);
int32_t DoProcessAttachment(std::shared_ptr<AbilityRecord> abilityRecord);
int32_t DoCallerProcessAttachment(std::shared_ptr<AbilityRecord> abilityRecord);

View File

@ -345,8 +345,11 @@ public:
int32_t UpdateSessionInfoBySCB(std::list<SessionInfo> &sessionInfos, std::vector<int32_t> &sessionIds);
int32_t RegisterStatusBarDelegate(sptr<AbilityRuntime::IStatusBarDelegate> delegate);
bool IsCallerInStatusBar();
bool IsInStatusBar(uint32_t accessTokenId);
int32_t TryPrepareTerminateByPids(const std::vector<int32_t>& pids);
int ChangeAbilityVisibility(sptr<IRemoteObject> token, bool isShow);

View File

@ -0,0 +1,61 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_ABILITY_RUNTIME_KEEP_ALIVE_UTILS_H
#define OHOS_ABILITY_RUNTIME_KEEP_ALIVE_UTILS_H
#include "bundle_info.h"
namespace OHOS {
namespace AAFwk {
/**
* @class KeepAliveType
* defines what type of keep-alive.
*/
enum class KeepAliveType : int32_t {
UNSPECIFIED = -1,
RESIDENT_PROCESS = 0,
THIRD_PARTY = 1,
};
/**
* @class KeepAliveUtils
* provides keep-alive utilities.
*/
class KeepAliveUtils final {
public:
/**
* CheckMainElement, check main element.
*
* @param bundleInfos The list of bundle info.
* @param userId User id.
* @return Whether or not the hap module has the main element.
*/
static void NotifyDisableKeepAliveProcesses(const std::vector<AppExecFwk::BundleInfo> &bundleInfos,
int32_t userId);
/**
* IsKeepAliveBundle, check if bundle is keep-alive.
*
* @param bundleInfo The bundle info.
* @param userId User id.
* @param type The returned type of keep-alive.
* @return Whether or not the bundle is keep-alive.
*/
static bool IsKeepAliveBundle(const AppExecFwk::BundleInfo &bundleInfo, int32_t userId, KeepAliveType &type);
};
} // namespace AAFwk
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_KEEP_ALIVE_UTILS_H

View File

@ -32,13 +32,14 @@ public:
* @param hapModuleInfo The hap module info.
* @param processName The process name.
* @param mainElement The returned main element.
* @param needEraseIndexSet The returned set of indices that need to be erased.
* @param bundleInfoIndex The index of the bundle info.
* @param isDataAbility The returned flag indicates whether the module contains data ability.
* @param uri Returned URI of the data ability.
* @param userId User id.
* @return Whether or not the hap module has the main element.
*/
static bool CheckMainElement(const AppExecFwk::HapModuleInfo &hapModuleInfo, const std::string &processName,
std::string &mainElement, std::set<uint32_t> &needEraseIndexSet, size_t bundleInfoIndex, int32_t userId = 0);
static bool CheckMainElement(const AppExecFwk::HapModuleInfo &hapModuleInfo,
const std::string &processName, std::string &mainElement, bool &isDataAbility,
std::string &uriStr, int32_t userId = 0);
/**
* UpdateMainElement, update main element.
@ -51,6 +52,33 @@ public:
*/
static void UpdateMainElement(const std::string &bundleName, const std::string &moduleName,
const std::string &mainElement, bool updateEnable, int32_t userId);
/**
* CheckMainUIAbility, check if bundle has main UIAbility.
*
* @param bundleInfo The bundle info.
* @param mainElementName The returned main element name.
* @return Whether or not the bundle has the main element.
*/
static bool CheckMainUIAbility(const AppExecFwk::BundleInfo &bundleInfo, std::string& mainElementName);
/**
* CheckStatusBarAbility, check if bundle has status bar ability.
*
* @param bundleInfo The bundle info.
* @return Whether or not the bundle has a status bar ability.
*/
static bool CheckStatusBarAbility(const AppExecFwk::BundleInfo &bundleInfo);
/**
* GetMainUIAbilityAccessTokenId, get the access token id of the main uiability.
*
* @param bundleInfo The bundle info.
* @param mainElementName The main element name.
* @param accessTokenId The returned access token id.
*/
static void GetMainUIAbilityAccessTokenId(const AppExecFwk::BundleInfo &bundleInfo,
const std::string &mainElementName, uint32_t &accessTokenId);
};
} // namespace AAFwk
} // namespace OHOS

View File

@ -61,6 +61,11 @@
*ImplicitStartProcessor*;
*InnerMissionInfo*;
*InsightIntentUtils*;
*JsonUtils*;
*KeepAliveAppType*;
*KeepAliveInfo*;
*KeepAliveSetter*;
*KeepAliveUtils*;
*LaunchParam*;
*LifeCycleStateInfo*;
*Mission*;

View File

@ -19,6 +19,7 @@
#include "accesstoken_kit.h"
#include "hilog_tag_wrapper.h"
#include "json_utils.h"
#include "os_account_manager_wrapper.h"
namespace OHOS {
@ -435,30 +436,6 @@ AutoStartupInfo AbilityAutoStartupDataManager::ConvertAutoStartupInfoFromKeyAndV
return info;
}
bool AbilityAutoStartupDataManager::IsEqual(
nlohmann::json &jsonObject, const std::string &key, const std::string &value, bool checkEmpty)
{
if (jsonObject.contains(key) && jsonObject[key].is_string()) {
std::string jsonValue = jsonObject.at(key).get<std::string>();
if (checkEmpty && !jsonValue.empty() && jsonValue != value) {
return false;
} else if (value != jsonValue) {
return false;
}
}
return true;
}
bool AbilityAutoStartupDataManager::IsEqual(nlohmann::json &jsonObject, const std::string &key, int32_t value)
{
if (jsonObject.contains(key) && jsonObject[key].is_number()) {
if (value != jsonObject.at(key).get<int32_t>()) {
return false;
}
}
return true;
}
bool AbilityAutoStartupDataManager::IsEqual(const DistributedKv::Key &key, const AutoStartupInfo &info)
{
nlohmann::json jsonObject = nlohmann::json::parse(key.ToString(), nullptr, false);
@ -467,12 +444,12 @@ bool AbilityAutoStartupDataManager::IsEqual(const DistributedKv::Key &key, const
return false;
}
if (!IsEqual(jsonObject, JSON_KEY_BUNDLE_NAME, info.bundleName)
|| !IsEqual(jsonObject, JSON_KEY_ABILITY_NAME, info.abilityName)
|| !IsEqual(jsonObject, JSON_KEY_MODULE_NAME, info.moduleName, true)
|| !IsEqual(jsonObject, JSON_KEY_APP_CLONE_INDEX, info.appCloneIndex)
|| !IsEqual(jsonObject, JSON_KEY_ACCESS_TOKENID, info.accessTokenId)
|| !IsEqual(jsonObject, JSON_KEY_USERID, info.userId)) {
if (!AAFwk::JsonUtils::GetInstance().IsEqual(jsonObject, JSON_KEY_BUNDLE_NAME, info.bundleName)
|| !AAFwk::JsonUtils::GetInstance().IsEqual(jsonObject, JSON_KEY_ABILITY_NAME, info.abilityName)
|| !AAFwk::JsonUtils::GetInstance().IsEqual(jsonObject, JSON_KEY_MODULE_NAME, info.moduleName, true)
|| !AAFwk::JsonUtils::GetInstance().IsEqual(jsonObject, JSON_KEY_APP_CLONE_INDEX, info.appCloneIndex)
|| !AAFwk::JsonUtils::GetInstance().IsEqual(jsonObject, JSON_KEY_ACCESS_TOKENID, info.accessTokenId)
|| !AAFwk::JsonUtils::GetInstance().IsEqual(jsonObject, JSON_KEY_USERID, info.userId)) {
return false;
}
return true;

View File

@ -5711,5 +5711,147 @@ bool AbilityManagerProxy::UpdateAssociateConfigInner(const std::map<std::string,
}
return true;
}
int32_t AbilityManagerProxy::SetApplicationKeepAlive(const std::string &bundleName, int32_t userId, bool flag)
{
MessageParcel data;
if (!WriteInterfaceToken(data)) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "writeInterfaceToken fail");
return INNER_ERR;
}
if (!data.WriteString(bundleName)) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "faled to write bundleName");
return ERR_INVALID_VALUE;
}
if (!data.WriteInt32(userId)) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "faled to write userID");
return ERR_INVALID_VALUE;
}
if (!data.WriteBool(flag)) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "faled to write flag");
return ERR_INVALID_VALUE;
}
MessageParcel reply;
MessageOption option;
auto ret = SendRequest(AbilityManagerInterfaceCode::SET_APPLICATION_KEEP_ALLIVE,
data, reply, option);
if (ret != NO_ERROR) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "request error: %{public}d", ret);
return ret;
}
return reply.ReadInt32();
}
int32_t AbilityManagerProxy::QueryKeepAliveApplications(int32_t appType, int32_t userId,
std::vector<KeepAliveInfo> &list)
{
MessageParcel data;
if (!WriteInterfaceToken(data)) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "writeInterfaceToken fail");
return INNER_ERR;
}
if (!data.WriteInt32(appType)) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "faled to write appType");
return ERR_INVALID_VALUE;
}
if (!data.WriteInt32(userId)) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "faled to write userID");
return ERR_INVALID_VALUE;
}
MessageParcel reply;
MessageOption option;
auto ret = SendRequest(AbilityManagerInterfaceCode::GET_APPLICATIONS_KEEP_ALIVE,
data, reply, option);
if (ret != NO_ERROR) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "request error: %{public}d", ret);
return ret;
}
ret = GetParcelableInfos<KeepAliveInfo>(reply, list);
if (ret != NO_ERROR) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "GetParcelableInfos error: %{public}d", ret);
return ret;
}
return reply.ReadInt32();
}
int32_t AbilityManagerProxy::SetApplicationKeepAliveByEDM(const std::string &bundleName, int32_t userId, bool flag)
{
MessageParcel data;
if (!WriteInterfaceToken(data)) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "writeInterfaceToken fail");
return INNER_ERR;
}
if (!data.WriteString(bundleName)) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "faled to write bundleName");
return ERR_INVALID_VALUE;
}
if (!data.WriteInt32(userId)) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "faled to write userID");
return ERR_INVALID_VALUE;
}
if (!data.WriteBool(flag)) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "faled to write flag");
return ERR_INVALID_VALUE;
}
MessageParcel reply;
MessageOption option;
auto ret = SendRequest(AbilityManagerInterfaceCode::SET_APPLICATION_KEEP_ALLIVE_BY_EDM,
data, reply, option);
if (ret != NO_ERROR) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "request error: %{public}d", ret);
return ret;
}
return reply.ReadInt32();
}
int32_t AbilityManagerProxy::QueryKeepAliveApplicationsByEDM(int32_t appType, int32_t userId,
std::vector<KeepAliveInfo> &list)
{
MessageParcel data;
if (!WriteInterfaceToken(data)) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "writeInterfaceToken fail");
return INNER_ERR;
}
if (!data.WriteInt32(appType)) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "faled to write appType");
return ERR_INVALID_VALUE;
}
if (!data.WriteInt32(userId)) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "faled to write userID");
return ERR_INVALID_VALUE;
}
MessageParcel reply;
MessageOption option;
auto ret = SendRequest(AbilityManagerInterfaceCode::GET_APPLICATIONS_KEEP_ALIVE_BY_EDM,
data, reply, option);
if (ret != NO_ERROR) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "request error: %{public}d", ret);
return ret;
}
ret = GetParcelableInfos<KeepAliveInfo>(reply, list);
if (ret != NO_ERROR) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "GetParcelableInfos error: %{public}d", ret);
return ret;
}
return reply.ReadInt32();
}
} // namespace AAFwk
} // namespace OHOS

View File

@ -18,7 +18,6 @@
#include "ability_background_connection.h"
#include "ability_connect_manager.h"
#include "ability_manager_radar.h"
#include "ability_resident_process_rdb.h"
#include "accesstoken_kit.h"
#include "ability_manager_xcollie.h"
#include "app_exception_handler.h"
@ -51,6 +50,8 @@
#include "int_wrapper.h"
#include "ipc_skeleton.h"
#include "iservice_registry.h"
#include "keep_alive_process_manager.h"
#include "keep_alive_utils.h"
#include "mock_session_manager_service.h"
#include "modal_system_dialog/modal_system_dialog_ui_extension.h"
#include "modal_system_ui_extension.h"
@ -185,6 +186,8 @@ constexpr const char* ABILITYMS_ENABLE_UISERVICE = "const.abilityms.enable_uiser
constexpr const char* DLP_PARAMS_SECURITY_FLAG = "ohos.dlp.params.securityFlag";
constexpr char PRODUCT_ENTERPRISE_FEATURE_SETTING_ENABLED[] = "const.product.enterprisefeature.setting.enabled";
constexpr int32_t RESOURCE_SCHEDULE_UID = 1096;
constexpr int32_t UPDATE_CONFIG_FLAG_COVER = 1;
constexpr int32_t UPDATE_CONFIG_FLAG_APPEND = 2;
@ -2372,18 +2375,22 @@ void AbilityManagerService::AppUpgradeCompleted(const std::string &bundleName, i
return;
}
bool keepAliveEnable = bundleInfo.isKeepAlive;
AmsResidentProcessRdb::GetInstance().GetResidentProcessEnable(bundleInfo.name, keepAliveEnable);
if (!keepAliveEnable) {
TAG_LOGW(AAFwkTag::ABILITYMGR, "not resident application");
KeepAliveType type = KeepAliveType::UNSPECIFIED;
if (!KeepAliveUtils::IsKeepAliveBundle(bundleInfo, userId, type)) {
TAG_LOGW(AAFwkTag::ABILITYMGR, "not keep-alive application");
return;
}
std::vector<AppExecFwk::BundleInfo> bundleInfos = { bundleInfo };
DelayedSingleton<ResidentProcessManager>::GetInstance()->StartResidentProcessWithMainElement(bundleInfos, userId);
if (!bundleInfos.empty()) {
DelayedSingleton<ResidentProcessManager>::GetInstance()->StartResidentProcess(bundleInfos);
if (type == KeepAliveType::THIRD_PARTY) {
KeepAliveProcessManager::GetInstance().StartKeepAliveProcessWithMainElement(bundleInfos, userId);
} else if (type == KeepAliveType::RESIDENT_PROCESS) {
auto residentProcessManager = DelayedSingleton<ResidentProcessManager>::GetInstance();
CHECK_POINTER(residentProcessManager);
residentProcessManager->StartResidentProcessWithMainElement(bundleInfos, userId);
if (!bundleInfos.empty()) {
residentProcessManager->StartResidentProcess(bundleInfos);
}
}
}
@ -6178,6 +6185,10 @@ void AbilityManagerService::OnAppStateChanged(const AppInfo &info)
auto residentProcessMgr = DelayedSingleton<ResidentProcessManager>::GetInstance();
CHECK_POINTER(residentProcessMgr);
residentProcessMgr->OnAppStateChanged(info);
if (system::GetBoolParameter(PRODUCT_ENTERPRISE_FEATURE_SETTING_ENABLED, false)) {
KeepAliveProcessManager::GetInstance().OnAppStateChanged(info);
}
}
std::shared_ptr<AbilityEventHandler> AbilityManagerService::GetEventHandler()
@ -6534,9 +6545,9 @@ int AbilityManagerService::KillProcess(const std::string &bundleName, bool clear
return GET_BUNDLE_INFO_FAILED;
}
bool keepAliveEnable = bundleInfo.isKeepAlive;
AmsResidentProcessRdb::GetInstance().GetResidentProcessEnable(bundleName, keepAliveEnable);
if (keepAliveEnable && DelayedSingleton<AppScheduler>::GetInstance()->IsMemorySizeSufficent()) {
KeepAliveType type;
if (KeepAliveUtils::IsKeepAliveBundle(bundleInfo, userId, type)
&& DelayedSingleton<AppScheduler>::GetInstance()->IsMemorySizeSufficent()) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "no kill alive process");
return KILL_PROCESS_KEEP_ALIVE;
}
@ -6588,6 +6599,8 @@ int32_t AbilityManagerService::UninstallAppInner(const std::string &bundleName,
IN_PROCESS_CALL_WITHOUT_RET(DelayedSingleton<AppExecFwk::AppMgrClient>::
GetInstance()->SetKeepAliveEnableState(bundleName, false, uid));
auto userId = uid / BASE_USER_RANGE;
IN_PROCESS_CALL_WITHOUT_RET(
KeepAliveProcessManager::GetInstance().SetApplicationKeepAlive(bundleName, userId, false, true));
auto connectManager = GetConnectManagerByUserId(userId);
if (connectManager) {
connectManager->UninstallApp(bundleName);
@ -6993,25 +7006,45 @@ void AbilityManagerService::StartResidentApps(int32_t userId)
{
TAG_LOGI(AAFwkTag::ABILITYMGR, "StartResidentApps %{public}d", userId);
ConnectServices();
auto residentProcessManager = DelayedSingleton<ResidentProcessManager>::GetInstance();
CHECK_POINTER(residentProcessManager);
std::vector<AppExecFwk::BundleInfo> bundleInfos;
if (!DelayedSingleton<ResidentProcessManager>::GetInstance()->GetResidentBundleInfosForUser(bundleInfos, userId)) {
if (!residentProcessManager->GetResidentBundleInfosForUser(bundleInfos, userId)) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "get resident bundleinfos failed");
return;
}
DelayedSingleton<ResidentProcessManager>::GetInstance()->Init();
residentProcessManager->Init();
TAG_LOGI(AAFwkTag::ABILITYMGR, "startResidentApps getBundleInfos size:%{public}zu", bundleInfos.size());
DelayedSingleton<ResidentProcessManager>::GetInstance()->StartResidentProcessWithMainElement(bundleInfos, userId);
residentProcessManager->StartResidentProcessWithMainElement(bundleInfos, userId);
if (!bundleInfos.empty()) {
#ifdef SUPPORT_GRAPHICS
if (userId == U0_USER_ID) {
WaitBootAnimationStart();
}
#endif
DelayedSingleton<ResidentProcessManager>::GetInstance()->StartResidentProcess(bundleInfos);
residentProcessManager->StartResidentProcess(bundleInfos);
}
}
void AbilityManagerService::StartKeepAliveApps(int32_t userId)
{
if (!system::GetBoolParameter(PRODUCT_ENTERPRISE_FEATURE_SETTING_ENABLED, false)) {
return;
}
TAG_LOGI(AAFwkTag::ABILITYMGR, "StartKeepAliveApps %{public}d", userId);
ConnectServices();
std::vector<AppExecFwk::BundleInfo> bundleInfos;
if (!KeepAliveProcessManager::GetInstance().GetKeepAliveBundleInfosForUser(
bundleInfos, userId)) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "get keep-alive bundle info failed");
return;
}
TAG_LOGI(AAFwkTag::ABILITYMGR, "StartKeepAliveApps getBundleInfos size:%{public}zu", bundleInfos.size());
KeepAliveProcessManager::GetInstance().StartKeepAliveProcessWithMainElement(bundleInfos, userId);
}
void AbilityManagerService::StartAutoStartupApps()
{
TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
@ -7510,6 +7543,18 @@ int AbilityManagerService::StopUser(int userId, const sptr<IUserCallback> &callb
if (callback) {
callback->OnStopUserDone(userId, ret);
}
if (!system::GetBoolParameter(PRODUCT_ENTERPRISE_FEATURE_SETTING_ENABLED, false)) {
return 0;
}
std::vector<AppExecFwk::BundleInfo> bundleInfos;
if (!KeepAliveProcessManager::GetInstance().GetKeepAliveBundleInfosForUser(bundleInfos, userId)) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "get keep-alive bundle info failed");
return 0;
}
for (const auto &bundleInfo : bundleInfos) {
IN_PROCESS_CALL_WITHOUT_RET(KeepAliveProcessManager::GetInstance().SetApplicationKeepAlive(
bundleInfo.name, userId, false, true));
}
return 0;
}
@ -8110,7 +8155,13 @@ void AbilityManagerService::SwitchToUser(int32_t oldUserId, int32_t userId, sptr
taskHandler_->SubmitTask([abilityMs = shared_from_this(), userId]() {
TAG_LOGI(AAFwkTag::ABILITYMGR, "StartResidentApps userId:%{public}d", userId);
abilityMs->StartResidentApps(userId);
});
if (system::GetBoolParameter(PRODUCT_ENTERPRISE_FEATURE_SETTING_ENABLED, false)) {
taskHandler_->SubmitTask([abilityMs = shared_from_this(), userId]() {
TAG_LOGI(AAFwkTag::ABILITYMGR, "StartKeepAliveApps userId:%{public}d", userId);
abilityMs->StartKeepAliveApps(userId);
});
}
}
if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled() &&
AmsConfigurationParameter::GetInstance().MultiUserType() != 0) {
@ -10436,15 +10487,17 @@ int32_t AbilityManagerService::CheckProcessOptions(const Want &want, const Start
TAG_LOGI(AAFwkTag::ABILITYMGR, "start ability with process options");
bool isEnable = AppUtils::GetInstance().IsStartOptionsWithProcessOptions();
if (!Rosen::SceneBoardJudgement::IsSceneBoardEnabled() || !isEnable) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "not support process options");
return ERR_CAPABILITY_NOT_SUPPORT;
}
CHECK_TRUE_RETURN_RET(!Rosen::SceneBoardJudgement::IsSceneBoardEnabled() || !isEnable,
ERR_CAPABILITY_NOT_SUPPORT, "not support process options");
auto element = want.GetElement();
if (element.GetAbilityName().empty() || want.GetAction().compare(ACTION_CHOOSE) == 0) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "not allow implicit start");
return ERR_NOT_ALLOW_IMPLICIT_START;
CHECK_TRUE_RETURN_RET(element.GetAbilityName().empty() || want.GetAction().compare(ACTION_CHOOSE) == 0,
ERR_NOT_ALLOW_IMPLICIT_START, "not allow implicit start");
if (PermissionVerification::GetInstance()->CheckSpecificSystemAbilityAccessPermission(FOUNDATION_PROCESS_NAME)
&& startOptions.processOptions->isRestartKeepAlive) {
TAG_LOGI(AAFwkTag::ABILITYMGR, "restart keep-alive app.");
return ERR_OK;
}
int32_t appIndex = 0;
@ -10854,19 +10907,39 @@ void AbilityManagerService::NotifyStartResidentProcess(std::vector<AppExecFwk::B
}
}
DelayedSingleton<ResidentProcessManager>::GetInstance()->StartResidentProcessWithMainElement(
auto residentProcessMgr = DelayedSingleton<ResidentProcessManager>::GetInstance();
CHECK_POINTER(residentProcessMgr);
residentProcessMgr->StartResidentProcessWithMainElement(
bundleInfosForU0, U0_USER_ID);
if (!bundleInfosForU0.empty()) {
DelayedSingleton<ResidentProcessManager>::GetInstance()->StartResidentProcess(bundleInfosForU0);
residentProcessMgr->StartResidentProcess(bundleInfosForU0);
}
DelayedSingleton<ResidentProcessManager>::GetInstance()->StartResidentProcessWithMainElement(
residentProcessMgr->StartResidentProcessWithMainElement(
bundleInfosForCurrentUser, currentUser);
if (!bundleInfosForCurrentUser.empty()) {
DelayedSingleton<ResidentProcessManager>::GetInstance()->StartResidentProcess(bundleInfosForCurrentUser);
residentProcessMgr->StartResidentProcess(bundleInfosForCurrentUser);
}
}
void AbilityManagerService::NotifyStartKeepAliveProcess(std::vector<AppExecFwk::BundleInfo> &bundleInfos)
{
if (!system::GetBoolParameter(PRODUCT_ENTERPRISE_FEATURE_SETTING_ENABLED, false)) {
return;
}
auto userId = GetUserId();
std::vector<AppExecFwk::BundleInfo> bundleInfosForCurrentUser;
for (const auto &item: bundleInfos) {
if (item.uid / BASE_USER_RANGE == userId) {
bundleInfosForCurrentUser.push_back(item);
}
}
KeepAliveProcessManager::GetInstance().StartKeepAliveProcessWithMainElement(bundleInfosForCurrentUser, userId);
}
void AbilityManagerService::NotifyAppPreCache(int32_t pid, int32_t userId)
{
ForceTerminateServiceExtensionByPid(pid, userId);
@ -11034,10 +11107,7 @@ int32_t AbilityManagerService::SetResidentProcessEnabled(const std::string &bund
}
auto residentProcessManager = DelayedSingleton<ResidentProcessManager>::GetInstance();
if (residentProcessManager == nullptr) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "get resident proces mgr null");
return INNER_ERR;
}
CHECK_POINTER_AND_RETURN(residentProcessManager, INNER_ERR);
std::string callerName;
int32_t uid = 0;
@ -12357,5 +12427,39 @@ int32_t AbilityManagerService::UpdateKeepAliveEnableState(const std::string &bun
}
return ret;
}
bool AbilityManagerService::IsInStatusBar(uint32_t accessTokenId)
{
auto uiAbilityManager = GetUIAbilityManagerByUid(IPCSkeleton::GetCallingUid());
CHECK_POINTER_AND_RETURN(uiAbilityManager, false);
return uiAbilityManager->IsInStatusBar(accessTokenId);
}
int32_t AbilityManagerService::SetApplicationKeepAlive(const std::string &bundleName, int32_t userId, bool flag)
{
return KeepAliveProcessManager::GetInstance().SetApplicationKeepAlive(
bundleName, userId, flag);
}
int32_t AbilityManagerService::QueryKeepAliveApplications(int32_t appType, int32_t userId,
std::vector<KeepAliveInfo> &list)
{
return KeepAliveProcessManager::GetInstance().QueryKeepAliveApplications(
appType, userId, list);
}
int32_t AbilityManagerService::SetApplicationKeepAliveByEDM(const std::string &bundleName, int32_t userId, bool flag)
{
return KeepAliveProcessManager::GetInstance().SetApplicationKeepAlive(
bundleName, userId, flag, true);
}
int32_t AbilityManagerService::QueryKeepAliveApplicationsByEDM(int32_t appType, int32_t userId,
std::vector<KeepAliveInfo> &list)
{
return KeepAliveProcessManager::GetInstance().QueryKeepAliveApplications(
appType, userId, list, true);
}
} // namespace AAFwk
} // namespace OHOS

View File

@ -715,7 +715,6 @@ int AbilityManagerStub::OnRemoteRequestInnerEighteenth(uint32_t code, MessagePar
return ERR_CODE_NOT_EXIST;
}
int AbilityManagerStub::OnRemoteRequestInnerNineteenth(uint32_t code, MessageParcel &data,
MessageParcel &reply, MessageOption &option)
{
@ -765,6 +764,25 @@ int AbilityManagerStub::OnRemoteRequestInnerNineteenth(uint32_t code, MessagePar
return ERR_CODE_NOT_EXIST;
}
int AbilityManagerStub::OnRemoteRequestInnerTwentieth(uint32_t code, MessageParcel &data,
MessageParcel &reply, MessageOption &option)
{
AbilityManagerInterfaceCode interfaceCode = static_cast<AbilityManagerInterfaceCode>(code);
if (interfaceCode == AbilityManagerInterfaceCode::SET_APPLICATION_KEEP_ALLIVE) {
return SetApplicationKeepAliveInner(data, reply);
}
if (interfaceCode == AbilityManagerInterfaceCode::GET_APPLICATIONS_KEEP_ALIVE) {
return QueryKeepAliveApplicationsInner(data, reply);
}
if (interfaceCode == AbilityManagerInterfaceCode::SET_APPLICATION_KEEP_ALLIVE_BY_EDM) {
return SetApplicationKeepAliveByEDMInner(data, reply);
}
if (interfaceCode == AbilityManagerInterfaceCode::GET_APPLICATIONS_KEEP_ALIVE_BY_EDM) {
return QueryKeepAliveApplicationsByEDMInner(data, reply);
}
return ERR_CODE_NOT_EXIST;
}
int AbilityManagerStub::OnRemoteRequestInner(uint32_t code, MessageParcel &data,
MessageParcel &reply, MessageOption &option)
{
@ -868,6 +886,10 @@ int AbilityManagerStub::HandleOnRemoteRequestInnerSecond(uint32_t code, MessageP
if (retCode != ERR_CODE_NOT_EXIST) {
return retCode;
}
retCode = OnRemoteRequestInnerTwentieth(code, data, reply, option);
if (retCode != ERR_CODE_NOT_EXIST) {
return retCode;
}
return ERR_CODE_NOT_EXIST;
}
@ -4093,5 +4115,69 @@ int32_t AbilityManagerStub::UpdateAssociateConfigListInner(MessageParcel &data,
reply.WriteInt32(result);
return NO_ERROR;
}
int AbilityManagerStub::SetApplicationKeepAliveInner(MessageParcel &data, MessageParcel &reply)
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
std::string bundleName = data.ReadString();
int32_t userId = data.ReadInt32();
bool flag = data.ReadBool();
int32_t result = SetApplicationKeepAlive(bundleName, userId, flag);
if (!reply.WriteInt32(result)) {
return ERR_INVALID_VALUE;
}
return result;
}
int AbilityManagerStub::QueryKeepAliveApplicationsInner(MessageParcel &data, MessageParcel &reply)
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
int32_t appType = data.ReadInt32();
int32_t userId = data.ReadInt32();
std::vector<KeepAliveInfo> list;
int32_t result = QueryKeepAliveApplications(appType, userId, list);
reply.WriteInt32(list.size());
for (auto &it : list) {
if (!reply.WriteParcelable(&it)) {
return ERR_INVALID_VALUE;
}
}
if (!reply.WriteInt32(result)) {
return ERR_INVALID_VALUE;
}
return result;
}
int AbilityManagerStub::SetApplicationKeepAliveByEDMInner(MessageParcel &data, MessageParcel &reply)
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
std::string bundleName = data.ReadString();
int32_t userId = data.ReadInt32();
bool flag = data.ReadBool();
int32_t result = SetApplicationKeepAliveByEDM(bundleName, userId, flag);
if (!reply.WriteInt32(result)) {
return ERR_INVALID_VALUE;
}
return result;
}
int AbilityManagerStub::QueryKeepAliveApplicationsByEDMInner(MessageParcel &data, MessageParcel &reply)
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
int32_t appType = data.ReadInt32();
int32_t userId = data.ReadInt32();
std::vector<KeepAliveInfo> list;
int32_t result = QueryKeepAliveApplicationsByEDM(appType, userId, list);
reply.WriteInt32(list.size());
for (auto &it : list) {
if (!reply.WriteParcelable(&it)) {
return ERR_INVALID_VALUE;
}
}
if (!reply.WriteInt32(result)) {
return ERR_INVALID_VALUE;
}
return result;
}
} // namespace AAFwk
} // namespace OHOS

View File

@ -32,6 +32,7 @@
#include "global_constant.h"
#include "hitrace_meter.h"
#include "image_source.h"
#include "keep_alive_process_manager.h"
#include "multi_instance_utils.h"
#include "os_account_manager_wrapper.h"
#include "ui_service_extension_connection_constants.h"
@ -322,25 +323,18 @@ int AbilityRecord::LoadAbility(bool isShellCall)
}
std::string appName = abilityInfo_.applicationInfo.name;
if (appName.empty()) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "app name empty");
return ERR_INVALID_VALUE;
}
if (!CanRestartRootLauncher()) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "root launcher restart out of max");
return ERR_INVALID_VALUE;
}
CHECK_TRUE_RETURN_RET(appName.empty(), ERR_INVALID_VALUE, "app name empty");
CHECK_TRUE_RETURN_RET(!CanRestartRootLauncher(), ERR_INVALID_VALUE, "root launcher restart out of max");
if (isRestarting_) {
restartTime_ = AbilityUtil::SystemTimeMillis();
}
sptr<Token> callerToken_ = nullptr;
sptr<Token> callerToken = nullptr;
if (!callerList_.empty() && callerList_.back()) {
auto caller = callerList_.back()->GetCaller();
if (caller) {
callerToken_ = caller->GetToken();
callerToken = caller->GetToken();
}
}
@ -348,22 +342,22 @@ int AbilityRecord::LoadAbility(bool isShellCall)
want_.SetParam(ABILITY_OWNER_USERID, ownerMissionUserId_);
AbilityRuntime::LoadParam loadParam;
loadParam.abilityRecordId = recordId_;
if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
loadParam.isShellCall = isShellCall;
} else {
loadParam.isShellCall = AAFwk::PermissionVerification::GetInstance()->IsShellCall();
}
loadParam.isShellCall = Rosen::SceneBoardJudgement::IsSceneBoardEnabled() ? isShellCall
: AAFwk::PermissionVerification::GetInstance()->IsShellCall();
loadParam.token = token_;
loadParam.preToken = callerToken_;
loadParam.preToken = callerToken;
loadParam.instanceKey = instanceKey_;
want_.RemoveParam(Want::PARAM_APP_KEEP_ALIVE_ENABLED);
if (KeepAliveProcessManager::GetInstance().IsKeepAliveBundle(abilityInfo_.applicationInfo.bundleName, -1)) {
want_.SetParam(Want::PARAM_APP_KEEP_ALIVE_ENABLED, true);
loadParam.isKeepAlive = true;
}
auto result = DelayedSingleton<AppScheduler>::GetInstance()->LoadAbility(
loadParam, abilityInfo_, abilityInfo_.applicationInfo, want_);
want_.RemoveParam(ABILITY_OWNER_USERID);
want_.RemoveParam(Want::PARAMS_NEED_CHECK_CALLER_IS_EXIST);
SetLoadState(AbilityLoadState::LOADING);
auto isAttachDebug = DelayedSingleton<AppScheduler>::GetInstance()->IsAttachDebug(abilityInfo_.bundleName);
if (isAttachDebug) {
if (DelayedSingleton<AppScheduler>::GetInstance()->IsAttachDebug(abilityInfo_.bundleName)) {
SetAttachDebug(true);
}
return result;

View File

@ -215,6 +215,13 @@ void AppScheduler::NotifyStartResidentProcess(std::vector<AppExecFwk::BundleInfo
callback->NotifyStartResidentProcess(bundleInfos);
}
void AppScheduler::NotifyStartKeepAliveProcess(std::vector<AppExecFwk::BundleInfo> &bundleInfos)
{
auto callback = callback_.lock();
CHECK_POINTER(callback);
callback->NotifyStartKeepAliveProcess(bundleInfos);
}
void AppScheduler::OnAppRemoteDied(const std::vector<sptr<IRemoteObject>> &abilityTokens)
{
auto callback = callback_.lock();

View File

@ -17,10 +17,8 @@
#include <unistd.h>
#include "accesstoken_kit.h"
#include "hilog_tag_wrapper.h"
#include "json_utils.h"
#include "os_account_manager_wrapper.h"
namespace OHOS {
namespace AbilityRuntime {
@ -32,7 +30,6 @@ const std::string JSON_KEY_BUNDLE_NAME = "bundleName";
const std::string JSON_KEY_USERID = "userId";
const std::string JSON_KEY_APP_TYPE = "appType";
const std::string JSON_KEY_SETTER = "setter";
const std::string JSON_KEY_IS_KEEP_ALIVE = "isKeepAlive";
} // namespace
const DistributedKv::AppId AbilityKeepAliveDataManager::APP_ID = { "keep_alive_storage" };
const DistributedKv::StoreId AbilityKeepAliveDataManager::STORE_ID = { "keep_alive_infos" };
@ -114,7 +111,7 @@ int32_t AbilityKeepAliveDataManager::InsertKeepAliveData(const KeepAliveInfo &in
}
DistributedKv::Key key = ConvertKeepAliveDataToKey(info);
DistributedKv::Value value = ConvertKeepAliveStatusToValue(true);
DistributedKv::Value value = ConvertKeepAliveStatusToValue(info.setter);
DistributedKv::Status status;
{
std::lock_guard<std::mutex> lock(kvStorePtrMutex_);
@ -200,8 +197,9 @@ KeepAliveStatus AbilityKeepAliveDataManager::QueryKeepAliveData(const KeepAliveI
kaStatus.code = ERR_NAME_NOT_FOUND;
for (const auto &item : allEntries) {
if (IsEqual(item.key, info)) {
ConvertKeepAliveStatusFromValue(item.value, kaStatus.isKeepAlive);
ConvertKeepAliveStatusFromValue(item.value, kaStatus.setter);
kaStatus.code = ERR_OK;
break;
}
}
@ -238,35 +236,32 @@ int32_t AbilityKeepAliveDataManager::QueryKeepAliveApplications(
if (!IsEqual(item.key, queryParam)) {
continue;
}
bool isKeepAlive;
ConvertKeepAliveStatusFromValue(item.value, isKeepAlive);
if (isKeepAlive) {
infoList.emplace_back(ConvertKeepAliveInfoFromKey(item.key));
}
infoList.emplace_back(ConvertKeepAliveInfoFromKey(item.key));
}
TAG_LOGD(AAFwkTag::KEEP_ALIVE, "InfoList.size: %{public}zu", infoList.size());
return ERR_OK;
}
DistributedKv::Value AbilityKeepAliveDataManager::ConvertKeepAliveStatusToValue(bool isKeepAlive)
DistributedKv::Value AbilityKeepAliveDataManager::ConvertKeepAliveStatusToValue(KeepAliveSetter setter)
{
nlohmann::json jsonObject = nlohmann::json {
{ JSON_KEY_IS_KEEP_ALIVE, isKeepAlive },
{ JSON_KEY_SETTER, setter },
};
DistributedKv::Value value(jsonObject.dump());
TAG_LOGD(AAFwkTag::KEEP_ALIVE, "value: %{public}s", value.ToString().c_str());
return value;
}
void AbilityKeepAliveDataManager::ConvertKeepAliveStatusFromValue(const DistributedKv::Value &value, bool &isKeepAlive)
void AbilityKeepAliveDataManager::ConvertKeepAliveStatusFromValue(const DistributedKv::Value &value,
KeepAliveSetter &setter)
{
nlohmann::json jsonObject = nlohmann::json::parse(value.ToString(), nullptr, false);
if (jsonObject.is_discarded()) {
TAG_LOGE(AAFwkTag::KEEP_ALIVE, "parse jsonObject fail");
return;
}
if (jsonObject.contains(JSON_KEY_IS_KEEP_ALIVE) && jsonObject[JSON_KEY_IS_KEEP_ALIVE].is_boolean()) {
isKeepAlive = jsonObject.at(JSON_KEY_IS_KEEP_ALIVE).get<bool>();
if (jsonObject.contains(JSON_KEY_SETTER) && jsonObject[JSON_KEY_SETTER].is_number()) {
setter = KeepAliveSetter(jsonObject.at(JSON_KEY_SETTER).get<int32_t>());
}
}
@ -333,10 +328,6 @@ bool AbilityKeepAliveDataManager::IsEqual(const DistributedKv::Key &key, const K
return false;
}
if (info.setter != KeepAliveSetter::UNSPECIFIED &&
!AAFwk::JsonUtils::GetInstance().IsEqual(jsonObject, JSON_KEY_SETTER, static_cast<int32_t>(info.setter))) {
return false;
}
return true;
}
} // namespace AbilityRuntime

View File

@ -17,18 +17,16 @@
#include "ability_keep_alive_data_manager.h"
#include "ability_manager_service.h"
#include "ability_util.h"
#include "hilog_tag_wrapper.h"
#include "in_process_call_wrapper.h"
#include "main_element_utils.h"
#include "permission_constants.h"
namespace OHOS {
namespace AbilityRuntime {
using namespace OHOS::AAFwk;
namespace {
constexpr char PRODUCT_ENTERPRISE_FEATURE_SETTING_ENABLED[] = "const.product.enterprisefeature.setting.enabled";
} // namespace
AbilityKeepAliveService &AbilityKeepAliveService::GetInstance()
{
static AbilityKeepAliveService instance;
return instance;
}
AbilityKeepAliveService::AbilityKeepAliveService() {}
@ -39,14 +37,8 @@ int32_t AbilityKeepAliveService::SetApplicationKeepAlive(KeepAliveInfo &info, bo
TAG_LOGD(AAFwkTag::KEEP_ALIVE, "SetApplicationKeepAlive is called,"
" bundleName: %{public}s, userId: %{public}d, flag: %{public}d",
info.bundleName.c_str(), info.userId, static_cast<int>(flag));
int32_t code = CheckPermission();
if (code != ERR_OK) {
return code;
}
GetValidUserId(info.userId);
info.appType = KeepAliveAppType::APP;
info.setter = KeepAliveSetter::USER;
if (flag) {
return SetKeepAliveTrue(info);
@ -56,36 +48,22 @@ int32_t AbilityKeepAliveService::SetApplicationKeepAlive(KeepAliveInfo &info, bo
int32_t AbilityKeepAliveService::SetKeepAliveTrue(const KeepAliveInfo &info)
{
auto bundleMgrHelper = AbilityUtil::GetBundleManagerHelper();
if (bundleMgrHelper == nullptr) {
TAG_LOGE(AAFwkTag::KEEP_ALIVE, "null bundleMgrHelper");
return INNER_ERR;
}
// check main element
AppExecFwk::BundleInfo bundleInfo;
if (!IN_PROCESS_CALL(bundleMgrHelper->GetBundleInfo(info.bundleName,
AppExecFwk::BundleFlag::GET_BUNDLE_WITH_ABILITIES, bundleInfo, info.userId))) {
TAG_LOGE(AAFwkTag::KEEP_ALIVE, "failed get bundle info");
return ERR_TARGET_BUNDLE_NOT_EXIST;
}
std::string mainElementName;
if (!MainElementUtils::CheckMainUIAbility(bundleInfo, mainElementName)) {
TAG_LOGE(AAFwkTag::KEEP_ALIVE, "bundle has no main uiability");
return ERR_NO_MAIN_ABILITY;
}
KeepAliveStatus status = AbilityKeepAliveDataManager::GetInstance().QueryKeepAliveData(info);
if (status.code != ERR_OK && status.code != ERR_NAME_NOT_FOUND) {
TAG_LOGE(AAFwkTag::KEEP_ALIVE, "QueryKeepAliveData fail");
return status.code;
}
if (status.code == ERR_OK) {
TAG_LOGI(AAFwkTag::KEEP_ALIVE, "app is already set");
return status.code;
if (status.code == ERR_NAME_NOT_FOUND) {
return AbilityKeepAliveDataManager::GetInstance().InsertKeepAliveData(info);
}
if (static_cast<int32_t>(status.setter) <= static_cast<int32_t>(info.setter)) {
TAG_LOGI(AAFwkTag::KEEP_ALIVE, "app is already set");
return ERR_OK;
}
(void)AbilityKeepAliveDataManager::GetInstance().DeleteKeepAliveData(info);
return AbilityKeepAliveDataManager::GetInstance().InsertKeepAliveData(info);
}
@ -97,69 +75,29 @@ int32_t AbilityKeepAliveService::CancelKeepAlive(const KeepAliveInfo &info)
return status.code;
}
if (!status.isKeepAlive) {
if (status.code == ERR_NAME_NOT_FOUND) {
return ERR_TARGET_BUNDLE_NOT_EXIST;
}
if (static_cast<int32_t>(status.setter) < static_cast<int32_t>(info.setter)) {
TAG_LOGE(AAFwkTag::KEEP_ALIVE, "app is set keep-alive by system, cannot unset by user");
return CHECK_PERMISSION_FAILED;
}
return AbilityKeepAliveDataManager::GetInstance().DeleteKeepAliveData(info);
}
int32_t AbilityKeepAliveService::QueryKeepAliveApplications(int32_t userId,
int32_t appType, std::vector<KeepAliveInfo> &infoList)
{
int32_t code = CheckPermission();
if (code != ERR_OK) {
TAG_LOGE(AAFwkTag::KEEP_ALIVE, "permission verification fail");
return code;
}
GetValidUserId(userId);
KeepAliveInfo queryParam;
queryParam.userId = userId;
queryParam.appType = KeepAliveAppType(appType);
queryParam.setter = KeepAliveSetter::USER;
return AbilityKeepAliveDataManager::GetInstance().QueryKeepAliveApplications(
queryParam, infoList);
}
int32_t AbilityKeepAliveService::QueryKeepAliveApplicationsByEDM(int32_t userId,
int32_t appType, std::vector<KeepAliveInfo> &infoList)
{
int32_t code = CheckPermissionForEDM();
if (code != ERR_OK) {
TAG_LOGE(AAFwkTag::KEEP_ALIVE, "permission verification fail");
return code;
}
GetValidUserId(userId);
KeepAliveInfo queryParam;
queryParam.userId = userId;
queryParam.appType = KeepAliveAppType(appType);
queryParam.setter = KeepAliveSetter::SYSTEM;
return AbilityKeepAliveDataManager::GetInstance().QueryKeepAliveApplications(
queryParam, infoList);
}
int32_t AbilityKeepAliveService::SetApplicationKeepAliveByEDM(KeepAliveInfo &info, bool flag)
{
TAG_LOGD(AAFwkTag::KEEP_ALIVE, "SetApplicationKeepAliveByEDM is called,"
" bundleName: %{public}s, userId: %{public}d, flag: %{public}d",
info.bundleName.c_str(), info.userId, static_cast<int>(flag));
int32_t code = CheckPermissionForEDM();
if (code != ERR_OK) {
return code;
}
GetValidUserId(info.userId);
info.appType = KeepAliveAppType::APP;
info.setter = KeepAliveSetter::SYSTEM;
if (flag) {
return SetKeepAliveTrue(info);
}
return CancelKeepAlive(info);
}
void AbilityKeepAliveService::GetValidUserId(int32_t &userId)
{
if (userId >= 0) {
@ -176,54 +114,11 @@ void AbilityKeepAliveService::GetValidUserId(int32_t &userId)
}
}
int32_t AbilityKeepAliveService::CheckPermission()
bool AbilityKeepAliveService::IsKeepAliveApp(const std::string &bundleName, int32_t userId)
{
if (!system::GetBoolParameter(PRODUCT_ENTERPRISE_FEATURE_SETTING_ENABLED, false)) {
TAG_LOGE(AAFwkTag::KEEP_ALIVE, "not supported");
return ERR_CAPABILITY_NOT_SUPPORT;
}
if (!PermissionVerification::GetInstance()->JudgeCallerIsAllowedToUseSystemAPI()) {
TAG_LOGE(AAFwkTag::KEEP_ALIVE, "not use system-api");
return ERR_NOT_SYSTEM_APP;
}
if (!PermissionVerification::GetInstance()->VerifyCallingPermission(
PermissionConstants::PERMISSION_MANAGE_APP_KEEP_ALIVE)) {
TAG_LOGE(AAFwkTag::KEEP_ALIVE, "verify PERMISSION_MANAGE_APP_KEEP_ALIVE fail");
return CHECK_PERMISSION_FAILED;
}
return ERR_OK;
}
int32_t AbilityKeepAliveService::CheckPermissionForEDM()
{
if (!system::GetBoolParameter(PRODUCT_ENTERPRISE_FEATURE_SETTING_ENABLED, false)) {
TAG_LOGE(AAFwkTag::KEEP_ALIVE, "not supported");
return ERR_CAPABILITY_NOT_SUPPORT;
}
if (!PermissionVerification::GetInstance()->IsSACall() ||
!PermissionVerification::GetInstance()->VerifyCallingPermission(
PermissionConstants::PERMISSION_MANAGE_APP_KEEP_ALIVE_INTERNAL)) {
TAG_LOGE(AAFwkTag::KEEP_ALIVE, "verify PERMISSION_MANAGE_APP_KEEP_ALIVE_INTERNAL fail");
return CHECK_PERMISSION_FAILED;
}
return ERR_OK;
}
int32_t AbilityKeepAliveService::GetKeepAliveProcessEnable(const std::string &bundleName, int32_t userId,
bool &isKeepAlive)
{
if (!system::GetBoolParameter(PRODUCT_ENTERPRISE_FEATURE_SETTING_ENABLED, false)) {
TAG_LOGI(AAFwkTag::KEEP_ALIVE, "not supported");
isKeepAlive = false;
return ERR_OK;
}
if (bundleName.empty()) {
TAG_LOGE(AAFwkTag::KEEP_ALIVE, "bundle name empty");
return ERR_INVALID_VALUE;
return false;
}
GetValidUserId(userId);
@ -231,20 +126,11 @@ int32_t AbilityKeepAliveService::GetKeepAliveProcessEnable(const std::string &bu
info.bundleName = bundleName;
info.userId = userId;
KeepAliveStatus status = AbilityKeepAliveDataManager::GetInstance().QueryKeepAliveData(info);
if (status.code != ERR_OK) {
TAG_LOGE(AAFwkTag::KEEP_ALIVE, "QueryKeepAliveData fail");
return status.code;
}
isKeepAlive = status.isKeepAlive;
return ERR_OK;
return (status.code == ERR_OK);
}
int32_t AbilityKeepAliveService::GetKeepAliveApplications(int32_t userId, std::vector<KeepAliveInfo> &infoList)
{
if (!system::GetBoolParameter(PRODUCT_ENTERPRISE_FEATURE_SETTING_ENABLED, false)) {
TAG_LOGI(AAFwkTag::KEEP_ALIVE, "not supported");
return ERR_OK;
}
KeepAliveInfo queryParam;
queryParam.userId = userId;
return AbilityKeepAliveDataManager::GetInstance().QueryKeepAliveApplications(

View File

@ -19,22 +19,27 @@
#include "ffrt.h"
#include "keep_alive_utils.h"
#include "main_element_utils.h"
#include "permission_constants.h"
#include "process_options.h"
namespace OHOS {
namespace AAFwk {
namespace {
constexpr char PRODUCT_ENTERPRISE_FEATURE_SETTING_ENABLED[] = "const.product.enterprisefeature.setting.enabled";
constexpr char FOUNDATION_PROCESS_NAME[] = "foundation";
} // namespace
constexpr int32_t CREATE_STATUS_BAR_TIMEOUT_SECONDS = 5; // 5s
KeepAliveProcessManager::KeepAliveProcessManager()
KeepAliveProcessManager &KeepAliveProcessManager::GetInstance()
{
abilityKeepAliveService_ = std::make_shared<AbilityRuntime::AbilityKeepAliveService>();
static KeepAliveProcessManager instance;
return instance;
}
KeepAliveProcessManager::~KeepAliveProcessManager()
{
abilityKeepAliveService_.reset();
abilityKeepAliveService_ = nullptr;
}
KeepAliveProcessManager::KeepAliveProcessManager() {}
KeepAliveProcessManager::~KeepAliveProcessManager() {}
void KeepAliveProcessManager::StartKeepAliveProcessWithMainElement(std::vector<AppExecFwk::BundleInfo> &bundleInfos,
int32_t userId)
@ -47,13 +52,7 @@ void KeepAliveProcessManager::StartKeepAliveProcessWithMainElement(std::vector<A
void KeepAliveProcessManager::StartKeepAliveProcessWithMainElementPerBundle(const AppExecFwk::BundleInfo &bundleInfo,
int32_t userId)
{
if (abilityKeepAliveService_ == nullptr) {
TAG_LOGE(AAFwkTag::KEEP_ALIVE, "abilityKeepAliveService_ null");
return;
}
bool keepAliveEnable = false;
(void)abilityKeepAliveService_->GetKeepAliveProcessEnable(bundleInfo.name, userId, keepAliveEnable);
if (!keepAliveEnable) {
if (!IsKeepAliveBundle(bundleInfo.name, userId)) {
return;
}
@ -68,8 +67,8 @@ void KeepAliveProcessManager::StartKeepAliveProcessWithMainElementPerBundle(cons
return;
}
ffrt::submit([self = shared_from_this(), bundleInfo, mainElementName, userId]() {
self->AfterStartKeepAliveApp(bundleInfo, mainElementName, userId);
ffrt::submit([bundleInfo, mainElementName, userId]() {
KeepAliveProcessManager::GetInstance().AfterStartKeepAliveApp(bundleInfo, mainElementName, userId);
});
}
@ -82,7 +81,7 @@ int32_t KeepAliveProcessManager::StartAbility(const std::string &bundleName, con
bundleName.c_str(), abilityName.c_str());
StartOptions options;
options.processOptions = std::make_shared<ProcessOptions>();
options.processOptions->processMode = ProcessMode::ATTACH_TO_STATUS_BAR_ITEM;
options.processOptions->isRestartKeepAlive = true;
options.processOptions->startupVisibility = StartupVisibility::STARTUP_HIDE;
auto ret = IN_PROCESS_CALL(DelayedSingleton<AbilityManagerService>::GetInstance()->StartAbility(want,
options, nullptr, userId, DEFAULT_INVAL_VALUE));
@ -103,15 +102,13 @@ void KeepAliveProcessManager::AfterStartKeepAliveApp(const AppExecFwk::BundleInf
abilityMgr = DelayedSingleton<AbilityManagerService>::GetInstance()]() {
if (accessTokenId == 0) {
TAG_LOGE(AAFwkTag::KEEP_ALIVE, "access token id is invalid");
std::lock_guard<ffrt::mutex> lock(taskMutex);
*isCanceled = true;
taskCv.notify_all();
return;
}
while (abilityMgr && !abilityMgr->IsInStatusBar(accessTokenId)) {
while (!abilityMgr || !abilityMgr->IsInStatusBar(accessTokenId)) {
{
std::lock_guard<ffrt::mutex> lock(taskMutex);
if (*isCanceled) {
if (!isCanceled || *isCanceled) {
TAG_LOGI(AAFwkTag::KEEP_ALIVE, "canceled in the middle");
return;
}
@ -126,7 +123,7 @@ void KeepAliveProcessManager::AfterStartKeepAliveApp(const AppExecFwk::BundleInf
taskCv.notify_all();
TAG_LOGI(AAFwkTag::KEEP_ALIVE, "finished checking status bar");
});
auto condition = [&isCreated, &isCanceled] { return (isCreated || isCanceled); };
auto condition = [&isCreated, isCanceled] { return (isCreated || (isCanceled && *isCanceled)); };
{
std::unique_lock<ffrt::mutex> lock(taskMutex);
TAG_LOGI(AAFwkTag::KEEP_ALIVE, "wait for condition");
@ -134,16 +131,20 @@ void KeepAliveProcessManager::AfterStartKeepAliveApp(const AppExecFwk::BundleInf
TAG_LOGE(AAFwkTag::KEEP_ALIVE, "attach status bar timeout");
*isCanceled = true;
}
TAG_LOGI(AAFwkTag::KEEP_ALIVE, "wait is over");
}
if (isCreated) {
return;
}
if (isCreated) { return; }
TAG_LOGW(AAFwkTag::KEEP_ALIVE, "not created, cancel keep-alive");
SetApplicationKeepAlive(bundleInfo.name, userId, false, true);
(void)DelayedSingleton<AppExecFwk::AppMgrClient>::GetInstance()->KillApplication(bundleInfo.name);
}
int32_t KeepAliveProcessManager::SetApplicationKeepAlive(const std::string &bundleName,
int32_t userId, bool updateEnable, bool isByEDM)
{
auto result = isByEDM ? CheckPermissionForEDM() : CheckPermission();
CHECK_RET_RETURN_RET(result, "permission denied");
CHECK_TRUE_RETURN_RET(bundleName.empty(), INVALID_PARAMETERS_ERR, "input parameter error");
auto bms = AbilityUtil::GetBundleManagerHelper();
@ -151,31 +152,25 @@ int32_t KeepAliveProcessManager::SetApplicationKeepAlive(const std::string &bund
auto abilityMgr = DelayedSingleton<AbilityManagerService>::GetInstance();
CHECK_POINTER_AND_RETURN(abilityMgr, INNER_ERR);
userId = userId < 0 ? abilityMgr->GetUserId() : userId;
AppExecFwk::BundleInfo bundleInfo;
if (userId < 0) {
userId = abilityMgr->GetUserId();
}
if (!IN_PROCESS_CALL(bms->GetBundleInfo(
bundleName, AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo, userId))) {
TAG_LOGE(AAFwkTag::KEEP_ALIVE, "get bundle info failed");
return ERR_INVALID_VALUE;
return ERR_TARGET_BUNDLE_NOT_EXIST;
}
CHECK_POINTER_AND_RETURN(abilityKeepAliveService_, INNER_ERR);
bool localEnable = false;
auto result = abilityKeepAliveService_->GetKeepAliveProcessEnable(bundleName, userId, localEnable);
CHECK_TRUE_RETURN_RET((result != ERR_OK && result != ERR_NAME_NOT_FOUND),
result, "GetKeepAliveProcessEnable failed");
CHECK_TRUE_RETURN_RET((updateEnable == localEnable),
ERR_OK, "no change to the KeepAlive process setting properties");
auto appMgrClient = DelayedSingleton<AppExecFwk::AppMgrClient>::GetInstance();
CHECK_POINTER_AND_RETURN(appMgrClient, INNER_ERR);
bool localEnable = IsKeepAliveBundle(bundleName, userId);
if (updateEnable) {
std::string mainElementName;
CHECK_TRUE_RETURN_RET(!MainElementUtils::CheckMainUIAbility(bundleInfo, mainElementName),
ERR_NO_MAIN_ABILITY, "bundle has no main uiability");
bool isRunning = false;
result = IN_PROCESS_CALL(appMgrClient->IsApplicationRunning(bundleName, isRunning));
CHECK_RET_RETURN_RET(result, "IsApplicationRunning failed");
result = IN_PROCESS_CALL(appMgrClient->IsAppRunning(bundleName, 0, isRunning));
CHECK_RET_RETURN_RET(result, "IsAppRunning failed");
CHECK_TRUE_RETURN_RET((!isRunning && !MainElementUtils::CheckStatusBarAbility(bundleInfo)),
ERR_NO_STATUS_BAR_ABILITY, "app has no status bar");
CHECK_TRUE_RETURN_RET((isRunning && !IsRunningAppInStatusBar(abilityMgr, bundleInfo)),
@ -185,11 +180,16 @@ int32_t KeepAliveProcessManager::SetApplicationKeepAlive(const std::string &bund
KeepAliveInfo info;
info.bundleName = bundleName;
info.userId = userId;
result = isByEDM ? abilityKeepAliveService_->SetApplicationKeepAliveByEDM(info, updateEnable)
: abilityKeepAliveService_->SetApplicationKeepAlive(info, updateEnable);
CHECK_RET_RETURN_RET(result, "KeepAlive process attribute update failed");
IN_PROCESS_CALL_WITHOUT_RET(appMgrClient->SetKeepAliveEnableState(bundleName, updateEnable, 0));
UpdateKeepAliveProcessesStatus(bundleInfo, userId, localEnable, updateEnable);
info.appType = bundleInfo.applicationInfo.isSystemApp ? KeepAliveAppType::SYSTEM : KeepAliveAppType::THIRD_PARTY;
info.setter = isByEDM ? KeepAliveSetter::SYSTEM : KeepAliveSetter::USER;
result = AbilityKeepAliveService::GetInstance().SetApplicationKeepAlive(info, updateEnable);
CHECK_RET_RETURN_RET(result, "set keep-alive failed");
IN_PROCESS_CALL_WITHOUT_RET(appMgrClient->SetKeepAliveDkv(bundleName, updateEnable, 0));
if (!updateEnable && localEnable) {
// just update
std::vector<AppExecFwk::BundleInfo> bundleInfos{ bundleInfo };
KeepAliveUtils::NotifyDisableKeepAliveProcesses(bundleInfos, userId);
}
return ERR_OK;
}
@ -212,16 +212,6 @@ bool KeepAliveProcessManager::IsRunningAppInStatusBar(std::shared_ptr<AbilityMan
return abilityMgr->IsInStatusBar(accessTokenId);
}
void KeepAliveProcessManager::UpdateKeepAliveProcessesStatus(
const AppExecFwk::BundleInfo &bundleInfo, int32_t userId, bool localEnable, bool updateEnable)
{
if (!updateEnable && localEnable) {
// just update
std::vector<AppExecFwk::BundleInfo> bundleInfos{ bundleInfo };
KeepAliveUtils::NotifyDisableKeepAliveProcesses(bundleInfos, userId);
}
}
void KeepAliveProcessManager::OnAppStateChanged(const AppInfo &info)
{
if (info.state != AppState::BEGIN) {
@ -248,43 +238,40 @@ void KeepAliveProcessManager::OnAppStateChanged(const AppInfo &info)
return;
}
if (abilityKeepAliveService_ == nullptr) {
TAG_LOGE(AAFwkTag::KEEP_ALIVE, "abilityKeepAliveService_ null");
return;
}
bool localEnable = false;
auto result = abilityKeepAliveService_->GetKeepAliveProcessEnable(bundleName, -1, localEnable);
if (result != ERR_OK) {
TAG_LOGE(AAFwkTag::KEEP_ALIVE, "GetKeepAliveProcessEnable failed: %{public}d", result);
bool localEnable = IsKeepAliveBundle(bundleName, -1);
if (!localEnable) {
return;
}
auto appMgrClient = DelayedSingleton<AppExecFwk::AppMgrClient>::GetInstance();
if (appMgrClient == nullptr) {
TAG_LOGE(AAFwkTag::KEEP_ALIVE, "set keep alive enable state error");
TAG_LOGE(AAFwkTag::KEEP_ALIVE, "appMgrClient is null");
return;
}
IN_PROCESS_CALL_WITHOUT_RET(appMgrClient->SetKeepAliveEnableState(bundleName, localEnable, uid));
IN_PROCESS_CALL_WITHOUT_RET(appMgrClient->SetKeepAliveDkv(bundleName, localEnable, uid));
}
bool KeepAliveProcessManager::IsKeepAliveBundle(const std::string &bundleName, int32_t userId)
{
CHECK_POINTER_AND_RETURN(abilityKeepAliveService_, false);
bool keepAliveEnable = false;
abilityKeepAliveService_->GetKeepAliveProcessEnable(bundleName, userId, keepAliveEnable);
return keepAliveEnable;
if (!system::GetBoolParameter(PRODUCT_ENTERPRISE_FEATURE_SETTING_ENABLED, false)) {
TAG_LOGI(AAFwkTag::KEEP_ALIVE, "not supported");
return false;
}
return AbilityKeepAliveService::GetInstance().IsKeepAliveApp(bundleName, userId);
}
bool KeepAliveProcessManager::GetKeepAliveBundleInfosForUser(std::vector<AppExecFwk::BundleInfo> &bundleInfos,
int32_t userId)
{
if (!system::GetBoolParameter(PRODUCT_ENTERPRISE_FEATURE_SETTING_ENABLED, false)) {
TAG_LOGW(AAFwkTag::KEEP_ALIVE, "not supported");
return false;
}
auto bundleMgrHelper = DelayedSingleton<AppExecFwk::BundleMgrHelper>::GetInstance();
CHECK_POINTER_AND_RETURN(bundleMgrHelper, false);
CHECK_POINTER_AND_RETURN(abilityKeepAliveService_, false);
std::vector<KeepAliveInfo> infoList;
auto ret = abilityKeepAliveService_->GetKeepAliveApplications(userId, infoList);
auto ret = AbilityKeepAliveService::GetInstance().GetKeepAliveApplications(userId, infoList);
if (ret != ERR_OK) {
TAG_LOGE(AAFwkTag::KEEP_ALIVE, "failed get keep_alive bundle info: %{public}d", ret);
return false;
@ -341,11 +328,46 @@ void KeepAliveProcessManager::AddFailedKeepAliveAbility(const std::string &bundl
int32_t KeepAliveProcessManager::QueryKeepAliveApplications(int32_t appType, int32_t userId,
std::vector<KeepAliveInfo> &infoList, bool isByEDM)
{
CHECK_POINTER_AND_RETURN(abilityKeepAliveService_, INNER_ERR);
if (isByEDM) {
return abilityKeepAliveService_->QueryKeepAliveApplicationsByEDM(userId, appType, infoList);
auto result = isByEDM ? CheckPermissionForEDM() : CheckPermission();
CHECK_RET_RETURN_RET(result, "permission denied");
return AbilityKeepAliveService::GetInstance().QueryKeepAliveApplications(userId, appType, infoList);
}
int32_t KeepAliveProcessManager::CheckPermission()
{
if (!system::GetBoolParameter(PRODUCT_ENTERPRISE_FEATURE_SETTING_ENABLED, false)) {
TAG_LOGE(AAFwkTag::KEEP_ALIVE, "not supported");
return ERR_CAPABILITY_NOT_SUPPORT;
}
return abilityKeepAliveService_->QueryKeepAliveApplications(userId, appType, infoList);
if (!PermissionVerification::GetInstance()->JudgeCallerIsAllowedToUseSystemAPI()) {
TAG_LOGE(AAFwkTag::KEEP_ALIVE, "not use system-api");
return ERR_NOT_SYSTEM_APP;
}
if (!PermissionVerification::GetInstance()->VerifyCallingPermission(
PermissionConstants::PERMISSION_MANAGE_APP_KEEP_ALIVE)) {
TAG_LOGE(AAFwkTag::KEEP_ALIVE, "verify PERMISSION_MANAGE_APP_KEEP_ALIVE fail");
return CHECK_PERMISSION_FAILED;
}
return ERR_OK;
}
int32_t KeepAliveProcessManager::CheckPermissionForEDM()
{
if (!system::GetBoolParameter(PRODUCT_ENTERPRISE_FEATURE_SETTING_ENABLED, false)) {
TAG_LOGE(AAFwkTag::KEEP_ALIVE, "not supported");
return ERR_CAPABILITY_NOT_SUPPORT;
}
if (PermissionVerification::GetInstance()->CheckSpecificSystemAbilityAccessPermission(FOUNDATION_PROCESS_NAME)
|| (PermissionVerification::GetInstance()->IsSACall()
&& PermissionVerification::GetInstance()->VerifyCallingPermission(
PermissionConstants::PERMISSION_MANAGE_APP_KEEP_ALIVE_INTERNAL))) {
return ERR_OK;
}
TAG_LOGE(AAFwkTag::KEEP_ALIVE, "verify PERMISSION_MANAGE_APP_KEEP_ALIVE_INTERNAL fail");
return CHECK_PERMISSION_FAILED;
}
} // namespace AAFwk
} // namespace OHOS

View File

@ -24,6 +24,7 @@ bool ProcessOptions::ReadFromParcel(Parcel &parcel)
processMode = static_cast<ProcessMode>(parcel.ReadInt32());
startupVisibility = static_cast<StartupVisibility>(parcel.ReadInt32());
processName = parcel.ReadString();
isRestartKeepAlive = parcel.ReadBool();
return true;
}
@ -56,6 +57,10 @@ bool ProcessOptions::Marshalling(Parcel &parcel) const
TAG_LOGE(AAFwkTag::ABILITYMGR, "ProcessName write failed");
return false;
}
if (!parcel.WriteBool(isRestartKeepAlive)) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "isRestartKeepAlive write failed");
return false;
}
return true;
}

View File

@ -19,6 +19,7 @@
#include "ability_resident_process_rdb.h"
#include "ability_util.h"
#include "ffrt.h"
#include "keep_alive_utils.h"
#include "main_element_utils.h"
namespace OHOS {
@ -70,40 +71,7 @@ void ResidentProcessManager::StartResidentProcessWithMainElement(std::vector<App
std::set<uint32_t> needEraseIndexSet;
for (size_t i = 0; i < bundleInfos.size(); i++) {
if (userId != 0 && !AmsConfigurationParameter::GetInstance().InResidentWhiteList(bundleInfos[i].name)) {
needEraseIndexSet.insert(i);
continue;
}
std::string processName = bundleInfos[i].applicationInfo.process;
bool keepAliveEnable = bundleInfos[i].isKeepAlive;
// Check startup permissions
AmsResidentProcessRdb::GetInstance().GetResidentProcessEnable(bundleInfos[i].name, keepAliveEnable);
if (!keepAliveEnable || processName.empty()) {
needEraseIndexSet.insert(i);
continue;
}
for (auto hapModuleInfo : bundleInfos[i].hapModuleInfos) {
std::string mainElement;
if (!MainElementUtils::CheckMainElement(hapModuleInfo,
processName, mainElement, needEraseIndexSet, i, userId)) {
continue;
}
needEraseIndexSet.insert(i);
// startAbility
Want want;
want.SetElementName(hapModuleInfo.bundleName, mainElement);
ResidentAbilityInfoGuard residentAbilityInfoGuard(hapModuleInfo.bundleName, mainElement, userId);
TAG_LOGI(AAFwkTag::ABILITYMGR, "call, bundleName: %{public}s, mainElement: %{public}s",
hapModuleInfo.bundleName.c_str(), mainElement.c_str());
auto ret = DelayedSingleton<AbilityManagerService>::GetInstance()->StartAbility(want, userId,
DEFAULT_INVAL_VALUE);
MainElementUtils::UpdateMainElement(hapModuleInfo.bundleName,
hapModuleInfo.name, mainElement, true, userId);
if (ret != ERR_OK) {
AddFailedResidentAbility(hapModuleInfo.bundleName, mainElement, userId);
}
}
StartResidentProcessWithMainElementPerBundle(bundleInfos[i], i, needEraseIndexSet, userId);
}
// delete item which process has been started.
@ -112,21 +80,59 @@ void ResidentProcessManager::StartResidentProcessWithMainElement(std::vector<App
}
}
void ResidentProcessManager::NotifyDisableResidentProcess(const std::vector<AppExecFwk::BundleInfo> &bundleInfos,
int32_t userId)
void ResidentProcessManager::StartResidentProcessWithMainElementPerBundle(const AppExecFwk::BundleInfo &bundleInfo,
size_t index, std::set<uint32_t> &needEraseIndexSet, int32_t userId)
{
std::set<uint32_t> needEraseIndexSet; // no use
for (size_t i = 0; i < bundleInfos.size(); i++) {
std::string processName = bundleInfos[i].applicationInfo.process;
for (const auto &hapModuleInfo : bundleInfos[i].hapModuleInfos) {
std::string mainElement;
if (!MainElementUtils::CheckMainElement(hapModuleInfo,
processName, mainElement, needEraseIndexSet, i, userId)) {
continue;
}
MainElementUtils::UpdateMainElement(hapModuleInfo.bundleName,
hapModuleInfo.name, mainElement, false, userId);
if (userId != 0 && !AmsConfigurationParameter::GetInstance().InResidentWhiteList(bundleInfo.name)) {
needEraseIndexSet.insert(index);
return;
}
std::string processName = bundleInfo.applicationInfo.process;
bool keepAliveEnable = bundleInfo.isKeepAlive;
// Check startup permissions
AmsResidentProcessRdb::GetInstance().GetResidentProcessEnable(bundleInfo.name, keepAliveEnable);
if (!keepAliveEnable || processName.empty()) {
needEraseIndexSet.insert(index);
return;
}
for (auto hapModuleInfo : bundleInfo.hapModuleInfos) {
StartResidentProcessWithMainElementPerBundleHap(hapModuleInfo, processName, index, needEraseIndexSet, userId);
}
}
void ResidentProcessManager::StartResidentProcessWithMainElementPerBundleHap(
const AppExecFwk::HapModuleInfo &hapModuleInfo, const std::string &processName,
size_t index, std::set<uint32_t> &needEraseIndexSet, int32_t userId)
{
std::string mainElement;
bool isDataAbility = false;
std::string uriStr;
if (!MainElementUtils::CheckMainElement(hapModuleInfo,
processName, mainElement, isDataAbility, uriStr, userId)) {
if (isDataAbility) {
// dataability, need use AcquireDataAbility
needEraseIndexSet.insert(index);
TAG_LOGI(AAFwkTag::ABILITYMGR, "call, mainElement: %{public}s, uri: %{public}s",
mainElement.c_str(), uriStr.c_str());
Uri uri(uriStr);
DelayedSingleton<AbilityManagerService>::GetInstance()->AcquireDataAbility(uri, true, nullptr);
}
return;
}
needEraseIndexSet.insert(index);
// startAbility
Want want;
want.SetElementName(hapModuleInfo.bundleName, mainElement);
ResidentAbilityInfoGuard residentAbilityInfoGuard(hapModuleInfo.bundleName, mainElement, userId);
TAG_LOGI(AAFwkTag::ABILITYMGR, "call, bundleName: %{public}s, mainElement: %{public}s",
hapModuleInfo.bundleName.c_str(), mainElement.c_str());
auto ret = DelayedSingleton<AbilityManagerService>::GetInstance()->StartAbility(want, userId,
DEFAULT_INVAL_VALUE);
MainElementUtils::UpdateMainElement(hapModuleInfo.bundleName,
hapModuleInfo.name, mainElement, true, userId);
if (ret != ERR_OK) {
AddFailedResidentAbility(hapModuleInfo.bundleName, mainElement, userId);
}
}
@ -211,7 +217,7 @@ void ResidentProcessManager::UpdateResidentProcessesStatus(
} else if (!updateEnable && localEnable) {
// just update
std::vector<AppExecFwk::BundleInfo> bundleInfos{ bundleInfo };
NotifyDisableResidentProcess(bundleInfos, userId);
KeepAliveUtils::NotifyDisableKeepAliveProcesses(bundleInfos, userId);
}
}
}

View File

@ -50,6 +50,21 @@ bool StatusBarDelegateManager::IsCallerInStatusBar()
return isExist;
}
bool StatusBarDelegateManager::IsInStatusBar(uint32_t accessTokenId)
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
auto statusBarDelegate = GetStatusBarDelegate();
CHECK_POINTER_AND_RETURN(statusBarDelegate, false);
bool isExist = false;
auto ret = statusBarDelegate->CheckIfStatusBarItemExists(accessTokenId, isExist);
if (ret != ERR_OK) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "failed, ret: %{public}d", ret);
return false;
}
TAG_LOGI(AAFwkTag::ABILITYMGR, "isExist: %{public}d", isExist);
return isExist;
}
int32_t StatusBarDelegateManager::DoProcessAttachment(std::shared_ptr<AbilityRecord> abilityRecord)
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);

View File

@ -2505,6 +2505,13 @@ bool UIAbilityLifecycleManager::IsCallerInStatusBar()
return statusBarDelegateManager->IsCallerInStatusBar();
}
bool UIAbilityLifecycleManager::IsInStatusBar(uint32_t accessTokenId)
{
auto statusBarDelegateManager = GetStatusBarDelegateManager();
CHECK_POINTER_AND_RETURN(statusBarDelegateManager, false);
return statusBarDelegateManager->IsInStatusBar(accessTokenId);
}
int32_t UIAbilityLifecycleManager::DoProcessAttachment(std::shared_ptr<AbilityRecord> abilityRecord)
{
auto statusBarDelegateManager = GetStatusBarDelegateManager();
@ -2591,14 +2598,16 @@ int UIAbilityLifecycleManager::ChangeAbilityVisibility(sptr<IRemoteObject> token
auto sessionInfo = abilityRecord->GetSessionInfo();
CHECK_POINTER_AND_RETURN(sessionInfo, ERR_INVALID_VALUE);
if (!IsCallerInStatusBar() && (sessionInfo->processOptions != nullptr &&
!ProcessOptions::IsNoAttachmentMode(sessionInfo->processOptions->processMode))) {
if (!IsCallerInStatusBar() && sessionInfo->processOptions != nullptr &&
!ProcessOptions::IsNoAttachmentMode(sessionInfo->processOptions->processMode) &&
!sessionInfo->processOptions->isRestartKeepAlive) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "caller not add to status bar");
return ERR_START_OPTIONS_CHECK_FAILED;
}
if (sessionInfo->processOptions == nullptr ||
(!ProcessOptions::IsAttachToStatusBarMode(sessionInfo->processOptions->processMode) &&
!ProcessOptions::IsNoAttachmentMode(sessionInfo->processOptions->processMode))) {
!ProcessOptions::IsNoAttachmentMode(sessionInfo->processOptions->processMode) &&
!sessionInfo->processOptions->isRestartKeepAlive)) {
auto ret = DoCallerProcessAttachment(abilityRecord);
if (ret != ERR_OK) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "caller attach to status bar failed, ret: %{public}d", ret);

View File

@ -0,0 +1,59 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "keep_alive_utils.h"
#include "ability_resident_process_rdb.h"
#include "ability_util.h"
#include "keep_alive_process_manager.h"
#include "main_element_utils.h"
namespace OHOS {
namespace AAFwk {
void KeepAliveUtils::NotifyDisableKeepAliveProcesses(
const std::vector<AppExecFwk::BundleInfo> &bundleInfos, int32_t userId)
{
for (size_t i = 0; i < bundleInfos.size(); i++) {
std::string processName = bundleInfos[i].applicationInfo.process;
for (const auto &hapModuleInfo : bundleInfos[i].hapModuleInfos) {
std::string mainElement;
bool isDataAbility = false;
std::string uriStr;
if (!MainElementUtils::CheckMainElement(hapModuleInfo,
processName, mainElement, isDataAbility, uriStr, userId)) {
continue;
}
MainElementUtils::UpdateMainElement(hapModuleInfo.bundleName,
hapModuleInfo.name, mainElement, false, userId);
}
}
}
bool KeepAliveUtils::IsKeepAliveBundle(const AppExecFwk::BundleInfo &bundleInfo, int32_t userId, KeepAliveType &type)
{
if (KeepAliveProcessManager::GetInstance().IsKeepAliveBundle(bundleInfo.name, userId)) {
type = KeepAliveType::THIRD_PARTY;
return true;
}
bool keepAliveEnable = bundleInfo.isKeepAlive;
AbilityRuntime::AmsResidentProcessRdb::GetInstance().GetResidentProcessEnable(bundleInfo.name, keepAliveEnable);
if (keepAliveEnable) {
type = KeepAliveType::RESIDENT_PROCESS;
}
return keepAliveEnable;
}
} // namespace AAFwk
} // namespace OHOS

View File

@ -65,8 +65,8 @@ void MainElementUtils::UpdateMainElement(const std::string &bundleName, const st
}
bool MainElementUtils::CheckMainElement(const AppExecFwk::HapModuleInfo &hapModuleInfo,
const std::string &processName, std::string &mainElement,
std::set<uint32_t> &needEraseIndexSet, size_t bundleInfoIndex, int32_t userId)
const std::string &processName, std::string &mainElement, bool &isDataAbility,
std::string &uriStr, int32_t userId)
{
if (!hapModuleInfo.isModuleJson) {
// old application model
@ -87,16 +87,9 @@ bool MainElementUtils::CheckMainElement(const AppExecFwk::HapModuleInfo &hapModu
return false;
}
std::string uriStr;
bool getDataAbilityUri = DelayedSingleton<AbilityManagerService>::GetInstance()->GetDataAbilityUri(
isDataAbility = DelayedSingleton<AbilityManagerService>::GetInstance()->GetDataAbilityUri(
hapModuleInfo.abilityInfos, mainElement, uriStr);
if (getDataAbilityUri) {
// dataability, need use AcquireDataAbility
TAG_LOGI(AAFwkTag::ABILITYMGR, "call, mainElement: %{public}s, uri: %{public}s",
mainElement.c_str(), uriStr.c_str());
Uri uri(uriStr);
DelayedSingleton<AbilityManagerService>::GetInstance()->AcquireDataAbility(uri, true, nullptr);
needEraseIndexSet.insert(bundleInfoIndex);
if (isDataAbility) {
return false;
}
} else {
@ -116,5 +109,61 @@ bool MainElementUtils::CheckMainElement(const AppExecFwk::HapModuleInfo &hapModu
}
return IsMainElementTypeOk(hapModuleInfo, mainElement, userId);
}
bool MainElementUtils::CheckMainUIAbility(const AppExecFwk::BundleInfo &bundleInfo, std::string& mainElementName)
{
for (const auto& hapModuleInfo : bundleInfo.hapModuleInfos) {
if (hapModuleInfo.moduleType != AppExecFwk::ModuleType::ENTRY) {
continue;
}
mainElementName = hapModuleInfo.mainElementName;
if (mainElementName.empty()) {
return false;
}
for (const auto &abilityInfo: hapModuleInfo.abilityInfos) {
if (abilityInfo.type != AppExecFwk::AbilityType::PAGE) {
continue;
}
if (abilityInfo.name == mainElementName) {
return true;
}
}
break;
}
return false;
}
bool MainElementUtils::CheckStatusBarAbility(const AppExecFwk::BundleInfo &bundleInfo)
{
for (const auto& hapModuleInfo : bundleInfo.hapModuleInfos) {
for (const auto &extensionInfo: hapModuleInfo.extensionInfos) {
if (extensionInfo.type == AppExecFwk::ExtensionAbilityType::STATUS_BAR_VIEW) {
return true;
}
}
}
return false;
}
void MainElementUtils::GetMainUIAbilityAccessTokenId(const AppExecFwk::BundleInfo &bundleInfo,
const std::string &mainElementName, uint32_t &accessTokenId)
{
for (const auto& hapModuleInfo : bundleInfo.hapModuleInfos) {
if (hapModuleInfo.moduleType != AppExecFwk::ModuleType::ENTRY ||
hapModuleInfo.mainElementName != mainElementName) {
continue;
}
for (const auto &abilityInfo: hapModuleInfo.abilityInfos) {
if (abilityInfo.type != AppExecFwk::AbilityType::PAGE ||
abilityInfo.name != mainElementName) {
continue;
}
accessTokenId = abilityInfo.applicationInfo.accessTokenId;
}
return;
}
}
} // namespace AAFwk
} // namespace OHOS

View File

@ -370,6 +370,14 @@ public:
*/
void SetKeepAliveEnableState(const std::string &bundleName, bool enable, int32_t uid) override;
/**
* @brief Set non-resident keep-alive process status.
* @param bundleName The application bundle name.
* @param enable The current updated enable status.
* @param uid indicates user, 0 for all users
*/
void SetKeepAliveDkv(const std::string &bundleName, bool enable, int32_t uid) override;
/**
* To clear the process by ability token.
*

View File

@ -1269,6 +1269,16 @@ public:
*/
void SetKeepAliveEnableState(const std::string &bundleName, bool enable, int32_t uid);
/**
* @brief Set non-resident keep-alive process status.
* when one process started, this method will be called from ability mgr with data selected from db.
*
* @param bundleName processed of witch to be configed
* @param enable config value
* @param uid indicates user, 0 for all users
*/
void SetKeepAliveDkv(const std::string &bundleName, bool enable, int32_t uid);
int32_t GetAppRunningUniqueIdByPid(pid_t pid, std::string &appRunningUniqueId);
int32_t GetAllUIExtensionRootHostPid(pid_t pid, std::vector<pid_t> &hostPids);
@ -1413,6 +1423,11 @@ private:
*/
void RestartResidentProcess(std::shared_ptr<AppRunningRecord> appRecord);
/**
* If one app needs keepalive and dies, restart the app again
*/
void RestartKeepAliveProcess(std::shared_ptr<AppRunningRecord> appRecord);
bool CheckLoadAbilityConditions(std::shared_ptr<AAFwk::Want> want,
std::shared_ptr<AbilityRuntime::LoadParam> loadParam, const std::shared_ptr<AbilityInfo> &abilityInfo,
const std::shared_ptr<ApplicationInfo> &appInfo);
@ -1609,6 +1624,8 @@ private:
void ApplicationTerminatedSendProcessEvent(const std::shared_ptr<AppRunningRecord> &appRecord);
void ClearAppRunningDataForKeepAlive(const std::shared_ptr<AppRunningRecord> &appRecord);
void ClearResidentProcessAppRunningData(const std::shared_ptr<AppRunningRecord> &appRecord);
void ClearNonResidentKeepAliveAppRunningData(const std::shared_ptr<AppRunningRecord> &appRecord);
int32_t StartChildProcessPreCheck(pid_t callingPid, int32_t childProcessType);
@ -1822,6 +1839,7 @@ private:
void AddUIExtensionLauncherItem(std::shared_ptr<AAFwk::Want> want, std::shared_ptr<AppRunningRecord> appRecord,
sptr<IRemoteObject> token);
void NotifyStartResidentProcess(std::vector<AppExecFwk::BundleInfo> &bundleInfos);
void NotifyStartKeepAliveProcess(std::vector<AppExecFwk::BundleInfo> &bundleInfos);
void RemoveUIExtensionLauncherItem(std::shared_ptr<AppRunningRecord> appRecord, sptr<IRemoteObject> token);
bool IsSceneBoardCall();
void CheckCleanAbilityByUserRequest(const std::shared_ptr<AppRunningRecord> &appRecord,

View File

@ -589,6 +589,11 @@ public:
*/
bool IsKeepAliveApp() const;
/**
* @brief Whether the process is non-resident keep-alive.
*/
bool IsKeepAliveDkv() const;
/**
* @brief Whether the process can keep empty alive.
*/
@ -615,6 +620,14 @@ public:
*/
void SetKeepAliveEnableState(bool isKeepAliveEnable);
/**
* @brief A process can be configured non-resident keep-alive.
* when one process started, this method will be called from ability mgr with data selected from db.
*
* @param isKeepAliveDkv new value
*/
void SetKeepAliveDkv(bool isKeepAliveDkv);
/**
* @brief roughly considered as a value from the process's bundle info.
*
@ -1056,6 +1069,7 @@ private:
bool isKeepAliveRdb_ = false; // Only resident processes can be set to true, please choose carefully
bool isKeepAliveBundle_ = false;
bool isEmptyKeepAliveApp_ = false; // Only empty resident processes can be set to true, please choose carefully
bool isKeepAliveDkv_ = false; // Only non-resident keep-alive processes can be set to true, please choose carefully
bool isMainProcess_ = true; // Only MainProcess can be keepalive
bool isSingleton_ = false;
bool isStageBasedModel_ = false;

View File

@ -627,6 +627,15 @@ void AmsMgrScheduler::SetKeepAliveEnableState(const std::string &bundleName, boo
amsMgrServiceInner_->SetKeepAliveEnableState(bundleName, enable, uid);
}
void AmsMgrScheduler::SetKeepAliveDkv(const std::string &bundleName, bool enable, int32_t uid)
{
if (!IsReady()) {
TAG_LOGE(AAFwkTag::APPMGR, "not ready");
return;
}
amsMgrServiceInner_->SetKeepAliveDkv(bundleName, enable, uid);
}
void AmsMgrScheduler::ClearProcessByToken(sptr<IRemoteObject> token)
{
if (!IsReady()) {

View File

@ -2608,6 +2608,7 @@ std::shared_ptr<AppRunningRecord> AppMgrServiceInner::CreateAppRunningRecord(
appRecord->SetProcessAndExtensionType(abilityInfo);
appRecord->SetKeepAliveEnableState(bundleInfo.isKeepAlive);
appRecord->SetKeepAliveDkv(loadParam->isKeepAlive);
appRecord->SetEmptyKeepAliveAppState(false);
appRecord->SetTaskHandler(taskHandler_);
appRecord->SetEventHandler(eventHandler_);
@ -4193,6 +4194,36 @@ bool AppMgrServiceInner::CheckRemoteClient()
return true;
}
void AppMgrServiceInner::RestartKeepAliveProcess(std::shared_ptr<AppRunningRecord> appRecord)
{
TAG_LOGI(AAFwkTag::APPMGR, "restart keep-alive process begins.");
if (appRecord == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "appRecord null");
return;
}
if (!CheckRemoteClient() || !appRecord || !appRunningManager_) {
TAG_LOGE(AAFwkTag::APPMGR, "restart keep-alive fail");
return;
}
auto bundleMgrHelper = remoteClientManager_->GetBundleManagerHelper();
BundleInfo bundleInfo;
auto userId = GetUserIdByUid(appRecord->GetUid());
auto flags = BundleFlag::GET_BUNDLE_DEFAULT | BundleFlag::GET_BUNDLE_WITH_REQUESTED_PERMISSION;
if (!IN_PROCESS_CALL(bundleMgrHelper->GetBundleInfo(
appRecord->GetBundleName(),
static_cast<BundleFlag>(flags),
bundleInfo, userId))) {
TAG_LOGE(AAFwkTag::APPMGR, "getBundleInfo fail");
return;
}
std::vector<BundleInfo> infos;
infos.emplace_back(bundleInfo);
TAG_LOGI(AAFwkTag::APPMGR, "keepAliveProcess %{public}s", appRecord->GetProcessName().c_str());
NotifyStartKeepAliveProcess(infos);
}
void AppMgrServiceInner::RestartResidentProcess(std::shared_ptr<AppRunningRecord> appRecord)
{
if (appRecord == nullptr) {
@ -6895,6 +6926,12 @@ void AppMgrServiceInner::ApplicationTerminatedSendProcessEvent(const std::shared
}
void AppMgrServiceInner::ClearAppRunningDataForKeepAlive(const std::shared_ptr<AppRunningRecord> &appRecord)
{
ClearResidentProcessAppRunningData(appRecord);
ClearNonResidentKeepAliveAppRunningData(appRecord);
}
void AppMgrServiceInner::ClearResidentProcessAppRunningData(const std::shared_ptr<AppRunningRecord> &appRecord)
{
if (appRecord == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "appRecord null");
@ -6942,6 +6979,38 @@ void AppMgrServiceInner::ClearAppRunningDataForKeepAlive(const std::shared_ptr<A
}
}
void AppMgrServiceInner::ClearNonResidentKeepAliveAppRunningData(const std::shared_ptr<AppRunningRecord> &appRecord)
{
if (appRecord == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "appRecord null");
return;
}
auto userId = GetUserIdByUid(appRecord->GetUid());
if (appRecord->IsKeepAliveDkv() && (userId == 0 || userId == currentUserId_) &&
appRecord->GetBundleName() != SCENE_BOARD_BUNDLE_NAME) {
if (ExitResidentProcessManager::GetInstance().IsKilledForUpgradeWeb(appRecord->GetBundleName())) {
TAG_LOGI(AAFwkTag::APPMGR, "is killed for upgrade web");
return;
}
if (!IsMemorySizeSufficient()) {
TAG_LOGI(AAFwkTag::APPMGR, "memory size insufficient");
return;
}
TAG_LOGI(AAFwkTag::APPMGR, "memory size sufficient");
auto restartProcess = [appRecord, innerService = shared_from_this()]() {
TAG_LOGI(AAFwkTag::APPMGR, "restarting keep-alive process.");
innerService->RestartKeepAliveProcess(appRecord);
};
if (taskHandler_ == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "taskHandler_ null");
return;
}
TAG_LOGI(AAFwkTag::APPMGR, "submit restart keep-alive process task.");
taskHandler_->SubmitTask(restartProcess, "RestartKeepAliveProcess");
}
}
int32_t AppMgrServiceInner::NotifyPageShow(const sptr<IRemoteObject> &token, const PageStateData &pageStateData)
{
if (!JudgeSelfCalledByToken(token, pageStateData)) {
@ -7741,6 +7810,7 @@ int32_t AppMgrServiceInner::NotifyMemorySizeStateChanged(bool isMemorySizeSuffic
ExitResidentProcessManager::GetInstance().QueryExitBundleInfos(exitProcessInfos, exitBundleInfos);
innerServicer->NotifyStartResidentProcess(exitBundleInfos);
innerServicer->NotifyStartKeepAliveProcess(exitBundleInfos);
};
taskHandler_->SubmitTask(StartExitKeepAliveProcessTask, "startexitkeepaliveprocess");
return ERR_OK;
@ -7771,6 +7841,16 @@ void AppMgrServiceInner::NotifyStartResidentProcess(std::vector<AppExecFwk::Bund
}
}
void AppMgrServiceInner::NotifyStartKeepAliveProcess(std::vector<AppExecFwk::BundleInfo> &bundleInfos)
{
std::lock_guard lock(appStateCallbacksLock_);
for (const auto &item : appStateCallbacks_) {
if (item.callback != nullptr) {
item.callback->NotifyStartKeepAliveProcess(bundleInfos);
}
}
}
void AppMgrServiceInner::SetKeepAliveEnableState(const std::string &bundleName, bool enable, int32_t uid)
{
TAG_LOGD(AAFwkTag::APPMGR, "called");
@ -7801,6 +7881,36 @@ void AppMgrServiceInner::SetKeepAliveEnableState(const std::string &bundleName,
}
}
void AppMgrServiceInner::SetKeepAliveDkv(const std::string &bundleName, bool enable, int32_t uid)
{
TAG_LOGD(AAFwkTag::APPMGR, "called");
if (bundleName.empty()) {
TAG_LOGE(AAFwkTag::APPMGR, "bundle name empty");
return;
}
if (appRunningManager_ == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "running manager error");
return;
}
auto callerUid = IPCSkeleton::GetCallingUid();
if (callerUid != FOUNDATION_UID) {
TAG_LOGE(AAFwkTag::APPMGR, "not foundation call");
return;
}
for (const auto &item : appRunningManager_->GetAppRunningRecordMap()) {
const auto &appRecord = item.second;
if (appRecord != nullptr && appRecord->GetBundleName() == bundleName &&
(uid == 0 || appRecord->GetUid() == uid)) {
TAG_LOGD(AAFwkTag::APPMGR, "%{public}s update state: %{public}d",
bundleName.c_str(), static_cast<int32_t>(enable));
appRecord->SetKeepAliveDkv(enable);
}
}
}
int32_t AppMgrServiceInner::SetSupportedProcessCacheSelf(bool isSupport)
{
TAG_LOGI(AAFwkTag::APPMGR, "call");
@ -8059,6 +8169,7 @@ void AppMgrServiceInner::RestartResidentProcessDependedOnWeb()
ExitResidentProcessManager::GetInstance().QueryExitBundleInfos(bundleNames, exitBundleInfos);
innerServicer->NotifyStartResidentProcess(exitBundleInfos);
innerServicer->NotifyStartKeepAliveProcess(exitBundleInfos);
};
taskHandler_->SubmitTask(RestartResidentProcessDependedOnWebTask, "RestartResidentProcessDependedOnWeb");
}

View File

@ -1458,11 +1458,21 @@ bool AppRunningRecord::IsKeepAliveApp() const
return true;
}
bool AppRunningRecord::IsKeepAliveDkv() const
{
return isKeepAliveDkv_;
}
void AppRunningRecord::SetKeepAliveEnableState(bool isKeepAliveEnable)
{
isKeepAliveRdb_ = isKeepAliveEnable;
}
void AppRunningRecord::SetKeepAliveDkv(bool isKeepAliveDkv)
{
isKeepAliveDkv_ = isKeepAliveDkv;
}
void AppRunningRecord::SetKeepAliveBundle(bool isKeepAliveBundle)
{
isKeepAliveBundle_ = isKeepAliveBundle;

View File

@ -90,6 +90,7 @@ enum class AAFwkLogTag : uint32_t {
CONTINUATION,
DISTRIBUTED,
FREE_INSTALL,
KEEP_ALIVE,
LOCAL_CALL = DEFAULT + 0x60, // 0xD001360
@ -158,7 +159,7 @@ inline const char* GetDomainName5(AAFwkLogTag tag)
{
const char* tagNames[] = { "WantAgent", "AutoFillMgr", "ExtMgr", "ServiceRouter",
"AutoStartup", "Startup", "Recovery", "ProcessMgr", "Continuation",
"Distributed", "FreeInstall" };
"Distributed", "FreeInstall", "KeepAlive" };
uint32_t offset = GetOffset(tag, AAFwkLogTag::WANTAGENT);
if (offset >= sizeof(tagNames) / sizeof(const char*)) {
return "UN";

View File

@ -24,16 +24,61 @@
namespace OHOS {
namespace AAFwk {
/**
* @class JsonUtils
* provides json utilities.
*/
class JsonUtils {
public:
/**
* GetInstance, get an instance of JsonUtils.
*
* @return an instance of JsonUtils.
*/
static JsonUtils &GetInstance()
{
static JsonUtils instance;
return instance;
}
/**
* JsonUtils, destructor.
*
*/
~JsonUtils() = default;
/**
* LoadConfiguration, load configuration.
*
* @param path The json file path.
* @param jsonBuf The json buffer to be returned.
* @param defaultPath The default output path.
* @return Whether or not the load operation succeeds.
*/
bool LoadConfiguration(const std::string& path, nlohmann::json& jsonBuf, const std::string& defaultPath = "");
/**
* IsEqual, check if json object contains certain key.
*
* @param jsonObject The json object.
* @param key The key.
* @param value The string value.
* @param checkEmpty The flag indicates whether the value can be empty.
* @return Whether or not the json object contains certain key.
*/
bool IsEqual(nlohmann::json &jsonObject, const std::string &key,
const std::string &value, bool checkEmpty = false);
/**
* IsEqual, check if json object contains certain key.
*
* @param jsonObject The json object.
* @param key The key.
* @param value The int32_t value.
* @return Whether or not the json object contains certain key.
*/
bool IsEqual(nlohmann::json &jsonObject, const std::string &key, int32_t value);
private:
std::string GetConfigPath(const std::string& path, const std::string& defaultPath);
bool ReadFileInfoJson(const std::string &filePath, nlohmann::json &jsonBuf);

View File

@ -67,6 +67,8 @@ constexpr const char* PERMISSION_BLOCK_ALL_APP_START = "ohos.permission.BLOCK_AL
constexpr const char* PERMISSION_START_UIABILITY_TO_HIDDEN = "ohos.permission.START_UIABILITY_TO_HIDDEN";
constexpr const char* PERMISSION_SUPERVISE_KIA_SERVICE = "ohos.permission.SUPERVISE_KIA_SERVICE";
constexpr const char* PERMISSION_GET_TELEPHONY_STATE = "ohos.permission.GET_TELEPHONY_STATE";
constexpr const char* PERMISSION_MANAGE_APP_KEEP_ALIVE = "ohos.permission.MANAGE_APP_KEEP_ALIVE";
constexpr const char* PERMISSION_MANAGE_APP_KEEP_ALIVE_INTERNAL = "ohos.permission.MANAGE_APP_KEEP_ALIVE_INTERNAL";
} // namespace PermissionConstants
} // namespace AAFwk
} // namespace OHOS

View File

@ -91,5 +91,28 @@ bool JsonUtils::ReadFileInfoJson(const std::string &filePath, nlohmann::json &js
return true;
}
bool JsonUtils::IsEqual(nlohmann::json &jsonObject, const std::string &key, const std::string &value, bool checkEmpty)
{
if (jsonObject.contains(key) && jsonObject[key].is_string()) {
std::string jsonValue = jsonObject.at(key).get<std::string>();
if (checkEmpty && !jsonValue.empty() && jsonValue != value) {
return false;
} else if (value != jsonValue) {
return false;
}
}
return true;
}
bool JsonUtils::IsEqual(nlohmann::json &jsonObject, const std::string &key, int32_t value)
{
if (jsonObject.contains(key) && jsonObject[key].is_number()) {
if (value != jsonObject.at(key).get<int32_t>()) {
return false;
}
}
return true;
}
} // namespace AAFwk
} // namespace OHOS

View File

@ -73,8 +73,6 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
std::string keys(data, size);
std::string values(data, size);
bool checkEmpty = *data % ENABLE;
abilityAutoStartupDataManager->IsEqual(jsonObject, keys, values, checkEmpty);
abilityAutoStartupDataManager->IsEqual(jsonObject, keys, values);
abilityAutoStartupDataManager->IsEqual(key, info);
abilityAutoStartupDataManager->IsEqual(key, strParam);
abilityAutoStartupDataManager->IsEqual(key, in32Param);

View File

@ -52,6 +52,7 @@ ohos_fuzztest("AbilityAutoStartupDataManageraFuzzTest") {
"${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_services_path}/abilitymgr:abilityms",
"${ability_runtime_services_path}/common:app_util",
"//third_party/jsoncpp:jsoncpp",
]

View File

@ -52,6 +52,7 @@ ohos_fuzztest("AbilityAutoStartupDataManagerbFuzzTest") {
"${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_services_path}/abilitymgr:abilityms",
"${ability_runtime_services_path}/common:app_util",
"//third_party/jsoncpp:jsoncpp",
]

View File

@ -101,14 +101,6 @@ void AbilityAutoStartupDataManagerFuzztest1(bool boolParam, std::string &stringP
dataMgr->ConvertAutoStartupInfoFromKeyAndValue(key2, value3);
nlohmann::json jsonObject = nlohmann::json::parse(key1.ToString(), nullptr, false);
dataMgr->IsEqual(jsonObject, "abilityName", "ability", boolParam); // branch,return true
dataMgr->IsEqual(jsonObject, "abilityName", "NaN", boolParam); // branch,return true
dataMgr->IsEqual(jsonObject, "userId", "ability", boolParam); // branch
dataMgr->IsEqual(jsonObject, "NaN", "ability", boolParam); // branch
dataMgr->IsEqual(jsonObject, "userId", 100); // 100 means userid,branch
dataMgr->IsEqual(jsonObject, "userId", int32Param); // branch
dataMgr->IsEqual(jsonObject, "NaN", int32Param);
dataMgr->IsEqual(key1, info);
dataMgr->IsEqual(key2, info);
dataMgr->IsEqual(key1Illegal, info);

View File

@ -56,6 +56,7 @@ ohos_fuzztest("AbilityAutoStartupServiceaFuzzTest") {
"${ability_runtime_native_path}/ability/native:auto_startup_callback",
"${ability_runtime_native_path}/appkit:appkit_manager_helper",
"${ability_runtime_services_path}/abilitymgr:abilityms",
"${ability_runtime_services_path}/common:app_util",
"${ability_runtime_services_path}/common:perm_verification",
"//third_party/jsoncpp:jsoncpp",
]

View File

@ -56,6 +56,7 @@ ohos_fuzztest("AbilityAutoStartupServicebFuzzTest") {
"${ability_runtime_native_path}/ability/native:auto_startup_callback",
"${ability_runtime_native_path}/appkit:appkit_manager_helper",
"${ability_runtime_services_path}/abilitymgr:abilityms",
"${ability_runtime_services_path}/common:app_util",
"${ability_runtime_services_path}/common:perm_verification",
"//third_party/jsoncpp:jsoncpp",
]

View File

@ -56,6 +56,12 @@ public:
*/
virtual void NotifyStartResidentProcess(std::vector<AppExecFwk::BundleInfo> &bundleInfos) override;
/**
* @brief Notify abilityms start keep-alive process.
* @param bundleInfos resident process bundle infos.
*/
virtual void NotifyStartKeepAliveProcess(std::vector<AppExecFwk::BundleInfo> &bundleInfos) override;
/**
* @brief Notify abilityms app process pre cache
* @param pid process pid.
@ -67,6 +73,7 @@ private:
int32_t HandleOnAppStateChanged(MessageParcel& data, MessageParcel& reply);
int32_t HandleOnAbilityRequestDone(MessageParcel& data, MessageParcel& reply);
int32_t HandleNotifyStartResidentProcess(MessageParcel &data, MessageParcel &reply);
int32_t HandleNotifyStartKeepAliveProcess(MessageParcel &data, MessageParcel &reply);
int32_t HandleNotifyAppPreCache(MessageParcel &data, MessageParcel &reply);
using AppStateCallbackFunc = int32_t(AppStateCallbackHost::*)(MessageParcel& data, MessageParcel& reply);

View File

@ -49,6 +49,11 @@ void AppStateCallbackHost::NotifyStartResidentProcess(std::vector<AppExecFwk::Bu
TAG_LOGD(AAFwkTag::TEST, "NotifyStartResidentProcess called");
}
void AppStateCallbackHost::NotifyStartKeepAliveProcess(std::vector<AppExecFwk::BundleInfo> &bundleInfos)
{
TAG_LOGD(AAFwkTag::APPMGR, "called");
}
void AppStateCallbackHost::NotifyAppPreCache(int32_t pid, int32_t userId)
{
TAG_LOGD(AAFwkTag::TEST, "NotifyAppPreCache called");
@ -68,6 +73,12 @@ int32_t AppStateCallbackHost::HandleNotifyStartResidentProcess(MessageParcel &da
{
return NO_ERROR;
}
int32_t AppStateCallbackHost::HandleNotifyStartKeepAliveProcess(MessageParcel &data, MessageParcel &reply)
{
return NO_ERROR;
}
int32_t AppStateCallbackHost::HandleNotifyAppPreCache(MessageParcel &data, MessageParcel &reply)
{
return NO_ERROR;

View File

@ -40,5 +40,8 @@ void AppStateCallbackProxy::NotifyAppPreCache(int32_t pid, int32_t userId)
void AppStateCallbackProxy::NotifyStartResidentProcess(std::vector<AppExecFwk::BundleInfo> &bundleInfos)
{}
void AppStateCallbackProxy::NotifyStartKeepAliveProcess(std::vector<AppExecFwk::BundleInfo> &bundleInfos)
{}
} // namespace AppExecFwk
} // namespace OHOS

View File

@ -133,6 +133,11 @@ void AppScheduler::NotifyStartResidentProcess(std::vector<AppExecFwk::BundleInfo
TAG_LOGI(AAFwkTag::TEST, "Test AppScheduler::NotifyStartResidentProcess()");
}
void AppScheduler::NotifyStartKeepAliveProcess(std::vector<AppExecFwk::BundleInfo> &bundleInfos)
{
TAG_LOGI(AAFwkTag::TEST, "Test AppScheduler::NotifyStartKeepAliveProcess()");
}
void AppScheduler::OnAppRemoteDied(const std::vector<sptr<IRemoteObject>> &abilityTokens)
{
TAG_LOGI(AAFwkTag::TEST, "Test AppScheduler::OnAppRemoteDied()");

View File

@ -34,6 +34,7 @@ public:
MOCK_METHOD1(OnAppStateChanged, void(const AppProcessData&));
MOCK_METHOD2(OnAbilityRequestDone, void(const sptr<IRemoteObject>&, const AbilityState));
MOCK_METHOD1(NotifyStartResidentProcess, void(std::vector<AppExecFwk::BundleInfo>&));
MOCK_METHOD1(NotifyStartKeepAliveProcess, void(std::vector<AppExecFwk::BundleInfo>&));
MOCK_METHOD2(NotifyAppPreCache, void(int32_t, int32_t));
};
} // namespace AppExecFwk

View File

@ -41,6 +41,7 @@ ohos_unittest("ability_auto_startup_data_manager_test") {
"${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr",
"${ability_runtime_native_path}/ability:ability_context_native",
"${ability_runtime_services_path}/abilitymgr:abilityms",
"${ability_runtime_services_path}/common:app_util",
"${ability_runtime_services_path}/common:perm_verification",
"//third_party/googletest:gtest_main",
]

View File

@ -48,6 +48,7 @@ ohos_unittest("ability_auto_startup_service_test") {
"${ability_runtime_native_path}/ability/native:auto_startup_callback",
"${ability_runtime_native_path}/appkit:appkit_manager_helper",
"${ability_runtime_services_path}/abilitymgr:abilityms",
"${ability_runtime_services_path}/common:app_util",
"${ability_runtime_services_path}/common:perm_verification",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",

View File

@ -44,6 +44,7 @@ ohos_unittest("ability_bundle_event_callback_test") {
"${ability_runtime_native_path}/ability/native:auto_startup_callback",
"${ability_runtime_native_path}/appkit:appkit_manager_helper",
"${ability_runtime_services_path}/abilitymgr:abilityms",
"${ability_runtime_services_path}/common:app_util",
"${ability_runtime_services_path}/common:event_report",
"${ability_runtime_services_path}/common:perm_verification",
"${ability_runtime_services_path}/common:task_handler_wrap",

View File

@ -2113,6 +2113,19 @@ HWTEST_F(AbilityManagerServiceFirstTest, NotifyStartResidentProcess_0100, TestSi
abilityMs->NotifyStartResidentProcess(bundleInfos);
}
/**
* @tc.name: AbilityManagerServiceFirstTest_NotifyStartKeepAliveProcess_0100
* @tc.desc: Test NotifyStartKeepAliveProcess.
* @tc.type: FUNC
*/
HWTEST_F(AbilityManagerServiceFirstTest, NotifyStartKeepAliveProcess_0100, TestSize.Level1)
{
std::vector<AppExecFwk::BundleInfo> bundleInfos;
auto abilityMs = std::make_shared<AbilityManagerService>();
EXPECT_NE(abilityMs, nullptr);
abilityMs->NotifyStartKeepAliveProcess(bundleInfos);
}
/**
* @tc.name: AbilityManagerServiceFirstTest_OnAppRemoteDied_0100
* @tc.desc: Test OnAppRemoteDied.

View File

@ -73,6 +73,7 @@ ohos_unittest("ability_manager_service_fourth_test") {
"${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper",
"${ability_runtime_native_path}/appkit:appkit_manager_helper",
"${ability_runtime_services_path}/abilitymgr:abilityms",
"${ability_runtime_services_path}/common:app_util",
"${ability_runtime_services_path}/common:perm_verification",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",

View File

@ -61,6 +61,7 @@ ohos_unittest("ability_manager_service_third_test") {
"${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper",
"${ability_runtime_native_path}/appkit:appkit_manager_helper",
"${ability_runtime_services_path}/abilitymgr:abilityms",
"${ability_runtime_services_path}/common:app_util",
"${ability_runtime_services_path}/common:perm_verification",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",

View File

@ -122,6 +122,22 @@ HWTEST_F(AmsAppStateCallBackTest, NotifyStartResidentProcess_001, TestSize.Level
host->NotifyStartResidentProcess(bundleInfos);
}
/*
* Feature: AppStateCallBackHost
* Function: AppStateCallBackHost
* SubFunction: NotifyStartKeepAliveProcess Function
* FunctionPoints: NotifyStartKeepAliveProcess Onreceived interface
* EnvConditions: Mobile that can run ohos test framework
* CaseDescription: Verify if Onreceived works when ability request done.
*/
HWTEST_F(AmsAppStateCallBackTest, NotifyStartKeepAliveProcess_001, TestSize.Level1)
{
sptr<AppStateCallbackHost> host(new AppStateCallbackHost());
EXPECT_NE(host, nullptr);
std::vector<AppExecFwk::BundleInfo> bundleInfos;
host->NotifyStartKeepAliveProcess(bundleInfos);
}
/*
* Feature: AppStateCallBackHost
* Function: AppStateCallBackHost

View File

@ -594,6 +594,22 @@ HWTEST_F(AppSchedulerTest, AppScheduler_NotifyStartResidentProcess_001, TestSize
DelayedSingleton<AppScheduler>::GetInstance()->NotifyStartResidentProcess(bundleInfos);
}
/*
* Feature: AppScheduler
* Function: NotifyStartKeepAliveProcess
* SubFunction: NA
* FunctionPoints: AppScheduler NotifyStartKeepAliveProcess
* EnvConditions: NA
* CaseDescription: Verify NotifyStartKeepAliveProcess
*/
HWTEST_F(AppSchedulerTest, AppScheduler_NotifyStartKeepAliveProcess_001, TestSize.Level1)
{
std::vector<AppExecFwk::BundleInfo> bundleInfos;
ASSERT_NE(appStateMock_, nullptr);
DelayedSingleton<AppScheduler>::GetInstance()->callback_ = appStateMock_;
DelayedSingleton<AppScheduler>::GetInstance()->NotifyStartKeepAliveProcess(bundleInfos);
}
/*
* Feature: AppScheduler
* Function: KillApplication

View File

@ -33,6 +33,7 @@ public:
MOCK_METHOD2(OnAbilityRequestDone, void(const sptr<IRemoteObject>&, const int32_t));
MOCK_METHOD1(OnAppStateChanged, void(const AppInfo& info));
MOCK_METHOD1(NotifyStartResidentProcess, void(std::vector<AppExecFwk::BundleInfo>&));
MOCK_METHOD1(NotifyStartKeepAliveProcess, void(std::vector<AppExecFwk::BundleInfo>&));
MOCK_METHOD2(NotifyAppPreCache, void(int32_t, int32_t));
};
} // namespace AAFwk

View File

@ -28,9 +28,7 @@ ohos_unittest("extension_permissions_util_test") {
include_dirs = [
"mock/include",
"${ability_runtime_services_path}/abilitymgr/include/utils",
"${ability_runtime_services_path}/abilitymgr/include/utils",
"${ability_runtime_services_path}/abilitymgr/include",
"${ability_runtime_services_path}/common/include",
]

View File

@ -38,7 +38,6 @@ config("module_private_config") {
"${ability_runtime_test_path}/mock/frameworks_kits_appkit_native_test/include",
"${ability_runtime_services_path}/abilitymgr/include/utils",
"${ability_runtime_services_path}/abilitymgr/include",
"${ability_runtime_services_path}/common/include",
"${distributeddatamgr_path}/distributeddatamgr/interfaces/innerkits/app_distributeddata/include",
"${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include",
@ -413,7 +412,6 @@ ohos_unittest("data_ability_helper_test") {
include_dirs = [
"${ability_runtime_services_path}/abilitymgr/include/utils",
"${ability_runtime_services_path}/abilitymgr/include",
"${ability_runtime_path}/interfaces/kits/native/ability/native",
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context",
]
@ -470,7 +468,6 @@ ohos_unittest("data_ability_helper_impl_test") {
include_dirs = [
"${ability_runtime_services_path}/abilitymgr/include/utils",
"${ability_runtime_services_path}/abilitymgr/include",
"${ability_runtime_path}/interfaces/kits/native/ability/native",
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context",
"${ability_runtime_path}/interfaces/kits/native/ability/native",
@ -1302,7 +1299,6 @@ ohos_unittest("data_ability_impl_test") {
include_dirs = [
"${ability_runtime_services_path}/abilitymgr/include/utils",
"${ability_runtime_services_path}/abilitymgr/include",
"${ability_runtime_path}/interfaces/kits/native/ability/native",
"${ability_base_kits_path}/extractortool/include",
"${distributeddatamgr_path}/relational_store/frameworks/js/napi/rdb/include",

View File

@ -54,8 +54,8 @@ HWTEST_F(MainElementUtilsTest, CheckMainElement_001, TestSize.Level1)
HapModuleInfo hapModuleInfo;
std::string processName = "processName";
std::string mainElement = "";
std::set<uint32_t> needEraseIndexSet;
size_t bundleInfoIndex = 0;
bool isDataAbility = false;
std::string uriStr;
AbilityInfo abilityInfo;
hapModuleInfo.mainAbility = "mainAbility";
hapModuleInfo.isModuleJson = false;
@ -63,7 +63,7 @@ HWTEST_F(MainElementUtilsTest, CheckMainElement_001, TestSize.Level1)
abilityInfo.name = "mainAbility";
hapModuleInfo.abilityInfos.push_back(abilityInfo);
bool res = MainElementUtils::CheckMainElement(hapModuleInfo,
processName, mainElement, needEraseIndexSet, bundleInfoIndex);
processName, mainElement, isDataAbility, uriStr);
EXPECT_FALSE(res);
}
@ -80,8 +80,8 @@ HWTEST_F(MainElementUtilsTest, CheckMainElement_002, TestSize.Level1)
HapModuleInfo hapModuleInfo;
std::string processName = "processName";
std::string mainElement = "";
std::set<uint32_t> needEraseIndexSet;
size_t bundleInfoIndex = 0;
bool isDataAbility = false;
std::string uriStr;
AbilityInfo abilityInfo;
hapModuleInfo.mainAbility = "mainAbility";
hapModuleInfo.isModuleJson = false;
@ -89,7 +89,7 @@ HWTEST_F(MainElementUtilsTest, CheckMainElement_002, TestSize.Level1)
abilityInfo.name = "";
hapModuleInfo.abilityInfos.push_back(abilityInfo);
bool res = MainElementUtils::CheckMainElement(hapModuleInfo,
processName, mainElement, needEraseIndexSet, bundleInfoIndex);
processName, mainElement, isDataAbility, uriStr);
EXPECT_FALSE(res);
}
@ -106,8 +106,8 @@ HWTEST_F(MainElementUtilsTest, CheckMainElement_003, TestSize.Level1)
HapModuleInfo hapModuleInfo;
std::string processName = "processName";
std::string mainElement = "";
std::set<uint32_t> needEraseIndexSet;
size_t bundleInfoIndex = 0;
bool isDataAbility = false;
std::string uriStr;
AbilityInfo abilityInfo;
hapModuleInfo.mainAbility = "mainAbility";
hapModuleInfo.isModuleJson = false;
@ -117,7 +117,7 @@ HWTEST_F(MainElementUtilsTest, CheckMainElement_003, TestSize.Level1)
abilityInfo.type = AbilityType::DATA;
hapModuleInfo.abilityInfos.push_back(abilityInfo);
bool res = MainElementUtils::CheckMainElement(hapModuleInfo,
processName, mainElement, needEraseIndexSet, bundleInfoIndex);
processName, mainElement, isDataAbility, uriStr);
EXPECT_FALSE(res);
}
@ -134,8 +134,8 @@ HWTEST_F(MainElementUtilsTest, CheckMainElement_004, TestSize.Level1)
HapModuleInfo hapModuleInfo;
std::string processName = "processName";
std::string mainElement = "";
std::set<uint32_t> needEraseIndexSet;
size_t bundleInfoIndex = 0;
bool isDataAbility = false;
std::string uriStr;
AbilityInfo abilityInfo;
hapModuleInfo.mainAbility = "mainAbility";
hapModuleInfo.isModuleJson = false;
@ -145,7 +145,7 @@ HWTEST_F(MainElementUtilsTest, CheckMainElement_004, TestSize.Level1)
abilityInfo.type = AbilityType::PAGE;
hapModuleInfo.abilityInfos.push_back(abilityInfo);
bool res = MainElementUtils::CheckMainElement(hapModuleInfo,
processName, mainElement, needEraseIndexSet, bundleInfoIndex);
processName, mainElement, isDataAbility, uriStr);
EXPECT_FALSE(res);
}
@ -162,12 +162,12 @@ HWTEST_F(MainElementUtilsTest, CheckMainElement_005, TestSize.Level1)
HapModuleInfo hapModuleInfo;
std::string processName = "processName";
std::string mainElement = "";
std::set<uint32_t> needEraseIndexSet;
size_t bundleInfoIndex = 0;
bool isDataAbility = false;
std::string uriStr;
hapModuleInfo.mainAbility = "";
hapModuleInfo.isModuleJson = true;
bool res = MainElementUtils::CheckMainElement(hapModuleInfo,
processName, mainElement, needEraseIndexSet, bundleInfoIndex);
processName, mainElement, isDataAbility, uriStr);
EXPECT_FALSE(res);
}
@ -184,13 +184,13 @@ HWTEST_F(MainElementUtilsTest, CheckMainElement_006, TestSize.Level1)
HapModuleInfo hapModuleInfo;
std::string processName = "processName";
std::string mainElement = "";
std::set<uint32_t> needEraseIndexSet;
size_t bundleInfoIndex = 0;
bool isDataAbility = false;
std::string uriStr;
hapModuleInfo.mainAbility = "mainAbility";
hapModuleInfo.isModuleJson = true;
hapModuleInfo.process = "";
bool res = MainElementUtils::CheckMainElement(hapModuleInfo,
processName, mainElement, needEraseIndexSet, bundleInfoIndex);
processName, mainElement, isDataAbility, uriStr);
EXPECT_FALSE(res);
}
} // namespace AAFwk

View File

@ -28,9 +28,7 @@ ohos_unittest("multi_app_utils_test") {
include_dirs = [
"include",
"${ability_runtime_services_path}/abilitymgr/include/utils",
"${ability_runtime_services_path}/abilitymgr/include/utils",
"${ability_runtime_services_path}/abilitymgr/include",
"${ability_runtime_services_path}/appmgr/include",
"${ability_runtime_services_path}/common/include",
"${ability_runtime_test_path}/mock/services_appmgr_test/include",

View File

@ -28,9 +28,7 @@ ohos_unittest("want_utils_test") {
include_dirs = [
"include",
"${ability_runtime_services_path}/abilitymgr/include/utils",
"${ability_runtime_services_path}/abilitymgr/include/utils",
"${ability_runtime_services_path}/abilitymgr/include",
"${ability_runtime_services_path}/common/include",
]

View File

@ -28,13 +28,9 @@ ohos_unittest("window_options_utils_test") {
include_dirs = [
"mock/include",
"${ability_runtime_services_path}/abilitymgr/include/utils",
"${ability_runtime_services_path}/abilitymgr/include/utils",
"${ability_runtime_services_path}/abilitymgr/include",
"${ability_runtime_services_path}/common/include",
"${ability_runtime_path}interfaces/inner_api/ability_manager/include",
"${ability_runtime_services_path}/abilitymgr/include/utils",
"${ability_runtime_services_path}/abilitymgr/include",
]
sources = [
@ -55,6 +51,7 @@ ohos_unittest("window_options_utils_test") {
]
external_deps = [
"ability_base:base",
"ability_runtime:app_manager",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",

View File

@ -43,6 +43,7 @@ struct LoadParam : public Parcelable {
sptr<IRemoteObject> token = nullptr;
sptr<IRemoteObject> preToken = nullptr;
std::string instanceKey = "";
bool isKeepAlive = false;
};
} // namespace AbilityRuntime
} // namespace OHOS

View File

@ -51,6 +51,9 @@ bool LoadParam::Marshalling(Parcel &parcel) const
return false;
}
}
if (!parcel.WriteBool(isKeepAlive)) {
return false;
}
return true;
}
@ -71,6 +74,7 @@ bool LoadParam::ReadFromParcel(Parcel &parcel)
return false;
}
}
isKeepAlive = parcel.ReadBool();
return true;
}