一些问题修复

Signed-off-by: jsjzju <jinsenjun@huawei.com>
Change-Id: I35d801626cc3665af4642016a9315a6a07de50ae
This commit is contained in:
jsjzju
2024-11-13 01:55:11 +08:00
parent ce6273fbea
commit bbb7018ee3
19 changed files with 218 additions and 34 deletions
@@ -449,6 +449,11 @@ public:
return false;
}
virtual bool IsCallerKilling(const std::string& callerKey)
{
return false;
}
virtual void SetAppExceptionCallback(sptr<IRemoteObject> callback) {}
enum class Message {
@@ -502,6 +507,7 @@ public:
CLEAN_UIABILITY_BY_USER_REQUEST,
FORCE_KILL_APPLICATION_BY_ACCESS_TOKEN_ID = 49,
IS_PROCESS_ATTACHED,
IS_CALLER_KILLING,
ENABLE_START_PROCESS_FLAG_BY_USER_ID,
SET_APP_EXCEPTION_CALLBACK,
SET_KEEP_ALIVE_DKV,
@@ -400,6 +400,8 @@ public:
*/
virtual bool IsProcessAttached(sptr<IRemoteObject> token) override;
virtual bool IsCallerKilling(const std::string& callerKey) override;
virtual void SetAppExceptionCallback(sptr<IRemoteObject> callback) override;
private:
@@ -102,6 +102,7 @@ private:
int32_t HandleCleanAbilityByUserRequest(MessageParcel &data, MessageParcel &reply);
int32_t HandleIsProcessContainsOnlyUIAbility(MessageParcel &data, MessageParcel &reply);
int32_t HandleIsProcessAttached(MessageParcel &data, MessageParcel &reply);
int32_t HandleIsCallerKilling(MessageParcel &data, MessageParcel &reply);
int32_t HandleSetAppExceptionCallback(MessageParcel &data, MessageParcel &reply);
DISALLOW_COPY_AND_MOVE(AmsMgrStub);
};
@@ -899,6 +899,8 @@ public:
*/
bool IsProcessAttached(sptr<IRemoteObject> token) const;
bool IsCallerKilling(const std::string& callerKey) const;
/**
* Check whether the bundle is running.
*
@@ -1344,6 +1344,28 @@ bool AmsMgrProxy::IsProcessAttached(sptr<IRemoteObject> token)
return reply.ReadBool();
}
bool AmsMgrProxy::IsCallerKilling(const std::string& callerKey)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!WriteInterfaceToken(data)) {
TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
return false;
}
if (!data.WriteString(callerKey)) {
TAG_LOGE(AAFwkTag::APPMGR, "Failed to write callerKey");
return false;
}
auto ret = SendTransactCmd(static_cast<uint32_t>(IAmsMgr::Message::IS_CALLER_KILLING), data, reply, option);
if (ret != NO_ERROR) {
TAG_LOGE(AAFwkTag::APPMGR, "Send request failed, error code is %{public}d.", ret);
return false;
}
return reply.ReadBool();
}
void AmsMgrProxy::SetAppExceptionCallback(sptr<IRemoteObject> callback)
{
MessageParcel data;
@@ -213,6 +213,8 @@ int32_t AmsMgrStub::OnRemoteRequestInnerFourth(uint32_t code, MessageParcel &dat
return HandleKillProcessesByAccessTokenId(data, reply);
case static_cast<uint32_t>(IAmsMgr::Message::IS_PROCESS_ATTACHED):
return HandleIsProcessAttached(data, reply);
case static_cast<uint32_t>(IAmsMgr::Message::IS_CALLER_KILLING):
return HandleIsCallerKilling(data, reply);
case static_cast<uint32_t>(IAmsMgr::Message::SET_KEEP_ALIVE_DKV):
return HandleSetKeepAliveDkv(data, reply);
}
@@ -861,6 +863,18 @@ int32_t AmsMgrStub::HandleIsProcessAttached(MessageParcel &data, MessageParcel &
return NO_ERROR;
}
int32_t AmsMgrStub::HandleIsCallerKilling(MessageParcel &data, MessageParcel &reply)
{
HITRACE_METER(HITRACE_TAG_APP);
auto callerKey = data.ReadString();
auto isCallerKilling = IsCallerKilling(callerKey);
if (!reply.WriteBool(isCallerKilling)) {
TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result");
return ERR_INVALID_VALUE;
}
return NO_ERROR;
}
int32_t AmsMgrStub::HandleSetAppExceptionCallback(MessageParcel &data, MessageParcel &reply)
{
sptr<IRemoteObject> callback = data.ReadRemoteObject();
@@ -1399,6 +1399,19 @@ bool AppMgrClient::IsProcessAttached(sptr<IRemoteObject> token) const
return amsService->IsProcessAttached(token);
}
bool AppMgrClient::IsCallerKilling(const std::string& callerKey) const
{
sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
if (service == nullptr) {
return false;
}
sptr<IAmsMgr> amsService = service->GetAmsMgr();
if (amsService == nullptr) {
return false;
}
return amsService->IsCallerKilling(callerKey);
}
AppMgrResultCode AppMgrClient::IsAppRunning(const std::string &bundleName, int32_t appCloneIndex,
bool &isRunning)
{
@@ -568,6 +568,8 @@ public:
bool IsProcessAttached(sptr<IRemoteObject> token) const;
bool IsCallerKilling(const std::string& callerKey) const;
protected:
/**
* OnAbilityRequestDone, app manager service call this interface after ability request done.
@@ -655,6 +655,15 @@ bool AppScheduler::IsProcessAttached(sptr<IRemoteObject> token) const
return appMgrClient_->IsProcessAttached(token);
}
bool AppScheduler::IsCallerKilling(const std::string& callerKey) const
{
if (!appMgrClient_) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "appMgrClient is nullptr");
return false;
}
return appMgrClient_->IsCallerKilling(callerKey);
}
void AppScheduler::SetProcessCacheStatus(int32_t pid, bool isSupport)
{
if (!appMgrClient_) {
@@ -30,7 +30,6 @@
#include "session/host/include/zidl/session_interface.h"
#include "startup_util.h"
#include "ui_extension_utils.h"
#include "utils/ability_permission_util.h"
#ifdef SUPPORT_GRAPHICS
#include "ability_first_frame_state_observer_manager.h"
#endif
@@ -168,6 +167,12 @@ bool UIAbilityLifecycleManager::CheckSessionInfo(sptr<SessionInfo> sessionInfo)
TAG_LOGE(AAFwkTag::ABILITYMGR, "token's Descriptor: %{public}s", descriptor.c_str());
return false;
}
std::string callerKey = sessionInfo->want.GetStringParam(Want::PARAMS_REAL_CALLER_KEY);
bool isCallerKilling = IN_PROCESS_CALL(DelayedSingleton<AppScheduler>::GetInstance()->IsCallerKilling(callerKey));
if (isCallerKilling) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "caller is killing");
return false;
}
return true;
}
@@ -345,6 +350,11 @@ int UIAbilityLifecycleManager::NotifySCBToStartUIAbility(AbilityRequest &ability
abilityRequest.want.SetParam(IS_SHELL_CALL, AAFwk::PermissionVerification::GetInstance()->IsShellCall());
std::string callerKey = std::to_string(IPCSkeleton::GetCallingPid()) + ":" +
std::to_string(IPCSkeleton::GetCallingUid());
bool isCallerKilling = IN_PROCESS_CALL(DelayedSingleton<AppScheduler>::GetInstance()->IsCallerKilling(callerKey));
if (isCallerKilling) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "caller is killing");
return ERR_INVALID_VALUE;
}
abilityRequest.want.SetParam(Want::PARAMS_REAL_CALLER_KEY, callerKey);
std::lock_guard<ffrt::mutex> guard(sessionLock_);
// start ability with persistentId by dms
@@ -427,6 +427,8 @@ public:
*/
virtual bool IsProcessAttached(sptr<IRemoteObject> token) override;
virtual bool IsCallerKilling(const std::string& callerKey) override;
virtual void SetAppExceptionCallback(sptr<IRemoteObject> callback) override;
private:
@@ -1369,6 +1369,12 @@ public:
*/
bool IsProcessAttached(sptr<IRemoteObject> token) const;
/**
* Is a process of a ability killing
* @param indicates the ability
*/
bool IsCallerKilling(const std::string& callerKey) const;
/**
* @brief Notify abilityms app process pre cache
* @param pid process pid.
@@ -1423,9 +1429,8 @@ private:
*/
void RestartKeepAliveProcess(std::shared_ptr<AppRunningRecord> appRecord);
bool CheckLoadAbilityConditions(std::shared_ptr<AAFwk::Want> want,
std::shared_ptr<AbilityRuntime::LoadParam> loadParam, const std::shared_ptr<AbilityInfo> &abilityInfo,
const std::shared_ptr<ApplicationInfo> &appInfo);
bool CheckLoadAbilityConditions(const sptr<IRemoteObject> &token,
const std::shared_ptr<AbilityInfo> &abilityInfo, const std::shared_ptr<ApplicationInfo> &appInfo);
/**
* query bundle info for the given bundleName
@@ -28,9 +28,9 @@ class KillingProcessManager {
public:
static KillingProcessManager& GetInstance();
~KillingProcessManager() = default;
bool IsCallerKilling(std::string callerKey) const;
void AddKillingCallerKey(std::string callerKey);
void RemoveKillingCallerKey(std::string callerKey);
bool IsCallerKilling(const std::string& callerKey) const;
void AddKillingCallerKey(const std::string& callerKey);
void RemoveKillingCallerKey(const std::string& callerKey);
private:
KillingProcessManager() = default;
@@ -752,6 +752,15 @@ bool AmsMgrScheduler::IsProcessAttached(sptr<IRemoteObject> token)
return amsMgrServiceInner_->IsProcessAttached(token);
}
bool AmsMgrScheduler::IsCallerKilling(const std::string& callerKey)
{
if (!IsReady()) {
TAG_LOGE(AAFwkTag::APPMGR, "AmsMgrService is not ready.");
return false;
}
return amsMgrServiceInner_->IsCallerKilling(callerKey);
}
void AmsMgrScheduler::SetAppExceptionCallback(sptr<IRemoteObject> callback)
{
if (!IsReady()) {
+22 -14
View File
@@ -623,9 +623,8 @@ void AppMgrServiceInner::LoadAbility(std::shared_ptr<AbilityInfo> abilityInfo, s
TAG_LOGE(AAFwkTag::APPMGR, "null loadParam");
return;
}
if (!CheckLoadAbilityConditions(want, loadParam, abilityInfo, appInfo)) {
if (!CheckLoadAbilityConditions(loadParam->token, abilityInfo, appInfo)) {
TAG_LOGE(AAFwkTag::APPMGR, "checkLoadAbilityConditions fail");
NotifyLoadAbilityFailed(loadParam->token);
return;
}
if (abilityInfo->type == AbilityType::PAGE) {
@@ -648,8 +647,11 @@ void AppMgrServiceInner::LoadAbility(std::shared_ptr<AbilityInfo> abilityInfo, s
BundleInfo bundleInfo;
HapModuleInfo hapModuleInfo;
int32_t appIndex = 0;
std::string callerKey;
if (want != nullptr) {
(void)AbilityRuntime::StartupUtil::GetAppIndex(*want, appIndex);
callerKey = want->GetStringParam(Want::PARAMS_REAL_CALLER_KEY);
want->RemoveParam(Want::PARAMS_REAL_CALLER_KEY);
}
if (!GetBundleAndHapInfo(*abilityInfo, appInfo, bundleInfo, hapModuleInfo, appIndex)) {
TAG_LOGE(AAFwkTag::APPMGR, "getBundleAndHapInfo fail");
@@ -691,6 +693,11 @@ void AppMgrServiceInner::LoadAbility(std::shared_ptr<AbilityInfo> abilityInfo, s
if (!appRecord) {
TAG_LOGD(AAFwkTag::APPMGR, "appRecord null");
if (KillingProcessManager::GetInstance().IsCallerKilling(callerKey)) {
TAG_LOGE(AAFwkTag::APPMGR, "caller is killing");
NotifyLoadAbilityFailed(loadParam->token);
return;
}
bool appExistFlag = appRunningManager_->CheckAppRunningRecordIsExistByBundleName(bundleInfo.name);
bool appMultiUserExistFlag = appRunningManager_->CheckAppRunningRecordIsExistByUid(bundleInfo.uid);
if (!appMultiUserExistFlag) {
@@ -827,11 +834,10 @@ void AppMgrServiceInner::RemoveUIExtensionLauncherItem(std::shared_ptr<AppRunnin
appRunningManager_->RemoveUIExtensionLauncherItemById(uiExtensionAbilityId);
}
bool AppMgrServiceInner::CheckLoadAbilityConditions(std::shared_ptr<AAFwk::Want> want,
std::shared_ptr<AbilityRuntime::LoadParam> loadParam, const std::shared_ptr<AbilityInfo> &abilityInfo,
const std::shared_ptr<ApplicationInfo> &appInfo)
bool AppMgrServiceInner::CheckLoadAbilityConditions(const sptr<IRemoteObject> &token,
const std::shared_ptr<AbilityInfo> &abilityInfo, const std::shared_ptr<ApplicationInfo> &appInfo)
{
if (!loadParam || !loadParam->token || !abilityInfo || !appInfo) {
if (!token || !abilityInfo || !appInfo) {
TAG_LOGE(AAFwkTag::APPMGR, "param error");
return false;
}
@@ -843,14 +849,6 @@ bool AppMgrServiceInner::CheckLoadAbilityConditions(std::shared_ptr<AAFwk::Want>
TAG_LOGE(AAFwkTag::APPMGR, "abilityInfo and appInfo have diff appName");
return false;
}
if (want) {
std::string callerKey = want->GetStringParam(Want::PARAMS_REAL_CALLER_KEY);
want->RemoveParam(Want::PARAMS_REAL_CALLER_KEY);
if (!callerKey.empty() && KillingProcessManager::GetInstance().IsCallerKilling(callerKey)) {
TAG_LOGE(AAFwkTag::APPMGR, "caller is killing");
return false;
}
}
return true;
}
@@ -8430,6 +8428,16 @@ bool AppMgrServiceInner::IsProcessAttached(sptr<IRemoteObject> token) const
return appRecord->IsProcessAttached();
}
bool AppMgrServiceInner::IsCallerKilling(const std::string& callerKey) const
{
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
if (IPCSkeleton::GetCallingUid() != FOUNDATION_UID) {
TAG_LOGE(AAFwkTag::APPMGR, "Not foundation call.");
return false;
}
return KillingProcessManager::GetInstance().IsCallerKilling(callerKey);
}
int32_t AppMgrServiceInner::GetSupportedProcessCachePids(const std::string &bundleName,
std::vector<int32_t> &pidList)
{
@@ -31,13 +31,13 @@ KillingProcessManager& KillingProcessManager::GetInstance()
return instance;
}
bool KillingProcessManager::IsCallerKilling(std::string callerKey) const
bool KillingProcessManager::IsCallerKilling(const std::string& callerKey) const
{
std::lock_guard<ffrt::mutex> lock(mutex_);
return killingCallerKeySet_.find(callerKey) != killingCallerKeySet_.end();
}
void KillingProcessManager::AddKillingCallerKey(std::string callerKey)
void KillingProcessManager::AddKillingCallerKey(const std::string& callerKey)
{
auto taskHandler = AAFwk::TaskHandlerWrap::GetFfrtHandler();
if (taskHandler == nullptr) {
@@ -54,6 +54,7 @@ void KillingProcessManager::AddKillingCallerKey(std::string callerKey)
auto ret = killingCallerKeySet_.insert(callerKey);
if (!ret.second) {
TAG_LOGI(AAFwkTag::APPMGR, "already inserted");
return;
}
}
auto task = [callerKey] () {
@@ -62,7 +63,7 @@ void KillingProcessManager::AddKillingCallerKey(std::string callerKey)
taskHandler->SubmitTask(task, "clearCallerKey", CLEAR_CALLER_KEY_DELAY_TIME);
}
void KillingProcessManager::RemoveKillingCallerKey(std::string callerKey)
void KillingProcessManager::RemoveKillingCallerKey(const std::string& callerKey)
{
if (callerKey.empty()) {
TAG_LOGE(AAFwkTag::APPMGR, "invalid callerKey");
@@ -2060,6 +2060,71 @@ HWTEST_F(AmsMgrSchedulerSecondTest, AmsMgrSchedulerSecondTest_IsProcessAttached_
EXPECT_FALSE(ret);
TAG_LOGI(AAFwkTag::TEST, "AmsMgrSchedulerSecondTest_IsProcessAttached_003 end");
}
/*
* @tc.name: AmsMgrSchedulerSecondTest_IsCallerKilling_001
* @tc.desc: Test IsCallerKilling
* @tc.type: FUNC
*/
HWTEST_F(AmsMgrSchedulerSecondTest, AmsMgrSchedulerSecondTest_IsCallerKilling_001, TestSize.Level1)
{
TAG_LOGI(AAFwkTag::TEST, "AmsMgrSchedulerSecondTest_IsCallerKilling_001 start");
auto appMgrServiceInner = std::make_shared<MockAppMgrServiceInner>();
std::shared_ptr<AmsMgrScheduler> amsMgrScheduler =
std::make_shared<AmsMgrScheduler>(appMgrServiceInner, nullptr);
/**
* @tc.steps: step1. amsMgrScheduler isReady false
* @tc.expected: step1. expect ERR_INVALID_OPERATION
*/
auto ret = amsMgrScheduler->IsCallerKilling("");
EXPECT_FALSE(ret);
TAG_LOGI(AAFwkTag::TEST, "AmsMgrSchedulerSecondTest_IsCallerKilling_001 end");
}
/*
* @tc.name: AmsMgrSchedulerSecondTest_IsCallerKilling_002
* @tc.desc: Test IsCallerKilling
* @tc.type: FUNC
*/
HWTEST_F(AmsMgrSchedulerSecondTest, AmsMgrSchedulerSecondTest_IsCallerKilling_002, TestSize.Level1)
{
TAG_LOGI(AAFwkTag::TEST, "AmsMgrSchedulerSecondTest_IsCallerKilling_002 start");
auto appMgrServiceInner = std::make_shared<MockAppMgrServiceInner>();
std::shared_ptr<AmsMgrScheduler> amsMgrScheduler =
std::make_shared<AmsMgrScheduler>(appMgrServiceInner, taskHandler_);
/**
* @tc.steps: step1. amsMgrScheduler isReady false
* @tc.expected: step1. expect ERR_INVALID_OPERATION
*/
IPCSkeleton::SetCallingUid(-1);
auto ret = amsMgrScheduler->IsCallerKilling("");
EXPECT_FALSE(ret);
TAG_LOGI(AAFwkTag::TEST, "AmsMgrSchedulerSecondTest_IsCallerKilling_002 end");
}
/*
* @tc.name: AmsMgrSchedulerSecondTest_IsCallerKilling_003
* @tc.desc: Test IsCallerKilling
* @tc.type: FUNC
*/
HWTEST_F(AmsMgrSchedulerSecondTest, AmsMgrSchedulerSecondTest_IsCallerKilling_003, TestSize.Level1)
{
TAG_LOGI(AAFwkTag::TEST, "AmsMgrSchedulerSecondTest_IsCallerKilling_003 start");
auto appMgrServiceInner = std::make_shared<MockAppMgrServiceInner>();
std::shared_ptr<AmsMgrScheduler> amsMgrScheduler =
std::make_shared<AmsMgrScheduler>(appMgrServiceInner, taskHandler_);
/**
* @tc.steps: step1. amsMgrScheduler isReady false
* @tc.expected: step1. expect ERR_INVALID_OPERATION
*/
IPCSkeleton::SetCallingUid(Constants::FOUNDATION_UID);
auto ret = amsMgrScheduler->IsCallerKilling("");
EXPECT_FALSE(ret);
TAG_LOGI(AAFwkTag::TEST, "AmsMgrSchedulerSecondTest_IsCallerKilling_003 end");
}
} // AppExecFwk
} // OHOS
@@ -194,5 +194,19 @@ HWTEST_F(AppMgrClientFirstTest, CleanAbilityByUserRequest_001, TestSize.Level0)
EXPECT_TRUE(result != true);
TAG_LOGI(AAFwkTag::TEST, "CleanAbilityByUserRequest_001 end");
}
/**
* @tc.name: IsCallerKilling_001
* @tc.desc: AppMgrClient test for IsCallerKilling.
* @tc.type: FUNC
*/
HWTEST_F(AppMgrClientFirstTest, IsCallerKilling_001, TestSize.Level0)
{
TAG_LOGI(AAFwkTag::TEST, "IsCallerKilling_001 start");
auto appMgrClient = std::make_unique<AppMgrClient>();
auto result = appMgrClient->IsCallerKilling("");
EXPECT_TRUE(result != true);
TAG_LOGI(AAFwkTag::TEST, "IsCallerKilling_001 end");
}
} // namespace AppExecFwk
} // namespace OHOS
@@ -434,24 +434,23 @@ HWTEST_F(AppMgrServiceInnerTest, CheckLoadAbilityConditions_001, TestSize.Level0
auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
EXPECT_NE(appMgrServiceInner, nullptr);
auto loadParam = std::make_shared<AbilityRuntime::LoadParam>();
loadParam->token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
OHOS::sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
appMgrServiceInner->CheckLoadAbilityConditions(nullptr, nullptr, nullptr, nullptr);
appMgrServiceInner->CheckLoadAbilityConditions(nullptr, nullptr, nullptr);
appMgrServiceInner->CheckLoadAbilityConditions(nullptr, nullptr, abilityInfo_, nullptr);
appMgrServiceInner->CheckLoadAbilityConditions(nullptr, abilityInfo_, nullptr);
appMgrServiceInner->CheckLoadAbilityConditions(nullptr, nullptr, nullptr, applicationInfo_);
appMgrServiceInner->CheckLoadAbilityConditions(nullptr, nullptr, applicationInfo_);
appMgrServiceInner->CheckLoadAbilityConditions(nullptr, loadParam, nullptr, nullptr);
appMgrServiceInner->CheckLoadAbilityConditions(token, nullptr, nullptr);
appMgrServiceInner->CheckLoadAbilityConditions(nullptr, loadParam, abilityInfo_, nullptr);
appMgrServiceInner->CheckLoadAbilityConditions(token, abilityInfo_, nullptr);
appMgrServiceInner->CheckLoadAbilityConditions(nullptr, nullptr, abilityInfo_, applicationInfo_);
appMgrServiceInner->CheckLoadAbilityConditions(nullptr, abilityInfo_, applicationInfo_);
appMgrServiceInner->CheckLoadAbilityConditions(nullptr, loadParam, nullptr, applicationInfo_);
appMgrServiceInner->CheckLoadAbilityConditions(token, nullptr, applicationInfo_);
appMgrServiceInner->CheckLoadAbilityConditions(nullptr, loadParam, abilityInfo_, applicationInfo_);
appMgrServiceInner->CheckLoadAbilityConditions(token, abilityInfo_, applicationInfo_);
EXPECT_NE(appMgrServiceInner, nullptr);
TAG_LOGI(AAFwkTag::TEST, "CheckLoadAbilityConditions_001 end");