Merge branch 'master' of gitee.com:openharmony/ability_ability_runtime into master

This commit is contained in:
徐承桦 2022-07-18 05:48:37 +00:00 committed by Gitee
commit ae0a76c26d
34 changed files with 333 additions and 121 deletions

View File

@ -767,6 +767,11 @@ public:
*/
ErrCode DumpAbilityInfoDone(std::vector<std::string> &infos, const sptr<IRemoteObject> &callerToken);
/**
* Called to update mission snapshot.
* @param token The target ability.
*/
void UpdateMissionSnapShot(const sptr<IRemoteObject>& token);
private:
class AbilityMgrDeathRecipient : public IRemoteObject::DeathRecipient {
public:

View File

@ -655,6 +655,12 @@ public:
return 0;
}
/**
* Called to update mission snapshot.
* @param token The target ability.
*/
virtual void UpdateMissionSnapShot(const sptr<IRemoteObject>& token) = 0;
enum {
// ipc id 1-1000 for kit
// ipc id for terminating ability (1)
@ -926,6 +932,7 @@ public:
STOP_SYNC_MISSIONS = 1113,
REGISTER_SNAPSHOT_HANDLER = 1114,
GET_MISSION_SNAPSHOT_INFO = 1115,
UPDATE_MISSION_SNAPSHOT = 1116,
// ipc id for user test(1120)
START_USER_TEST = 1120,

View File

@ -584,6 +584,12 @@ public:
*/
virtual int DumpAbilityInfoDone(std::vector<std::string> &infos, const sptr<IRemoteObject> &callerToken) override;
/**
* Called to update mission snapshot.
* @param token The target ability.
*/
virtual void UpdateMissionSnapShot(const sptr<IRemoteObject>& token) override;
private:
template <typename T>
int GetParcelableInfos(MessageParcel &reply, std::vector<T> &parcelableInfos);

View File

@ -783,6 +783,14 @@ public:
bool GetLocalDeviceId(std::string& localDeviceId);
int JudgeAbilityVisibleControl(const AppExecFwk::AbilityInfo &abilityInfo, int callerUid = -1);
/**
* Called to update mission snapshot.
* @param token The target ability.
*/
virtual void UpdateMissionSnapShot(const sptr<IRemoteObject>& token) override;
// MSG 0 - 20 represents timeout message
static constexpr uint32_t LOAD_TIMEOUT_MSG = 0;
static constexpr uint32_t ACTIVE_TIMEOUT_MSG = 1;
@ -962,7 +970,7 @@ private:
int32_t InitAbilityInfoFromExtension(AppExecFwk::ExtensionAbilityInfo &extensionInfo,
AppExecFwk::AbilityInfo &abilityInfo);
// multi user
void StartFreezingScreen();
void StopFreezingScreen();
@ -1000,6 +1008,8 @@ private:
int VerifyAccountPermission(int32_t userId);
bool CheckCallerEligibility(const AppExecFwk::AbilityInfo &abilityInfo, int callerUid);
using DumpFuncType = void (AbilityManagerService::*)(const std::string &args, std::vector<std::string> &info);
std::map<uint32_t, DumpFuncType> dumpFuncMap_;
@ -1043,7 +1053,7 @@ private:
std::shared_ptr<MissionListManager> currentMissionListManager_;
std::shared_ptr<FreeInstallManager> freeInstallManager_;
std::shared_ptr<UserController> userController_;
sptr<AppExecFwk::IAbilityController> abilityController_ = nullptr;
bool controllerIsAStabilityTest_ = false;

View File

@ -53,6 +53,7 @@ public:
* @return Returns ERR_OK on success, others on failure.
*/
virtual int DoAbilityBackground(const sptr<IRemoteObject> &token, uint32_t flag) override;
private:
void FirstStepInit();
void SecondStepInit();
@ -152,6 +153,7 @@ private:
int IsRunningInStabilityTestInner(MessageParcel &data, MessageParcel &reply);
int MoveMissionToFrontByOptionsInner(MessageParcel &data, MessageParcel &reply);
int UpdateMissionSnapShotInner(MessageParcel &data, MessageParcel &reply);
#ifdef SUPPORT_GRAPHICS
int SetMissionLabelInner(MessageParcel &data, MessageParcel &reply);
int SetMissionIconInner(MessageParcel &data, MessageParcel &reply);

View File

@ -409,6 +409,15 @@ public:
*/
bool IsReady() const;
inline void SetNeedSnapShot(bool needTakeSnapShot)
{
needTakeSnapShot_ = needTakeSnapShot;
}
inline bool IsNeedTakeSnapShot()
{
return needTakeSnapShot_;
}
#ifdef SUPPORT_GRAPHICS
/**
* check whether the ability 's window is attached.
@ -929,6 +938,7 @@ private:
mutable std::condition_variable dumpCondition_;
mutable bool isDumpTimeout_ = false;
std::vector<std::string> dumpInfos_;
bool needTakeSnapShot_ = true;
#ifdef SUPPORT_GRAPHICS
bool isStartingWindow_ = false;

View File

@ -161,7 +161,7 @@ static constexpr int64_t MICROSECONDS = 1000000; // MICROSECONDS mean 10^6 mi
return false;
}
static sptr<AppExecFwk::IBundleMgr> GetBundleManager()
[[maybe_unused]] static sptr<AppExecFwk::IBundleMgr> GetBundleManager()
{
auto bundleObj =
OHOS::DelayedSingleton<SaMgrClient>::GetInstance()->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
@ -172,40 +172,6 @@ static sptr<AppExecFwk::IBundleMgr> GetBundleManager()
return iface_cast<AppExecFwk::IBundleMgr>(bundleObj);
}
[[maybe_unused]] static int JudgeAbilityVisibleControl(const AppExecFwk::AbilityInfo &abilityInfo, int callerUid = -1)
{
HILOG_DEBUG("Judge ability visible begin.");
if (!abilityInfo.visible) {
HILOG_INFO("Ability visible is false.");
if (callerUid == -1) {
callerUid = IPCSkeleton::GetCallingUid();
}
auto bms = GetBundleManager();
CHECK_POINTER_AND_RETURN(bms, GET_ABILITY_SERVICE_FAILED);
auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall();
auto apl = abilityInfo.applicationInfo.appPrivilegeLevel;
if (!isSaCall && apl != SYSTEM_BASIC && apl != SYSTEM_CORE) {
HILOG_INFO("Caller is not systemAp or system.");
std::string bundleName;
bool result = bms->GetBundleNameForUid(callerUid, bundleName);
if (!result) {
HILOG_ERROR("GetBundleNameForUid fail");
return ABILITY_VISIBLE_FALSE_DENY_REQUEST;
}
if (bundleName != abilityInfo.bundleName) {
HILOG_ERROR("Judge ability visible error, caller bundleName:%{public}s not equal callee "
"bundleName: %{public}s",
bundleName.c_str(),
abilityInfo.bundleName.c_str());
return ABILITY_VISIBLE_FALSE_DENY_REQUEST;
}
}
}
HILOG_DEBUG("Judge ability visible success.");
return ERR_OK;
}
[[maybe_unused]] static bool HandleDlpApp(Want &want)
{
AppExecFwk::ElementName element = want.GetElement();

View File

@ -324,6 +324,12 @@ public:
MissionSnapshot& missionSnapshot, bool isLowResolution);
void GetAbilityRunningInfos(std::vector<AbilityRunningInfo> &info, bool isPerm);
/**
* Called to update mission snapshot.
* @param token The target ability.
*/
void UpdateSnapShot(const sptr<IRemoteObject>& token);
#ifdef ABILITY_COMMAND_FOR_TEST
/**
* Block ability.

View File

@ -61,7 +61,9 @@ int AbilityConnectManager::TerminateAbility(const std::shared_ptr<AbilityRecord>
if (it->GetCaller() == caller && it->GetRequestCode() == requestCode) {
targetAbility = service.second;
if (targetAbility) {
result = AbilityUtil::JudgeAbilityVisibleControl(targetAbility->GetAbilityInfo());
auto abilityMs = DelayedSingleton<AbilityManagerService>::GetInstance();
CHECK_POINTER(abilityMs);
result = abilityMs->JudgeAbilityVisibleControl(targetAbility->GetAbilityInfo());
}
break;
}
@ -314,7 +316,9 @@ int AbilityConnectManager::DisconnectAbilityLocked(const sptr<IAbilityConnection
auto abilityRecord = connectRecord->GetAbilityRecord();
CHECK_POINTER_AND_RETURN(abilityRecord, ERR_INVALID_VALUE);
HILOG_INFO("Disconnect ability, caller:%{public}s.", abilityRecord->GetAbilityInfo().name.c_str());
int result = AbilityUtil::JudgeAbilityVisibleControl(abilityRecord->GetAbilityInfo());
auto abilityMs = DelayedSingleton<AbilityManagerService>::GetInstance();
CHECK_POINTER_AND_RETURN(abilityMs, GET_ABILITY_SERVICE_FAILED);
int result = abilityMs->JudgeAbilityVisibleControl(abilityRecord->GetAbilityInfo());
if (result != ERR_OK) {
HILOG_ERROR("Judge ability visible error.");
return result;

View File

@ -854,6 +854,13 @@ ErrCode AbilityManagerClient::SendANRProcessID(int pid)
return abms->SendANRProcessID(pid);
}
void AbilityManagerClient::UpdateMissionSnapShot(const sptr<IRemoteObject>& token)
{
auto abms = GetAbilityManager();
CHECK_POINTER_RETURN(abms);
return abms->UpdateMissionSnapShot(token);
}
#ifdef ABILITY_COMMAND_FOR_TEST
ErrCode AbilityManagerClient::BlockAmsService()
{

View File

@ -880,6 +880,28 @@ int AbilityManagerProxy::GetMissionSnapshot(const std::string& deviceId, int32_t
return reply.ReadInt32();
}
void AbilityManagerProxy::UpdateMissionSnapShot(const sptr<IRemoteObject>& token)
{
int error;
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!WriteInterfaceToken(data)) {
return;
}
if (!data.WriteRemoteObject(token)) {
HILOG_ERROR("token write failed.");
return;
}
error = Remote()->SendRequest(IAbilityManager::UPDATE_MISSION_SNAPSHOT, data, reply, option);
if (error != NO_ERROR) {
HILOG_ERROR("Send request error: %{public}d", error);
return;
}
return;
}
int AbilityManagerProxy::KillProcess(const std::string &bundleName)
{
MessageParcel data;

View File

@ -429,7 +429,7 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptr<IRemot
return result;
}
GrantUriPermission(want, validUserId);
result = AbilityUtil::JudgeAbilityVisibleControl(abilityInfo, callerUid);
result = JudgeAbilityVisibleControl(abilityInfo, callerUid);
if (result != ERR_OK) {
HILOG_ERROR("JudgeAbilityVisibleControl error, result is %{public}d.", result);
return result;
@ -559,7 +559,7 @@ int AbilityManagerService::StartAbility(const Want &want, const AbilityStartSett
HiSysEventType::FAULT, eventInfo);
return result;
}
result = AbilityUtil::JudgeAbilityVisibleControl(abilityInfo);
result = JudgeAbilityVisibleControl(abilityInfo);
if (result != ERR_OK) {
HILOG_ERROR("%{public}s JudgeAbilityVisibleControl error.", __func__);
eventInfo.errCode = result;
@ -710,7 +710,7 @@ int AbilityManagerService::StartAbility(const Want &want, const StartOptions &st
HiSysEventType::FAULT, eventInfo);
return result;
}
result = AbilityUtil::JudgeAbilityVisibleControl(abilityInfo);
result = JudgeAbilityVisibleControl(abilityInfo);
if (result != ERR_OK) {
HILOG_ERROR("%{public}s JudgeAbilityVisibleControl error.", __func__);
eventInfo.errCode = result;
@ -785,7 +785,7 @@ int AbilityManagerService::CheckOptExtensionAbility(const Want &want, AbilityReq
return result;
}
GrantUriPermission(want, validUserId);
result = AbilityUtil::JudgeAbilityVisibleControl(abilityInfo);
result = JudgeAbilityVisibleControl(abilityInfo);
if (result != ERR_OK) {
HILOG_ERROR("JudgeAbilityVisibleControl error, result is %{public}d.", result);
return result;
@ -1073,7 +1073,7 @@ int AbilityManagerService::TerminateAbilityWithFlag(const sptr<IRemoteObject> &t
auto abilityRecord = Token::GetAbilityRecordByToken(token);
CHECK_POINTER_AND_RETURN(abilityRecord, ERR_INVALID_VALUE);
int result = AbilityUtil::JudgeAbilityVisibleControl(abilityRecord->GetAbilityInfo());
int result = JudgeAbilityVisibleControl(abilityRecord->GetAbilityInfo());
if (result != ERR_OK) {
HILOG_ERROR("%{public}s JudgeAbilityVisibleControl error.", __func__);
return result;
@ -1290,7 +1290,7 @@ int AbilityManagerService::MinimizeAbility(const sptr<IRemoteObject> &token, boo
auto abilityRecord = Token::GetAbilityRecordByToken(token);
CHECK_POINTER_AND_RETURN(abilityRecord, ERR_INVALID_VALUE);
int result = AbilityUtil::JudgeAbilityVisibleControl(abilityRecord->GetAbilityInfo());
int result = JudgeAbilityVisibleControl(abilityRecord->GetAbilityInfo());
if (result != ERR_OK) {
HILOG_ERROR("%{public}s JudgeAbilityVisibleControl error.", __func__);
return result;
@ -1452,7 +1452,7 @@ int AbilityManagerService::ConnectLocalAbility(const Want &want, const int32_t u
return ERR_INVALID_OPERATION;
}
result = AbilityUtil::JudgeAbilityVisibleControl(abilityInfo);
result = JudgeAbilityVisibleControl(abilityInfo);
if (result != ERR_OK) {
HILOG_ERROR("%{public}s JudgeAbilityVisibleControl error.", __func__);
return result;
@ -2104,7 +2104,7 @@ sptr<IAbilityScheduler> AbilityManagerService::AcquireDataAbility(
bool AbilityManagerService::CheckDataAbilityRequest(AbilityRequest &abilityRequest)
{
int result = AbilityUtil::JudgeAbilityVisibleControl(abilityRequest.abilityInfo);
int result = JudgeAbilityVisibleControl(abilityRequest.abilityInfo);
if (result != ERR_OK) {
HILOG_ERROR("%{public}s JudgeAbilityVisibleControl error.", __func__);
return false;
@ -2996,7 +2996,7 @@ int AbilityManagerService::TerminateAbilityResult(const sptr<IRemoteObject> &tok
auto abilityRecord = Token::GetAbilityRecordByToken(token);
CHECK_POINTER_AND_RETURN(abilityRecord, ERR_INVALID_VALUE);
int result = AbilityUtil::JudgeAbilityVisibleControl(abilityRecord->GetAbilityInfo());
int result = JudgeAbilityVisibleControl(abilityRecord->GetAbilityInfo());
if (result != ERR_OK) {
HILOG_ERROR("%{public}s JudgeAbilityVisibleControl error.", __func__);
return result;
@ -3723,38 +3723,13 @@ int AbilityManagerService::CheckCallPermissions(const AbilityRequest &abilityReq
HILOG_DEBUG("%{public}s begin", __func__);
auto abilityInfo = abilityRequest.abilityInfo;
auto callerUid = abilityRequest.callerUid;
auto targetUid = abilityInfo.applicationInfo.uid;
auto bms = GetBundleManager();
CHECK_POINTER_AND_RETURN(bms, GET_ABILITY_SERVICE_FAILED);
std::string bundleName;
bool result = IN_PROCESS_CALL(bms->GetBundleNameForUid(callerUid, bundleName));
if (!result) {
HILOG_ERROR("GetBundleNameForUid from bms fail.");
return RESOLVE_CALL_NO_PERMISSIONS;
}
AppExecFwk::ApplicationInfo callerAppInfo;
result = IN_PROCESS_CALL(
bms->GetApplicationInfo(bundleName, AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT, GetUserId(), callerAppInfo));
if (!result) {
HILOG_ERROR("GetApplicationInfo from bms fail.");
if (!CheckCallerEligibility(abilityInfo, callerUid)) {
HILOG_ERROR("called ability has no permission.");
return RESOLVE_CALL_NO_PERMISSIONS;
}
auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall();
auto apl = callerAppInfo.appPrivilegeLevel;
if (!isSaCall && apl != AbilityUtil::SYSTEM_BASIC && apl != AbilityUtil::SYSTEM_CORE) {
HILOG_DEBUG("caller is normal app.");
if (bundleName != abilityInfo.bundleName && callerUid != targetUid) {
HILOG_ERROR("the bundle name of caller is different from target one, caller: %{public}s "
"target: %{public}s",
bundleName.c_str(),
abilityInfo.bundleName.c_str());
return RESOLVE_CALL_NO_PERMISSIONS;
}
}
HILOG_DEBUG("the caller has permission to resolve the callproxy of common ability.");
HILOG_DEBUG("the caller has permission to resolve the call proxy of common ability.");
// check whether the target ability is singleton mode and page type.
if (abilityInfo.type == AppExecFwk::AbilityType::PAGE &&
abilityInfo.launchMode == AppExecFwk::LaunchMode::SINGLETON) {
@ -3766,6 +3741,65 @@ int AbilityManagerService::CheckCallPermissions(const AbilityRequest &abilityReq
return ERR_OK;
}
int AbilityManagerService::JudgeAbilityVisibleControl(const AppExecFwk::AbilityInfo &abilityInfo, int callerUid)
{
HILOG_DEBUG("Judge ability visible begin.");
if (!abilityInfo.visible) {
HILOG_INFO("Ability visible is false.");
if (callerUid == -1) {
callerUid = IPCSkeleton::GetCallingUid();
}
if (!CheckCallerEligibility(abilityInfo, callerUid)) {
HILOG_ERROR("called ability has no permission.");
return ABILITY_VISIBLE_FALSE_DENY_REQUEST;
}
}
HILOG_DEBUG("Judge ability visible success.");
return ERR_OK;
}
bool AbilityManagerService::CheckCallerEligibility(const AppExecFwk::AbilityInfo &abilityInfo, int callerUid)
{
auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall();
if (!isSaCall) {
auto bms = GetBundleManager();
if (!bms) {
HILOG_ERROR("fail to get bundle manager.");
return false;
}
std::string bundleName;
bool result = IN_PROCESS_CALL(bms->GetBundleNameForUid(callerUid, bundleName));
if (!result) {
HILOG_ERROR("GetBundleNameForUid from bms fail.");
return false;
}
AppExecFwk::ApplicationInfo callerAppInfo;
result = IN_PROCESS_CALL(bms->GetApplicationInfo(bundleName, AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT,
GetUserId(), callerAppInfo));
if (!result) {
HILOG_ERROR("GetApplicationInfo from bms fail.");
return false;
}
auto apl = callerAppInfo.appPrivilegeLevel;
if (apl != AbilityUtil::SYSTEM_BASIC && apl != AbilityUtil::SYSTEM_CORE) {
HILOG_DEBUG("caller is normal app.");
auto callerTokenId = IPCSkeleton::GetCallingTokenID();
auto targetTokenId = abilityInfo.applicationInfo.accessTokenId;
if (callerTokenId != targetTokenId) {
HILOG_ERROR("the bundle name of caller is different from target one, caller: %{public}s "
"target: %{public}s",
bundleName.c_str(),
abilityInfo.bundleName.c_str());
return false;
}
}
}
HILOG_DEBUG("Success to check caller permission.");
return true;
}
int AbilityManagerService::StartUser(int userId)
{
HILOG_DEBUG("%{public}s, userId:%{public}d", __func__, userId);
@ -3910,6 +3944,17 @@ int32_t AbilityManagerService::GetMissionSnapshot(const std::string& deviceId, i
return ERR_OK;
}
void AbilityManagerService::UpdateMissionSnapShot(const sptr<IRemoteObject>& token)
{
CHECK_POINTER_LOG(currentMissionListManager_, "Current mission manager not init.");
auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall();
if (!isSaCall) {
HILOG_ERROR("%{public}s: Permission verification failed", __func__);
return;
}
currentMissionListManager_->UpdateSnapShot(token);
}
int32_t AbilityManagerService::GetRemoteMissionSnapshotInfo(const std::string& deviceId, int32_t missionId,
MissionSnapshot& missionSnapshot)
{
@ -4353,7 +4398,7 @@ int AbilityManagerService::DoAbilityForeground(const sptr<IRemoteObject> &token,
std::lock_guard<std::recursive_mutex> guard(globalLock_);
auto abilityRecord = Token::GetAbilityRecordByToken(token);
CHECK_POINTER_AND_RETURN(abilityRecord, ERR_INVALID_VALUE);
int result = AbilityUtil::JudgeAbilityVisibleControl(abilityRecord->GetAbilityInfo());
int result = JudgeAbilityVisibleControl(abilityRecord->GetAbilityInfo());
if (result != ERR_OK) {
HILOG_ERROR("%{public}s JudgeAbilityVisibleControl error.", __func__);
return result;

View File

@ -138,6 +138,7 @@ void AbilityManagerStub::ThirdStepInit()
requestFuncMap_[DUMP_ABILITY_INFO_DONE] = &AbilityManagerStub::DumpAbilityInfoDoneInner;
requestFuncMap_[START_EXTENSION_ABILITY] = &AbilityManagerStub::StartExtensionAbilityInner;
requestFuncMap_[STOP_EXTENSION_ABILITY] = &AbilityManagerStub::StopExtensionAbilityInner;
requestFuncMap_[UPDATE_MISSION_SNAPSHOT] = &AbilityManagerStub::UpdateMissionSnapShotInner;
#ifdef SUPPORT_GRAPHICS
requestFuncMap_[SET_MISSION_LABEL] = &AbilityManagerStub::SetMissionLabelInner;
requestFuncMap_[SET_MISSION_ICON] = &AbilityManagerStub::SetMissionIconInner;
@ -1408,6 +1409,17 @@ int AbilityManagerStub::DumpAbilityInfoDoneInner(MessageParcel &data, MessagePar
return NO_ERROR;
}
int AbilityManagerStub::UpdateMissionSnapShotInner(MessageParcel &data, MessageParcel &reply)
{
sptr<IRemoteObject> token = data.ReadRemoteObject();
if (!token) {
HILOG_ERROR("UpdateMissionSnapShot read ability token failed.");
return ERR_NULL_OBJECT;
}
UpdateMissionSnapShot(token);
return NO_ERROR;
}
#ifdef SUPPORT_GRAPHICS
int AbilityManagerStub::SetMissionLabelInner(MessageParcel &data, MessageParcel &reply)
{

View File

@ -149,7 +149,9 @@ int DataAbilityManager::Release(
auto abilityRecord = dataAbilityRecord->GetAbilityRecord();
CHECK_POINTER_AND_RETURN(abilityRecord, ERR_UNKNOWN_OBJECT);
int result = AbilityUtil::JudgeAbilityVisibleControl(abilityRecord->GetAbilityInfo());
auto abilityMs = DelayedSingleton<AbilityManagerService>::GetInstance();
CHECK_POINTER_AND_RETURN(abilityMs, GET_ABILITY_SERVICE_FAILED);
int result = abilityMs->JudgeAbilityVisibleControl(abilityRecord->GetAbilityInfo());
if (result != ERR_OK) {
HILOG_ERROR("%{public}s JudgeAbilityVisibleControl error.", __func__);
return result;

View File

@ -1057,7 +1057,9 @@ int MissionListManager::TerminateAbility(const std::shared_ptr<AbilityRecord> &c
return NO_FOUND_ABILITY_BY_CALLER;
}
int result = AbilityUtil::JudgeAbilityVisibleControl(targetAbility->GetAbilityInfo());
auto abilityMs = DelayedSingleton<AbilityManagerService>::GetInstance();
CHECK_POINTER_AND_RETURN(abilityMs, GET_ABILITY_SERVICE_FAILED)
int result = abilityMs->JudgeAbilityVisibleControl(targetAbility->GetAbilityInfo());
if (result != ERR_OK) {
HILOG_ERROR("%{public}s JudgeAbilityVisibleControl error.", __func__);
return result;
@ -1402,6 +1404,19 @@ int MissionListManager::SetMissionLockedState(int missionId, bool lockedState)
return ERR_OK;
}
void MissionListManager::UpdateSnapShot(const sptr<IRemoteObject>& token)
{
std::lock_guard<std::recursive_mutex> guard(managerLock_);
auto abilityRecord = GetAbilityRecordByToken(token);
if (!abilityRecord) {
HILOG_ERROR("Cannot find AbilityRecord by Token.");
return;
}
HILOG_INFO("UpdateSnapShot, ability:%{public}s.", abilityRecord->GetAbilityInfo().name.c_str());
UpdateMissionSnapshot(abilityRecord);
abilityRecord->SetNeedSnapShot(false);
}
void MissionListManager::MoveToBackgroundTask(const std::shared_ptr<AbilityRecord> &abilityRecord)
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
@ -1412,7 +1427,11 @@ void MissionListManager::MoveToBackgroundTask(const std::shared_ptr<AbilityRecor
HILOG_INFO("Move the ability to background, ability:%{public}s.", abilityRecord->GetAbilityInfo().name.c_str());
abilityRecord->SetIsNewWant(false);
NotifyMissionCreated(abilityRecord);
UpdateMissionSnapshot(abilityRecord);
if (abilityRecord->IsNeedTakeSnapShot()) {
UpdateMissionSnapshot(abilityRecord);
} else {
abilityRecord->SetNeedSnapShot(true);
}
auto self(shared_from_this());
auto task = [abilityRecord, self]() {

View File

@ -529,6 +529,15 @@ public:
* @return
*/
void NotifyAppStatus(const std::string &bundleName, const std::string &eventData);
/**
* KillProcessByPid, Kill process by PID.
*
* @param pid_t, the app record pid.
*
* @return ERR_OK, return back successothers fail.
*/
int32_t KillProcessByPid(const pid_t pid) const;
private:
void StartEmptyResidentProcess(const BundleInfo &info, const std::string &processName, int restartCount);
@ -540,10 +549,12 @@ private:
bool GetBundleInfo(const std::string &bundleName, BundleInfo &bundleInfo);
void MakeProcessName(std::string &processName, const std::shared_ptr<AbilityInfo> &abilityInfo,
const std::shared_ptr<ApplicationInfo> &appInfo, HapModuleInfo &hapModuleInfo, int32_t appIndex);
void MakeProcessName(const std::shared_ptr<AbilityInfo> &abilityInfo,
const std::shared_ptr<ApplicationInfo> &appInfo,
const HapModuleInfo &hapModuleInfo, int32_t appIndex, std::string &processName);
void MakeProcessName(
std::string &processName, const std::shared_ptr<ApplicationInfo> &appInfo, HapModuleInfo &hapModuleInfo);
const std::shared_ptr<ApplicationInfo> &appInfo, const HapModuleInfo &hapModuleInfo, std::string &processName);
/**
* StartAbility, load the ability that needed to be started(Start on the basis of the original process).
* Start on a new boot process
@ -623,15 +634,6 @@ private:
*/
int32_t KillApplicationByUserIdLocked(const std::string &bundleName, const int userId);
/**
* KillProcessByPid, Kill process by PID.
*
* @param pid_t, the app record pid.
*
* @return ERR_OK, return back successothers fail.
*/
int32_t KillProcessByPid(const pid_t pid) const;
/**
* WaitForRemoteProcessExit, Wait for the process to exit normally.
*

View File

@ -148,7 +148,7 @@ void AppMgrServiceInner::LoadAbility(const sptr<IRemoteObject> &token, const spt
}
std::string processName;
MakeProcessName(processName, abilityInfo, appInfo, hapModuleInfo, appIndex);
MakeProcessName(abilityInfo, appInfo, hapModuleInfo, appIndex, processName);
auto appRecord =
appRunningManager_->CheckAppRunningRecordIsExist(appInfo->name, processName, appInfo->uid, bundleInfo);
@ -191,8 +191,9 @@ bool AppMgrServiceInner::CheckLoadabilityConditions(const sptr<IRemoteObject> &t
return true;
}
void AppMgrServiceInner::MakeProcessName(std::string &processName, const std::shared_ptr<AbilityInfo> &abilityInfo,
const std::shared_ptr<ApplicationInfo> &appInfo, HapModuleInfo &hapModuleInfo, int32_t appIndex)
void AppMgrServiceInner::MakeProcessName(const std::shared_ptr<AbilityInfo> &abilityInfo,
const std::shared_ptr<ApplicationInfo> &appInfo, const HapModuleInfo &hapModuleInfo, int32_t appIndex,
std::string &processName)
{
if (!abilityInfo || !appInfo) {
return;
@ -201,14 +202,14 @@ void AppMgrServiceInner::MakeProcessName(std::string &processName, const std::sh
processName = abilityInfo->process;
return;
}
MakeProcessName(processName, appInfo, hapModuleInfo);
MakeProcessName(appInfo, hapModuleInfo, processName);
if (appIndex != 0) {
processName += std::to_string(appIndex);
}
}
void AppMgrServiceInner::MakeProcessName(
std::string &processName, const std::shared_ptr<ApplicationInfo> &appInfo, HapModuleInfo &hapModuleInfo)
const std::shared_ptr<ApplicationInfo> &appInfo, const HapModuleInfo &hapModuleInfo, std::string &processName)
{
if (!appInfo) {
return;
@ -1771,7 +1772,7 @@ int AppMgrServiceInner::StartUserTestProcess(
}
std::string processName;
MakeProcessName(processName, std::make_shared<ApplicationInfo>(bundleInfo.applicationInfo), hapModuleInfo);
MakeProcessName(std::make_shared<ApplicationInfo>(bundleInfo.applicationInfo), hapModuleInfo, processName);
HILOG_INFO("processName = [%{public}s]", processName.c_str());
// Inspection records
@ -1968,7 +1969,7 @@ void AppMgrServiceInner::StartSpecifiedAbility(const AAFwk::Want &want, const Ap
HILOG_ERROR("abilityInfoPtr is nullptr.");
return;
}
MakeProcessName(processName, abilityInfoPtr, appInfo, hapModuleInfo, appIndex);
MakeProcessName(abilityInfoPtr, appInfo, hapModuleInfo, appIndex, processName);
std::vector<HapModuleInfo> hapModules;
hapModules.emplace_back(hapModuleInfo);

View File

@ -388,10 +388,17 @@ void AppRunningManager::TerminateAbility(const sptr<IRemoteObject> &token, bool
appRecord->TerminateAbility(token, false);
if (isLastAbilityRecord && !appRecord->IsKeepAliveApp()) {
HILOG_INFO("The ability is the last in the app:%{public}s.", appRecord->GetName().c_str());
HILOG_DEBUG("The ability is the last in the app:%{public}s.", appRecord->GetName().c_str());
appRecord->SetTerminating();
if (isClearMission) {
HILOG_INFO("The ability is the last, KillApplication");
HILOG_DEBUG("The ability is the last, kill application");
auto pid = appRecord->GetPriorityObject()->GetPid();
auto result = appMgrServiceInner->KillProcessByPid(pid);
if (result < 0) {
HILOG_WARN("Kill application directly failed, pid: %{public}d", pid);
}
appMgrServiceInner->NotifyAppStatus(appRecord->GetBundleName(),
EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_RESTARTED);
}
}
}

View File

@ -154,6 +154,11 @@ public:
return 0;
}
virtual void UpdateMissionSnapShot(const sptr<IRemoteObject>& token) override
{
return;
}
virtual int ClearUpApplicationData(const std::string &bundleName) override
{
return 0;

View File

@ -197,6 +197,10 @@ public:
{
return 0;
}
virtual void UpdateMissionSnapShot(const sptr<IRemoteObject>& token) override
{
return;
}
virtual int RegisterSnapshotHandler(const sptr<ISnapshotHandler>& handler)
{
return 0;

View File

@ -102,6 +102,11 @@ int MockAbilityDelegatorStub::GetMissionSnapshot(const std::string& deviceId, in
return 0;
}
void MockAbilityDelegatorStub::UpdateMissionSnapShot(const sptr<IRemoteObject>& token)
{
return;
}
int MockAbilityDelegatorStub::RegisterSnapshotHandler(const sptr<ISnapshotHandler>& handler)
{
return 0;
@ -284,6 +289,11 @@ int MockAbilityDelegatorStub2::GetMissionSnapshot(const std::string& deviceId, i
return 0;
}
void MockAbilityDelegatorStub2::UpdateMissionSnapShot(const sptr<IRemoteObject>& token)
{
return;
}
int MockAbilityDelegatorStub2::RegisterSnapshotHandler(const sptr<ISnapshotHandler>& handler)
{
return 0;

View File

@ -127,6 +127,7 @@ public:
const AppExecFwk::ElementName &element) override;
virtual int GetMissionSnapshot(const std::string& deviceId, int32_t missionId,
MissionSnapshot& snapshot, bool isLowResolution) override;
virtual void UpdateMissionSnapShot(const sptr<IRemoteObject>& token) override;
virtual int RegisterSnapshotHandler(const sptr<ISnapshotHandler>& handler) override;
virtual int SendANRProcessID(int pid) override;
virtual int SetAbilityController(const sptr<AppExecFwk::IAbilityController> &abilityController,
@ -263,6 +264,7 @@ public:
const AppExecFwk::ElementName &element) override;
virtual int GetMissionSnapshot(const std::string& deviceId, int32_t missionId,
MissionSnapshot& snapshot, bool isLowResolution) override;
virtual void UpdateMissionSnapShot(const sptr<IRemoteObject>& token) override;
virtual int RegisterSnapshotHandler(const sptr<ISnapshotHandler>& handler) override;
virtual int SendANRProcessID(int pid) override;
virtual int SetAbilityController(const sptr<AppExecFwk::IAbilityController> &abilityController,

View File

@ -181,6 +181,10 @@ public:
{
return 0;
}
virtual void UpdateMissionSnapShot(const sptr<IRemoteObject>& token)
{
return;
}
virtual int RegisterSnapshotHandler(const sptr<ISnapshotHandler> &handler)
{
return 0;

View File

@ -193,6 +193,12 @@ public:
{
return 0;
}
virtual void UpdateMissionSnapShot(const sptr<IRemoteObject>& token)
{
return;
}
virtual int RegisterSnapshotHandler(const sptr<ISnapshotHandler>& handler)
{
return 0;

View File

@ -158,6 +158,10 @@ public:
{
return 0;
}
virtual void UpdateMissionSnapShot(const sptr<IRemoteObject>& token)
{
return;
}
virtual int RegisterSnapshotHandler(const sptr<ISnapshotHandler>& handler)
{
return 0;

View File

@ -210,6 +210,12 @@ public:
{
return 0;
}
virtual void UpdateMissionSnapShot(const sptr<IRemoteObject>& token)
{
return;
}
virtual int RegisterSnapshotHandler(const sptr<ISnapshotHandler>& handler)
{
return 0;

View File

@ -216,6 +216,12 @@ public:
{
return 0;
}
virtual void UpdateMissionSnapShot(const sptr<IRemoteObject>& token)
{
return;
}
virtual int RegisterSnapshotHandler(const sptr<ISnapshotHandler>& handler)
{
return 0;

View File

@ -288,6 +288,12 @@ public:
{
return 0;
}
virtual void UpdateMissionSnapShot(const sptr<IRemoteObject>& token)
{
return;
}
virtual int RegisterSnapshotHandler(const sptr<ISnapshotHandler>& handler)
{
return 0;

View File

@ -125,6 +125,12 @@ public:
{
return 0;
}
virtual void UpdateMissionSnapShot(const sptr<IRemoteObject>& token)
{
return;
}
virtual int RegisterSnapshotHandler(const sptr<ISnapshotHandler>& handler)
{
return 0;

View File

@ -45,6 +45,7 @@ ohos_unittest("ability_record_test") {
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock",
"${ability_runtime_test_path}/unittest:abilityms_test_source",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
"//third_party/libpng:libpng",
"//utils/native/base:utils",

View File

@ -21,13 +21,17 @@
#undef private
#undef protected
#include "ability_connect_callback_stub.h"
#include "ability_manager_service.h"
#include "ability_scheduler.h"
#include "connection_record.h"
#include "mock_ability_connect_callback.h"
#include "ability_connect_callback_stub.h"
#include "mock_bundle_manager.h"
#include "sa_mgr_client.h"
#include "system_ability_definition.h"
using namespace testing::ext;
using namespace OHOS::AppExecFwk;
namespace OHOS {
namespace AAFwk {
@ -46,11 +50,14 @@ public:
void AbilityRecordTest::SetUpTestCase(void)
{
OHOS::DelayedSingleton<SaMgrClient>::GetInstance()->RegisterSystemAbility(
OHOS::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID, new BundleMgrService());
OHOS::DelayedSingleton<AbilityManagerService>::GetInstance()->OnStart();
}
void AbilityRecordTest::TearDownTestCase(void)
{
OHOS::DelayedSingleton<AbilityManagerService>::GetInstance()->OnStop();
OHOS::DelayedSingleton<SaMgrClient>::DestroyInstance();
}
void AbilityRecordTest::SetUp(void)

View File

@ -21,14 +21,17 @@
#undef private
#undef protected
#include "ability_connect_callback_stub.h"
#include "ability_manager_service.h"
#include "ability_scheduler.h"
#include "ability_scheduler_mock.h"
#include "connection_record.h"
#include "mock_ability_connect_callback.h"
#include "ability_scheduler_mock.h"
#include "ability_connect_callback_stub.h"
#include "mock_bundle_manager.h"
#include "sa_mgr_client.h"
#include "system_ability_definition.h"
using namespace testing::ext;
using namespace OHOS::AppExecFwk;
namespace OHOS {
namespace AAFwk {
@ -47,11 +50,14 @@ public:
void AbilityRecordTest::SetUpTestCase(void)
{
OHOS::DelayedSingleton<SaMgrClient>::GetInstance()->RegisterSystemAbility(
OHOS::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID, new BundleMgrService());
OHOS::DelayedSingleton<AbilityManagerService>::GetInstance()->OnStart();
}
void AbilityRecordTest::TearDownTestCase(void)
{
OHOS::DelayedSingleton<AbilityManagerService>::GetInstance()->OnStop();
OHOS::DelayedSingleton<SaMgrClient>::DestroyInstance();
}
void AbilityRecordTest::SetUp(void)

View File

@ -199,7 +199,7 @@ HWTEST_F(WantAgentHelperTest, WantAgentHelper_0900, Function | MediumTest | Leve
* @tc.number : WantAgentHelper_1000
* @tc.name : WantAgentHelper GetWantAgent
* @tc.desc : 1.GetWantAgent context is not nullptr
* 2.wantAgentInfo.wants_.siez() != wantAgentInfo.flags_.siez()
* 2.wantAgentInfo.wants_.size() != wantAgentInfo.flags_.size()
*/
HWTEST_F(WantAgentHelperTest, WantAgentHelper_1000, Function | MediumTest | Level1)
{
@ -220,7 +220,7 @@ HWTEST_F(WantAgentHelperTest, WantAgentHelper_1000, Function | MediumTest | Leve
* @tc.number : WantAgentHelper_1100
* @tc.name : WantAgentHelper GetWantAgent
* @tc.desc : 1.GetWantAgent context is not nullptr
* 2.wantAgentInfo.wants_.siez() == wantAgentInfo.flags_.siez()
* 2.wantAgentInfo.wants_.size() == wantAgentInfo.flags_.size()
* 3.FlagsTransformer return 0
*/
HWTEST_F(WantAgentHelperTest, WantAgentHelper_1100, Function | MediumTest | Level1)
@ -242,7 +242,7 @@ HWTEST_F(WantAgentHelperTest, WantAgentHelper_1100, Function | MediumTest | Leve
* @tc.number : WantAgentHelper_1200
* @tc.name : WantAgentHelper GetWantAgent
* @tc.desc : 1.GetWantAgent context is not nullptr
* 2.wantAgentInfo.wants_.siez() == wantAgentInfo.flags_.siez()
* 2.wantAgentInfo.wants_.size() == wantAgentInfo.flags_.size()
* 3.FlagsTransformer return ok
* 4.Type is WantAgentConstant::OperationType::START_ABILITY
*/
@ -267,7 +267,7 @@ HWTEST_F(WantAgentHelperTest, WantAgentHelper_1200, Function | MediumTest | Leve
* @tc.number : WantAgentHelper_1300
* @tc.name : WantAgentHelper GetWantAgent
* @tc.desc : 1.GetWantAgent context is not nullptr
* 2.wantAgentInfo.wants_.siez() == wantAgentInfo.flags_.siez()
* 2.wantAgentInfo.wants_.size() == wantAgentInfo.flags_.size()
* 3.FlagsTransformer return ok
* 4.Type is WantAgentConstant::OperationType::START_ABILITIES
*/
@ -292,7 +292,7 @@ HWTEST_F(WantAgentHelperTest, WantAgentHelper_1300, Function | MediumTest | Leve
* @tc.number : WantAgentHelper_1400
* @tc.name : WantAgentHelper GetWantAgent
* @tc.desc : 1.GetWantAgent context is not nullptr
* 2.wantAgentInfo.wants_.siez() == wantAgentInfo.flags_.siez()
* 2.wantAgentInfo.wants_.size() == wantAgentInfo.flags_.size()
* 3.FlagsTransformer return ok
* 4.Type is WantAgentConstant::OperationType::START_SERVICE
*/
@ -317,7 +317,7 @@ HWTEST_F(WantAgentHelperTest, WantAgentHelper_1400, Function | MediumTest | Leve
* @tc.number : WantAgentHelper_1500
* @tc.name : WantAgentHelper GetWantAgent
* @tc.desc : 1.GetWantAgent context is not nullptr
* 2.wantAgentInfo.wants_.siez() == wantAgentInfo.flags_.siez()
* 2.wantAgentInfo.wants_.size() == wantAgentInfo.flags_.size()
* 3.FlagsTransformer return ok
* 4.Type is WantAgentConstant::OperationType::START_FOREGROUND_SERVICE
*/
@ -342,7 +342,7 @@ HWTEST_F(WantAgentHelperTest, WantAgentHelper_1500, Function | MediumTest | Leve
* @tc.number : WantAgentHelper_1600
* @tc.name : WantAgentHelper GetWantAgent
* @tc.desc : 1.GetWantAgent context is not nullptr
* 2.wantAgentInfo.wants_.siez() == wantAgentInfo.flags_.siez()
* 2.wantAgentInfo.wants_.size() == wantAgentInfo.flags_.size()
* 3.FlagsTransformer return ok
* 4.Type is WantAgentConstant::OperationType::START_FOREGROUND_SERVICE
*/
@ -367,7 +367,7 @@ HWTEST_F(WantAgentHelperTest, WantAgentHelper_1600, Function | MediumTest | Leve
* @tc.number : WantAgentHelper_1700
* @tc.name : WantAgentHelper GetWantAgent
* @tc.desc : 1.GetWantAgent context is not nullptr
* 2.wantAgentInfo.wants_.siez() == wantAgentInfo.flags_.siez()
* 2.wantAgentInfo.wants_.size() == wantAgentInfo.flags_.size()
* 3.FlagsTransformer return ok
* 4.Type is 100
*/
@ -391,7 +391,7 @@ HWTEST_F(WantAgentHelperTest, WantAgentHelper_1700, Function | MediumTest | Leve
/*
* @tc.number : WantAgentHelper_1800
* @tc.name : WantAgentHelper GetWantAgent(const WantAgentInfo &paramsInfo)
* @tc.desc : 1.wantAgentInfo.wants_.siez() == 0
* @tc.desc : 1.wantAgentInfo.wants_.size() == 0
*/
HWTEST_F(WantAgentHelperTest, WantAgentHelper_1800, Function | MediumTest | Level1)
{
@ -409,7 +409,7 @@ HWTEST_F(WantAgentHelperTest, WantAgentHelper_1800, Function | MediumTest | Leve
* @tc.number : WantAgentHelper_1900
* @tc.name : WantAgentHelper GetWantAgent(const WantAgentInfo &paramsInfo)
* @tc.desc : 1.wantAgentInfo.wants_ not empty
* 2.wantAgentInfo.wants_.siez() != wantAgentInfo.flags_.siez()
* 2.wantAgentInfo.wants_.size() != wantAgentInfo.flags_.size()
*/
HWTEST_F(WantAgentHelperTest, WantAgentHelper_1900, Function | MediumTest | Level1)
{
@ -423,14 +423,14 @@ HWTEST_F(WantAgentHelperTest, WantAgentHelper_1900, Function | MediumTest | Leve
wantAgentInfo.operationType_ = static_cast<WantAgentConstant::OperationType>(100);
wantAgentInfo.requestCode_ = 10;
auto wantAgent = wantAgentHelper->GetWantAgent(wantAgentInfo);
EXPECT_EQ(wantAgent, nullptr);
EXPECT_NE(wantAgent, nullptr);
}
/*
* @tc.number : WantAgentHelper_2000
* @tc.name : WantAgentHelper GetWantAgent(const WantAgentInfo &paramsInfo)
* @tc.desc : 1.wantAgentInfo.wants_ not empty
* 2.wantAgentInfo.wants_.siez() == wantAgentInfo.flags_.siez()
* 2.wantAgentInfo.wants_.size() == wantAgentInfo.flags_.size()
* 3.wantAgentInfo.wants_[0] is nullptr
*/
HWTEST_F(WantAgentHelperTest, WantAgentHelper_2000, Function | MediumTest | Level1)
@ -454,7 +454,7 @@ HWTEST_F(WantAgentHelperTest, WantAgentHelper_2000, Function | MediumTest | Leve
* @tc.number : WantAgentHelper_2100
* @tc.name : WantAgentHelper GetWantAgent(const WantAgentInfo &paramsInfo)
* @tc.desc : 1.wantAgentInfo.wants_ not empty
* 2.wantAgentInfo.wants_.siez() == wantAgentInfo.flags_.siez()
* 2.wantAgentInfo.wants_.size() == wantAgentInfo.flags_.size()
* 3.wantAgentInfo.wants_[0] is not nullptr
* 4.wantAgentInfo.extraInfo_ is not nullptr
*/
@ -475,14 +475,14 @@ HWTEST_F(WantAgentHelperTest, WantAgentHelper_2100, Function | MediumTest | Leve
wParams->SetParam(key, Boolean::Box(value));
wantAgentInfo.extraInfo_ = wParams;
auto wantAgent = wantAgentHelper->GetWantAgent(wantAgentInfo);
EXPECT_EQ(wantAgent, nullptr);
EXPECT_NE(wantAgent, nullptr);
}
/*
* @tc.number : WantAgentHelper_2200
* @tc.name : WantAgentHelper GetWantAgent(const WantAgentInfo &paramsInfo)
* @tc.desc : 1.wantAgentInfo.wants_ not empty
* 2.wantAgentInfo.wants_.siez() == wantAgentInfo.flags_.siez()
* 2.wantAgentInfo.wants_.size() == wantAgentInfo.flags_.size()
* 3.wantAgentInfo.wants_[0] is not nullptr
* 4.wantAgentInfo.extraInfo_ is nullptr
*/
@ -499,7 +499,7 @@ HWTEST_F(WantAgentHelperTest, WantAgentHelper_2200, Function | MediumTest | Leve
wantAgentInfo.requestCode_ = 10;
wantAgentInfo.extraInfo_ = nullptr;
auto wantAgent = wantAgentHelper->GetWantAgent(wantAgentInfo);
EXPECT_EQ(wantAgent, nullptr);
EXPECT_NE(wantAgent, nullptr);
}
/*

View File

@ -163,6 +163,12 @@ public:
{
return 0;
}
virtual void UpdateMissionSnapShot(const sptr<IRemoteObject>& token)
{
return;
}
virtual int RegisterSnapshotHandler(const sptr<ISnapshotHandler>& handler)
{
return 0;