mirror of
https://gitee.com/openharmony/ability_ability_runtime
synced 2024-11-27 09:21:28 +00:00
restartApp supports multi-instance
Signed-off-by: yuwenze <yuwenze1@huawei.com> Change-Id: I0c86a42d316a68fd7a57b4c511c8c856b0a8867f
This commit is contained in:
parent
d459fff78c
commit
c7b200fd90
@ -730,10 +730,11 @@ public:
|
||||
/**
|
||||
* @brief mark a process which is going restart.
|
||||
* @param uid the uid of the process.
|
||||
* @param instanceKey the instance key of the process.
|
||||
*
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
virtual int32_t SignRestartAppFlag(int32_t uid)
|
||||
virtual int32_t SignRestartAppFlag(int32_t uid, const std::string &instanceKey)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@ -855,13 +856,8 @@ public:
|
||||
*/
|
||||
virtual int32_t GetSupportedProcessCachePids(const std::string &bundleName, std::vector<int32_t> &pidList) = 0;
|
||||
|
||||
/**
|
||||
* Get appIndex of pid.
|
||||
* @param pid The pid.
|
||||
* @param appIndex appIndex of pid.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
virtual int32_t GetAppIndexByPid(pid_t pid, int32_t &appIndex)
|
||||
virtual int32_t KillAppSelfWithInstanceKey(const std::string &instanceKey, bool clearPageStack,
|
||||
const std::string& reason)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ enum class AppMgrInterfaceCode {
|
||||
CHECK_IS_KIA_PROCESS = 91,
|
||||
GET_All_RUNNING_INSTANCE_KEYS_BY_BUNDLENAME = 92,
|
||||
GET_All_RUNNING_INSTANCE_KEYS_BY_SELF = 93,
|
||||
GET_APP_INDEX_BY_PID = 94,
|
||||
KILL_APP_SELF_WITH_INSTANCE_KEY = 94,
|
||||
};
|
||||
} // AppExecFwk
|
||||
} // OHOS
|
||||
|
@ -641,10 +641,11 @@ public:
|
||||
/**
|
||||
* @brief mark a process which is going restart.
|
||||
* @param uid the uid of the process.
|
||||
* @param instanceKey the instance key of the process.
|
||||
*
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
int32_t SignRestartAppFlag(int32_t uid) override;
|
||||
int32_t SignRestartAppFlag(int32_t uid, const std::string &instanceKey) override;
|
||||
|
||||
/**
|
||||
* Get appRunningUniqueId by pid.
|
||||
@ -740,7 +741,8 @@ public:
|
||||
virtual int32_t GetSupportedProcessCachePids(const std::string &bundleName,
|
||||
std::vector<int32_t> &pidList) override;
|
||||
|
||||
virtual int32_t GetAppIndexByPid(pid_t pid, int32_t &appIndex) override;
|
||||
virtual int32_t KillAppSelfWithInstanceKey(const std::string &instanceKey, bool clearPageStack,
|
||||
const std::string& reason) override;
|
||||
private:
|
||||
bool SendTransactCmd(AppMgrInterfaceCode code, MessageParcel &data, MessageParcel &reply);
|
||||
bool WriteInterfaceToken(MessageParcel &data);
|
||||
|
@ -158,7 +158,7 @@ private:
|
||||
int32_t HandleNotifyProcessDependedOnWeb(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleKillProcessDependedOnWeb(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleRestartResidentProcessDependedOnWeb(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleGetAppIndexByPid(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleKillAppSelfWithInstanceKey(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t OnRemoteRequestInner(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
|
||||
int32_t OnRemoteRequestInnerFirst(uint32_t code, MessageParcel &data,
|
||||
MessageParcel &reply, MessageOption &option);
|
||||
|
@ -65,6 +65,8 @@ struct RunningProcessInfo : public Parcelable {
|
||||
bool isStrictMode = false;
|
||||
std::int32_t bundleType = 0;
|
||||
std::int32_t appCloneIndex = -1;
|
||||
std::string instanceKey = "";
|
||||
AppExecFwk::MultiAppModeType appMode = AppExecFwk::MultiAppModeType::UNSPECIFIED;
|
||||
|
||||
bool ReadFromParcel(Parcel &parcel);
|
||||
virtual bool Marshalling(Parcel &parcel) const override;
|
||||
|
@ -1750,7 +1750,7 @@ int32_t AppMgrProxy::UpdateRenderState(pid_t renderPid, int32_t state)
|
||||
return reply.ReadInt32();
|
||||
}
|
||||
|
||||
int32_t AppMgrProxy::SignRestartAppFlag(int32_t uid)
|
||||
int32_t AppMgrProxy::SignRestartAppFlag(int32_t uid, const std::string &instanceKey)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::APPMGR, "called");
|
||||
MessageParcel data;
|
||||
@ -1761,6 +1761,7 @@ int32_t AppMgrProxy::SignRestartAppFlag(int32_t uid)
|
||||
return IPC_PROXY_ERR;
|
||||
}
|
||||
PARCEL_UTIL_WRITE_RET_INT(data, Int32, uid);
|
||||
PARCEL_UTIL_WRITE_RET_INT(data, String, instanceKey);
|
||||
|
||||
PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::SIGN_RESTART_APP_FLAG, data, reply, option);
|
||||
return reply.ReadInt32();
|
||||
@ -2073,25 +2074,22 @@ int32_t AppMgrProxy::CheckIsKiaProcess(pid_t pid, bool &isKia)
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int32_t AppMgrProxy::GetAppIndexByPid(pid_t pid, int32_t &appIndex)
|
||||
int32_t AppMgrProxy::KillAppSelfWithInstanceKey(const std::string &instanceKey, bool clearPageStack,
|
||||
const std::string& reason)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
if (!WriteInterfaceToken(data)) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
PARCEL_UTIL_WRITE_RET_INT(data, Int32, pid);
|
||||
PARCEL_UTIL_WRITE_RET_INT(data, String, instanceKey);
|
||||
PARCEL_UTIL_WRITE_RET_INT(data, Bool, clearPageStack);
|
||||
PARCEL_UTIL_WRITE_RET_INT(data, String, reason);
|
||||
|
||||
PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::GET_APP_INDEX_BY_PID, data, reply, option);
|
||||
int32_t ret = reply.ReadInt32();
|
||||
if (ret != ERR_OK) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "failed,ret=%{public}d.", ret);
|
||||
return ret;
|
||||
}
|
||||
appIndex = reply.ReadInt32();
|
||||
return ERR_OK;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::KILL_APP_SELF_WITH_INSTANCE_KEY, data, reply, option);
|
||||
return reply.ReadInt32();
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
@ -345,8 +345,8 @@ int32_t AppMgrStub::OnRemoteRequestInnerSeventh(uint32_t code, MessageParcel &da
|
||||
return HandleRegisterKiaInterceptor(data, reply);
|
||||
case static_cast<uint32_t>(AppMgrInterfaceCode::CHECK_IS_KIA_PROCESS):
|
||||
return HandleCheckIsKiaProcess(data, reply);
|
||||
case static_cast<uint32_t>(AppMgrInterfaceCode::GET_APP_INDEX_BY_PID):
|
||||
return HandleGetAppIndexByPid(data, reply);
|
||||
case static_cast<uint32_t>(AppMgrInterfaceCode::KILL_APP_SELF_WITH_INSTANCE_KEY):
|
||||
return HandleKillAppSelfWithInstanceKey(data, reply);
|
||||
}
|
||||
return INVALID_FD;
|
||||
}
|
||||
@ -1468,7 +1468,8 @@ int32_t AppMgrStub::HandleSignRestartAppFlag(MessageParcel &data, MessageParcel
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::APPMGR, "called");
|
||||
auto uid = data.ReadInt32();
|
||||
auto ret = SignRestartAppFlag(uid);
|
||||
auto instanceKey = data.ReadString();
|
||||
auto ret = SignRestartAppFlag(uid, instanceKey);
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "Write ret error.");
|
||||
return IPC_STUB_ERR;
|
||||
@ -1691,19 +1692,16 @@ int32_t AppMgrStub::HandleCheckIsKiaProcess(MessageParcel &data, MessageParcel &
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
int32_t AppMgrStub::HandleGetAppIndexByPid(MessageParcel &data, MessageParcel &reply)
|
||||
int32_t AppMgrStub::HandleKillAppSelfWithInstanceKey(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::APPMGR, "call");
|
||||
auto pid = data.ReadInt32();
|
||||
int32_t appIndex = -1;
|
||||
int32_t result = GetAppIndexByPid(pid, appIndex);
|
||||
auto instanceKey = data.ReadString();
|
||||
auto clearPageStack = data.ReadBool();
|
||||
auto reason = data.ReadString();
|
||||
auto result = KillAppSelfWithInstanceKey(instanceKey, clearPageStack, reason);
|
||||
if (!reply.WriteInt32(result)) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "fail to write GetAppIndexByPid result.");
|
||||
return IPC_STUB_ERR;
|
||||
}
|
||||
if (!reply.WriteInt32(appIndex)) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "fail to write appIndex.");
|
||||
return IPC_STUB_ERR;
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "fail to write result.");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
@ -61,6 +61,10 @@ bool RunningProcessInfo::ReadFromParcel(Parcel &parcel)
|
||||
READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, extensionType);
|
||||
extensionType_ = static_cast<ExtensionAbilityType>(extensionType);
|
||||
appCloneIndex = parcel.ReadInt32();
|
||||
instanceKey = Str16ToStr8(parcel.ReadString16());
|
||||
int32_t appModeType;
|
||||
READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, appModeType);
|
||||
appMode = static_cast<AppExecFwk::MultiAppModeType>(appModeType);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -95,6 +99,8 @@ bool RunningProcessInfo::Marshalling(Parcel &parcel) const
|
||||
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(processType_));
|
||||
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(extensionType_));
|
||||
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, appCloneIndex);
|
||||
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(instanceKey));
|
||||
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(appMode));
|
||||
return true;
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
|
@ -102,8 +102,9 @@ public:
|
||||
/**
|
||||
* Sign the restart flag by uid of ability from ability cache manager.
|
||||
* @param uid the ability uid to be searched in cache manager.
|
||||
* @param instanceKey the instance key of the process.
|
||||
*/
|
||||
void SignRestartAppFlag(int32_t uid);
|
||||
void SignRestartAppFlag(int32_t uid, const std::string &instanceKey);
|
||||
|
||||
/**
|
||||
* Delete the invalid ability by bundleName from ability cache manager.
|
||||
|
@ -325,7 +325,7 @@ public:
|
||||
|
||||
void CloseAssertDialog(const std::string &assertSessionId);
|
||||
|
||||
void SignRestartAppFlag(int32_t uid);
|
||||
void SignRestartAppFlag(int32_t uid, const std::string &instanceKey);
|
||||
|
||||
std::shared_ptr<AAFwk::AbilityRecord> GetUIExtensionRootHostInfo(const sptr<IRemoteObject> token);
|
||||
void UninstallApp(const std::string &bundleName);
|
||||
|
@ -2255,8 +2255,9 @@ private:
|
||||
|
||||
void WaitBootAnimationStart();
|
||||
|
||||
int32_t SignRestartAppFlag(int32_t userId, int32_t uid, bool isAppRecovery = false);
|
||||
int32_t CheckRestartAppWant(const AAFwk::Want &want, int32_t appIndex);
|
||||
int32_t SignRestartAppFlag(int32_t userId, int32_t uid, const std::string &instanceKey,
|
||||
AppExecFwk::MultiAppModeType type, bool isAppRecovery = false);
|
||||
int32_t CheckRestartAppWant(const AAFwk::Want &want, int32_t appIndex, int32_t userId);
|
||||
|
||||
int StartUIAbilityForOptionWrap(const Want &want, const StartOptions &options, sptr<IRemoteObject> callerToken,
|
||||
bool isPendingWantCaller, int32_t userId, int requestCode, uint32_t callerTokenId = 0, bool isImplicit = false,
|
||||
|
@ -222,7 +222,7 @@ public:
|
||||
int32_t GetMissionCount() const;
|
||||
void GetActiveAbilityList(int32_t uid, std::vector<std::string> &abilityList, int32_t pid = NO_PID);
|
||||
|
||||
void SignRestartAppFlag(int32_t uid);
|
||||
void SignRestartAppFlag(int32_t uid, const std::string &instanceKey);
|
||||
|
||||
private:
|
||||
std::string GetTypeName();
|
||||
|
@ -365,7 +365,7 @@ public:
|
||||
|
||||
bool IsAbilityStarted(AbilityRequest &abilityRequest, std::shared_ptr<AbilityRecord> &targetRecord) override;
|
||||
|
||||
void SignRestartAppFlag(int32_t uid) override;
|
||||
void SignRestartAppFlag(int32_t uid, const std::string &instanceKey) override;
|
||||
|
||||
void SetAnimationFlag(bool IsAnimationEnabled);
|
||||
#ifdef SUPPORT_SCREEN
|
||||
|
@ -113,7 +113,7 @@ public:
|
||||
const AAFwk::ContinueState &state) = 0;
|
||||
|
||||
virtual bool IsAbilityStarted(AbilityRequest &abilityRequest, std::shared_ptr<AbilityRecord> &targetRecord) = 0;
|
||||
virtual void SignRestartAppFlag(int32_t uid) = 0;
|
||||
virtual void SignRestartAppFlag(int32_t uid, const std::string &instanceKey) = 0;
|
||||
#ifdef SUPPORT_SCREEN
|
||||
public:
|
||||
virtual int SetMissionLabel(const sptr<IRemoteObject> &abilityToken, const std::string &label) = 0;
|
||||
|
@ -24,25 +24,47 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace AAFwk {
|
||||
typedef struct RestartAppKey {
|
||||
int32_t uid = 0;
|
||||
std::string instanceKey = "";
|
||||
|
||||
RestartAppKey(std::string callingInstanceKey, int32_t callingUid)
|
||||
{
|
||||
instanceKey = callingInstanceKey;
|
||||
uid = callingUid;
|
||||
}
|
||||
bool operator ==(const struct RestartAppKey &other) const
|
||||
{
|
||||
return instanceKey == other.instanceKey && uid == other.uid;
|
||||
}
|
||||
} RestartAppKeyType;
|
||||
|
||||
struct RestartAppKeyHash {
|
||||
size_t operator()(const RestartAppKeyType &p) const
|
||||
{
|
||||
return std::hash<std::string>()(p.instanceKey) ^ std::hash<int>()(p.uid);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @class RestartAppManager
|
||||
* RestartAppManager provides a facility for managing restart app history.
|
||||
*/
|
||||
class RestartAppManager {
|
||||
public:
|
||||
using RestartAppMapType = std::unordered_map<RestartAppKeyType, time_t, RestartAppKeyHash>;
|
||||
virtual ~RestartAppManager() = default;
|
||||
static RestartAppManager &GetInstance();
|
||||
|
||||
bool IsRestartAppFrequent(int32_t uid, time_t time);
|
||||
void AddRestartAppHistory(int32_t uid, time_t time);
|
||||
bool IsForegroundToRestartApp() const;
|
||||
bool IsRestartAppFrequent(const RestartAppKeyType &key, time_t time);
|
||||
void AddRestartAppHistory(const RestartAppKeyType &key, time_t time);
|
||||
|
||||
private:
|
||||
RestartAppManager() = default;
|
||||
DISALLOW_COPY_AND_MOVE(RestartAppManager);
|
||||
|
||||
ffrt::mutex restartAppMapLock_;
|
||||
std::unordered_map<int32_t, time_t> restartAppHistory_; // RestartAppKey:time
|
||||
RestartAppMapType restartAppHistory_; // RestartAppKey:time
|
||||
};
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
|
@ -56,7 +56,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
void SignRestartAppFlag(int32_t uid, bool isAppRecovery = false);
|
||||
void SignRestartAppFlag(int32_t uid, const std::string &instanceKey, bool isAppRecovery = false);
|
||||
|
||||
/**
|
||||
* StartUIAbility with request.
|
||||
|
@ -54,14 +54,6 @@ public:
|
||||
* @return Flag if the want contains atomic service url.
|
||||
*/
|
||||
static bool IsAtomicServiceUrl(const Want& want);
|
||||
|
||||
/**
|
||||
* Get app index.
|
||||
*
|
||||
* @param want The want.
|
||||
* @return AppIndex if the want contains app index.
|
||||
*/
|
||||
static int32_t GetAppIndex(const Want& want);
|
||||
};
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
|
@ -284,13 +284,14 @@ void AbilityCacheManager::RemoveLauncherDeathRecipient()
|
||||
}
|
||||
}
|
||||
|
||||
void AbilityCacheManager::SignRestartAppFlag(int32_t uid)
|
||||
void AbilityCacheManager::SignRestartAppFlag(int32_t uid, const std::string &instanceKey)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
auto it = devRecLru_.begin();
|
||||
while (it != devRecLru_.end()) {
|
||||
auto abilityRecord = *it;
|
||||
if (abilityRecord != nullptr && abilityRecord->GetUid() == uid) {
|
||||
if (abilityRecord != nullptr && abilityRecord->GetUid() == uid &&
|
||||
abilityRecord->GetInstanceKey() == instanceKey) {
|
||||
abilityRecord->SetRestartAppFlag(true);
|
||||
}
|
||||
it++;
|
||||
|
@ -3116,18 +3116,19 @@ int32_t AbilityConnectManager::GetUIExtensionSessionInfo(const sptr<IRemoteObjec
|
||||
return uiExtensionAbilityRecordMgr_->GetUIExtensionSessionInfo(token, uiExtensionSessionInfo);
|
||||
}
|
||||
|
||||
void AbilityConnectManager::SignRestartAppFlag(int32_t uid)
|
||||
void AbilityConnectManager::SignRestartAppFlag(int32_t uid, const std::string &instanceKey)
|
||||
{
|
||||
{
|
||||
std::lock_guard lock(serviceMapMutex_);
|
||||
for (auto &[key, abilityRecord] : serviceMap_) {
|
||||
if (abilityRecord == nullptr || abilityRecord->GetUid() != uid) {
|
||||
if (abilityRecord == nullptr || abilityRecord->GetUid() != uid ||
|
||||
abilityRecord->GetInstanceKey() != instanceKey) {
|
||||
continue;
|
||||
}
|
||||
abilityRecord->SetRestartAppFlag(true);
|
||||
}
|
||||
}
|
||||
AbilityCacheManager::GetInstance().SignRestartAppFlag(uid);
|
||||
AbilityCacheManager::GetInstance().SignRestartAppFlag(uid, instanceKey);
|
||||
}
|
||||
|
||||
bool AbilityConnectManager::AddToServiceMap(const std::string &key, std::shared_ptr<AbilityRecord> abilityRecord)
|
||||
|
@ -11252,55 +11252,50 @@ int32_t AbilityManagerService::GetUIExtensionSessionInfo(const sptr<IRemoteObjec
|
||||
int32_t AbilityManagerService::RestartApp(const AAFwk::Want &want, bool isAppRecovery)
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::ABILITYMGR, "RestartApp, isAppRecovery: %{public}d", isAppRecovery);
|
||||
auto appIndex = WantUtils::GetAppIndex(want);
|
||||
int result = CheckRestartAppWant(want, appIndex);
|
||||
auto callerPid = IPCSkeleton::GetCallingPid();
|
||||
AppExecFwk::RunningProcessInfo processInfo;
|
||||
DelayedSingleton<AppScheduler>::GetInstance()->GetRunningProcessInfoByPid(callerPid, processInfo);
|
||||
int32_t callerUid = IPCSkeleton::GetCallingUid();
|
||||
int32_t userId = callerUid / BASE_USER_RANGE;
|
||||
auto result = CheckRestartAppWant(want, processInfo.appCloneIndex, userId);
|
||||
if (result != ERR_OK) {
|
||||
TAG_LOGE(AAFwkTag::ABILITYMGR, "checkRestartAppWant error");
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t callerUid = IPCSkeleton::GetCallingUid();
|
||||
int64_t now = time(nullptr);
|
||||
if (!isAppRecovery && RestartAppManager::GetInstance().IsRestartAppFrequent(callerUid, now)) {
|
||||
return AAFwk::ERR_RESTART_APP_FREQUENT;
|
||||
}
|
||||
|
||||
bool isForegroundToRestartApp = RestartAppManager::GetInstance().IsForegroundToRestartApp();
|
||||
if (!isForegroundToRestartApp) {
|
||||
TAG_LOGE(AAFwkTag::ABILITYMGR, "restartApp, isForegroundToRestartApp failed");
|
||||
if (!processInfo.isFocused && !processInfo.isAbilityForegrounding) {
|
||||
TAG_LOGE(AAFwkTag::ABILITYMGR, "restartApp, is not foreground");
|
||||
return AAFwk::NOT_TOP_ABILITY;
|
||||
}
|
||||
|
||||
int32_t userId = IPCSkeleton::GetCallingUid() / BASE_USER_RANGE;
|
||||
result = SignRestartAppFlag(userId, callerUid, isAppRecovery);
|
||||
RestartAppKeyType key(processInfo.instanceKey, callerUid);
|
||||
int64_t now = time(nullptr);
|
||||
if (!isAppRecovery && RestartAppManager::GetInstance().IsRestartAppFrequent(key, now)) {
|
||||
return AAFwk::ERR_RESTART_APP_FREQUENT;
|
||||
}
|
||||
|
||||
result = SignRestartAppFlag(userId, callerUid, processInfo.instanceKey, processInfo.appMode, isAppRecovery);
|
||||
if (result != ERR_OK) {
|
||||
TAG_LOGE(AAFwkTag::ABILITYMGR, "signRestartAppFlag error");
|
||||
return result;
|
||||
}
|
||||
result = DelayedSingleton<AppExecFwk::AppMgrClient>::GetInstance()->KillApplicationSelf(false, "RestartApp");
|
||||
if (result != ERR_OK) {
|
||||
TAG_LOGE(AAFwkTag::ABILITYMGR, "killApplicationSelf error");
|
||||
return result;
|
||||
}
|
||||
|
||||
TAG_LOGD(AAFwkTag::ABILITYMGR, "restartApp, without checkCallAbilityPermission.");
|
||||
(const_cast<Want &>(want)).SetParam(AAFwk::Want::PARAM_APP_CLONE_INDEX_KEY, appIndex);
|
||||
result = StartAbilityWrap(want, nullptr,
|
||||
DEFAULT_INVAL_VALUE, false, DEFAULT_INVAL_VALUE, false, 0, isForegroundToRestartApp);
|
||||
(const_cast<Want &>(want)).SetParam(AAFwk::Want::PARAM_APP_CLONE_INDEX_KEY, processInfo.appCloneIndex);
|
||||
(const_cast<Want &>(want)).SetParam(AAFwk::Want::APP_INSTANCE_KEY, processInfo.instanceKey);
|
||||
(const_cast<Want &>(want)).RemoveParam(Want::CREATE_APP_INSTANCE_KEY);
|
||||
result = StartAbilityWrap(want, nullptr, DEFAULT_INVAL_VALUE, false, DEFAULT_INVAL_VALUE, false, 0, true);
|
||||
if (result != ERR_OK) {
|
||||
TAG_LOGE(AAFwkTag::ABILITYMGR, "startAbility error");
|
||||
return result;
|
||||
}
|
||||
if (!isAppRecovery) {
|
||||
RestartAppManager::GetInstance().AddRestartAppHistory(callerUid, now);
|
||||
RestartAppManager::GetInstance().AddRestartAppHistory(key, now);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t AbilityManagerService::CheckRestartAppWant(const AAFwk::Want &want, int32_t appIndex)
|
||||
int32_t AbilityManagerService::CheckRestartAppWant(const AAFwk::Want &want, int32_t appIndex, int32_t userId)
|
||||
{
|
||||
std::string bundleName = want.GetElement().GetBundleName();
|
||||
auto userId = IPCSkeleton::GetCallingUid() / BASE_USER_RANGE;
|
||||
if (!CheckCallingTokenId(bundleName, userId, appIndex)) {
|
||||
TAG_LOGE(AAFwkTag::ABILITYMGR, "no itself called, no allowed");
|
||||
return AAFwk::ERR_RESTART_APP_INCORRECT_ABILITY;
|
||||
@ -11320,34 +11315,40 @@ int32_t AbilityManagerService::CheckRestartAppWant(const AAFwk::Want &want, int3
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int32_t AbilityManagerService::SignRestartAppFlag(int32_t userId, int32_t uid, bool isAppRecovery)
|
||||
int32_t AbilityManagerService::SignRestartAppFlag(int32_t userId, int32_t uid, const std::string &instanceKey,
|
||||
AppExecFwk::MultiAppModeType type, bool isAppRecovery)
|
||||
{
|
||||
auto appMgr = AppMgrUtil::GetAppMgr();
|
||||
if (appMgr == nullptr) {
|
||||
TAG_LOGW(AAFwkTag::ABILITYMGR, "AppMgrUtil::GetAppMgr failed");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
auto ret = IN_PROCESS_CALL(appMgr->SignRestartAppFlag(uid));
|
||||
auto ret = IN_PROCESS_CALL(appMgr->SignRestartAppFlag(uid, instanceKey));
|
||||
if (ret != ERR_OK) {
|
||||
TAG_LOGE(AAFwkTag::ABILITYMGR, "appMgr signRestartAppFlag error");
|
||||
return ret;
|
||||
}
|
||||
|
||||
auto connectManager = GetConnectManagerByUserId(userId);
|
||||
connectManager->SignRestartAppFlag(uid);
|
||||
connectManager->SignRestartAppFlag(uid, instanceKey);
|
||||
if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
|
||||
auto uiAbilityManager = GetUIAbilityManagerByUserId(userId);
|
||||
CHECK_POINTER_AND_RETURN(uiAbilityManager, ERR_INVALID_VALUE);
|
||||
uiAbilityManager->SignRestartAppFlag(uid, isAppRecovery);
|
||||
return ERR_OK;
|
||||
}
|
||||
uiAbilityManager->SignRestartAppFlag(uid, instanceKey, isAppRecovery);
|
||||
} else {
|
||||
auto missionListManager = GetMissionListManagerByUserId(userId);
|
||||
if (missionListManager == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::ABILITYMGR, "missionListManager null userId:%{public}d", userId);
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
missionListManager->SignRestartAppFlag(uid);
|
||||
return ERR_OK;
|
||||
missionListManager->SignRestartAppFlag(uid, instanceKey);
|
||||
}
|
||||
|
||||
if (type == AppExecFwk::MultiAppModeType::MULTI_INSTANCE) {
|
||||
return appMgr->KillAppSelfWithInstanceKey(instanceKey, false, "RestartInstance");
|
||||
} else {
|
||||
return DelayedSingleton<AppExecFwk::AppMgrClient>::GetInstance()->KillApplicationSelf(false, "RestartApp");
|
||||
}
|
||||
}
|
||||
|
||||
bool AbilityManagerService::IsEmbeddedOpenAllowed(sptr<IRemoteObject> callerToken, const std::string &appId)
|
||||
|
@ -468,7 +468,7 @@ void MissionList::GetActiveAbilityList(int32_t uid, std::vector<std::string> &ab
|
||||
}
|
||||
}
|
||||
|
||||
void MissionList::SignRestartAppFlag(int32_t uid)
|
||||
void MissionList::SignRestartAppFlag(int32_t uid, const std::string &instanceKey)
|
||||
{
|
||||
for (auto it = missions_.begin(); it != missions_.end();) {
|
||||
auto mission = *it;
|
||||
@ -485,6 +485,10 @@ void MissionList::SignRestartAppFlag(int32_t uid)
|
||||
it++;
|
||||
continue;
|
||||
}
|
||||
if (abilityRecord->GetInstanceKey() != instanceKey) {
|
||||
it++;
|
||||
continue;
|
||||
}
|
||||
abilityRecord->SetRestartAppFlag(true);
|
||||
it = missions_.erase(it);
|
||||
}
|
||||
|
@ -4272,20 +4272,20 @@ void MissionListManager::SendKeyEvent(const AbilityRequest &abilityRequest)
|
||||
EventReport::SendKeyEvent(EventName::START_PRIVATE_ABILITY, HiSysEventType::BEHAVIOR, eventInfo);
|
||||
}
|
||||
|
||||
void MissionListManager::SignRestartAppFlag(int32_t uid)
|
||||
void MissionListManager::SignRestartAppFlag(int32_t uid, const std::string &instanceKey)
|
||||
{
|
||||
std::lock_guard guard(managerLock_);
|
||||
for (const auto& missionList : currentMissionLists_) {
|
||||
if (!missionList) {
|
||||
continue;
|
||||
}
|
||||
missionList->SignRestartAppFlag(uid);
|
||||
missionList->SignRestartAppFlag(uid, instanceKey);
|
||||
}
|
||||
if (defaultStandardList_) {
|
||||
defaultStandardList_->SignRestartAppFlag(uid);
|
||||
defaultStandardList_->SignRestartAppFlag(uid, instanceKey);
|
||||
}
|
||||
if (defaultSingleList_) {
|
||||
defaultSingleList_->SignRestartAppFlag(uid);
|
||||
defaultSingleList_->SignRestartAppFlag(uid, instanceKey);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,11 +28,11 @@ RestartAppManager &RestartAppManager::GetInstance()
|
||||
return instance;
|
||||
}
|
||||
|
||||
bool RestartAppManager::IsRestartAppFrequent(int32_t uid, time_t time)
|
||||
bool RestartAppManager::IsRestartAppFrequent(const RestartAppKeyType &key, time_t time)
|
||||
{
|
||||
std::lock_guard<ffrt::mutex> lock(restartAppMapLock_);
|
||||
constexpr int64_t MIN_RESTART_TIME = 10;
|
||||
auto it = restartAppHistory_.find(uid);
|
||||
auto it = restartAppHistory_.find(key);
|
||||
if ((it != restartAppHistory_.end()) && (it->second + MIN_RESTART_TIME > time)) {
|
||||
TAG_LOGE(AAFwkTag::ABILITYMGR, "restart too frequently. try again at least 10s later");
|
||||
return true;
|
||||
@ -40,24 +40,11 @@ bool RestartAppManager::IsRestartAppFrequent(int32_t uid, time_t time)
|
||||
return false;
|
||||
}
|
||||
|
||||
void RestartAppManager::AddRestartAppHistory(int32_t uid, time_t time)
|
||||
void RestartAppManager::AddRestartAppHistory(const RestartAppKeyType &key, time_t time)
|
||||
{
|
||||
std::lock_guard<ffrt::mutex> lock(restartAppMapLock_);
|
||||
TAG_LOGD(AAFwkTag::ABILITYMGR, "Refresh history, uid=%{public}d", uid);
|
||||
restartAppHistory_[uid] = time;
|
||||
}
|
||||
|
||||
bool RestartAppManager::IsForegroundToRestartApp() const
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
|
||||
auto callerPid = IPCSkeleton::GetCallingPid();
|
||||
AppExecFwk::RunningProcessInfo processInfo;
|
||||
DelayedSingleton<AppScheduler>::GetInstance()->GetRunningProcessInfoByPid(callerPid, processInfo);
|
||||
if (processInfo.isFocused || processInfo.isAbilityForegrounding) {
|
||||
return true;
|
||||
}
|
||||
TAG_LOGE(AAFwkTag::ABILITYMGR, "IsForegroundToRestartApp, state not foreground");
|
||||
return false;
|
||||
TAG_LOGD(AAFwkTag::ABILITYMGR, "Refresh uid=%{public}d, instanceKey:%{public}s", key.uid, key.instanceKey.c_str());
|
||||
restartAppHistory_[key] = time;
|
||||
}
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
|
@ -2652,12 +2652,13 @@ int32_t UIAbilityLifecycleManager::UpdateSessionInfoBySCB(std::list<SessionInfo>
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
void UIAbilityLifecycleManager::SignRestartAppFlag(int32_t uid, bool isAppRecovery)
|
||||
void UIAbilityLifecycleManager::SignRestartAppFlag(int32_t uid, const std::string &instanceKey, bool isAppRecovery)
|
||||
{
|
||||
std::lock_guard<ffrt::mutex> guard(sessionLock_);
|
||||
auto tempSessionAbilityMap = sessionAbilityMap_;
|
||||
for (auto &[sessionId, abilityRecord] : tempSessionAbilityMap) {
|
||||
if (abilityRecord == nullptr || abilityRecord->GetUid() != uid) {
|
||||
if (abilityRecord == nullptr || abilityRecord->GetUid() != uid ||
|
||||
abilityRecord->GetInstanceKey() != instanceKey) {
|
||||
continue;
|
||||
}
|
||||
abilityRecord->SetRestartAppFlag(true);
|
||||
|
@ -81,23 +81,5 @@ bool WantUtils::IsAtomicServiceUrl(const Want& want)
|
||||
}
|
||||
return isAtomicServiceShortUrl;
|
||||
}
|
||||
|
||||
int32_t WantUtils::GetAppIndex(const Want& want)
|
||||
{
|
||||
int32_t appIndex = want.GetIntParam(AAFwk::Want::PARAM_APP_CLONE_INDEX_KEY, -1);
|
||||
if (appIndex == -1) {
|
||||
auto appMgr = AppMgrUtil::GetAppMgr();
|
||||
if (appMgr == nullptr) {
|
||||
TAG_LOGW(AAFwkTag::ABILITYMGR, "AppMgrUtil::GetAppMgr failed");
|
||||
return appIndex;
|
||||
}
|
||||
auto callingPid = IPCSkeleton::GetCallingPid();
|
||||
auto ret = IN_PROCESS_CALL(appMgr->GetAppIndexByPid(callingPid, appIndex));
|
||||
if (ret != ERR_OK) {
|
||||
TAG_LOGE(AAFwkTag::ABILITYMGR, "appMgr GetAppIndexByPid error");
|
||||
}
|
||||
}
|
||||
return appIndex;
|
||||
}
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
|
@ -683,10 +683,11 @@ public:
|
||||
/**
|
||||
* @brief mark a process which is going restart.
|
||||
* @param uid the uid of the process.
|
||||
* @param instanceKey the instance key of the process.
|
||||
*
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
int32_t SignRestartAppFlag(int32_t uid) override;
|
||||
int32_t SignRestartAppFlag(int32_t uid, const std::string &instanceKey) override;
|
||||
|
||||
/**
|
||||
* Get appRunningUniqueId by pid.
|
||||
@ -772,7 +773,8 @@ public:
|
||||
*/
|
||||
virtual void RestartResidentProcessDependedOnWeb() override;
|
||||
|
||||
int32_t GetAppIndexByPid(pid_t pid, int32_t &appIndex) override;
|
||||
virtual int32_t KillAppSelfWithInstanceKey(const std::string &instanceKey, bool clearPageStack,
|
||||
const std::string& reason) override;
|
||||
private:
|
||||
/**
|
||||
* Init, Initialize application services.
|
||||
|
@ -314,6 +314,8 @@ public:
|
||||
virtual int32_t KillApplicationSelf(const bool clearPageStack = false,
|
||||
const std::string& reason = "KillApplicationSelf");
|
||||
|
||||
int32_t KillAppSelfWithInstanceKey(const std::string &instanceKey, bool clearPageStack, const std::string& reason);
|
||||
|
||||
/**
|
||||
* KillApplicationByUserId, kill the application by user ID.
|
||||
*
|
||||
@ -1237,9 +1239,7 @@ public:
|
||||
/**
|
||||
* Mark processes of the uid as the app is going to be restarted.
|
||||
*/
|
||||
int32_t SignRestartAppFlag(int32_t uid);
|
||||
|
||||
int32_t GetAppIndexByPid(pid_t pid, int32_t &appIndex) const;
|
||||
int32_t SignRestartAppFlag(int32_t uid, const std::string &instanceKey);
|
||||
|
||||
/**
|
||||
* Set application assertion pause state.
|
||||
|
@ -255,6 +255,8 @@ public:
|
||||
|
||||
bool ProcessExitByBundleNameAndUid(
|
||||
const std::string &bundleName, const int uid, std::list<pid_t> &pids, const bool clearPageStack = false);
|
||||
bool ProcessExitByTokenIdAndInstance(uint32_t accessTokenId, const std::string &instanceKey, std::list<pid_t> &pids,
|
||||
bool clearPageStack);
|
||||
bool GetPidsByUserId(int32_t userId, std::list<pid_t> &pids);
|
||||
|
||||
void PrepareTerminate(const sptr<IRemoteObject> &token, bool clearMissionFlag = false);
|
||||
@ -312,7 +314,7 @@ public:
|
||||
*/
|
||||
int32_t GetAllAppRunningRecordCountByBundleName(const std::string &bundleName);
|
||||
|
||||
int32_t SignRestartAppFlag(int32_t uid);
|
||||
int32_t SignRestartAppFlag(int32_t uid, const std::string &instanceKey);
|
||||
|
||||
int32_t GetAppRunningUniqueIdByPid(pid_t pid, std::string &appRunningUniqueId);
|
||||
|
||||
|
@ -1474,7 +1474,7 @@ int32_t AppMgrService::UpdateRenderState(pid_t renderPid, int32_t state)
|
||||
return appMgrServiceInner_->UpdateRenderState(renderPid, state);
|
||||
}
|
||||
|
||||
int32_t AppMgrService::SignRestartAppFlag(int32_t uid)
|
||||
int32_t AppMgrService::SignRestartAppFlag(int32_t uid, const std::string &instanceKey)
|
||||
{
|
||||
if (!IsReady()) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "not ready");
|
||||
@ -1486,7 +1486,7 @@ int32_t AppMgrService::SignRestartAppFlag(int32_t uid)
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "verification failed");
|
||||
return ERR_PERMISSION_DENIED;
|
||||
}
|
||||
return appMgrServiceInner_->SignRestartAppFlag(uid);
|
||||
return appMgrServiceInner_->SignRestartAppFlag(uid, instanceKey);
|
||||
}
|
||||
|
||||
int32_t AppMgrService::GetAppRunningUniqueIdByPid(pid_t pid, std::string &appRunningUniqueId)
|
||||
@ -1667,19 +1667,14 @@ int32_t AppMgrService::CheckIsKiaProcess(pid_t pid, bool &isKia)
|
||||
return appMgrServiceInner_->CheckIsKiaProcess(pid, isKia);
|
||||
}
|
||||
|
||||
int32_t AppMgrService::GetAppIndexByPid(pid_t pid, int32_t &appIndex)
|
||||
int32_t AppMgrService::KillAppSelfWithInstanceKey(const std::string &instanceKey, bool clearPageStack,
|
||||
const std::string& reason)
|
||||
{
|
||||
bool isCallingPermission =
|
||||
AAFwk::PermissionVerification::GetInstance()->CheckSpecificSystemAbilityAccessPermission(FOUNDATION_PROCESS);
|
||||
if (!isCallingPermission) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "verification failed");
|
||||
return ERR_PERMISSION_DENIED;
|
||||
}
|
||||
if (!appMgrServiceInner_) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "appMgrServiceInner_ is nullptr");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
return appMgrServiceInner_->GetAppIndexByPid(pid, appIndex);
|
||||
return appMgrServiceInner_->KillAppSelfWithInstanceKey(instanceKey, clearPageStack, reason);
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
@ -1584,15 +1584,47 @@ int32_t AppMgrServiceInner::KillApplicationSelf(const bool clearPageStack, const
|
||||
TAG_LOGI(AAFwkTag::APPMGR, "remote process exited successs");
|
||||
return ERR_OK;
|
||||
}
|
||||
int32_t result = ERR_OK;
|
||||
for (auto iter = pids.begin(); iter != pids.end(); ++iter) {
|
||||
auto result = KillProcessByPid(*iter, reason);
|
||||
if (result < 0) {
|
||||
auto singleRet = KillProcessByPid(*iter, reason);
|
||||
if (singleRet < 0) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "killApplication fail for bundleName:%{public}s pid:%{public}d",
|
||||
bundleName.c_str(), *iter);
|
||||
result = singleRet;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t AppMgrServiceInner::KillAppSelfWithInstanceKey(const std::string &instanceKey, bool clearPageStack,
|
||||
const std::string& reason)
|
||||
{
|
||||
if (!appRunningManager_) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "appRunningManager_ null");
|
||||
return ERR_NO_INIT;
|
||||
}
|
||||
}
|
||||
|
||||
int64_t startTime = SystemTimeMillisecond();
|
||||
auto callingTokenId = IPCSkeleton::GetCallingTokenID();
|
||||
TAG_LOGI(AAFwkTag::APPMGR, "callingTokenId value: %{public}d", callingTokenId);
|
||||
std::list<pid_t> pids;
|
||||
if (!appRunningManager_->ProcessExitByTokenIdAndInstance(callingTokenId, instanceKey, pids, clearPageStack)) {
|
||||
TAG_LOGI(AAFwkTag::APPMGR, "not exist");
|
||||
return ERR_OK;
|
||||
}
|
||||
if (WaitForRemoteProcessExit(pids, startTime)) {
|
||||
TAG_LOGI(AAFwkTag::APPMGR, "remote process exited success");
|
||||
return ERR_OK;
|
||||
}
|
||||
int32_t result = ERR_OK;
|
||||
for (auto iter = pids.begin(); iter != pids.end(); ++iter) {
|
||||
auto singleRet = KillProcessByPid(*iter, reason);
|
||||
if (singleRet < 0) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "Failed to kill pid:%{public}d", *iter);
|
||||
result = singleRet;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t AppMgrServiceInner::KillApplicationByBundleName(
|
||||
@ -7506,25 +7538,14 @@ int32_t AppMgrServiceInner::UpdateRenderState(pid_t renderPid, int32_t state)
|
||||
renderRecord, state);
|
||||
}
|
||||
|
||||
int32_t AppMgrServiceInner::SignRestartAppFlag(int32_t uid)
|
||||
int32_t AppMgrServiceInner::SignRestartAppFlag(int32_t uid, const std::string &instanceKey)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::APPMGR, "call.");
|
||||
if (!appRunningManager_) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "appRunningManager_ null");
|
||||
return ERR_NO_INIT;
|
||||
}
|
||||
return appRunningManager_->SignRestartAppFlag(uid);
|
||||
}
|
||||
|
||||
int32_t AppMgrServiceInner::GetAppIndexByPid(pid_t pid, int32_t &appIndex) const
|
||||
{
|
||||
auto appRecord = GetAppRunningRecordByPid(pid);
|
||||
if (appRecord == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "no appRecord, pid:%{public}d", pid);
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
appIndex = appRecord->GetAppIndex();
|
||||
return ERR_OK;
|
||||
return appRunningManager_->SignRestartAppFlag(uid, instanceKey);
|
||||
}
|
||||
|
||||
int32_t AppMgrServiceInner::GetAppRunningUniqueIdByPid(pid_t pid, std::string &appRunningUniqueId)
|
||||
|
@ -375,6 +375,46 @@ bool AppRunningManager::ProcessExitByBundleNameAndUid(
|
||||
return (pids.empty() ? false : true);
|
||||
}
|
||||
|
||||
bool AppRunningManager::ProcessExitByTokenIdAndInstance(uint32_t accessTokenId, const std::string &instanceKey,
|
||||
std::list<pid_t> &pids, bool clearPageStack)
|
||||
{
|
||||
auto appRunningMap = GetAppRunningRecordMap();
|
||||
for (const auto &item : appRunningMap) {
|
||||
const auto &appRecord = item.second;
|
||||
if (appRecord == nullptr) {
|
||||
continue;
|
||||
}
|
||||
auto appInfo = appRecord->GetApplicationInfo();
|
||||
if (appInfo == nullptr) {
|
||||
continue;
|
||||
}
|
||||
if (appInfo->multiAppMode.multiAppModeType != MultiAppModeType::MULTI_INSTANCE) {
|
||||
TAG_LOGI(AAFwkTag::APPMGR, "not multi-instance");
|
||||
}
|
||||
if (appInfo->accessTokenId != accessTokenId) {
|
||||
continue;
|
||||
}
|
||||
if (appRecord->GetInstanceKey() != instanceKey) {
|
||||
continue;
|
||||
}
|
||||
if (appRecord->GetPriorityObject() == nullptr) {
|
||||
continue;
|
||||
}
|
||||
pid_t pid = appRecord->GetPriorityObject()->GetPid();
|
||||
if (pid <= 0) {
|
||||
continue;
|
||||
}
|
||||
pids.push_back(pid);
|
||||
if (clearPageStack) {
|
||||
appRecord->ScheduleClearPageStack();
|
||||
}
|
||||
appRecord->SetKilling();
|
||||
appRecord->ScheduleProcessSecurityExit();
|
||||
}
|
||||
|
||||
return pids.empty() ? false : true;
|
||||
}
|
||||
|
||||
bool AppRunningManager::GetPidsByBundleNameUserIdAndAppIndex(const std::string &bundleName,
|
||||
const int userId, const int appIndex, std::list<pid_t> &pids)
|
||||
{
|
||||
@ -760,11 +800,10 @@ int32_t AppRunningManager::AssignRunningProcessInfoByAppRecord(
|
||||
auto appInfo = appRecord->GetApplicationInfo();
|
||||
if (appInfo) {
|
||||
info.bundleType = static_cast<int32_t>(appInfo->bundleType);
|
||||
info.appMode = appInfo->multiAppMode.multiAppModeType;
|
||||
}
|
||||
if (appInfo && (static_cast<int32_t>(appInfo->multiAppMode.multiAppModeType) ==
|
||||
static_cast<int32_t>(MultiAppModeType::APP_CLONE))) {
|
||||
info.appCloneIndex = appRecord->GetAppIndex();
|
||||
}
|
||||
info.instanceKey = appRecord->GetInstanceKey();
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
@ -1389,13 +1428,13 @@ std::shared_ptr<ChildProcessRecord> AppRunningManager::OnChildProcessRemoteDied(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int32_t AppRunningManager::SignRestartAppFlag(int32_t uid)
|
||||
int32_t AppRunningManager::SignRestartAppFlag(int32_t uid, const std::string &instanceKey)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::APPMGR, "called");
|
||||
std::lock_guard guard(runningRecordMapMutex_);
|
||||
for (const auto &item : appRunningRecordMap_) {
|
||||
const auto &appRecord = item.second;
|
||||
if (appRecord == nullptr || appRecord->GetUid() != uid) {
|
||||
if (appRecord == nullptr || appRecord->GetUid() != uid || appRecord->GetInstanceKey() != instanceKey) {
|
||||
continue;
|
||||
}
|
||||
TAG_LOGD(AAFwkTag::APPMGR, "sign");
|
||||
|
@ -132,7 +132,7 @@ void DoSomethingInterestingWithMyAPIaddb(const char* data, size_t size)
|
||||
manager->OnChildProcessRemoteDied(remote);
|
||||
manager->GetAllAppRunningRecordCountByBundleName(jsonStr);
|
||||
auto uid = static_cast<int32_t>(GetU32Data(data));
|
||||
manager->SignRestartAppFlag(uid);
|
||||
manager->SignRestartAppFlag(uid, jsonStr);
|
||||
manager->GetAppRunningUniqueIdByPid(pidApps, jsonStr);
|
||||
std::vector<pid_t> hostPids;
|
||||
manager->GetAllUIExtensionRootHostPid(pidApps, hostPids);
|
||||
|
@ -111,7 +111,7 @@ void AbilityCacheManagerFuzztest1(bool boolParam, std::string &stringParam, int3
|
||||
mgr.FindRecordBySessionId(stringParam);
|
||||
mgr.FindRecordByServiceKey(stringParam);
|
||||
mgr.RemoveLauncherDeathRecipient();
|
||||
mgr.SignRestartAppFlag(int32Param);
|
||||
mgr.SignRestartAppFlag(int32Param, stringParam);
|
||||
mgr.DeleteInvalidServiceRecord(stringParam);
|
||||
}
|
||||
|
||||
|
@ -52,11 +52,11 @@ bool DoSomethingInterestingWithMyAPI(const char *data, size_t size)
|
||||
std::shared_ptr<RestartAppManager> restartAppManager = std::make_shared<RestartAppManager>();
|
||||
std::string stringParam(data, size);
|
||||
int32_t uid = static_cast<int32_t>(GetU32Data(data));
|
||||
RestartAppKeyType key(stringParam, uid);
|
||||
time_t currentTime = static_cast<time_t>(GetU32Data(data));
|
||||
restartAppManager-> GetInstance();
|
||||
restartAppManager-> IsRestartAppFrequent(uid, currentTime);
|
||||
restartAppManager-> AddRestartAppHistory(uid, currentTime);
|
||||
restartAppManager-> IsForegroundToRestartApp();
|
||||
restartAppManager->GetInstance();
|
||||
restartAppManager->IsRestartAppFrequent(key, currentTime);
|
||||
restartAppManager->AddRestartAppHistory(key, currentTime);
|
||||
return true;
|
||||
}
|
||||
} // namespace OHOS
|
||||
|
@ -106,7 +106,7 @@ bool DoSomethingInterestingWithMyAPI(const char *data, size_t size)
|
||||
auto uIAbilityLifecycleManager = std::make_shared<UIAbilityLifecycleManager>(userId);
|
||||
std::string strParam(data, size);
|
||||
int32_t uid = static_cast<int32_t>(GetU32Data(data));
|
||||
uIAbilityLifecycleManager->SignRestartAppFlag(uid);
|
||||
uIAbilityLifecycleManager->SignRestartAppFlag(uid, strParam);
|
||||
AbilityRequest abilityRequest;
|
||||
sptr<SessionInfo> sessionInfo;
|
||||
uint32_t sceneFlag = GetU32Data(data);
|
||||
|
@ -624,7 +624,7 @@ HWTEST_F(AbilityCacheManagerTest, AbilityCacheManagerSignRestartAppFlag_001, Tes
|
||||
int recId = abilityRecord_->GetRecordId();
|
||||
std::shared_ptr<AbilityRecord> rec = OHOS::AAFwk::AbilityCacheManager::GetInstance().Put(abilityRecord_);
|
||||
EXPECT_EQ(rec, nullptr);
|
||||
OHOS::AAFwk::AbilityCacheManager::GetInstance().SignRestartAppFlag(applicationInfo.uid);
|
||||
OHOS::AAFwk::AbilityCacheManager::GetInstance().SignRestartAppFlag(applicationInfo.uid, "");
|
||||
AbilityRequest abilityRequest;
|
||||
abilityRequest.abilityInfo = abilityInfo;
|
||||
abilityRequest.appInfo = applicationInfo;
|
||||
|
@ -3246,7 +3246,7 @@ HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_SignRestartAppFlag_001, Test
|
||||
abilityRecord2->abilityInfo_.bundleName = "errTestBundleName";
|
||||
connectManager->serviceMap_.emplace("second", abilityRecord2);
|
||||
int32_t uid = 100;
|
||||
connectManager->SignRestartAppFlag(uid);
|
||||
connectManager->SignRestartAppFlag(uid, "");
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1096,7 +1096,8 @@ HWTEST_F(AbilityManagerServiceThirdTest, CheckRestartAppWant_001, TestSize.Level
|
||||
auto abilityMs = std::make_shared<AbilityManagerService>();
|
||||
EXPECT_NE(abilityMs, nullptr);
|
||||
AAFwk::Want want;
|
||||
int32_t res = abilityMs->CheckRestartAppWant(want, 0);
|
||||
int32_t userId = 100;
|
||||
int32_t res = abilityMs->CheckRestartAppWant(want, 0, userId);
|
||||
EXPECT_EQ(res, AAFwk::ERR_RESTART_APP_INCORRECT_ABILITY);
|
||||
}
|
||||
|
||||
@ -2468,7 +2469,8 @@ HWTEST_F(AbilityManagerServiceThirdTest, SignRestartAppFlag_001, TestSize.Level1
|
||||
auto abilityMs_ = std::make_shared<AbilityManagerService>();
|
||||
EXPECT_NE(abilityMs_, nullptr);
|
||||
|
||||
abilityMs_->SignRestartAppFlag(USER_ID_U100, 1);
|
||||
int32_t uid = 100;
|
||||
abilityMs_->SignRestartAppFlag(USER_ID_U100, uid, "", AppExecFwk::MultiAppModeType::UNSPECIFIED, 1);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -555,7 +555,7 @@ HWTEST_F(AppMgrProxyTest, SignRestartAppFlag_0100, TestSize.Level1)
|
||||
{
|
||||
EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _)).Times(1);
|
||||
int32_t uid = 0;
|
||||
auto res = appMgrProxy_->SignRestartAppFlag(uid);
|
||||
auto res = appMgrProxy_->SignRestartAppFlag(uid, "");
|
||||
EXPECT_EQ(res, NO_ERROR);
|
||||
}
|
||||
|
||||
@ -761,27 +761,5 @@ HWTEST_F(AppMgrProxyTest, GetSupportedProcessCachePids_001, TestSize.Level0)
|
||||
|
||||
TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetAppIndexByPid_001
|
||||
* @tc.desc: Get app index of pid.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(AppMgrProxyTest, GetAppIndexByPid_001, TestSize.Level1)
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__);
|
||||
|
||||
EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _))
|
||||
.Times(1)
|
||||
.WillOnce(Invoke(mockAppMgrService_.GetRefPtr(), &MockAppMgrService::InvokeSendRequest));
|
||||
|
||||
pid_t pid = 1;
|
||||
int32_t appIndex = -1;
|
||||
appMgrProxy_->GetAppIndexByPid(pid, appIndex);
|
||||
EXPECT_EQ(mockAppMgrService_->code_, static_cast<uint32_t>(AppMgrInterfaceCode::GET_APP_INDEX_BY_PID));
|
||||
|
||||
TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__);
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
@ -1545,7 +1545,7 @@ HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_SignRestartAppFlag_0100,
|
||||
* @tc.steps: step2. Initialize AppRunningManager instance
|
||||
* @tc.expected: expect step1 first focused true
|
||||
*/
|
||||
auto ret = appRunningManager->SignRestartAppFlag(0);
|
||||
auto ret = appRunningManager->SignRestartAppFlag(0, "");
|
||||
EXPECT_EQ(ret, ERR_INVALID_VALUE);
|
||||
TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_SignRestartAppFlag_0100 end");
|
||||
}
|
||||
@ -1572,7 +1572,7 @@ HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_SignRestartAppFlag_0200,
|
||||
* @tc.steps: step2. Initialize AppRunningManager instance
|
||||
* @tc.expected: expect step1 different bundle unfocused true
|
||||
*/
|
||||
auto ret = appRunningManager->SignRestartAppFlag(0);
|
||||
auto ret = appRunningManager->SignRestartAppFlag(0, "");
|
||||
EXPECT_EQ(ret, ERR_INVALID_VALUE);
|
||||
TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_SignRestartAppFlag_0200 end");
|
||||
}
|
||||
@ -1600,7 +1600,7 @@ HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_SignRestartAppFlag_0300,
|
||||
* @tc.steps: step2. Initialize AppRunningManager instance
|
||||
* @tc.expected: expect step2 focused false
|
||||
*/
|
||||
auto ret = appRunningManager->SignRestartAppFlag(0);
|
||||
auto ret = appRunningManager->SignRestartAppFlag(0, "");
|
||||
EXPECT_EQ(ret, ERR_OK);
|
||||
EXPECT_TRUE(record->GetRestartAppFlag());
|
||||
TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_SignRestartAppFlag_0300 end");
|
||||
|
@ -162,17 +162,17 @@ HWTEST_F(MissionListManagerSecondTest, SignRestartAppFlag_001, TestSize.Level1)
|
||||
missionList->missions_.push_front(mission);
|
||||
missionListManager->currentMissionLists_.push_front(missionList);
|
||||
missionListManager->currentMissionLists_.push_front(missionList2);
|
||||
missionListManager->SignRestartAppFlag(uid);
|
||||
missionListManager->SignRestartAppFlag(uid, "");
|
||||
auto result = missionListManager->currentMissionLists_.size();
|
||||
EXPECT_EQ(2, result);
|
||||
|
||||
missionListManager->defaultStandardList_ = missionList;
|
||||
missionListManager->SignRestartAppFlag(uid);
|
||||
missionListManager->SignRestartAppFlag(uid, "");
|
||||
result = missionListManager->defaultStandardList_->missions_.size();
|
||||
EXPECT_EQ(0, result);
|
||||
|
||||
missionListManager->defaultSingleList_ = missionList;
|
||||
missionListManager->SignRestartAppFlag(uid);
|
||||
missionListManager->SignRestartAppFlag(uid, "");
|
||||
result = missionListManager->defaultSingleList_->missions_.size();
|
||||
EXPECT_EQ(0, result);
|
||||
}
|
||||
|
@ -1096,24 +1096,24 @@ HWTEST_F(MissionListTest, SignRestartAppFlag_0100, TestSize.Level1)
|
||||
missionList->missions_.push_back(nullptr);
|
||||
std::string bundleName("testbundlename");
|
||||
int32_t userId = 100;
|
||||
missionList->SignRestartAppFlag(userId);
|
||||
missionList->SignRestartAppFlag(userId, "");
|
||||
EXPECT_EQ(*missionList->missions_.begin(), nullptr);
|
||||
|
||||
missionList->missions_.clear();
|
||||
missionList->missions_.push_back(mission);
|
||||
missionList->SignRestartAppFlag(userId);
|
||||
missionList->SignRestartAppFlag(userId, "");
|
||||
EXPECT_NE(*missionList->missions_.begin(), nullptr);
|
||||
EXPECT_EQ((*missionList->missions_.begin())->GetAbilityRecord(), nullptr);
|
||||
|
||||
missionList->missions_.clear();
|
||||
mission = std::make_shared<Mission>(1, abilityRecord, "bundle");
|
||||
missionList->missions_.push_back(mission);
|
||||
missionList->SignRestartAppFlag(userId);
|
||||
missionList->SignRestartAppFlag(userId, "");
|
||||
EXPECT_NE(*missionList->missions_.begin(), nullptr);
|
||||
auto ai = (*missionList->missions_.begin())->GetAbilityRecord();
|
||||
EXPECT_NE(ai->GetApplicationInfo().bundleName, bundleName);
|
||||
|
||||
missionList->SignRestartAppFlag(0);
|
||||
missionList->SignRestartAppFlag(0, "");
|
||||
EXPECT_EQ(*missionList->missions_.begin(), nullptr);
|
||||
}
|
||||
} // namespace AAFwk
|
||||
|
@ -50,9 +50,10 @@ void RestartAppManagerTest::SetUp()
|
||||
HWTEST_F(RestartAppManagerTest, IsRestartAppFrequent_001, TestSize.Level1)
|
||||
{
|
||||
RestartAppManager &instance = RestartAppManager::GetInstance();
|
||||
RestartAppKeyType key("", 123);
|
||||
time_t time = 0;
|
||||
instance.restartAppHistory_[1] = time;
|
||||
auto res = instance.IsRestartAppFrequent(1, time);
|
||||
instance.restartAppHistory_[key] = time;
|
||||
auto res = instance.IsRestartAppFrequent(key, time);
|
||||
EXPECT_EQ(res, true);
|
||||
}
|
||||
|
||||
@ -65,21 +66,9 @@ HWTEST_F(RestartAppManagerTest, IsRestartAppFrequent_001, TestSize.Level1)
|
||||
HWTEST_F(RestartAppManagerTest, IsRestartAppFrequent_002, TestSize.Level1)
|
||||
{
|
||||
RestartAppManager &instance = RestartAppManager::GetInstance();
|
||||
RestartAppKeyType key("", 123);
|
||||
time_t time = 20;
|
||||
auto res = instance.IsRestartAppFrequent(1, time);
|
||||
EXPECT_EQ(res, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: IsForegroundToRestartApp_001
|
||||
* @tc.name: IsForegroundToRestartApp
|
||||
* @tc.desc: Test whether IsForegroundToRestartApp is called normally.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(RestartAppManagerTest, IsForegroundToRestartApp_001, TestSize.Level1)
|
||||
{
|
||||
RestartAppManager &instance = RestartAppManager::GetInstance();
|
||||
auto res = instance.IsForegroundToRestartApp();
|
||||
auto res = instance.IsRestartAppFrequent(key, time);
|
||||
EXPECT_EQ(res, false);
|
||||
}
|
||||
} // namespace AAFwk
|
||||
|
Loading…
Reference in New Issue
Block a user