1eace7efcSopenharmony_ci/* 2eace7efcSopenharmony_ci * Copyright (c) 2021-2024 Huawei Device Co., Ltd. 3eace7efcSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4eace7efcSopenharmony_ci * you may not use this file except in compliance with the License. 5eace7efcSopenharmony_ci * You may obtain a copy of the License at 6eace7efcSopenharmony_ci * 7eace7efcSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8eace7efcSopenharmony_ci * 9eace7efcSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10eace7efcSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11eace7efcSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12eace7efcSopenharmony_ci * See the License for the specific language governing permissions and 13eace7efcSopenharmony_ci * limitations under the License. 14eace7efcSopenharmony_ci */ 15eace7efcSopenharmony_ci 16eace7efcSopenharmony_ci#include "app_mgr_service.h" 17eace7efcSopenharmony_ci 18eace7efcSopenharmony_ci#include <chrono> 19eace7efcSopenharmony_ci#include <cstdlib> 20eace7efcSopenharmony_ci#include <nlohmann/json.hpp> 21eace7efcSopenharmony_ci#include <sys/types.h> 22eace7efcSopenharmony_ci#include <thread> 23eace7efcSopenharmony_ci 24eace7efcSopenharmony_ci#include "ability_manager_errors.h" 25eace7efcSopenharmony_ci#include "app_death_recipient.h" 26eace7efcSopenharmony_ci#include "app_mgr_constants.h" 27eace7efcSopenharmony_ci#include "datetime_ex.h" 28eace7efcSopenharmony_ci#include "freeze_util.h" 29eace7efcSopenharmony_ci#include "global_constant.h" 30eace7efcSopenharmony_ci#include "hilog_tag_wrapper.h" 31eace7efcSopenharmony_ci#include "hitrace_meter.h" 32eace7efcSopenharmony_ci#include "in_process_call_wrapper.h" 33eace7efcSopenharmony_ci#include "ipc_skeleton.h" 34eace7efcSopenharmony_ci#include "perf_profile.h" 35eace7efcSopenharmony_ci#include "permission_constants.h" 36eace7efcSopenharmony_ci#include "permission_verification.h" 37eace7efcSopenharmony_ci#include "system_ability_definition.h" 38eace7efcSopenharmony_ci#include "accesstoken_kit.h" 39eace7efcSopenharmony_ci#include "app_mgr_service_const.h" 40eace7efcSopenharmony_ci#include "app_mgr_service_dump_error_code.h" 41eace7efcSopenharmony_ci#include "cache_process_manager.h" 42eace7efcSopenharmony_ci 43eace7efcSopenharmony_cinamespace OHOS { 44eace7efcSopenharmony_cinamespace AppExecFwk { 45eace7efcSopenharmony_ciconstexpr const char* OPTION_KEY_HELP = "-h"; 46eace7efcSopenharmony_ciconstexpr const char* OPTION_KEY_DUMP_IPC = "--ipc"; 47eace7efcSopenharmony_ciconstexpr const char* OPTION_KEY_DUMP_FFRT = "--ffrt"; 48eace7efcSopenharmony_ciconst int32_t HIDUMPER_SERVICE_UID = 1212; 49eace7efcSopenharmony_ciconstexpr const int INDEX_PID = 1; 50eace7efcSopenharmony_ciconstexpr const int INDEX_CMD = 2; 51eace7efcSopenharmony_ciconstexpr const size_t VALID_DUMP_IPC_ARG_SIZE = 3; 52eace7efcSopenharmony_ciconstexpr const size_t VALID_DUMP_FFRT_ARG_SIZE = 2; 53eace7efcSopenharmony_ciconstexpr const int MAX_DUMP_FFRT_PID_NUMBER = 3; 54eace7efcSopenharmony_ciconstexpr const int BASE_TEN = 10; 55eace7efcSopenharmony_ciconstexpr const char SIGN_TERMINAL = '\0'; 56eace7efcSopenharmony_ciconstexpr int32_t DEFAULT_CONCURRENT_NUMBER = 1; 57eace7efcSopenharmony_cinamespace { 58eace7efcSopenharmony_ciusing namespace std::chrono_literals; 59eace7efcSopenharmony_ciconstexpr const char* TASK_INIT_APPMGRSERVICEINNER = "InitAppMgrServiceInnerTask"; 60eace7efcSopenharmony_ciconstexpr const char* TASK_ATTACH_APPLICATION = "AttachApplicationTask"; 61eace7efcSopenharmony_ciconstexpr const char* TASK_APPLICATION_FOREGROUNDED = "ApplicationForegroundedTask"; 62eace7efcSopenharmony_ciconstexpr const char* TASK_APPLICATION_BACKGROUNDED = "ApplicationBackgroundedTask"; 63eace7efcSopenharmony_ciconstexpr const char* TASK_APPLICATION_TERMINATED = "ApplicationTerminatedTask"; 64eace7efcSopenharmony_ciconstexpr const char* TASK_ABILITY_CLEANED = "AbilityCleanedTask"; 65eace7efcSopenharmony_ciconstexpr const char* TASK_STARTUP_RESIDENT_PROCESS = "StartupResidentProcess"; 66eace7efcSopenharmony_ciconstexpr const char* TASK_ADD_ABILITY_STAGE_DONE = "AddAbilityStageDone"; 67eace7efcSopenharmony_ciconstexpr const char* TASK_START_USER_TEST_PROCESS = "StartUserTestProcess"; 68eace7efcSopenharmony_ciconstexpr const char* TASK_FINISH_USER_TEST = "FinishUserTest"; 69eace7efcSopenharmony_ciconstexpr const char* TASK_ATTACH_RENDER_PROCESS = "AttachRenderTask"; 70eace7efcSopenharmony_ciconstexpr const char* TASK_ATTACH_CHILD_PROCESS = "AttachChildProcessTask"; 71eace7efcSopenharmony_ciconstexpr const char* TASK_EXIT_CHILD_PROCESS_SAFELY = "ExitChildProcessSafelyTask"; 72eace7efcSopenharmony_ciconstexpr const char* FOUNDATION_PROCESS = "foundation"; 73eace7efcSopenharmony_ciconstexpr int32_t USER_UID = 2000; 74eace7efcSopenharmony_ci} // namespace 75eace7efcSopenharmony_ci 76eace7efcSopenharmony_ciREGISTER_SYSTEM_ABILITY_BY_ID(AppMgrService, APP_MGR_SERVICE_ID, true); 77eace7efcSopenharmony_ci 78eace7efcSopenharmony_ciAppMgrService::AppMgrService() 79eace7efcSopenharmony_ci{ 80eace7efcSopenharmony_ci appMgrServiceInner_ = std::make_shared<AppMgrServiceInner>(); 81eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::APPMGR, "instance created"); 82eace7efcSopenharmony_ci PerfProfile::GetInstance().SetAmsLoadStartTime(GetTickCount()); 83eace7efcSopenharmony_ci} 84eace7efcSopenharmony_ci 85eace7efcSopenharmony_ciAppMgrService::AppMgrService(const int32_t serviceId, bool runOnCreate) : SystemAbility(serviceId, runOnCreate) 86eace7efcSopenharmony_ci{ 87eace7efcSopenharmony_ci appMgrServiceInner_ = std::make_shared<AppMgrServiceInner>(); 88eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::APPMGR, "instance created"); 89eace7efcSopenharmony_ci PerfProfile::GetInstance().SetAmsLoadStartTime(GetTickCount()); 90eace7efcSopenharmony_ci} 91eace7efcSopenharmony_ci 92eace7efcSopenharmony_ciAppMgrService::~AppMgrService() 93eace7efcSopenharmony_ci{ 94eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::APPMGR, "instance destroyed"); 95eace7efcSopenharmony_ci} 96eace7efcSopenharmony_ci 97eace7efcSopenharmony_civoid AppMgrService::OnStart() 98eace7efcSopenharmony_ci{ 99eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::APPMGR, "start service ready"); 100eace7efcSopenharmony_ci if (appMgrServiceState_.serviceRunningState == ServiceRunningState::STATE_RUNNING) { 101eace7efcSopenharmony_ci TAG_LOGW(AAFwkTag::APPMGR, "start service fail"); 102eace7efcSopenharmony_ci return; 103eace7efcSopenharmony_ci } 104eace7efcSopenharmony_ci 105eace7efcSopenharmony_ci ErrCode errCode = Init(); 106eace7efcSopenharmony_ci if (FAILED(errCode)) { 107eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "fail, errCode: %{public}08x", errCode); 108eace7efcSopenharmony_ci return; 109eace7efcSopenharmony_ci } 110eace7efcSopenharmony_ci appMgrServiceState_.serviceRunningState = ServiceRunningState::STATE_RUNNING; 111eace7efcSopenharmony_ci AddSystemAbilityListener(WINDOW_MANAGER_SERVICE_ID); 112eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::APPMGR, "start service success"); 113eace7efcSopenharmony_ci PerfProfile::GetInstance().SetAmsLoadEndTime(GetTickCount()); 114eace7efcSopenharmony_ci PerfProfile::GetInstance().Dump(); 115eace7efcSopenharmony_ci} 116eace7efcSopenharmony_ci 117eace7efcSopenharmony_civoid AppMgrService::OnStop() 118eace7efcSopenharmony_ci{ 119eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::APPMGR, "stop service ready"); 120eace7efcSopenharmony_ci appMgrServiceState_.serviceRunningState = ServiceRunningState::STATE_NOT_START; 121eace7efcSopenharmony_ci eventHandler_.reset(); 122eace7efcSopenharmony_ci taskHandler_.reset(); 123eace7efcSopenharmony_ci if (appMgrServiceInner_) { 124eace7efcSopenharmony_ci appMgrServiceInner_->OnStop(); 125eace7efcSopenharmony_ci } 126eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::APPMGR, "stop service success"); 127eace7efcSopenharmony_ci} 128eace7efcSopenharmony_ci 129eace7efcSopenharmony_civoid AppMgrService::SetInnerService(const std::shared_ptr<AppMgrServiceInner> &innerService) 130eace7efcSopenharmony_ci{ 131eace7efcSopenharmony_ci appMgrServiceInner_ = innerService; 132eace7efcSopenharmony_ci} 133eace7efcSopenharmony_ci 134eace7efcSopenharmony_ciAppMgrServiceState AppMgrService::QueryServiceState() 135eace7efcSopenharmony_ci{ 136eace7efcSopenharmony_ci if (appMgrServiceInner_) { 137eace7efcSopenharmony_ci appMgrServiceState_.connectionState = appMgrServiceInner_->QueryAppSpawnConnectionState(); 138eace7efcSopenharmony_ci } 139eace7efcSopenharmony_ci return appMgrServiceState_; 140eace7efcSopenharmony_ci} 141eace7efcSopenharmony_ci 142eace7efcSopenharmony_ciErrCode AppMgrService::Init() 143eace7efcSopenharmony_ci{ 144eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::APPMGR, "init ready"); 145eace7efcSopenharmony_ci if (!appMgrServiceInner_) { 146eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "init failed"); 147eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 148eace7efcSopenharmony_ci } 149eace7efcSopenharmony_ci 150eace7efcSopenharmony_ci taskHandler_ = AAFwk::TaskHandlerWrap::CreateConcurrentQueueHandler("app_mgr_task_queue", 151eace7efcSopenharmony_ci DEFAULT_CONCURRENT_NUMBER); 152eace7efcSopenharmony_ci eventHandler_ = std::make_shared<AMSEventHandler>(taskHandler_, appMgrServiceInner_); 153eace7efcSopenharmony_ci appMgrServiceInner_->SetTaskHandler(taskHandler_); 154eace7efcSopenharmony_ci appMgrServiceInner_->SetEventHandler(eventHandler_); 155eace7efcSopenharmony_ci DelayedSingleton<CacheProcessManager>::GetInstance()->SetAppMgr(appMgrServiceInner_); 156eace7efcSopenharmony_ci std::function<void()> initAppMgrServiceInnerTask = [appMgrServiceInner = appMgrServiceInner_]() { 157eace7efcSopenharmony_ci appMgrServiceInner->Init(); 158eace7efcSopenharmony_ci }; 159eace7efcSopenharmony_ci taskHandler_->SubmitTask(initAppMgrServiceInnerTask, TASK_INIT_APPMGRSERVICEINNER); 160eace7efcSopenharmony_ci 161eace7efcSopenharmony_ci ErrCode openErr = appMgrServiceInner_->OpenAppSpawnConnection(); 162eace7efcSopenharmony_ci if (FAILED(openErr)) { 163eace7efcSopenharmony_ci TAG_LOGW(AAFwkTag::APPMGR, "fail, errCode: %{public}08x", openErr); 164eace7efcSopenharmony_ci } 165eace7efcSopenharmony_ci if (!Publish(this)) { 166eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, " publish fail"); 167eace7efcSopenharmony_ci return ERR_APPEXECFWK_SERVICE_NOT_CONNECTED; 168eace7efcSopenharmony_ci } 169eace7efcSopenharmony_ci amsMgrScheduler_ = new (std::nothrow) AmsMgrScheduler(appMgrServiceInner_, taskHandler_); 170eace7efcSopenharmony_ci if (!amsMgrScheduler_) { 171eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "init failed"); 172eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 173eace7efcSopenharmony_ci } 174eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::APPMGR, "init success"); 175eace7efcSopenharmony_ci return ERR_OK; 176eace7efcSopenharmony_ci} 177eace7efcSopenharmony_ci 178eace7efcSopenharmony_civoid AppMgrService::AttachApplication(const sptr<IRemoteObject> &app) 179eace7efcSopenharmony_ci{ 180eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::APPMGR, "called"); 181eace7efcSopenharmony_ci if (!IsReady()) { 182eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "AttachApplication failed"); 183eace7efcSopenharmony_ci return; 184eace7efcSopenharmony_ci } 185eace7efcSopenharmony_ci 186eace7efcSopenharmony_ci AbilityRuntime::FreezeUtil::GetInstance().AddAppLifecycleEvent(IPCSkeleton::GetCallingPid(), 187eace7efcSopenharmony_ci "AppMgrService::AttachApplication"); 188eace7efcSopenharmony_ci pid_t pid = IPCSkeleton::GetCallingPid(); 189eace7efcSopenharmony_ci auto appScheduler = iface_cast<IAppScheduler>(app); 190eace7efcSopenharmony_ci if (appScheduler == nullptr) { 191eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "appScheduler null"); 192eace7efcSopenharmony_ci } 193eace7efcSopenharmony_ci std::function<void()> attachApplicationFunc = [appMgrServiceInner = appMgrServiceInner_, pid, appScheduler]() { 194eace7efcSopenharmony_ci appMgrServiceInner->AttachApplication(pid, appScheduler); 195eace7efcSopenharmony_ci }; 196eace7efcSopenharmony_ci taskHandler_->SubmitTask(attachApplicationFunc, AAFwk::TaskAttribute{ 197eace7efcSopenharmony_ci .taskName_ = TASK_ATTACH_APPLICATION, 198eace7efcSopenharmony_ci .taskQos_ = AAFwk::TaskQoS::USER_INTERACTIVE 199eace7efcSopenharmony_ci }); 200eace7efcSopenharmony_ci} 201eace7efcSopenharmony_ci 202eace7efcSopenharmony_ciint32_t AppMgrService::PreloadApplication(const std::string &bundleName, int32_t userId, 203eace7efcSopenharmony_ci AppExecFwk::PreloadMode preloadMode, int32_t appIndex) 204eace7efcSopenharmony_ci{ 205eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::APPMGR, "PreloadApplication called"); 206eace7efcSopenharmony_ci if (!IsReady()) { 207eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "PreloadApplication failed"); 208eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 209eace7efcSopenharmony_ci } 210eace7efcSopenharmony_ci return appMgrServiceInner_->PreloadApplication(bundleName, userId, preloadMode, appIndex); 211eace7efcSopenharmony_ci} 212eace7efcSopenharmony_ci 213eace7efcSopenharmony_civoid AppMgrService::ApplicationForegrounded(const int32_t recordId) 214eace7efcSopenharmony_ci{ 215eace7efcSopenharmony_ci if (!IsReady()) { 216eace7efcSopenharmony_ci return; 217eace7efcSopenharmony_ci } 218eace7efcSopenharmony_ci if (!JudgeAppSelfCalled(recordId)) { 219eace7efcSopenharmony_ci return; 220eace7efcSopenharmony_ci } 221eace7efcSopenharmony_ci AbilityRuntime::FreezeUtil::GetInstance().AddAppLifecycleEvent(IPCSkeleton::GetCallingPid(), 222eace7efcSopenharmony_ci "AppMgrService::AppForegrounded"); 223eace7efcSopenharmony_ci std::function<void()> applicationForegroundedFunc = [appMgrServiceInner = appMgrServiceInner_, recordId]() { 224eace7efcSopenharmony_ci appMgrServiceInner->ApplicationForegrounded(recordId); 225eace7efcSopenharmony_ci }; 226eace7efcSopenharmony_ci taskHandler_->SubmitTask(applicationForegroundedFunc, AAFwk::TaskAttribute{ 227eace7efcSopenharmony_ci .taskName_ = TASK_APPLICATION_FOREGROUNDED, 228eace7efcSopenharmony_ci .taskQos_ = AAFwk::TaskQoS::USER_INTERACTIVE 229eace7efcSopenharmony_ci }); 230eace7efcSopenharmony_ci} 231eace7efcSopenharmony_ci 232eace7efcSopenharmony_civoid AppMgrService::ApplicationBackgrounded(const int32_t recordId) 233eace7efcSopenharmony_ci{ 234eace7efcSopenharmony_ci if (!IsReady()) { 235eace7efcSopenharmony_ci return; 236eace7efcSopenharmony_ci } 237eace7efcSopenharmony_ci if (!JudgeAppSelfCalled(recordId)) { 238eace7efcSopenharmony_ci return; 239eace7efcSopenharmony_ci } 240eace7efcSopenharmony_ci AbilityRuntime::FreezeUtil::GetInstance().AddAppLifecycleEvent(IPCSkeleton::GetCallingPid(), 241eace7efcSopenharmony_ci "AppMgrService::AppBackgrounded"); 242eace7efcSopenharmony_ci taskHandler_->CancelTask("appbackground_" + std::to_string(recordId)); 243eace7efcSopenharmony_ci std::function<void()> applicationBackgroundedFunc = [appMgrServiceInner = appMgrServiceInner_, recordId]() { 244eace7efcSopenharmony_ci appMgrServiceInner->ApplicationBackgrounded(recordId); 245eace7efcSopenharmony_ci }; 246eace7efcSopenharmony_ci taskHandler_->SubmitTask(applicationBackgroundedFunc, AAFwk::TaskAttribute{ 247eace7efcSopenharmony_ci .taskName_ = TASK_APPLICATION_BACKGROUNDED, 248eace7efcSopenharmony_ci .taskQos_ = AAFwk::TaskQoS::USER_INTERACTIVE 249eace7efcSopenharmony_ci }); 250eace7efcSopenharmony_ci} 251eace7efcSopenharmony_ci 252eace7efcSopenharmony_civoid AppMgrService::ApplicationTerminated(const int32_t recordId) 253eace7efcSopenharmony_ci{ 254eace7efcSopenharmony_ci if (!IsReady()) { 255eace7efcSopenharmony_ci return; 256eace7efcSopenharmony_ci } 257eace7efcSopenharmony_ci if (!JudgeAppSelfCalled(recordId)) { 258eace7efcSopenharmony_ci return; 259eace7efcSopenharmony_ci } 260eace7efcSopenharmony_ci std::function<void()> applicationTerminatedFunc = [appMgrServiceInner = appMgrServiceInner_, recordId]() { 261eace7efcSopenharmony_ci appMgrServiceInner->ApplicationTerminated(recordId); 262eace7efcSopenharmony_ci }; 263eace7efcSopenharmony_ci taskHandler_->SubmitTask(applicationTerminatedFunc, AAFwk::TaskAttribute{ 264eace7efcSopenharmony_ci .taskName_ = TASK_APPLICATION_TERMINATED, 265eace7efcSopenharmony_ci .taskQos_ = AAFwk::TaskQoS::USER_INTERACTIVE 266eace7efcSopenharmony_ci }); 267eace7efcSopenharmony_ci} 268eace7efcSopenharmony_ci 269eace7efcSopenharmony_civoid AppMgrService::AbilityCleaned(const sptr<IRemoteObject> &token) 270eace7efcSopenharmony_ci{ 271eace7efcSopenharmony_ci if (!IsReady()) { 272eace7efcSopenharmony_ci return; 273eace7efcSopenharmony_ci } 274eace7efcSopenharmony_ci 275eace7efcSopenharmony_ci auto callerUid = IPCSkeleton::GetCallingUid(); 276eace7efcSopenharmony_ci auto appRecord = appMgrServiceInner_->GetTerminatingAppRunningRecord(token); 277eace7efcSopenharmony_ci if (!appRecord || appRecord->GetUid() != callerUid) { 278eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "verification failed"); 279eace7efcSopenharmony_ci return; 280eace7efcSopenharmony_ci } 281eace7efcSopenharmony_ci 282eace7efcSopenharmony_ci std::function<void()> abilityCleanedFunc = [appMgrServiceInner = appMgrServiceInner_, token]() { 283eace7efcSopenharmony_ci appMgrServiceInner->AbilityTerminated(token); 284eace7efcSopenharmony_ci }; 285eace7efcSopenharmony_ci taskHandler_->SubmitTask(abilityCleanedFunc, AAFwk::TaskAttribute{ 286eace7efcSopenharmony_ci .taskName_ = TASK_ABILITY_CLEANED, 287eace7efcSopenharmony_ci .taskQos_ = AAFwk::TaskQoS::USER_INTERACTIVE 288eace7efcSopenharmony_ci }); 289eace7efcSopenharmony_ci} 290eace7efcSopenharmony_ci 291eace7efcSopenharmony_cibool AppMgrService::IsReady() const 292eace7efcSopenharmony_ci{ 293eace7efcSopenharmony_ci if (appMgrServiceInner_ && taskHandler_ && eventHandler_) { 294eace7efcSopenharmony_ci return true; 295eace7efcSopenharmony_ci } 296eace7efcSopenharmony_ci 297eace7efcSopenharmony_ci TAG_LOGW(AAFwkTag::APPMGR, "not ready"); 298eace7efcSopenharmony_ci return false; 299eace7efcSopenharmony_ci} 300eace7efcSopenharmony_ci 301eace7efcSopenharmony_civoid AppMgrService::StartupResidentProcess(const std::vector<AppExecFwk::BundleInfo> &bundleInfos) 302eace7efcSopenharmony_ci{ 303eace7efcSopenharmony_ci if (!IsReady()) { 304eace7efcSopenharmony_ci return; 305eace7efcSopenharmony_ci } 306eace7efcSopenharmony_ci pid_t callingPid = IPCSkeleton::GetCallingPid(); 307eace7efcSopenharmony_ci pid_t pid = getprocpid(); 308eace7efcSopenharmony_ci if (callingPid != pid) { 309eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not process call"); 310eace7efcSopenharmony_ci return; 311eace7efcSopenharmony_ci } 312eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::APPMGR, "start process"); 313eace7efcSopenharmony_ci std::function <void()> startupResidentProcess = [appMgrServiceInner = appMgrServiceInner_, bundleInfos]() { 314eace7efcSopenharmony_ci appMgrServiceInner->LoadResidentProcess(bundleInfos); 315eace7efcSopenharmony_ci }; 316eace7efcSopenharmony_ci taskHandler_->SubmitTask(startupResidentProcess, AAFwk::TaskAttribute{ 317eace7efcSopenharmony_ci .taskName_ = TASK_STARTUP_RESIDENT_PROCESS, 318eace7efcSopenharmony_ci .taskQos_ = AAFwk::TaskQoS::USER_INTERACTIVE 319eace7efcSopenharmony_ci }); 320eace7efcSopenharmony_ci} 321eace7efcSopenharmony_ci 322eace7efcSopenharmony_cisptr<IAmsMgr> AppMgrService::GetAmsMgr() 323eace7efcSopenharmony_ci{ 324eace7efcSopenharmony_ci return amsMgrScheduler_; 325eace7efcSopenharmony_ci} 326eace7efcSopenharmony_ci 327eace7efcSopenharmony_ciint32_t AppMgrService::ClearUpApplicationData(const std::string &bundleName, int32_t appCloneIndex, int32_t userId) 328eace7efcSopenharmony_ci{ 329eace7efcSopenharmony_ci if (!AAFwk::PermissionVerification::GetInstance()->JudgeCallerIsAllowedToUseSystemAPI()) { 330eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "caller is not SA"); 331eace7efcSopenharmony_ci return AAFwk::ERR_NOT_SYSTEM_APP; 332eace7efcSopenharmony_ci } 333eace7efcSopenharmony_ci if (!IsReady()) { 334eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 335eace7efcSopenharmony_ci } 336eace7efcSopenharmony_ci std::shared_ptr<RemoteClientManager> remoteClientManager = std::make_shared<RemoteClientManager>(); 337eace7efcSopenharmony_ci if (remoteClientManager == nullptr) { 338eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "null remoteClientManager"); 339eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 340eace7efcSopenharmony_ci } 341eace7efcSopenharmony_ci auto bundleMgrHelper = remoteClientManager->GetBundleManagerHelper(); 342eace7efcSopenharmony_ci if (bundleMgrHelper == nullptr) { 343eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "null bundleMgrHelper"); 344eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 345eace7efcSopenharmony_ci } 346eace7efcSopenharmony_ci int32_t callingUid = IPCSkeleton::GetCallingUid(); 347eace7efcSopenharmony_ci if ((callingUid != 0 && callingUid != USER_UID) || userId < 0) { 348eace7efcSopenharmony_ci std::string callerBundleName; 349eace7efcSopenharmony_ci auto result = IN_PROCESS_CALL(bundleMgrHelper->GetNameForUid(callingUid, callerBundleName)); 350eace7efcSopenharmony_ci if (result != ERR_OK) { 351eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "getBundleName failed: %{public}d", result); 352eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 353eace7efcSopenharmony_ci } 354eace7efcSopenharmony_ci auto isCallingPerm = AAFwk::PermissionVerification::GetInstance()->VerifyCallingPermission( 355eace7efcSopenharmony_ci AAFwk::PermissionConstants::PERMISSION_CLEAN_APPLICATION_DATA); 356eace7efcSopenharmony_ci if (!isCallingPerm) { 357eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "verification failed"); 358eace7efcSopenharmony_ci return AAFwk::CHECK_PERMISSION_FAILED; 359eace7efcSopenharmony_ci } 360eace7efcSopenharmony_ci } 361eace7efcSopenharmony_ci if (appCloneIndex < 0 || appCloneIndex > AbilityRuntime::GlobalConstant::MAX_APP_CLONE_INDEX) { 362eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "appCloneIndex invalid"); 363eace7efcSopenharmony_ci return AAFwk::ERR_APP_CLONE_INDEX_INVALID; 364eace7efcSopenharmony_ci } 365eace7efcSopenharmony_ci pid_t pid = IPCSkeleton::GetCallingPid(); 366eace7efcSopenharmony_ci return appMgrServiceInner_->ClearUpApplicationData(bundleName, callingUid, pid, appCloneIndex, userId); 367eace7efcSopenharmony_ci} 368eace7efcSopenharmony_ci 369eace7efcSopenharmony_ciint32_t AppMgrService::ClearUpApplicationDataBySelf(int32_t userId) 370eace7efcSopenharmony_ci{ 371eace7efcSopenharmony_ci if (!IsReady()) { 372eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 373eace7efcSopenharmony_ci } 374eace7efcSopenharmony_ci int32_t uid = IPCSkeleton::GetCallingUid(); 375eace7efcSopenharmony_ci pid_t pid = IPCSkeleton::GetCallingPid(); 376eace7efcSopenharmony_ci return appMgrServiceInner_->ClearUpApplicationDataBySelf(uid, pid, userId); 377eace7efcSopenharmony_ci} 378eace7efcSopenharmony_ci 379eace7efcSopenharmony_ciint32_t AppMgrService::GetAllRunningProcesses(std::vector<RunningProcessInfo> &info) 380eace7efcSopenharmony_ci{ 381eace7efcSopenharmony_ci if (!IsReady()) { 382eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 383eace7efcSopenharmony_ci } 384eace7efcSopenharmony_ci return appMgrServiceInner_->GetAllRunningProcesses(info); 385eace7efcSopenharmony_ci} 386eace7efcSopenharmony_ci 387eace7efcSopenharmony_ciint32_t AppMgrService::GetRunningMultiAppInfoByBundleName(const std::string &bundleName, 388eace7efcSopenharmony_ci RunningMultiAppInfo &info) 389eace7efcSopenharmony_ci{ 390eace7efcSopenharmony_ci if (!IsReady()) { 391eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 392eace7efcSopenharmony_ci } 393eace7efcSopenharmony_ci 394eace7efcSopenharmony_ci if (!AAFwk::PermissionVerification::GetInstance()->JudgeCallerIsAllowedToUseSystemAPI()) { 395eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "caller is not SA"); 396eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 397eace7efcSopenharmony_ci } 398eace7efcSopenharmony_ci 399eace7efcSopenharmony_ci bool isCallingPermission = AAFwk::PermissionVerification::GetInstance()->VerifyRunningInfoPerm(); 400eace7efcSopenharmony_ci if (!isCallingPermission) { 401eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "verification failed"); 402eace7efcSopenharmony_ci return ERR_PERMISSION_DENIED; 403eace7efcSopenharmony_ci } 404eace7efcSopenharmony_ci return appMgrServiceInner_->GetRunningMultiAppInfoByBundleName(bundleName, info); 405eace7efcSopenharmony_ci} 406eace7efcSopenharmony_ci 407eace7efcSopenharmony_ciint32_t AppMgrService::GetAllRunningInstanceKeysBySelf(std::vector<std::string> &instanceKeys) 408eace7efcSopenharmony_ci{ 409eace7efcSopenharmony_ci if (!IsReady()) { 410eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 411eace7efcSopenharmony_ci } 412eace7efcSopenharmony_ci return appMgrServiceInner_->GetAllRunningInstanceKeysBySelf(instanceKeys); 413eace7efcSopenharmony_ci} 414eace7efcSopenharmony_ci 415eace7efcSopenharmony_ciint32_t AppMgrService::GetAllRunningInstanceKeysByBundleName(const std::string &bundleName, 416eace7efcSopenharmony_ci std::vector<std::string> &instanceKeys, int32_t userId) 417eace7efcSopenharmony_ci{ 418eace7efcSopenharmony_ci if (!IsReady()) { 419eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 420eace7efcSopenharmony_ci } 421eace7efcSopenharmony_ci return appMgrServiceInner_->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys, userId); 422eace7efcSopenharmony_ci} 423eace7efcSopenharmony_ci 424eace7efcSopenharmony_ciint32_t AppMgrService::GetRunningProcessesByBundleType(BundleType bundleType, 425eace7efcSopenharmony_ci std::vector<RunningProcessInfo> &info) 426eace7efcSopenharmony_ci{ 427eace7efcSopenharmony_ci if (!IsReady()) { 428eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 429eace7efcSopenharmony_ci } 430eace7efcSopenharmony_ci return appMgrServiceInner_->GetRunningProcessesByBundleType(bundleType, info); 431eace7efcSopenharmony_ci} 432eace7efcSopenharmony_ci 433eace7efcSopenharmony_ciint32_t AppMgrService::GetAllRenderProcesses(std::vector<RenderProcessInfo> &info) 434eace7efcSopenharmony_ci{ 435eace7efcSopenharmony_ci if (!IsReady()) { 436eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 437eace7efcSopenharmony_ci } 438eace7efcSopenharmony_ci return appMgrServiceInner_->GetAllRenderProcesses(info); 439eace7efcSopenharmony_ci} 440eace7efcSopenharmony_ci 441eace7efcSopenharmony_ciint AppMgrService::GetAllChildrenProcesses(std::vector<ChildProcessInfo> &info) 442eace7efcSopenharmony_ci{ 443eace7efcSopenharmony_ci if (!IsReady()) { 444eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 445eace7efcSopenharmony_ci } 446eace7efcSopenharmony_ci return appMgrServiceInner_->GetAllChildrenProcesses(info); 447eace7efcSopenharmony_ci} 448eace7efcSopenharmony_ci 449eace7efcSopenharmony_ciint32_t AppMgrService::JudgeSandboxByPid(pid_t pid, bool &isSandbox) 450eace7efcSopenharmony_ci{ 451eace7efcSopenharmony_ci if (!IsReady()) { 452eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 453eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 454eace7efcSopenharmony_ci } 455eace7efcSopenharmony_ci bool isCallingPermission = 456eace7efcSopenharmony_ci AAFwk::PermissionVerification::GetInstance()->CheckSpecificSystemAbilityAccessPermission(FOUNDATION_PROCESS); 457eace7efcSopenharmony_ci if (!isCallingPermission) { 458eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "verification failed"); 459eace7efcSopenharmony_ci return ERR_PERMISSION_DENIED; 460eace7efcSopenharmony_ci } 461eace7efcSopenharmony_ci auto appRunningRecord = appMgrServiceInner_->GetAppRunningRecordByPid(pid); 462eace7efcSopenharmony_ci if (appRunningRecord && appRunningRecord->GetAppIndex() > AbilityRuntime::GlobalConstant::MAX_APP_CLONE_INDEX) { 463eace7efcSopenharmony_ci isSandbox = true; 464eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::APPMGR, "current app is a sandbox."); 465eace7efcSopenharmony_ci return ERR_OK; 466eace7efcSopenharmony_ci } 467eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::APPMGR, "current app is not a sandbox."); 468eace7efcSopenharmony_ci return ERR_OK; 469eace7efcSopenharmony_ci} 470eace7efcSopenharmony_ci 471eace7efcSopenharmony_ciint32_t AppMgrService::GetProcessRunningInfosByUserId(std::vector<RunningProcessInfo> &info, int32_t userId) 472eace7efcSopenharmony_ci{ 473eace7efcSopenharmony_ci if (!IsReady()) { 474eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 475eace7efcSopenharmony_ci } 476eace7efcSopenharmony_ci return appMgrServiceInner_->GetProcessRunningInfosByUserId(info, userId); 477eace7efcSopenharmony_ci} 478eace7efcSopenharmony_ci 479eace7efcSopenharmony_ciint32_t AppMgrService::GetProcessRunningInformation(RunningProcessInfo &info) 480eace7efcSopenharmony_ci{ 481eace7efcSopenharmony_ci if (!IsReady()) { 482eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 483eace7efcSopenharmony_ci } 484eace7efcSopenharmony_ci return appMgrServiceInner_->GetProcessRunningInformation(info); 485eace7efcSopenharmony_ci} 486eace7efcSopenharmony_ci 487eace7efcSopenharmony_ciint32_t AppMgrService::NotifyMemoryLevel(int32_t level) 488eace7efcSopenharmony_ci{ 489eace7efcSopenharmony_ci if (!IsReady()) { 490eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 491eace7efcSopenharmony_ci } 492eace7efcSopenharmony_ci return appMgrServiceInner_->NotifyMemoryLevel(level); 493eace7efcSopenharmony_ci} 494eace7efcSopenharmony_ci 495eace7efcSopenharmony_ciint32_t AppMgrService::NotifyProcMemoryLevel(const std::map<pid_t, MemoryLevel> &procLevelMap) 496eace7efcSopenharmony_ci{ 497eace7efcSopenharmony_ci if (!IsReady()) { 498eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 499eace7efcSopenharmony_ci } 500eace7efcSopenharmony_ci return appMgrServiceInner_->NotifyProcMemoryLevel(procLevelMap); 501eace7efcSopenharmony_ci} 502eace7efcSopenharmony_ci 503eace7efcSopenharmony_ciint32_t AppMgrService::DumpHeapMemory(const int32_t pid, OHOS::AppExecFwk::MallocInfo &mallocInfo) 504eace7efcSopenharmony_ci{ 505eace7efcSopenharmony_ci if (!IsReady()) { 506eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 507eace7efcSopenharmony_ci } 508eace7efcSopenharmony_ci return appMgrServiceInner_->DumpHeapMemory(pid, mallocInfo); 509eace7efcSopenharmony_ci} 510eace7efcSopenharmony_ci 511eace7efcSopenharmony_ci// Authenticate dump permissions 512eace7efcSopenharmony_cibool AppMgrService::HasDumpPermission() const 513eace7efcSopenharmony_ci{ 514eace7efcSopenharmony_ci uint32_t callingTokenID = IPCSkeleton::GetCallingTokenID(); 515eace7efcSopenharmony_ci int res = Security::AccessToken::AccessTokenKit::VerifyAccessToken(callingTokenID, "ohos.permission.DUMP"); 516eace7efcSopenharmony_ci if (res != Security::AccessToken::PermissionState::PERMISSION_GRANTED) { 517eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "no permission"); 518eace7efcSopenharmony_ci return false; 519eace7efcSopenharmony_ci } 520eace7efcSopenharmony_ci return true; 521eace7efcSopenharmony_ci} 522eace7efcSopenharmony_ci 523eace7efcSopenharmony_ciint32_t AppMgrService::DumpJsHeapMemory(OHOS::AppExecFwk::JsHeapDumpInfo &info) 524eace7efcSopenharmony_ci{ 525eace7efcSopenharmony_ci if (!IsReady() || !HasDumpPermission()) { 526eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 527eace7efcSopenharmony_ci } 528eace7efcSopenharmony_ci return appMgrServiceInner_->DumpJsHeapMemory(info); 529eace7efcSopenharmony_ci} 530eace7efcSopenharmony_ci 531eace7efcSopenharmony_civoid AppMgrService::AddAbilityStageDone(const int32_t recordId) 532eace7efcSopenharmony_ci{ 533eace7efcSopenharmony_ci if (!IsReady()) { 534eace7efcSopenharmony_ci return; 535eace7efcSopenharmony_ci } 536eace7efcSopenharmony_ci if (!JudgeAppSelfCalled(recordId)) { 537eace7efcSopenharmony_ci return; 538eace7efcSopenharmony_ci } 539eace7efcSopenharmony_ci std::function <void()> addAbilityStageDone = [appMgrServiceInner = appMgrServiceInner_, recordId]() { 540eace7efcSopenharmony_ci appMgrServiceInner->AddAbilityStageDone(recordId); 541eace7efcSopenharmony_ci }; 542eace7efcSopenharmony_ci taskHandler_->SubmitTask(addAbilityStageDone, AAFwk::TaskAttribute{ 543eace7efcSopenharmony_ci .taskName_ = TASK_ADD_ABILITY_STAGE_DONE, 544eace7efcSopenharmony_ci .taskQos_ = AAFwk::TaskQoS::USER_INTERACTIVE 545eace7efcSopenharmony_ci }); 546eace7efcSopenharmony_ci} 547eace7efcSopenharmony_ci 548eace7efcSopenharmony_ciint32_t AppMgrService::RegisterApplicationStateObserver(const sptr<IApplicationStateObserver> &observer, 549eace7efcSopenharmony_ci const std::vector<std::string> &bundleNameList) 550eace7efcSopenharmony_ci{ 551eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::APPMGR, "begin"); 552eace7efcSopenharmony_ci if (!IsReady()) { 553eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 554eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 555eace7efcSopenharmony_ci } 556eace7efcSopenharmony_ci return appMgrServiceInner_->RegisterApplicationStateObserver(observer, bundleNameList); 557eace7efcSopenharmony_ci} 558eace7efcSopenharmony_ci 559eace7efcSopenharmony_ciint32_t AppMgrService::UnregisterApplicationStateObserver(const sptr<IApplicationStateObserver> &observer) 560eace7efcSopenharmony_ci{ 561eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::APPMGR, "begin"); 562eace7efcSopenharmony_ci if (!IsReady()) { 563eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 564eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 565eace7efcSopenharmony_ci } 566eace7efcSopenharmony_ci return appMgrServiceInner_->UnregisterApplicationStateObserver(observer); 567eace7efcSopenharmony_ci} 568eace7efcSopenharmony_ci 569eace7efcSopenharmony_ciint32_t AppMgrService::RegisterAbilityForegroundStateObserver(const sptr<IAbilityForegroundStateObserver> &observer) 570eace7efcSopenharmony_ci{ 571eace7efcSopenharmony_ci HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); 572eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::APPMGR, "called"); 573eace7efcSopenharmony_ci if (!IsReady()) { 574eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 575eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 576eace7efcSopenharmony_ci } 577eace7efcSopenharmony_ci return appMgrServiceInner_->RegisterAbilityForegroundStateObserver(observer); 578eace7efcSopenharmony_ci} 579eace7efcSopenharmony_ci 580eace7efcSopenharmony_ciint32_t AppMgrService::UnregisterAbilityForegroundStateObserver(const sptr<IAbilityForegroundStateObserver> &observer) 581eace7efcSopenharmony_ci{ 582eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::APPMGR, "called"); 583eace7efcSopenharmony_ci if (!IsReady()) { 584eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 585eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 586eace7efcSopenharmony_ci } 587eace7efcSopenharmony_ci return appMgrServiceInner_->UnregisterAbilityForegroundStateObserver(observer); 588eace7efcSopenharmony_ci} 589eace7efcSopenharmony_ci 590eace7efcSopenharmony_ciint32_t AppMgrService::GetForegroundApplications(std::vector<AppStateData> &list) 591eace7efcSopenharmony_ci{ 592eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::APPMGR, "begin"); 593eace7efcSopenharmony_ci if (!IsReady()) { 594eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 595eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 596eace7efcSopenharmony_ci } 597eace7efcSopenharmony_ci return appMgrServiceInner_->GetForegroundApplications(list); 598eace7efcSopenharmony_ci} 599eace7efcSopenharmony_ci 600eace7efcSopenharmony_ciint AppMgrService::StartUserTestProcess(const AAFwk::Want &want, const sptr<IRemoteObject> &observer, 601eace7efcSopenharmony_ci const AppExecFwk::BundleInfo &bundleInfo, int32_t userId) 602eace7efcSopenharmony_ci{ 603eace7efcSopenharmony_ci if (!IsReady()) { 604eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 605eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 606eace7efcSopenharmony_ci } 607eace7efcSopenharmony_ci if (!AAFwk::PermissionVerification::GetInstance()->IsShellCall()) { 608eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "StartUserTestProcess is not shell call"); 609eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 610eace7efcSopenharmony_ci } 611eace7efcSopenharmony_ci std::function<void()> startUserTestProcessFunc = [appMgrServiceInner = appMgrServiceInner_, 612eace7efcSopenharmony_ci want, observer, bundleInfo, userId]() { 613eace7efcSopenharmony_ci appMgrServiceInner->StartUserTestProcess(want, observer, bundleInfo, userId); 614eace7efcSopenharmony_ci }; 615eace7efcSopenharmony_ci taskHandler_->SubmitTask(startUserTestProcessFunc, TASK_START_USER_TEST_PROCESS); 616eace7efcSopenharmony_ci return ERR_OK; 617eace7efcSopenharmony_ci} 618eace7efcSopenharmony_ci 619eace7efcSopenharmony_ciint AppMgrService::FinishUserTest(const std::string &msg, const int64_t &resultCode, const std::string &bundleName) 620eace7efcSopenharmony_ci{ 621eace7efcSopenharmony_ci if (!IsReady()) { 622eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 623eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 624eace7efcSopenharmony_ci } 625eace7efcSopenharmony_ci std::shared_ptr<RemoteClientManager> remoteClientManager = std::make_shared<RemoteClientManager>(); 626eace7efcSopenharmony_ci if (remoteClientManager == nullptr) { 627eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "null remoteClientManager"); 628eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 629eace7efcSopenharmony_ci } 630eace7efcSopenharmony_ci auto bundleMgrHelper = remoteClientManager->GetBundleManagerHelper(); 631eace7efcSopenharmony_ci if (bundleMgrHelper == nullptr) { 632eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "null bundleMgrHelper"); 633eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 634eace7efcSopenharmony_ci } 635eace7efcSopenharmony_ci int32_t callingUid = IPCSkeleton::GetCallingUid(); 636eace7efcSopenharmony_ci std::string callerBundleName; 637eace7efcSopenharmony_ci auto result = IN_PROCESS_CALL(bundleMgrHelper->GetNameForUid(callingUid, callerBundleName)); 638eace7efcSopenharmony_ci if (result == ERR_OK) { 639eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::APPMGR, "callingPid_ %{public}s", callerBundleName.c_str()); 640eace7efcSopenharmony_ci if (bundleName != callerBundleName) { 641eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not process call"); 642eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 643eace7efcSopenharmony_ci } 644eace7efcSopenharmony_ci } else { 645eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "fail: %{public}d", result); 646eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 647eace7efcSopenharmony_ci } 648eace7efcSopenharmony_ci pid_t callingPid = IPCSkeleton::GetCallingPid(); 649eace7efcSopenharmony_ci std::function<void()> finishUserTestProcessFunc = [appMgrServiceInner = appMgrServiceInner_, msg, 650eace7efcSopenharmony_ci resultCode, bundleName, callingPid]() { 651eace7efcSopenharmony_ci appMgrServiceInner->FinishUserTest(msg, resultCode, bundleName, callingPid); 652eace7efcSopenharmony_ci }; 653eace7efcSopenharmony_ci taskHandler_->SubmitTask(finishUserTestProcessFunc, TASK_FINISH_USER_TEST); 654eace7efcSopenharmony_ci return ERR_OK; 655eace7efcSopenharmony_ci} 656eace7efcSopenharmony_ci 657eace7efcSopenharmony_ciint AppMgrService::Dump(int fd, const std::vector<std::u16string>& args) 658eace7efcSopenharmony_ci{ 659eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::APPMGR, "called"); 660eace7efcSopenharmony_ci if (!IsReady()) { 661eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 662eace7efcSopenharmony_ci return ERR_APPEXECFWK_HIDUMP_ERROR; 663eace7efcSopenharmony_ci } 664eace7efcSopenharmony_ci 665eace7efcSopenharmony_ci std::string result; 666eace7efcSopenharmony_ci auto errCode = Dump(args, result); 667eace7efcSopenharmony_ci int ret = dprintf(fd, "%s\n", result.c_str()); 668eace7efcSopenharmony_ci if (ret < 0) { 669eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "dprintf error"); 670eace7efcSopenharmony_ci return ERR_APPEXECFWK_HIDUMP_ERROR; 671eace7efcSopenharmony_ci } 672eace7efcSopenharmony_ci return errCode; 673eace7efcSopenharmony_ci} 674eace7efcSopenharmony_ci 675eace7efcSopenharmony_ciint AppMgrService::Dump(const std::vector<std::u16string>& args, std::string& result) 676eace7efcSopenharmony_ci{ 677eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::APPMGR, "called"); 678eace7efcSopenharmony_ci auto size = args.size(); 679eace7efcSopenharmony_ci if (size == 0) { 680eace7efcSopenharmony_ci return ShowHelp(args, result); 681eace7efcSopenharmony_ci } 682eace7efcSopenharmony_ci 683eace7efcSopenharmony_ci std::string optionKey = Str16ToStr8(args[0]); 684eace7efcSopenharmony_ci if (optionKey == OPTION_KEY_HELP) { 685eace7efcSopenharmony_ci return ShowHelp(args, result); 686eace7efcSopenharmony_ci } 687eace7efcSopenharmony_ci if (optionKey == OPTION_KEY_DUMP_IPC) { 688eace7efcSopenharmony_ci return DumpIpc(args, result); 689eace7efcSopenharmony_ci } 690eace7efcSopenharmony_ci if (optionKey == OPTION_KEY_DUMP_FFRT) { 691eace7efcSopenharmony_ci return DumpFfrt(args, result); 692eace7efcSopenharmony_ci } 693eace7efcSopenharmony_ci result.append("error: unkown option.\n"); 694eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "option key %{public}s does not exist", optionKey.c_str()); 695eace7efcSopenharmony_ci return DumpErrorCode::ERR_UNKNOWN_OPTION_ERROR; 696eace7efcSopenharmony_ci} 697eace7efcSopenharmony_ci 698eace7efcSopenharmony_ciint AppMgrService::ShowHelp(const std::vector<std::u16string>& args, std::string& result) 699eace7efcSopenharmony_ci{ 700eace7efcSopenharmony_ci result.append("Usage:\n") 701eace7efcSopenharmony_ci .append("-h ") 702eace7efcSopenharmony_ci .append("help text for the tool\n") 703eace7efcSopenharmony_ci .append("--ffrt pid1[,pid2,pid3] ") 704eace7efcSopenharmony_ci .append("dump ffrt info\n"); 705eace7efcSopenharmony_ci 706eace7efcSopenharmony_ci return ERR_OK; 707eace7efcSopenharmony_ci} 708eace7efcSopenharmony_ci 709eace7efcSopenharmony_ciint AppMgrService::DumpIpcAllInner(const AppMgrService::DumpIpcKey key, std::string& result) 710eace7efcSopenharmony_ci{ 711eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::APPMGR, "call"); 712eace7efcSopenharmony_ci switch (key) { 713eace7efcSopenharmony_ci case KEY_DUMP_IPC_START: 714eace7efcSopenharmony_ci return DumpIpcAllStart(result); 715eace7efcSopenharmony_ci case KEY_DUMP_IPC_STOP: 716eace7efcSopenharmony_ci return DumpIpcAllStop(result); 717eace7efcSopenharmony_ci case KEY_DUMP_IPC_STAT: 718eace7efcSopenharmony_ci return DumpIpcAllStat(result); 719eace7efcSopenharmony_ci default: { 720eace7efcSopenharmony_ci result.append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) 721eace7efcSopenharmony_ci .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL)); 722eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "dump ipc all function does not exist"); 723eace7efcSopenharmony_ci return DumpErrorCode::ERR_INTERNAL_ERROR; 724eace7efcSopenharmony_ci } 725eace7efcSopenharmony_ci } 726eace7efcSopenharmony_ci} 727eace7efcSopenharmony_ci 728eace7efcSopenharmony_ciint AppMgrService::DumpIpcWithPidInner(const AppMgrService::DumpIpcKey key, 729eace7efcSopenharmony_ci const std::string& optionPid, std::string& result) 730eace7efcSopenharmony_ci{ 731eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::APPMGR, "call"); 732eace7efcSopenharmony_ci int32_t pid = -1; 733eace7efcSopenharmony_ci char* end = nullptr; 734eace7efcSopenharmony_ci pid = static_cast<int32_t>(std::strtol(optionPid.c_str(), &end, BASE_TEN)); 735eace7efcSopenharmony_ci if (end && *end != SIGN_TERMINAL) { 736eace7efcSopenharmony_ci result.append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) 737eace7efcSopenharmony_ci .append(MSG_DUMP_FAIL_REASON_INVALILD_PID, strlen(MSG_DUMP_FAIL_REASON_INVALILD_PID)); 738eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "invalid pid: %{public}s", optionPid.c_str()); 739eace7efcSopenharmony_ci return DumpErrorCode::ERR_INVALID_PID_ERROR; 740eace7efcSopenharmony_ci } 741eace7efcSopenharmony_ci if (pid < 0) { 742eace7efcSopenharmony_ci result.append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) 743eace7efcSopenharmony_ci .append(MSG_DUMP_FAIL_REASON_INVALILD_PID, strlen(MSG_DUMP_FAIL_REASON_INVALILD_PID)); 744eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "invalid pid: %{public}s", optionPid.c_str()); 745eace7efcSopenharmony_ci return DumpErrorCode::ERR_INVALID_PID_ERROR; 746eace7efcSopenharmony_ci } 747eace7efcSopenharmony_ci 748eace7efcSopenharmony_ci switch (key) { 749eace7efcSopenharmony_ci case KEY_DUMP_IPC_START: 750eace7efcSopenharmony_ci return DumpIpcStart(pid, result); 751eace7efcSopenharmony_ci case KEY_DUMP_IPC_STOP: 752eace7efcSopenharmony_ci return DumpIpcStop(pid, result); 753eace7efcSopenharmony_ci case KEY_DUMP_IPC_STAT: 754eace7efcSopenharmony_ci return DumpIpcStat(pid, result); 755eace7efcSopenharmony_ci default: { 756eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "option key %{public}d does not exist", key); 757eace7efcSopenharmony_ci result.append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) 758eace7efcSopenharmony_ci .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL)); 759eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "dump ipc function does not exist"); 760eace7efcSopenharmony_ci return DumpErrorCode::ERR_INTERNAL_ERROR; 761eace7efcSopenharmony_ci } 762eace7efcSopenharmony_ci } 763eace7efcSopenharmony_ci} 764eace7efcSopenharmony_ci 765eace7efcSopenharmony_ciint AppMgrService::DumpFfrtInner(const std::string& pidsRaw, std::string& result) 766eace7efcSopenharmony_ci{ 767eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::APPMGR, "call"); 768eace7efcSopenharmony_ci std::vector<std::string> pidsStr; 769eace7efcSopenharmony_ci SplitStr(pidsRaw, ",", pidsStr); 770eace7efcSopenharmony_ci if (pidsStr.empty()) { 771eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "pids are empty"); 772eace7efcSopenharmony_ci return DumpErrorCode::ERR_INVALID_PID_ERROR; 773eace7efcSopenharmony_ci } 774eace7efcSopenharmony_ci if (pidsStr.size() > MAX_DUMP_FFRT_PID_NUMBER) { 775eace7efcSopenharmony_ci pidsStr.resize(MAX_DUMP_FFRT_PID_NUMBER); 776eace7efcSopenharmony_ci } 777eace7efcSopenharmony_ci std::vector<int32_t> pids; 778eace7efcSopenharmony_ci for (const auto& pidStr : pidsStr) { 779eace7efcSopenharmony_ci int pid = -1; 780eace7efcSopenharmony_ci char* end = nullptr; 781eace7efcSopenharmony_ci pid = static_cast<int32_t>(std::strtol(pidStr.c_str(), &end, BASE_TEN)); 782eace7efcSopenharmony_ci if (end && *end != SIGN_TERMINAL) { 783eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "invalid pid:%{public}s", pidStr.c_str()); 784eace7efcSopenharmony_ci continue; 785eace7efcSopenharmony_ci } 786eace7efcSopenharmony_ci if (pid < 0) { 787eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "invalid pid: %{public}s", pidStr.c_str()); 788eace7efcSopenharmony_ci continue; 789eace7efcSopenharmony_ci } 790eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::APPMGR, "valid pid:%{public}d", pid); 791eace7efcSopenharmony_ci pids.push_back(pid); 792eace7efcSopenharmony_ci } 793eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::APPMGR, "number of valid pids:%{public}d", static_cast<int>(pids.size())); 794eace7efcSopenharmony_ci if (pids.empty()) { 795eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "pids are empty"); 796eace7efcSopenharmony_ci return DumpErrorCode::ERR_INVALID_PID_ERROR; 797eace7efcSopenharmony_ci } 798eace7efcSopenharmony_ci return appMgrServiceInner_->DumpFfrt(pids, result); 799eace7efcSopenharmony_ci} 800eace7efcSopenharmony_ci 801eace7efcSopenharmony_cibool AppMgrService::GetDumpIpcKeyByOption(const std::string &option, DumpIpcKey &key) 802eace7efcSopenharmony_ci{ 803eace7efcSopenharmony_ci if (option == "--start-stat") { 804eace7efcSopenharmony_ci key = KEY_DUMP_IPC_START; 805eace7efcSopenharmony_ci return true; 806eace7efcSopenharmony_ci } 807eace7efcSopenharmony_ci if (option == "--stop-stat") { 808eace7efcSopenharmony_ci key = KEY_DUMP_IPC_STOP; 809eace7efcSopenharmony_ci return true; 810eace7efcSopenharmony_ci } 811eace7efcSopenharmony_ci if (option == "--stat") { 812eace7efcSopenharmony_ci key = KEY_DUMP_IPC_STAT; 813eace7efcSopenharmony_ci return true; 814eace7efcSopenharmony_ci } 815eace7efcSopenharmony_ci return false; 816eace7efcSopenharmony_ci} 817eace7efcSopenharmony_ci 818eace7efcSopenharmony_ciint AppMgrService::DumpIpc(const std::vector<std::u16string>& args, std::string& result) 819eace7efcSopenharmony_ci{ 820eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::APPMGR, "Called. AppMgrService::DumpIpc start"); 821eace7efcSopenharmony_ci if (args.size() != VALID_DUMP_IPC_ARG_SIZE) { 822eace7efcSopenharmony_ci result.append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) 823eace7efcSopenharmony_ci .append(MSG_DUMP_FAIL_REASON_INVALILD_NUM_ARGS, strlen(MSG_DUMP_FAIL_REASON_INVALILD_NUM_ARGS)); 824eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "invalid arguments"); 825eace7efcSopenharmony_ci return DumpErrorCode::ERR_INVALID_NUM_ARGS_ERROR; 826eace7efcSopenharmony_ci } 827eace7efcSopenharmony_ci auto isHidumperServiceCall = (IPCSkeleton::GetCallingUid() == HIDUMPER_SERVICE_UID); 828eace7efcSopenharmony_ci if (!isHidumperServiceCall) { 829eace7efcSopenharmony_ci result.append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) 830eace7efcSopenharmony_ci .append(MSG_DUMP_FAIL_REASON_PERMISSION_DENY, strlen(MSG_DUMP_FAIL_REASON_PERMISSION_DENY)); 831eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "permission deny"); 832eace7efcSopenharmony_ci return DumpErrorCode::ERR_PERMISSION_DENY_ERROR; 833eace7efcSopenharmony_ci } 834eace7efcSopenharmony_ci 835eace7efcSopenharmony_ci std::string optionCmd = Str16ToStr8(args[INDEX_CMD]); 836eace7efcSopenharmony_ci std::string optionPid = Str16ToStr8(args[INDEX_PID]); 837eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::APPMGR, "option pid:%{public}s, option cmd:%{public}s", 838eace7efcSopenharmony_ci optionPid.c_str(), optionCmd.c_str()); 839eace7efcSopenharmony_ci 840eace7efcSopenharmony_ci DumpIpcKey key; 841eace7efcSopenharmony_ci if (!GetDumpIpcKeyByOption(optionCmd, key)) { 842eace7efcSopenharmony_ci result.append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) 843eace7efcSopenharmony_ci .append(MSG_DUMP_FAIL_REASON_INVALILD_CMD, strlen(MSG_DUMP_FAIL_REASON_INVALILD_CMD)); 844eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "option command %{public}s does not exist", optionCmd.c_str()); 845eace7efcSopenharmony_ci return DumpErrorCode::ERR_INVALID_CMD_ERROR; 846eace7efcSopenharmony_ci } 847eace7efcSopenharmony_ci 848eace7efcSopenharmony_ci if (optionPid == "-a" || optionPid == "all" || optionPid == "--all") { 849eace7efcSopenharmony_ci return DumpIpcAllInner(key, result); 850eace7efcSopenharmony_ci } 851eace7efcSopenharmony_ci return DumpIpcWithPidInner(key, optionPid, result); 852eace7efcSopenharmony_ci} 853eace7efcSopenharmony_ci 854eace7efcSopenharmony_ciint AppMgrService::DumpFfrt(const std::vector<std::u16string>& args, std::string& result) 855eace7efcSopenharmony_ci{ 856eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::APPMGR, "Called. AppMgrService::DumpFfrt start"); 857eace7efcSopenharmony_ci if (args.size() != VALID_DUMP_FFRT_ARG_SIZE) { 858eace7efcSopenharmony_ci result.append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) 859eace7efcSopenharmony_ci .append(MSG_DUMP_FAIL_REASON_INVALILD_NUM_ARGS, strlen(MSG_DUMP_FAIL_REASON_INVALILD_NUM_ARGS)); 860eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "invalid arguments"); 861eace7efcSopenharmony_ci return DumpErrorCode::ERR_INVALID_NUM_ARGS_ERROR; 862eace7efcSopenharmony_ci } 863eace7efcSopenharmony_ci auto isHidumperServiceCall = (IPCSkeleton::GetCallingUid() == HIDUMPER_SERVICE_UID); 864eace7efcSopenharmony_ci if (!isHidumperServiceCall) { 865eace7efcSopenharmony_ci result.append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) 866eace7efcSopenharmony_ci .append(MSG_DUMP_FAIL_REASON_PERMISSION_DENY, strlen(MSG_DUMP_FAIL_REASON_PERMISSION_DENY)); 867eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "permission deny"); 868eace7efcSopenharmony_ci return DumpErrorCode::ERR_PERMISSION_DENY_ERROR; 869eace7efcSopenharmony_ci } 870eace7efcSopenharmony_ci 871eace7efcSopenharmony_ci std::string pidsRaw = Str16ToStr8(args[INDEX_PID]); 872eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::APPMGR, "pids:%{public}s", pidsRaw.c_str()); 873eace7efcSopenharmony_ci 874eace7efcSopenharmony_ci return DumpFfrtInner(pidsRaw, result); 875eace7efcSopenharmony_ci} 876eace7efcSopenharmony_ci 877eace7efcSopenharmony_ciint AppMgrService::DumpIpcAllStart(std::string& result) 878eace7efcSopenharmony_ci{ 879eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::APPMGR, "called"); 880eace7efcSopenharmony_ci return appMgrServiceInner_->DumpIpcAllStart(result); 881eace7efcSopenharmony_ci} 882eace7efcSopenharmony_ci 883eace7efcSopenharmony_ciint AppMgrService::DumpIpcAllStop(std::string& result) 884eace7efcSopenharmony_ci{ 885eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::APPMGR, "called"); 886eace7efcSopenharmony_ci return appMgrServiceInner_->DumpIpcAllStop(result); 887eace7efcSopenharmony_ci} 888eace7efcSopenharmony_ci 889eace7efcSopenharmony_ciint AppMgrService::DumpIpcAllStat(std::string& result) 890eace7efcSopenharmony_ci{ 891eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::APPMGR, "called"); 892eace7efcSopenharmony_ci return appMgrServiceInner_->DumpIpcAllStat(result); 893eace7efcSopenharmony_ci} 894eace7efcSopenharmony_ci 895eace7efcSopenharmony_ciint AppMgrService::DumpIpcStart(const int32_t pid, std::string& result) 896eace7efcSopenharmony_ci{ 897eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::APPMGR, "called"); 898eace7efcSopenharmony_ci return appMgrServiceInner_->DumpIpcStart(pid, result); 899eace7efcSopenharmony_ci} 900eace7efcSopenharmony_ci 901eace7efcSopenharmony_ciint AppMgrService::DumpIpcStop(const int32_t pid, std::string& result) 902eace7efcSopenharmony_ci{ 903eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::APPMGR, "called"); 904eace7efcSopenharmony_ci return appMgrServiceInner_->DumpIpcStop(pid, result); 905eace7efcSopenharmony_ci} 906eace7efcSopenharmony_ci 907eace7efcSopenharmony_ciint AppMgrService::DumpIpcStat(const int32_t pid, std::string& result) 908eace7efcSopenharmony_ci{ 909eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::APPMGR, "called"); 910eace7efcSopenharmony_ci return appMgrServiceInner_->DumpIpcStat(pid, result); 911eace7efcSopenharmony_ci} 912eace7efcSopenharmony_ci 913eace7efcSopenharmony_civoid AppMgrService::ScheduleAcceptWantDone(const int32_t recordId, const AAFwk::Want &want, const std::string &flag) 914eace7efcSopenharmony_ci{ 915eace7efcSopenharmony_ci if (!IsReady()) { 916eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 917eace7efcSopenharmony_ci return; 918eace7efcSopenharmony_ci } 919eace7efcSopenharmony_ci if (!JudgeAppSelfCalled(recordId)) { 920eace7efcSopenharmony_ci return; 921eace7efcSopenharmony_ci } 922eace7efcSopenharmony_ci auto task = [appMgrServiceInner = appMgrServiceInner_, recordId, want, flag]() { 923eace7efcSopenharmony_ci appMgrServiceInner->ScheduleAcceptWantDone(recordId, want, flag); 924eace7efcSopenharmony_ci }; 925eace7efcSopenharmony_ci taskHandler_->SubmitTask(task); 926eace7efcSopenharmony_ci} 927eace7efcSopenharmony_ci 928eace7efcSopenharmony_civoid AppMgrService::ScheduleNewProcessRequestDone(const int32_t recordId, const AAFwk::Want &want, 929eace7efcSopenharmony_ci const std::string &flag) 930eace7efcSopenharmony_ci{ 931eace7efcSopenharmony_ci if (!IsReady()) { 932eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 933eace7efcSopenharmony_ci return; 934eace7efcSopenharmony_ci } 935eace7efcSopenharmony_ci if (!JudgeAppSelfCalled(recordId)) { 936eace7efcSopenharmony_ci return; 937eace7efcSopenharmony_ci } 938eace7efcSopenharmony_ci auto task = [appMgrServiceInner = appMgrServiceInner_, recordId, want, flag]() { 939eace7efcSopenharmony_ci appMgrServiceInner->ScheduleNewProcessRequestDone(recordId, want, flag); 940eace7efcSopenharmony_ci }; 941eace7efcSopenharmony_ci taskHandler_->SubmitTask(task, AAFwk::TaskQoS::USER_INTERACTIVE); 942eace7efcSopenharmony_ci} 943eace7efcSopenharmony_ci 944eace7efcSopenharmony_ciint AppMgrService::GetAbilityRecordsByProcessID(const int pid, std::vector<sptr<IRemoteObject>> &tokens) 945eace7efcSopenharmony_ci{ 946eace7efcSopenharmony_ci if (!IsReady()) { 947eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 948eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 949eace7efcSopenharmony_ci } 950eace7efcSopenharmony_ci auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall(); 951eace7efcSopenharmony_ci if (!isSaCall) { 952eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "null Sacall"); 953eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 954eace7efcSopenharmony_ci } 955eace7efcSopenharmony_ci return appMgrServiceInner_->GetAbilityRecordsByProcessID(pid, tokens); 956eace7efcSopenharmony_ci} 957eace7efcSopenharmony_ci 958eace7efcSopenharmony_ciint32_t AppMgrService::PreStartNWebSpawnProcess() 959eace7efcSopenharmony_ci{ 960eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::APPMGR, "PreStartNWebSpawnProcess"); 961eace7efcSopenharmony_ci if (!IsReady()) { 962eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 963eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 964eace7efcSopenharmony_ci } 965eace7efcSopenharmony_ci 966eace7efcSopenharmony_ci return appMgrServiceInner_->PreStartNWebSpawnProcess(IPCSkeleton::GetCallingPid()); 967eace7efcSopenharmony_ci} 968eace7efcSopenharmony_ci 969eace7efcSopenharmony_ciint32_t AppMgrService::StartRenderProcess(const std::string &renderParam, int32_t ipcFd, 970eace7efcSopenharmony_ci int32_t sharedFd, int32_t crashFd, pid_t &renderPid, bool isGPU) 971eace7efcSopenharmony_ci{ 972eace7efcSopenharmony_ci if (!IsReady()) { 973eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 974eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 975eace7efcSopenharmony_ci } 976eace7efcSopenharmony_ci 977eace7efcSopenharmony_ci return appMgrServiceInner_->StartRenderProcess(IPCSkeleton::GetCallingPid(), 978eace7efcSopenharmony_ci renderParam, ipcFd, sharedFd, crashFd, renderPid, isGPU); 979eace7efcSopenharmony_ci} 980eace7efcSopenharmony_ci 981eace7efcSopenharmony_civoid AppMgrService::AttachRenderProcess(const sptr<IRemoteObject> &scheduler) 982eace7efcSopenharmony_ci{ 983eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::APPMGR, "call"); 984eace7efcSopenharmony_ci if (!IsReady()) { 985eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 986eace7efcSopenharmony_ci return; 987eace7efcSopenharmony_ci } 988eace7efcSopenharmony_ci 989eace7efcSopenharmony_ci auto pid = IPCSkeleton::GetCallingPid(); 990eace7efcSopenharmony_ci auto fun = [appMgrServiceInner = appMgrServiceInner_, pid, scheduler]() { 991eace7efcSopenharmony_ci appMgrServiceInner->AttachRenderProcess(pid, iface_cast<IRenderScheduler>(scheduler)); 992eace7efcSopenharmony_ci }; 993eace7efcSopenharmony_ci taskHandler_->SubmitTask(fun, AAFwk::TaskAttribute{ 994eace7efcSopenharmony_ci .taskName_ = TASK_ATTACH_RENDER_PROCESS, 995eace7efcSopenharmony_ci .taskQos_ = AAFwk::TaskQoS::USER_INTERACTIVE 996eace7efcSopenharmony_ci }); 997eace7efcSopenharmony_ci} 998eace7efcSopenharmony_ci 999eace7efcSopenharmony_civoid AppMgrService::SaveBrowserChannel(sptr<IRemoteObject> browser) 1000eace7efcSopenharmony_ci{ 1001eace7efcSopenharmony_ci if (!IsReady()) { 1002eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 1003eace7efcSopenharmony_ci return; 1004eace7efcSopenharmony_ci } 1005eace7efcSopenharmony_ci 1006eace7efcSopenharmony_ci appMgrServiceInner_->SaveBrowserChannel(IPCSkeleton::GetCallingPid(), browser); 1007eace7efcSopenharmony_ci} 1008eace7efcSopenharmony_ci 1009eace7efcSopenharmony_ciint32_t AppMgrService::GetRenderProcessTerminationStatus(pid_t renderPid, int &status) 1010eace7efcSopenharmony_ci{ 1011eace7efcSopenharmony_ci if (!IsReady()) { 1012eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 1013eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 1014eace7efcSopenharmony_ci } 1015eace7efcSopenharmony_ci 1016eace7efcSopenharmony_ci return appMgrServiceInner_->GetRenderProcessTerminationStatus(renderPid, status); 1017eace7efcSopenharmony_ci} 1018eace7efcSopenharmony_ci 1019eace7efcSopenharmony_ciint32_t AppMgrService::GetConfiguration(Configuration& config) 1020eace7efcSopenharmony_ci{ 1021eace7efcSopenharmony_ci if (!IsReady()) { 1022eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 1023eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 1024eace7efcSopenharmony_ci } 1025eace7efcSopenharmony_ci config = *(appMgrServiceInner_->GetConfiguration()); 1026eace7efcSopenharmony_ci return ERR_OK; 1027eace7efcSopenharmony_ci} 1028eace7efcSopenharmony_ci 1029eace7efcSopenharmony_ciint32_t AppMgrService::UpdateConfiguration(const Configuration& config, const int32_t userId) 1030eace7efcSopenharmony_ci{ 1031eace7efcSopenharmony_ci HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); 1032eace7efcSopenharmony_ci if (!IsReady()) { 1033eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 1034eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 1035eace7efcSopenharmony_ci } 1036eace7efcSopenharmony_ci return appMgrServiceInner_->UpdateConfiguration(config, userId); 1037eace7efcSopenharmony_ci} 1038eace7efcSopenharmony_ci 1039eace7efcSopenharmony_ciint32_t AppMgrService::UpdateConfigurationByBundleName(const Configuration& config, const std::string &name) 1040eace7efcSopenharmony_ci{ 1041eace7efcSopenharmony_ci if (!IsReady()) { 1042eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 1043eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 1044eace7efcSopenharmony_ci } 1045eace7efcSopenharmony_ci return appMgrServiceInner_->UpdateConfigurationByBundleName(config, name); 1046eace7efcSopenharmony_ci} 1047eace7efcSopenharmony_ci 1048eace7efcSopenharmony_ciint32_t AppMgrService::RegisterConfigurationObserver(const sptr<IConfigurationObserver> &observer) 1049eace7efcSopenharmony_ci{ 1050eace7efcSopenharmony_ci if (!IsReady()) { 1051eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 1052eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 1053eace7efcSopenharmony_ci } 1054eace7efcSopenharmony_ci return appMgrServiceInner_->RegisterConfigurationObserver(observer); 1055eace7efcSopenharmony_ci} 1056eace7efcSopenharmony_ci 1057eace7efcSopenharmony_ciint32_t AppMgrService::UnregisterConfigurationObserver(const sptr<IConfigurationObserver> &observer) 1058eace7efcSopenharmony_ci{ 1059eace7efcSopenharmony_ci if (!IsReady()) { 1060eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 1061eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 1062eace7efcSopenharmony_ci } 1063eace7efcSopenharmony_ci return appMgrServiceInner_->UnregisterConfigurationObserver(observer); 1064eace7efcSopenharmony_ci} 1065eace7efcSopenharmony_ci 1066eace7efcSopenharmony_cibool AppMgrService::GetAppRunningStateByBundleName(const std::string &bundleName) 1067eace7efcSopenharmony_ci{ 1068eace7efcSopenharmony_ci if (!IsReady()) { 1069eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 1070eace7efcSopenharmony_ci return false; 1071eace7efcSopenharmony_ci } 1072eace7efcSopenharmony_ci 1073eace7efcSopenharmony_ci return appMgrServiceInner_->GetAppRunningStateByBundleName(bundleName); 1074eace7efcSopenharmony_ci} 1075eace7efcSopenharmony_ci 1076eace7efcSopenharmony_ciint32_t AppMgrService::NotifyLoadRepairPatch(const std::string &bundleName, const sptr<IQuickFixCallback> &callback) 1077eace7efcSopenharmony_ci{ 1078eace7efcSopenharmony_ci if (!IsReady()) { 1079eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 1080eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 1081eace7efcSopenharmony_ci } 1082eace7efcSopenharmony_ci return appMgrServiceInner_->NotifyLoadRepairPatch(bundleName, callback); 1083eace7efcSopenharmony_ci} 1084eace7efcSopenharmony_ci 1085eace7efcSopenharmony_ciint32_t AppMgrService::NotifyHotReloadPage(const std::string &bundleName, const sptr<IQuickFixCallback> &callback) 1086eace7efcSopenharmony_ci{ 1087eace7efcSopenharmony_ci if (!IsReady()) { 1088eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 1089eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 1090eace7efcSopenharmony_ci } 1091eace7efcSopenharmony_ci return appMgrServiceInner_->NotifyHotReloadPage(bundleName, callback); 1092eace7efcSopenharmony_ci} 1093eace7efcSopenharmony_ci 1094eace7efcSopenharmony_ci#ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE 1095eace7efcSopenharmony_ciint32_t AppMgrService::SetContinuousTaskProcess(int32_t pid, bool isContinuousTask) 1096eace7efcSopenharmony_ci{ 1097eace7efcSopenharmony_ci if (!AAFwk::PermissionVerification::GetInstance()->CheckSpecificSystemAbilityAccessPermission(FOUNDATION_PROCESS)) { 1098eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "not foundation"); 1099eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 1100eace7efcSopenharmony_ci } 1101eace7efcSopenharmony_ci if (!IsReady()) { 1102eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 1103eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 1104eace7efcSopenharmony_ci } 1105eace7efcSopenharmony_ci 1106eace7efcSopenharmony_ci return appMgrServiceInner_->SetContinuousTaskProcess(pid, isContinuousTask); 1107eace7efcSopenharmony_ci} 1108eace7efcSopenharmony_ci#endif 1109eace7efcSopenharmony_ci 1110eace7efcSopenharmony_ciint32_t AppMgrService::NotifyUnLoadRepairPatch(const std::string &bundleName, const sptr<IQuickFixCallback> &callback) 1111eace7efcSopenharmony_ci{ 1112eace7efcSopenharmony_ci if (!IsReady()) { 1113eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 1114eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 1115eace7efcSopenharmony_ci } 1116eace7efcSopenharmony_ci return appMgrServiceInner_->NotifyUnLoadRepairPatch(bundleName, callback); 1117eace7efcSopenharmony_ci} 1118eace7efcSopenharmony_ci 1119eace7efcSopenharmony_cibool AppMgrService::JudgeAppSelfCalled(int32_t recordId) 1120eace7efcSopenharmony_ci{ 1121eace7efcSopenharmony_ci if (appMgrServiceInner_ == nullptr) { 1122eace7efcSopenharmony_ci return false; 1123eace7efcSopenharmony_ci } 1124eace7efcSopenharmony_ci 1125eace7efcSopenharmony_ci auto callingTokenId = IPCSkeleton::GetCallingTokenID(); 1126eace7efcSopenharmony_ci std::shared_ptr<AppRunningRecord> appRecord = appMgrServiceInner_->GetAppRunningRecordByAppRecordId(recordId); 1127eace7efcSopenharmony_ci if (appRecord == nullptr || ((appRecord->GetApplicationInfo())->accessTokenId) != callingTokenId) { 1128eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not enabled"); 1129eace7efcSopenharmony_ci return false; 1130eace7efcSopenharmony_ci } 1131eace7efcSopenharmony_ci 1132eace7efcSopenharmony_ci return true; 1133eace7efcSopenharmony_ci} 1134eace7efcSopenharmony_ci 1135eace7efcSopenharmony_cibool AppMgrService::IsSharedBundleRunning(const std::string &bundleName, uint32_t versionCode) 1136eace7efcSopenharmony_ci{ 1137eace7efcSopenharmony_ci if (!IsReady()) { 1138eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 1139eace7efcSopenharmony_ci } 1140eace7efcSopenharmony_ci return appMgrServiceInner_->IsSharedBundleRunning(bundleName, versionCode); 1141eace7efcSopenharmony_ci} 1142eace7efcSopenharmony_ci 1143eace7efcSopenharmony_ciint32_t AppMgrService::StartNativeProcessForDebugger(const AAFwk::Want &want) 1144eace7efcSopenharmony_ci{ 1145eace7efcSopenharmony_ci if (!IsReady()) { 1146eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 1147eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 1148eace7efcSopenharmony_ci } 1149eace7efcSopenharmony_ci auto isShellCall = AAFwk::PermissionVerification::GetInstance()->IsShellCall(); 1150eace7efcSopenharmony_ci if (!isShellCall) { 1151eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "permission denied"); 1152eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 1153eace7efcSopenharmony_ci } 1154eace7efcSopenharmony_ci auto ret = appMgrServiceInner_->StartNativeProcessForDebugger(want); 1155eace7efcSopenharmony_ci if (ret != ERR_OK) { 1156eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "start native process fail"); 1157eace7efcSopenharmony_ci } 1158eace7efcSopenharmony_ci return ret; 1159eace7efcSopenharmony_ci} 1160eace7efcSopenharmony_ci 1161eace7efcSopenharmony_ciint32_t AppMgrService::GetBundleNameByPid(const int32_t pid, std::string &bundleName, int32_t &uid) 1162eace7efcSopenharmony_ci{ 1163eace7efcSopenharmony_ci if (!IsReady()) { 1164eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 1165eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 1166eace7efcSopenharmony_ci } 1167eace7efcSopenharmony_ci return appMgrServiceInner_->GetBundleNameByPid(pid, bundleName, uid); 1168eace7efcSopenharmony_ci} 1169eace7efcSopenharmony_ci 1170eace7efcSopenharmony_ciint32_t AppMgrService::GetRunningProcessInfoByPid(const pid_t pid, OHOS::AppExecFwk::RunningProcessInfo &info) 1171eace7efcSopenharmony_ci{ 1172eace7efcSopenharmony_ci if (!IsReady()) { 1173eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 1174eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 1175eace7efcSopenharmony_ci } 1176eace7efcSopenharmony_ci return appMgrServiceInner_->GetRunningProcessInfoByPid(pid, info); 1177eace7efcSopenharmony_ci} 1178eace7efcSopenharmony_ci 1179eace7efcSopenharmony_ciint32_t AppMgrService::NotifyAppFault(const FaultData &faultData) 1180eace7efcSopenharmony_ci{ 1181eace7efcSopenharmony_ci if (!IsReady()) { 1182eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 1183eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 1184eace7efcSopenharmony_ci } 1185eace7efcSopenharmony_ci 1186eace7efcSopenharmony_ci auto ret = appMgrServiceInner_->NotifyAppFault(faultData); 1187eace7efcSopenharmony_ci if (ret != ERR_OK) { 1188eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "faultData fail"); 1189eace7efcSopenharmony_ci } 1190eace7efcSopenharmony_ci return ret; 1191eace7efcSopenharmony_ci} 1192eace7efcSopenharmony_ci 1193eace7efcSopenharmony_ciint32_t AppMgrService::NotifyAppFaultBySA(const AppFaultDataBySA &faultData) 1194eace7efcSopenharmony_ci{ 1195eace7efcSopenharmony_ci if (!IsReady()) { 1196eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 1197eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 1198eace7efcSopenharmony_ci } 1199eace7efcSopenharmony_ci 1200eace7efcSopenharmony_ci auto ret = appMgrServiceInner_->NotifyAppFaultBySA(faultData); 1201eace7efcSopenharmony_ci if (ret != ERR_OK) { 1202eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "faultData fail"); 1203eace7efcSopenharmony_ci } 1204eace7efcSopenharmony_ci return ret; 1205eace7efcSopenharmony_ci} 1206eace7efcSopenharmony_ci 1207eace7efcSopenharmony_cibool AppMgrService::SetAppFreezeFilter(int32_t pid) 1208eace7efcSopenharmony_ci{ 1209eace7efcSopenharmony_ci if (!IsReady()) { 1210eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 1211eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 1212eace7efcSopenharmony_ci } 1213eace7efcSopenharmony_ci 1214eace7efcSopenharmony_ci auto ret = appMgrServiceInner_->SetAppFreezeFilter(pid); 1215eace7efcSopenharmony_ci if (!ret) { 1216eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "SetAppFreezeFilter fail"); 1217eace7efcSopenharmony_ci } 1218eace7efcSopenharmony_ci return ret; 1219eace7efcSopenharmony_ci} 1220eace7efcSopenharmony_ci 1221eace7efcSopenharmony_ciint32_t AppMgrService::GetProcessMemoryByPid(const int32_t pid, int32_t &memorySize) 1222eace7efcSopenharmony_ci{ 1223eace7efcSopenharmony_ci if (!IsReady()) { 1224eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 1225eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 1226eace7efcSopenharmony_ci } 1227eace7efcSopenharmony_ci 1228eace7efcSopenharmony_ci return appMgrServiceInner_->GetProcessMemoryByPid(pid, memorySize); 1229eace7efcSopenharmony_ci} 1230eace7efcSopenharmony_ci 1231eace7efcSopenharmony_ciint32_t AppMgrService::GetRunningProcessInformation(const std::string &bundleName, int32_t userId, 1232eace7efcSopenharmony_ci std::vector<RunningProcessInfo> &info) 1233eace7efcSopenharmony_ci{ 1234eace7efcSopenharmony_ci if (!IsReady()) { 1235eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 1236eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 1237eace7efcSopenharmony_ci } 1238eace7efcSopenharmony_ci 1239eace7efcSopenharmony_ci return appMgrServiceInner_->GetRunningProcessInformation(bundleName, userId, info); 1240eace7efcSopenharmony_ci} 1241eace7efcSopenharmony_ci 1242eace7efcSopenharmony_civoid AppMgrService::OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) 1243eace7efcSopenharmony_ci{ 1244eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::APPMGR, "systemAbilityId: %{public}d add", systemAbilityId); 1245eace7efcSopenharmony_ci if (!IsReady()) { 1246eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 1247eace7efcSopenharmony_ci return; 1248eace7efcSopenharmony_ci } 1249eace7efcSopenharmony_ci 1250eace7efcSopenharmony_ci if (systemAbilityId != WINDOW_MANAGER_SERVICE_ID) { 1251eace7efcSopenharmony_ci return; 1252eace7efcSopenharmony_ci } 1253eace7efcSopenharmony_ci 1254eace7efcSopenharmony_ci appMgrServiceInner_->InitFocusListener(); 1255eace7efcSopenharmony_ci#ifdef SUPPORT_SCREEN 1256eace7efcSopenharmony_ci appMgrServiceInner_->InitWindowVisibilityChangedListener(); 1257eace7efcSopenharmony_ci appMgrServiceInner_->InitWindowPidVisibilityChangedListener(); 1258eace7efcSopenharmony_ci#endif 1259eace7efcSopenharmony_ci} 1260eace7efcSopenharmony_ci 1261eace7efcSopenharmony_civoid AppMgrService::OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) 1262eace7efcSopenharmony_ci{ 1263eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::APPMGR, "systemAbilityId: %{public}d remove", systemAbilityId); 1264eace7efcSopenharmony_ci if (!IsReady()) { 1265eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 1266eace7efcSopenharmony_ci return; 1267eace7efcSopenharmony_ci } 1268eace7efcSopenharmony_ci 1269eace7efcSopenharmony_ci if (systemAbilityId != WINDOW_MANAGER_SERVICE_ID) { 1270eace7efcSopenharmony_ci return; 1271eace7efcSopenharmony_ci } 1272eace7efcSopenharmony_ci 1273eace7efcSopenharmony_ci appMgrServiceInner_->FreeFocusListener(); 1274eace7efcSopenharmony_ci#ifdef SUPPORT_SCREEN 1275eace7efcSopenharmony_ci appMgrServiceInner_->FreeWindowVisibilityChangedListener(); 1276eace7efcSopenharmony_ci appMgrServiceInner_->FreeWindowPidVisibilityChangedListener(); 1277eace7efcSopenharmony_ci#endif 1278eace7efcSopenharmony_ci} 1279eace7efcSopenharmony_ci 1280eace7efcSopenharmony_ciint32_t AppMgrService::ChangeAppGcState(pid_t pid, int32_t state) 1281eace7efcSopenharmony_ci{ 1282eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::APPMGR, "called"); 1283eace7efcSopenharmony_ci if (!appMgrServiceInner_) { 1284eace7efcSopenharmony_ci return ERR_INVALID_VALUE; 1285eace7efcSopenharmony_ci } 1286eace7efcSopenharmony_ci return appMgrServiceInner_->ChangeAppGcState(pid, state); 1287eace7efcSopenharmony_ci} 1288eace7efcSopenharmony_ci 1289eace7efcSopenharmony_ciint32_t AppMgrService::NotifyPageShow(const sptr<IRemoteObject> &token, const PageStateData &pageStateData) 1290eace7efcSopenharmony_ci{ 1291eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::APPMGR, 1292eace7efcSopenharmony_ci "bundleName: %{public}s, moduelName: %{public}s, abilityName: %{public}s, pageName: %{public}s", 1293eace7efcSopenharmony_ci pageStateData.bundleName.c_str(), pageStateData.moduleName.c_str(), pageStateData.abilityName.c_str(), 1294eace7efcSopenharmony_ci pageStateData.pageName.c_str()); 1295eace7efcSopenharmony_ci if (!IsReady()) { 1296eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 1297eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 1298eace7efcSopenharmony_ci } 1299eace7efcSopenharmony_ci return appMgrServiceInner_->NotifyPageShow(token, pageStateData); 1300eace7efcSopenharmony_ci} 1301eace7efcSopenharmony_ci 1302eace7efcSopenharmony_ciint32_t AppMgrService::NotifyPageHide(const sptr<IRemoteObject> &token, const PageStateData &pageStateData) 1303eace7efcSopenharmony_ci{ 1304eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::APPMGR, 1305eace7efcSopenharmony_ci "bundleName: %{public}s, moduelName: %{public}s, abilityName: %{public}s, pageName: %{public}s", 1306eace7efcSopenharmony_ci pageStateData.bundleName.c_str(), pageStateData.moduleName.c_str(), pageStateData.abilityName.c_str(), 1307eace7efcSopenharmony_ci pageStateData.pageName.c_str()); 1308eace7efcSopenharmony_ci if (!IsReady()) { 1309eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 1310eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 1311eace7efcSopenharmony_ci } 1312eace7efcSopenharmony_ci return appMgrServiceInner_->NotifyPageHide(token, pageStateData); 1313eace7efcSopenharmony_ci} 1314eace7efcSopenharmony_ci 1315eace7efcSopenharmony_ciint32_t AppMgrService::RegisterAppRunningStatusListener(const sptr<IRemoteObject> &listener) 1316eace7efcSopenharmony_ci{ 1317eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::APPMGR, "called"); 1318eace7efcSopenharmony_ci if (!IsReady()) { 1319eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 1320eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 1321eace7efcSopenharmony_ci } 1322eace7efcSopenharmony_ci return appMgrServiceInner_->RegisterAppRunningStatusListener(listener); 1323eace7efcSopenharmony_ci} 1324eace7efcSopenharmony_ci 1325eace7efcSopenharmony_ciint32_t AppMgrService::UnregisterAppRunningStatusListener(const sptr<IRemoteObject> &listener) 1326eace7efcSopenharmony_ci{ 1327eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::APPMGR, "called"); 1328eace7efcSopenharmony_ci if (!IsReady()) { 1329eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 1330eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 1331eace7efcSopenharmony_ci } 1332eace7efcSopenharmony_ci return appMgrServiceInner_->UnregisterAppRunningStatusListener(listener); 1333eace7efcSopenharmony_ci} 1334eace7efcSopenharmony_ci 1335eace7efcSopenharmony_ciint32_t AppMgrService::RegisterAppForegroundStateObserver(const sptr<IAppForegroundStateObserver> &observer) 1336eace7efcSopenharmony_ci{ 1337eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::APPMGR, "called"); 1338eace7efcSopenharmony_ci if (!IsReady()) { 1339eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 1340eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 1341eace7efcSopenharmony_ci } 1342eace7efcSopenharmony_ci return appMgrServiceInner_->RegisterAppForegroundStateObserver(observer); 1343eace7efcSopenharmony_ci} 1344eace7efcSopenharmony_ci 1345eace7efcSopenharmony_ciint32_t AppMgrService::UnregisterAppForegroundStateObserver(const sptr<IAppForegroundStateObserver> &observer) 1346eace7efcSopenharmony_ci{ 1347eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::APPMGR, "called"); 1348eace7efcSopenharmony_ci if (!IsReady()) { 1349eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 1350eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 1351eace7efcSopenharmony_ci } 1352eace7efcSopenharmony_ci return appMgrServiceInner_->UnregisterAppForegroundStateObserver(observer); 1353eace7efcSopenharmony_ci} 1354eace7efcSopenharmony_ci 1355eace7efcSopenharmony_ciint32_t AppMgrService::IsApplicationRunning(const std::string &bundleName, bool &isRunning) 1356eace7efcSopenharmony_ci{ 1357eace7efcSopenharmony_ci if (!IsReady()) { 1358eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 1359eace7efcSopenharmony_ci } 1360eace7efcSopenharmony_ci return appMgrServiceInner_->IsApplicationRunning(bundleName, isRunning); 1361eace7efcSopenharmony_ci} 1362eace7efcSopenharmony_ci 1363eace7efcSopenharmony_ciint32_t AppMgrService::IsAppRunning(const std::string &bundleName, int32_t appCloneIndex, bool &isRunning) 1364eace7efcSopenharmony_ci{ 1365eace7efcSopenharmony_ci if (!IsReady()) { 1366eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 1367eace7efcSopenharmony_ci } 1368eace7efcSopenharmony_ci return appMgrServiceInner_->IsAppRunning(bundleName, appCloneIndex, isRunning); 1369eace7efcSopenharmony_ci} 1370eace7efcSopenharmony_ci 1371eace7efcSopenharmony_ciint32_t AppMgrService::StartChildProcess(pid_t &childPid, const ChildProcessRequest &request) 1372eace7efcSopenharmony_ci{ 1373eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::APPMGR, "called"); 1374eace7efcSopenharmony_ci if (!IsReady()) { 1375eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 1376eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 1377eace7efcSopenharmony_ci } 1378eace7efcSopenharmony_ci return appMgrServiceInner_->StartChildProcess(IPCSkeleton::GetCallingPid(), childPid, request); 1379eace7efcSopenharmony_ci} 1380eace7efcSopenharmony_ci 1381eace7efcSopenharmony_ciint32_t AppMgrService::GetChildProcessInfoForSelf(ChildProcessInfo &info) 1382eace7efcSopenharmony_ci{ 1383eace7efcSopenharmony_ci if (!IsReady()) { 1384eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 1385eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 1386eace7efcSopenharmony_ci } 1387eace7efcSopenharmony_ci return appMgrServiceInner_->GetChildProcessInfoForSelf(info); 1388eace7efcSopenharmony_ci} 1389eace7efcSopenharmony_ci 1390eace7efcSopenharmony_civoid AppMgrService::AttachChildProcess(const sptr<IRemoteObject> &childScheduler) 1391eace7efcSopenharmony_ci{ 1392eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::APPMGR, "AttachChildProcess."); 1393eace7efcSopenharmony_ci if (!IsReady()) { 1394eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 1395eace7efcSopenharmony_ci return; 1396eace7efcSopenharmony_ci } 1397eace7efcSopenharmony_ci if (!taskHandler_) { 1398eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "null taskHandler_"); 1399eace7efcSopenharmony_ci return; 1400eace7efcSopenharmony_ci } 1401eace7efcSopenharmony_ci pid_t pid = IPCSkeleton::GetCallingPid(); 1402eace7efcSopenharmony_ci std::function<void()> task = [appMgrServiceInner = appMgrServiceInner_, pid, childScheduler]() { 1403eace7efcSopenharmony_ci appMgrServiceInner->AttachChildProcess(pid, iface_cast<IChildScheduler>(childScheduler)); 1404eace7efcSopenharmony_ci }; 1405eace7efcSopenharmony_ci taskHandler_->SubmitTask(task, AAFwk::TaskAttribute{ 1406eace7efcSopenharmony_ci .taskName_ = TASK_ATTACH_CHILD_PROCESS, 1407eace7efcSopenharmony_ci .taskQos_ = AAFwk::TaskQoS::USER_INTERACTIVE 1408eace7efcSopenharmony_ci }); 1409eace7efcSopenharmony_ci} 1410eace7efcSopenharmony_ci 1411eace7efcSopenharmony_civoid AppMgrService::ExitChildProcessSafely() 1412eace7efcSopenharmony_ci{ 1413eace7efcSopenharmony_ci if (!IsReady()) { 1414eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 1415eace7efcSopenharmony_ci return; 1416eace7efcSopenharmony_ci } 1417eace7efcSopenharmony_ci if (!taskHandler_) { 1418eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "null taskHandler_"); 1419eace7efcSopenharmony_ci return; 1420eace7efcSopenharmony_ci } 1421eace7efcSopenharmony_ci pid_t pid = IPCSkeleton::GetCallingPid(); 1422eace7efcSopenharmony_ci std::function<void()> task = [appMgrServiceInner = appMgrServiceInner_, pid]() { 1423eace7efcSopenharmony_ci appMgrServiceInner->ExitChildProcessSafelyByChildPid(pid); 1424eace7efcSopenharmony_ci }; 1425eace7efcSopenharmony_ci taskHandler_->SubmitTask(task, AAFwk::TaskAttribute{ 1426eace7efcSopenharmony_ci .taskName_ = TASK_EXIT_CHILD_PROCESS_SAFELY, 1427eace7efcSopenharmony_ci .taskQos_ = AAFwk::TaskQoS::USER_INTERACTIVE 1428eace7efcSopenharmony_ci }); 1429eace7efcSopenharmony_ci} 1430eace7efcSopenharmony_ci 1431eace7efcSopenharmony_cibool AppMgrService::IsFinalAppProcess() 1432eace7efcSopenharmony_ci{ 1433eace7efcSopenharmony_ci if (!IsReady()) { 1434eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 1435eace7efcSopenharmony_ci return false; 1436eace7efcSopenharmony_ci } 1437eace7efcSopenharmony_ci return appMgrServiceInner_->IsFinalAppProcessByBundleName(""); 1438eace7efcSopenharmony_ci} 1439eace7efcSopenharmony_ci 1440eace7efcSopenharmony_ciint32_t AppMgrService::RegisterRenderStateObserver(const sptr<IRenderStateObserver> &observer) 1441eace7efcSopenharmony_ci{ 1442eace7efcSopenharmony_ci if (!IsReady()) { 1443eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 1444eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 1445eace7efcSopenharmony_ci } 1446eace7efcSopenharmony_ci 1447eace7efcSopenharmony_ci if (AAFwk::PermissionVerification::GetInstance()->VerifyAppStateObserverPermission() == ERR_PERMISSION_DENIED) { 1448eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "verification failed"); 1449eace7efcSopenharmony_ci return ERR_PERMISSION_DENIED; 1450eace7efcSopenharmony_ci } 1451eace7efcSopenharmony_ci return appMgrServiceInner_->RegisterRenderStateObserver(observer); 1452eace7efcSopenharmony_ci} 1453eace7efcSopenharmony_ci 1454eace7efcSopenharmony_ciint32_t AppMgrService::UnregisterRenderStateObserver(const sptr<IRenderStateObserver> &observer) 1455eace7efcSopenharmony_ci{ 1456eace7efcSopenharmony_ci if (!IsReady()) { 1457eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 1458eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 1459eace7efcSopenharmony_ci } 1460eace7efcSopenharmony_ci 1461eace7efcSopenharmony_ci if (AAFwk::PermissionVerification::GetInstance()->VerifyAppStateObserverPermission() == ERR_PERMISSION_DENIED) { 1462eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "verification failed"); 1463eace7efcSopenharmony_ci return ERR_PERMISSION_DENIED; 1464eace7efcSopenharmony_ci } 1465eace7efcSopenharmony_ci return appMgrServiceInner_->UnregisterRenderStateObserver(observer); 1466eace7efcSopenharmony_ci} 1467eace7efcSopenharmony_ci 1468eace7efcSopenharmony_ciint32_t AppMgrService::UpdateRenderState(pid_t renderPid, int32_t state) 1469eace7efcSopenharmony_ci{ 1470eace7efcSopenharmony_ci if (!IsReady()) { 1471eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 1472eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 1473eace7efcSopenharmony_ci } 1474eace7efcSopenharmony_ci return appMgrServiceInner_->UpdateRenderState(renderPid, state); 1475eace7efcSopenharmony_ci} 1476eace7efcSopenharmony_ci 1477eace7efcSopenharmony_ciint32_t AppMgrService::SignRestartAppFlag(int32_t uid) 1478eace7efcSopenharmony_ci{ 1479eace7efcSopenharmony_ci if (!IsReady()) { 1480eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 1481eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 1482eace7efcSopenharmony_ci } 1483eace7efcSopenharmony_ci bool isCallingPermission = 1484eace7efcSopenharmony_ci AAFwk::PermissionVerification::GetInstance()->CheckSpecificSystemAbilityAccessPermission(FOUNDATION_PROCESS); 1485eace7efcSopenharmony_ci if (!isCallingPermission) { 1486eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "verification failed"); 1487eace7efcSopenharmony_ci return ERR_PERMISSION_DENIED; 1488eace7efcSopenharmony_ci } 1489eace7efcSopenharmony_ci return appMgrServiceInner_->SignRestartAppFlag(uid); 1490eace7efcSopenharmony_ci} 1491eace7efcSopenharmony_ci 1492eace7efcSopenharmony_ciint32_t AppMgrService::GetAppRunningUniqueIdByPid(pid_t pid, std::string &appRunningUniqueId) 1493eace7efcSopenharmony_ci{ 1494eace7efcSopenharmony_ci if (!IsReady()) { 1495eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 1496eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 1497eace7efcSopenharmony_ci } 1498eace7efcSopenharmony_ci bool isCallingPermission = AAFwk::PermissionVerification::GetInstance()->IsSACall() && 1499eace7efcSopenharmony_ci AAFwk::PermissionVerification::GetInstance()->VerifyRunningInfoPerm(); 1500eace7efcSopenharmony_ci if (!isCallingPermission) { 1501eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "GetAppRunningUniqueIdByPid not SA call or verification failed"); 1502eace7efcSopenharmony_ci return ERR_PERMISSION_DENIED; 1503eace7efcSopenharmony_ci } 1504eace7efcSopenharmony_ci return appMgrServiceInner_->GetAppRunningUniqueIdByPid(pid, appRunningUniqueId); 1505eace7efcSopenharmony_ci} 1506eace7efcSopenharmony_ci 1507eace7efcSopenharmony_ciint32_t AppMgrService::GetAllUIExtensionRootHostPid(pid_t pid, std::vector<pid_t> &hostPids) 1508eace7efcSopenharmony_ci{ 1509eace7efcSopenharmony_ci if (!IsReady()) { 1510eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 1511eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 1512eace7efcSopenharmony_ci } 1513eace7efcSopenharmony_ci 1514eace7efcSopenharmony_ci return appMgrServiceInner_->GetAllUIExtensionRootHostPid(pid, hostPids); 1515eace7efcSopenharmony_ci} 1516eace7efcSopenharmony_ci 1517eace7efcSopenharmony_ciint32_t AppMgrService::GetAllUIExtensionProviderPid(pid_t hostPid, std::vector<pid_t> &providerPids) 1518eace7efcSopenharmony_ci{ 1519eace7efcSopenharmony_ci if (!IsReady()) { 1520eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 1521eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 1522eace7efcSopenharmony_ci } 1523eace7efcSopenharmony_ci 1524eace7efcSopenharmony_ci return appMgrServiceInner_->GetAllUIExtensionProviderPid(hostPid, providerPids); 1525eace7efcSopenharmony_ci} 1526eace7efcSopenharmony_ci 1527eace7efcSopenharmony_ciint32_t AppMgrService::NotifyMemorySizeStateChanged(bool isMemorySizeSufficient) 1528eace7efcSopenharmony_ci{ 1529eace7efcSopenharmony_ci if (!IsReady()) { 1530eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 1531eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 1532eace7efcSopenharmony_ci } 1533eace7efcSopenharmony_ci 1534eace7efcSopenharmony_ci return appMgrServiceInner_->NotifyMemorySizeStateChanged(isMemorySizeSufficient); 1535eace7efcSopenharmony_ci} 1536eace7efcSopenharmony_ci 1537eace7efcSopenharmony_ciint32_t AppMgrService::SetSupportedProcessCacheSelf(bool isSupport) 1538eace7efcSopenharmony_ci{ 1539eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::APPMGR, "call"); 1540eace7efcSopenharmony_ci if (!IsReady()) { 1541eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 1542eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 1543eace7efcSopenharmony_ci } 1544eace7efcSopenharmony_ci return appMgrServiceInner_->SetSupportedProcessCacheSelf(isSupport); 1545eace7efcSopenharmony_ci} 1546eace7efcSopenharmony_ci 1547eace7efcSopenharmony_ciint32_t AppMgrService::SetSupportedProcessCache(int32_t pid, bool isSupport) 1548eace7efcSopenharmony_ci{ 1549eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::APPMGR, "Called"); 1550eace7efcSopenharmony_ci if (!IsReady()) { 1551eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "Not ready."); 1552eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 1553eace7efcSopenharmony_ci } 1554eace7efcSopenharmony_ci if (!AAFwk::PermissionVerification::GetInstance()->CheckSpecificSystemAbilityAccessPermission(FOUNDATION_PROCESS)) { 1555eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "caller not foundation"); 1556eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 1557eace7efcSopenharmony_ci } 1558eace7efcSopenharmony_ci return appMgrServiceInner_->SetSupportedProcessCache(pid, isSupport); 1559eace7efcSopenharmony_ci} 1560eace7efcSopenharmony_ci 1561eace7efcSopenharmony_civoid AppMgrService::SetAppAssertionPauseState(bool flag) 1562eace7efcSopenharmony_ci{ 1563eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::APPMGR, "call"); 1564eace7efcSopenharmony_ci if (!IsReady()) { 1565eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 1566eace7efcSopenharmony_ci return; 1567eace7efcSopenharmony_ci } 1568eace7efcSopenharmony_ci return appMgrServiceInner_->SetAppAssertionPauseState(flag); 1569eace7efcSopenharmony_ci} 1570eace7efcSopenharmony_ci 1571eace7efcSopenharmony_ciint32_t AppMgrService::StartNativeChildProcess(const std::string &libName, int32_t childProcessCount, 1572eace7efcSopenharmony_ci const sptr<IRemoteObject> &callback) 1573eace7efcSopenharmony_ci{ 1574eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::APPMGR, "call"); 1575eace7efcSopenharmony_ci if (!IsReady()) { 1576eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 1577eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 1578eace7efcSopenharmony_ci } 1579eace7efcSopenharmony_ci 1580eace7efcSopenharmony_ci return appMgrServiceInner_->StartNativeChildProcess( 1581eace7efcSopenharmony_ci IPCSkeleton::GetCallingPid(), libName, childProcessCount, callback); 1582eace7efcSopenharmony_ci} 1583eace7efcSopenharmony_ci 1584eace7efcSopenharmony_ciint32_t AppMgrService::CheckCallingIsUserTestMode(const pid_t pid, bool &isUserTest) 1585eace7efcSopenharmony_ci{ 1586eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::APPMGR, "called"); 1587eace7efcSopenharmony_ci if (!appMgrServiceInner_) { 1588eace7efcSopenharmony_ci return ERR_INVALID_VALUE; 1589eace7efcSopenharmony_ci } 1590eace7efcSopenharmony_ci return appMgrServiceInner_->CheckCallingIsUserTestModeInner(pid, isUserTest); 1591eace7efcSopenharmony_ci} 1592eace7efcSopenharmony_ci 1593eace7efcSopenharmony_ciint32_t AppMgrService::NotifyProcessDependedOnWeb() 1594eace7efcSopenharmony_ci{ 1595eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::APPMGR, "called"); 1596eace7efcSopenharmony_ci if (!appMgrServiceInner_) { 1597eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 1598eace7efcSopenharmony_ci return ERR_INVALID_VALUE; 1599eace7efcSopenharmony_ci } 1600eace7efcSopenharmony_ci return appMgrServiceInner_->NotifyProcessDependedOnWeb(); 1601eace7efcSopenharmony_ci} 1602eace7efcSopenharmony_ci 1603eace7efcSopenharmony_civoid AppMgrService::KillProcessDependedOnWeb() 1604eace7efcSopenharmony_ci{ 1605eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::APPMGR, "called"); 1606eace7efcSopenharmony_ci if (!AAFwk::PermissionVerification::GetInstance()->VerifyKillProcessDependedOnWebPermission()) { 1607eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "no permission"); 1608eace7efcSopenharmony_ci return; 1609eace7efcSopenharmony_ci } 1610eace7efcSopenharmony_ci if (!appMgrServiceInner_) { 1611eace7efcSopenharmony_ci return; 1612eace7efcSopenharmony_ci } 1613eace7efcSopenharmony_ci appMgrServiceInner_->KillProcessDependedOnWeb(); 1614eace7efcSopenharmony_ci} 1615eace7efcSopenharmony_ci 1616eace7efcSopenharmony_civoid AppMgrService::RestartResidentProcessDependedOnWeb() 1617eace7efcSopenharmony_ci{ 1618eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::APPMGR, "called"); 1619eace7efcSopenharmony_ci if (!AAFwk::PermissionVerification::GetInstance()->CheckSpecificSystemAbilityAccessPermission(FOUNDATION_PROCESS)) { 1620eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "not foundation"); 1621eace7efcSopenharmony_ci return; 1622eace7efcSopenharmony_ci } 1623eace7efcSopenharmony_ci if (!appMgrServiceInner_) { 1624eace7efcSopenharmony_ci return; 1625eace7efcSopenharmony_ci } 1626eace7efcSopenharmony_ci appMgrServiceInner_->RestartResidentProcessDependedOnWeb(); 1627eace7efcSopenharmony_ci} 1628eace7efcSopenharmony_ci 1629eace7efcSopenharmony_ciint32_t AppMgrService::GetSupportedProcessCachePids(const std::string &bundleName, 1630eace7efcSopenharmony_ci std::vector<int32_t> &pidList) 1631eace7efcSopenharmony_ci{ 1632eace7efcSopenharmony_ci if (!IsReady()) { 1633eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "not ready"); 1634eace7efcSopenharmony_ci return ERR_INVALID_OPERATION; 1635eace7efcSopenharmony_ci } 1636eace7efcSopenharmony_ci if (!AAFwk::PermissionVerification::GetInstance()->JudgeCallerIsAllowedToUseSystemAPI()) { 1637eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "caller is not SA"); 1638eace7efcSopenharmony_ci return AAFwk::ERR_NOT_SYSTEM_APP; 1639eace7efcSopenharmony_ci } 1640eace7efcSopenharmony_ci auto isPerm = AAFwk::PermissionVerification::GetInstance()->VerifyRunningInfoPerm(); 1641eace7efcSopenharmony_ci if (!isPerm) { 1642eace7efcSopenharmony_ci return AAFwk::CHECK_PERMISSION_FAILED; 1643eace7efcSopenharmony_ci } 1644eace7efcSopenharmony_ci if (!DelayedSingleton<CacheProcessManager>::GetInstance()->QueryEnableProcessCache()) { 1645eace7efcSopenharmony_ci return AAFwk::ERR_CAPABILITY_NOT_SUPPORT; 1646eace7efcSopenharmony_ci } 1647eace7efcSopenharmony_ci return appMgrServiceInner_->GetSupportedProcessCachePids(bundleName, pidList); 1648eace7efcSopenharmony_ci} 1649eace7efcSopenharmony_ci 1650eace7efcSopenharmony_ciint32_t AppMgrService::RegisterKiaInterceptor(const sptr<IKiaInterceptor> &interceptor) 1651eace7efcSopenharmony_ci{ 1652eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::APPMGR, "Called"); 1653eace7efcSopenharmony_ci if (!appMgrServiceInner_) { 1654eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "appMgrServiceInner_ is nullptr"); 1655eace7efcSopenharmony_ci return ERR_INVALID_VALUE; 1656eace7efcSopenharmony_ci } 1657eace7efcSopenharmony_ci return appMgrServiceInner_->RegisterKiaInterceptor(interceptor); 1658eace7efcSopenharmony_ci} 1659eace7efcSopenharmony_ci 1660eace7efcSopenharmony_ciint32_t AppMgrService::CheckIsKiaProcess(pid_t pid, bool &isKia) 1661eace7efcSopenharmony_ci{ 1662eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::APPMGR, "Called"); 1663eace7efcSopenharmony_ci if (!appMgrServiceInner_) { 1664eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "appMgrServiceInner_ is nullptr"); 1665eace7efcSopenharmony_ci return ERR_INVALID_VALUE; 1666eace7efcSopenharmony_ci } 1667eace7efcSopenharmony_ci return appMgrServiceInner_->CheckIsKiaProcess(pid, isKia); 1668eace7efcSopenharmony_ci} 1669eace7efcSopenharmony_ci 1670eace7efcSopenharmony_ciint32_t AppMgrService::GetAppIndexByPid(pid_t pid, int32_t &appIndex) 1671eace7efcSopenharmony_ci{ 1672eace7efcSopenharmony_ci bool isCallingPermission = 1673eace7efcSopenharmony_ci AAFwk::PermissionVerification::GetInstance()->CheckSpecificSystemAbilityAccessPermission(FOUNDATION_PROCESS); 1674eace7efcSopenharmony_ci if (!isCallingPermission) { 1675eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "verification failed"); 1676eace7efcSopenharmony_ci return ERR_PERMISSION_DENIED; 1677eace7efcSopenharmony_ci } 1678eace7efcSopenharmony_ci if (!appMgrServiceInner_) { 1679eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::APPMGR, "appMgrServiceInner_ is nullptr"); 1680eace7efcSopenharmony_ci return ERR_INVALID_VALUE; 1681eace7efcSopenharmony_ci } 1682eace7efcSopenharmony_ci return appMgrServiceInner_->GetAppIndexByPid(pid, appIndex); 1683eace7efcSopenharmony_ci} 1684eace7efcSopenharmony_ci} // namespace AppExecFwk 1685eace7efcSopenharmony_ci} // namespace OHOS 1686