mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-24 22:21:36 -04:00
web
Signed-off-by: savior-xzh <xuzheheng2@huawei.com> Change-Id: I82d8d7d5abef2324f342024ac5012af031cfd4e8
This commit is contained in:
@@ -321,6 +321,17 @@ public:
|
||||
*/
|
||||
virtual void BlockProcessCacheByPids(const std::vector<int32_t> &pids) {}
|
||||
|
||||
/**
|
||||
* whether killed for upgrade web.
|
||||
*
|
||||
* @param bundleName the bundle name is killed for upgrade web.
|
||||
* @return Returns true is killed for upgrade web, others return false.
|
||||
*/
|
||||
virtual bool IsKilledForUpgradeWeb(const std::string &bundleName)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
enum class Message {
|
||||
LOAD_ABILITY = 0,
|
||||
TERMINATE_ABILITY,
|
||||
@@ -367,6 +378,7 @@ public:
|
||||
NOTIFY_APP_MGR_RECORD_EXIT_REASON,
|
||||
ATTACHED_TO_STATUS_BAR,
|
||||
BLOCK_PROCESS_CACHE_BY_PIDS,
|
||||
IS_KILLED_FOR_UPGRADE_WEB,
|
||||
};
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
|
||||
@@ -290,6 +290,14 @@ public:
|
||||
*/
|
||||
virtual void BlockProcessCacheByPids(const std::vector<int32_t> &pids) override;
|
||||
|
||||
/**
|
||||
* whether killed for upgrade web.
|
||||
*
|
||||
* @param bundleName the bundle name is killed for upgrade web.
|
||||
* @return Returns true is killed for upgrade web, others return false.
|
||||
*/
|
||||
virtual bool IsKilledForUpgradeWeb(const std::string &bundleName) override;
|
||||
|
||||
private:
|
||||
bool WriteInterfaceToken(MessageParcel &data);
|
||||
int32_t SendTransactCmd(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
|
||||
|
||||
@@ -93,6 +93,7 @@ private:
|
||||
int32_t OnRemoteRequestInnerThird(uint32_t code, MessageParcel &data,
|
||||
MessageParcel &reply, MessageOption &option);
|
||||
int32_t HandleBlockProcessCacheByPids(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleIsKilledForUpgradeWeb(MessageParcel &data, MessageParcel &reply);
|
||||
DISALLOW_COPY_AND_MOVE(AmsMgrStub);
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
|
||||
@@ -775,6 +775,15 @@ public:
|
||||
* @param pids the pids of the processes that should be blocked.
|
||||
*/
|
||||
virtual AppMgrResultCode BlockProcessCacheByPids(const std::vector<int32_t> &pids);
|
||||
|
||||
/**
|
||||
* whether killed for upgrade web.
|
||||
*
|
||||
* @param bundleName the bundle name is killed for upgrade web.
|
||||
* @return Returns true is killed for upgrade web, others return false.
|
||||
*/
|
||||
bool IsKilledForUpgradeWeb(const std::string &bundleName);
|
||||
|
||||
private:
|
||||
void SetServiceManager(std::unique_ptr<AppServiceManager> serviceMgr);
|
||||
/**
|
||||
|
||||
@@ -1170,5 +1170,27 @@ void AmsMgrProxy::BlockProcessCacheByPids(const std::vector<int32_t> &pids)
|
||||
}
|
||||
TAG_LOGD(AAFwkTag::APPMGR, "end");
|
||||
}
|
||||
|
||||
bool AmsMgrProxy::IsKilledForUpgradeWeb(const std::string &bundleName)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
if (!WriteInterfaceToken(data)) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteString(bundleName)) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "parcel WriteString failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto ret = SendTransactCmd(static_cast<uint32_t>(IAmsMgr::Message::IS_KILLED_FOR_UPGRADE_WEB), 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();
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -188,6 +188,8 @@ int32_t AmsMgrStub::OnRemoteRequestInnerThird(uint32_t code, MessageParcel &data
|
||||
return 0;
|
||||
case static_cast<uint32_t>(IAmsMgr::Message::BLOCK_PROCESS_CACHE_BY_PIDS):
|
||||
return HandleBlockProcessCacheByPids(data, reply);
|
||||
case static_cast<uint32_t>(IAmsMgr::Message::IS_KILLED_FOR_UPGRADE_WEB):
|
||||
return HandleIsKilledForUpgradeWeb(data, reply);
|
||||
}
|
||||
return AAFwk::ERR_CODE_NOT_EXIST;
|
||||
}
|
||||
@@ -747,5 +749,22 @@ ErrCode AmsMgrStub::HandleBlockProcessCacheByPids(MessageParcel &data, MessagePa
|
||||
BlockProcessCacheByPids(pids);
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
int32_t AmsMgrStub::HandleIsKilledForUpgradeWeb(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::APPMGR, "Called.");
|
||||
auto bundleName = data.ReadString();
|
||||
if (bundleName.empty()) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "Bundle name is empty.");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
|
||||
auto result = IsKilledForUpgradeWeb(bundleName);
|
||||
if (!reply.WriteBool(result)) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
return NO_ERROR;
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -1250,5 +1250,21 @@ AppMgrResultCode AppMgrClient::BlockProcessCacheByPids(const std::vector<int32_t
|
||||
}
|
||||
return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
|
||||
bool AppMgrClient::IsKilledForUpgradeWeb(const std::string &bundleName)
|
||||
{
|
||||
sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
|
||||
if (service == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "Service is nullptr.");
|
||||
return false;
|
||||
}
|
||||
sptr<IAmsMgr> amsService = service->GetAmsMgr();
|
||||
if (amsService == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "amsService is nullptr.");
|
||||
return false;
|
||||
}
|
||||
TAG_LOGD(AAFwkTag::APPMGR, "call");
|
||||
return amsService->IsKilledForUpgradeWeb(bundleName);
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -436,6 +436,8 @@ public:
|
||||
|
||||
void BlockProcessCacheByPids(const std::vector<int32_t>& pids);
|
||||
|
||||
bool IsKilledForUpgradeWeb(const std::string &bundleName);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* OnAbilityRequestDone, app manager service call this interface after ability request done.
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "ability_manager_service.h"
|
||||
#include "ability_util.h"
|
||||
#include "hilog_tag_wrapper.h"
|
||||
#include "parameters.h"
|
||||
#include "uri_permission_manager_client.h"
|
||||
|
||||
namespace OHOS {
|
||||
@@ -25,6 +26,9 @@ namespace AAFwk {
|
||||
namespace {
|
||||
constexpr const char* KEY_TOKEN = "accessTokenId";
|
||||
constexpr const char* KEY_UID = "uid";
|
||||
constexpr const char* WEB_BUNDLE_NAME = "com.ohos.nweb";
|
||||
constexpr const char* ARKWEB_CORE_PACKAGE_NAME = "persist.arkwebcore.package_name";
|
||||
|
||||
}
|
||||
AbilityBundleEventCallback::AbilityBundleEventCallback(
|
||||
std::shared_ptr<TaskHandlerWrap> taskHandler, std::shared_ptr<AbilityAutoStartupService> abilityAutoStartupService)
|
||||
@@ -63,7 +67,10 @@ void AbilityBundleEventCallback::OnReceiveEvent(const EventFwk::CommonEventData
|
||||
// install or uninstall module/bundle
|
||||
HandleUpdatedModuleInfo(bundleName, uid);
|
||||
} else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_CHANGED) {
|
||||
HandleRestartResidentProcessDependedOnWeb();
|
||||
if (bundleName == WEB_BUNDLE_NAME ||
|
||||
bundleName == system::GetParameter(ARKWEB_CORE_PACKAGE_NAME, "false")) {
|
||||
HandleRestartResidentProcessDependedOnWeb();
|
||||
}
|
||||
HandleUpdatedModuleInfo(bundleName, uid);
|
||||
HandleAppUpgradeCompleted(bundleName, uid);
|
||||
if (abilityAutoStartupService_ == nullptr) {
|
||||
|
||||
@@ -2138,6 +2138,10 @@ void AbilityConnectManager::KeepAbilityAlive(const std::shared_ptr<AbilityRecord
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (DelayedSingleton<AppScheduler>::GetInstance()->IsKilledForUpgradeWeb(abilityInfo.bundleName)) {
|
||||
TAG_LOGI(AAFwkTag::ABILITYMGR, "bundle is killed for upgrade web");
|
||||
return;
|
||||
}
|
||||
if (DelayedSingleton<AppScheduler>::GetInstance()->IsMemorySizeSufficent() ||
|
||||
IsLauncher(abilityRecord) || abilityRecord->IsSceneBoard() ||
|
||||
AppUtils::GetInstance().IsAllowResidentInExtremeMemory(abilityInfo.bundleName, abilityInfo.name)) {
|
||||
|
||||
@@ -11017,6 +11017,7 @@ void AbilityManagerService::NotifyFrozenProcessByRSS(const std::vector<int32_t>
|
||||
|
||||
void AbilityManagerService::HandleRestartResidentProcessDependedOnWeb()
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::ABILITYMGR, "call");
|
||||
auto appMgr = GetAppMgr();
|
||||
CHECK_POINTER_LOG(appMgr, "get appMgr fail");
|
||||
appMgr->RestartResidentProcessDependedOnWeb();
|
||||
|
||||
@@ -607,5 +607,14 @@ void AppScheduler::BlockProcessCacheByPids(const std::vector<int32_t> &pids)
|
||||
CHECK_POINTER(appMgrClient_);
|
||||
appMgrClient_->BlockProcessCacheByPids(pids);
|
||||
}
|
||||
|
||||
bool AppScheduler::IsKilledForUpgradeWeb(const std::string &bundleName)
|
||||
{
|
||||
if (!appMgrClient_) {
|
||||
TAG_LOGE(AAFwkTag::ABILITYMGR, "appMgrClient is nullptr");
|
||||
return false;
|
||||
}
|
||||
return appMgrClient_->IsKilledForUpgradeWeb(bundleName);
|
||||
}
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -298,6 +298,14 @@ public:
|
||||
|
||||
virtual void BlockProcessCacheByPids(const std::vector<int32_t> &pids) override;
|
||||
|
||||
/**
|
||||
* whether killed for upgrade web.
|
||||
*
|
||||
* @param bundleName the bundle name is killed for upgrade web.
|
||||
* @return Returns true is killed for upgrade web, others return false.
|
||||
*/
|
||||
virtual bool IsKilledForUpgradeWeb(const std::string &bundleName) override;
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Judge whether the application service is ready.
|
||||
|
||||
@@ -1137,6 +1137,9 @@ public:
|
||||
void RestartResidentProcessDependedOnWeb();
|
||||
|
||||
void BlockProcessCacheByPids(const std::vector<int32_t>& pids);
|
||||
|
||||
bool IsKilledForUpgradeWeb(const std::string &bundleName) const;
|
||||
|
||||
private:
|
||||
|
||||
std::string FaultTypeToString(FaultDataType type);
|
||||
|
||||
@@ -38,12 +38,13 @@ public:
|
||||
~ExitResidentProcessManager();
|
||||
bool IsMemorySizeSufficent() const;
|
||||
bool RecordExitResidentBundleName(const std::string &bundleName);
|
||||
bool RecordExitResidentBundleDependedOnWeb(const std::string &bundleName);
|
||||
void RecordExitResidentBundleDependedOnWeb(const std::string &bundleName);
|
||||
int32_t HandleMemorySizeInSufficent();
|
||||
int32_t HandleMemorySizeSufficent(std::vector<std::string>& bundleNames);
|
||||
void HandleExitResidentBundleDependedOnWeb(std::vector<std::string>& bundleNames);
|
||||
void QueryExitBundleInfos(const std::vector<std::string>& exitBundleNames,
|
||||
std::vector<AppExecFwk::BundleInfo>& exitBundleInfos);
|
||||
bool IsKilledForUpgradeWeb(const std::string &bundleName) const;
|
||||
|
||||
private:
|
||||
ExitResidentProcessManager();
|
||||
|
||||
@@ -645,5 +645,14 @@ void AmsMgrScheduler::BlockProcessCacheByPids(const std::vector<int32_t> &pids)
|
||||
};
|
||||
amsHandler_->SubmitTask(blockProcCacheFunc, TASK_BLOCK_PROCESS_CACHE_BY_PIDS);
|
||||
}
|
||||
|
||||
bool AmsMgrScheduler::IsKilledForUpgradeWeb(const std::string &bundleName)
|
||||
{
|
||||
if (!IsReady()) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "AmsMgrService is not ready.");
|
||||
return false;
|
||||
}
|
||||
return amsMgrServiceInner_->IsKilledForUpgradeWeb(bundleName);
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -1569,8 +1569,8 @@ int32_t AppMgrService::NotifyProcessDependedOnWeb()
|
||||
void AppMgrService::KillProcessDependedOnWeb()
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::APPMGR, "called.");
|
||||
if (!AAFwk::PermissionVerification::GetInstance()->IsSACall()) {
|
||||
TAG_LOGE(AAFwkTag::ABILITYMGR, "caller is not SA.");
|
||||
if (!AAFwk::PermissionVerification::GetInstance()->VerifyKillProcessDependedOnWebPermission()) {
|
||||
TAG_LOGE(AAFwkTag::ABILITYMGR, "caller have not permission.");
|
||||
return;
|
||||
}
|
||||
if (!appMgrServiceInner_) {
|
||||
|
||||
@@ -6051,6 +6051,10 @@ void AppMgrServiceInner::ClearAppRunningDataForKeepAlive(const std::shared_ptr<A
|
||||
}
|
||||
|
||||
if (appRecord->IsKeepAliveApp()) {
|
||||
if (ExitResidentProcessManager::GetInstance().IsKilledForUpgradeWeb(appRecord->GetBundleName())) {
|
||||
TAG_LOGI(AAFwkTag::APPMGR, "Is killed for upgrade web");
|
||||
return;
|
||||
}
|
||||
if (!AAFwk::AppUtils::GetInstance().IsAllowResidentInExtremeMemory(appRecord->GetBundleName()) &&
|
||||
ExitResidentProcessManager::GetInstance().RecordExitResidentBundleName(appRecord->GetBundleName())) {
|
||||
TAG_LOGI(AAFwkTag::APPMGR, "memory size is insufficent, record exit resident process info");
|
||||
@@ -7074,17 +7078,17 @@ void AppMgrServiceInner::KillProcessDependedOnWeb()
|
||||
CHECK_POINTER_AND_RETURN_LOG(appRunningManager_, "appRunningManager_ is nullptr");
|
||||
for (const auto &item : appRunningManager_->GetAppRunningRecordMap()) {
|
||||
const auto &appRecord = item.second;
|
||||
if (!appRecord || !appRecord->GetSpawned() || !appRecord->GetPriorityObject()) {
|
||||
if (!appRecord || !appRecord->GetSpawned() ||
|
||||
!appRecord->GetPriorityObject() || !appRecord->IsDependedOnArkWeb()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (appRecord->IsDependedOnArkWeb()) {
|
||||
std::string bundleName = appRecord->GetBundleName();
|
||||
pid_t pid = appRecord->GetPriorityObject()->GetPid();
|
||||
appRecord->IsKeepAliveApp() &&
|
||||
ExitResidentProcessManager::GetInstance().RecordExitResidentBundleDependedOnWeb(bundleName);
|
||||
KillProcessByPid(pid, "KillProcessDependedOnWeb");
|
||||
std::string bundleName = appRecord->GetBundleName();
|
||||
pid_t pid = appRecord->GetPriorityObject()->GetPid();
|
||||
if (appRecord->IsKeepAliveApp()) {
|
||||
ExitResidentProcessManager::GetInstance().RecordExitResidentBundleDependedOnWeb(bundleName);
|
||||
}
|
||||
KillProcessByPid(pid, "KillProcessDependedOnWeb");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7120,5 +7124,15 @@ void AppMgrServiceInner::BlockProcessCacheByPids(const std::vector<int32_t>& pid
|
||||
appRecord->SetProcessCacheBlocked(true);
|
||||
}
|
||||
}
|
||||
|
||||
bool AppMgrServiceInner::IsKilledForUpgradeWeb(const std::string &bundleName) const
|
||||
{
|
||||
auto callerUid = IPCSkeleton::GetCallingUid();
|
||||
if (callerUid != FOUNDATION_UID) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "Not foundation call.");
|
||||
return false;
|
||||
}
|
||||
return ExitResidentProcessManager::GetInstance().IsKilledForUpgradeWeb(bundleName);
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
@@ -52,12 +52,11 @@ bool ExitResidentProcessManager::RecordExitResidentBundleName(const std::string
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ExitResidentProcessManager::RecordExitResidentBundleDependedOnWeb(const std::string &bundleName)
|
||||
void ExitResidentProcessManager::RecordExitResidentBundleDependedOnWeb(const std::string &bundleName)
|
||||
{
|
||||
std::lock_guard<ffrt::mutex> lock(webMutexLock_);
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "call");
|
||||
exitResidentBundlesDependedOnWeb_.emplace_back(bundleName);
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t ExitResidentProcessManager::HandleMemorySizeInSufficent()
|
||||
@@ -119,5 +118,23 @@ void ExitResidentProcessManager::QueryExitBundleInfos(const std::vector<std::str
|
||||
exitBundleInfos.emplace_back(bundleInfo);
|
||||
}
|
||||
}
|
||||
|
||||
bool ExitResidentProcessManager::IsKilledForUpgradeWeb(const std::string &bundleName) const
|
||||
{
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "call");
|
||||
std::vector<std::string> bundleNames;
|
||||
{
|
||||
std::lock_guard<ffrt::mutex> lock(webMutexLock_);
|
||||
bundleNames = exitResidentBundlesDependedOnWeb_;
|
||||
}
|
||||
for (const auto &innerBundleName : bundleNames) {
|
||||
if (innerBundleName == bundleName) {
|
||||
TAG_LOGD(AAFwkTag::APPMGR, "Is killed for upgrade web.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
TAG_LOGD(AAFwkTag::APPMGR, "Not killed for upgrade web.");
|
||||
return false;
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -58,6 +58,7 @@ constexpr const char* PERMISSION_SET_PROCESS_CACHE_STATE = "ohos.permission.SET_
|
||||
constexpr const char* PERMISSION_PRELOAD_UI_EXTENSION_ABILITY = "ohos.permission.PRELOAD_UI_EXTENSION_ABILITY";
|
||||
constexpr const char* PERMISSION_PRE_START_ATOMIC_SERVICE = "ohos.permission.PRE_START_ATOMIC_SERVICE";
|
||||
constexpr const char* PERMISSION_KILL_APP_PROCESSES = "ohos.permission.KILL_APP_PROCESSES";
|
||||
constexpr const char* PERMISSION_KILL_PROCESS_DEPENDED_ON_WEB = "ohos.permission.KILL_PROCESS_DEPENDED_ON_ARKWEB";
|
||||
} // namespace PermissionConstants
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -101,6 +101,8 @@ struct VerificationInfo {
|
||||
|
||||
bool VerifyPreStartAtomicServicePermission() const;
|
||||
|
||||
bool VerifyKillProcessDependedOnWebPermission() const;
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_MOVE(PermissionVerification);
|
||||
|
||||
|
||||
@@ -484,5 +484,15 @@ bool PermissionVerification::VerifyPreStartAtomicServicePermission() const
|
||||
PermissionConstants::PERMISSION_PRE_START_ATOMIC_SERVICE);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PermissionVerification::VerifyKillProcessDependedOnWebPermission() const
|
||||
{
|
||||
if (IsSACall() && VerifyCallingPermission(PermissionConstants::PERMISSION_KILL_PROCESS_DEPENDED_ON_WEB)) {
|
||||
TAG_LOGD(AAFwkTag::APPMGR, "Permission verification succeeded.");
|
||||
return true;
|
||||
}
|
||||
TAG_LOGW(AAFwkTag::APPMGR, "Permission verification failed");
|
||||
return false;
|
||||
}
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
|
||||
Reference in New Issue
Block a user