Add permission check for collaborator kill

Signed-off-by: wangzhen <wangzhen416@huawei.com>
Change-Id: I0197346f51850b121fff3080ef658011adda55cc
This commit is contained in:
wangzhen
2025-04-30 15:46:35 +08:00
parent a1d5d13f2b
commit 373adfe970
3 changed files with 39 additions and 27 deletions
@@ -2076,6 +2076,8 @@ protected:
const std::string &bundleName, const std::vector<std::string> &abilityNames,
const std::vector<std::string> &uiExtensionNames) override;
int32_t GetCollaboratorType(const std::string &codePath) const;
int32_t KillProcessForCollaborator(int32_t collaboratorType, const std::string &bundleName, int32_t userId);
private:
int TerminateAbilityWithFlag(const sptr<IRemoteObject> &token, int resultCode = DEFAULT_INVAL_VALUE,
const Want *resultWant = nullptr, bool flag = true);
@@ -6860,12 +6860,7 @@ int AbilityManagerService::GenerateAbilityRequest(const Want &want, int requestC
request.abilityInfo = abilityInfo->abilityInfo;
request.extensionProcessMode = abilityInfo->extensionProcessMode;
request.customProcess = abilityInfo->customProcess;
if (request.abilityInfo.applicationInfo.codePath == std::to_string(CollaboratorType::RESERVE_TYPE)) {
request.collaboratorType = CollaboratorType::RESERVE_TYPE;
} else if (request.abilityInfo.applicationInfo.codePath == std::to_string(CollaboratorType::OTHERS_TYPE)) {
request.collaboratorType = CollaboratorType::OTHERS_TYPE;
}
request.collaboratorType = GetCollaboratorType(request.abilityInfo.applicationInfo.codePath);
if (request.abilityInfo.type == AppExecFwk::AbilityType::SERVICE && request.abilityInfo.isStageBasedModel) {
TAG_LOGI(AAFwkTag::ABILITYMGR, "stage mode, abilityInfo SERVICE type reset EXTENSION");
@@ -7120,23 +7115,9 @@ int AbilityManagerService::KillProcess(const std::string &bundleName, bool clear
return GET_BUNDLE_INFO_FAILED;
}
int32_t collaboratorType = -1;
if (bundleInfo.applicationInfo.codePath == std::to_string(CollaboratorType::RESERVE_TYPE)) {
collaboratorType = CollaboratorType::RESERVE_TYPE;
} else if (bundleInfo.applicationInfo.codePath == std::to_string(CollaboratorType::OTHERS_TYPE)) {
collaboratorType = CollaboratorType::OTHERS_TYPE;
}
if (collaboratorType != -1) {
TAG_LOGI(AAFwkTag::ABILITYMGR, "Collaborator kill");
auto collaborator = GetCollaborator(collaboratorType);
if (collaborator == nullptr) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "Collaborator null");
return KILL_PROCESS_FAILED;
}
if (collaborator->NotifyKillProcesses(bundleName, userId) != ERR_OK) {
return KILL_PROCESS_FAILED;
}
return ERR_OK;
int32_t collaboratorType = GetCollaboratorType(bundleInfo.applicationInfo.codePath);
if (CheckCollaboratorType(collaboratorType)) {
return KillProcessForCollaborator(collaboratorType, bundleName, userId);
}
KeepAliveType type;
@@ -7147,10 +7128,29 @@ int AbilityManagerService::KillProcess(const std::string &bundleName, bool clear
}
int ret = DelayedSingleton<AppScheduler>::GetInstance()->KillApplication(bundleName, clearPageStack, appIndex);
if (ret != ERR_OK) {
return ret == ERR_OK ? ERR_OK : KILL_PROCESS_FAILED;
}
int32_t AbilityManagerService::KillProcessForCollaborator(int32_t collaboratorType,
const std::string &bundleName, int32_t userId)
{
TAG_LOGI(AAFwkTag::ABILITYMGR, "Collaborator kill");
auto collaborator = GetCollaborator(collaboratorType);
if (collaborator == nullptr) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "Collaborator null");
return KILL_PROCESS_FAILED;
}
auto isSaCall = PermissionVerification::GetInstance()->IsSACall();
auto isShellCall = PermissionVerification::GetInstance()->IsShellCall();
auto isCallingPerm = PermissionVerification::GetInstance()->VerifyCallingPermission(
PermissionConstants::PERMISSION_KILL_APP_PROCESSES);
if (!isCallingPerm && !isSaCall && !isShellCall) {
TAG_LOGE(AAFwkTag::APPMGR, "KillProcess permission verification fail");
return ERR_PERMISSION_DENIED;
}
if (collaborator->NotifyKillProcesses(bundleName, userId) != ERR_OK) {
return KILL_PROCESS_FAILED;
}
return ERR_OK;
}
@@ -11222,6 +11222,16 @@ int32_t AbilityManagerService::UnregisterIAbilityManagerCollaborator(int32_t typ
return ERR_OK;
}
int32_t AbilityManagerService::GetCollaboratorType(const std::string &codePath) const
{
if (codePath == std::to_string(CollaboratorType::RESERVE_TYPE)) {
return CollaboratorType::RESERVE_TYPE;
} else if (codePath == std::to_string(CollaboratorType::OTHERS_TYPE)) {
return CollaboratorType::OTHERS_TYPE;
}
return 0;
}
sptr<IAbilityManagerCollaborator> AbilityManagerService::GetCollaborator(int32_t type)
{
if (!CheckCollaboratorType(type)) {
+2 -2
View File
@@ -110,10 +110,10 @@ public:
}
private:
bool isExtension_ = false;
uint32_t eventId_;
uint32_t eventId_ = 0;
uint32_t timeout_ = 0;
int runCount_ = 0;
int64_t param_;
int64_t param_ = 0;
std::shared_ptr<EventDataBase> eventData_;
TaskHandle eventTask_;
std::string taskName_;