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_scheduler.h" 17eace7efcSopenharmony_ci 18eace7efcSopenharmony_ci#include "ability_manager_service.h" 19eace7efcSopenharmony_ci#include "ability_util.h" 20eace7efcSopenharmony_ci#include "hitrace_meter.h" 21eace7efcSopenharmony_ci#include "param.h" 22eace7efcSopenharmony_ci#include "utils/state_utils.h" 23eace7efcSopenharmony_ci 24eace7efcSopenharmony_cinamespace OHOS { 25eace7efcSopenharmony_cinamespace AAFwk { 26eace7efcSopenharmony_ciAppScheduler::AppScheduler() : appMgrClient_(std::make_unique<AppExecFwk::AppMgrClient>()) 27eace7efcSopenharmony_ci{} 28eace7efcSopenharmony_ci 29eace7efcSopenharmony_ciAppScheduler::~AppScheduler() 30eace7efcSopenharmony_ci{} 31eace7efcSopenharmony_ci 32eace7efcSopenharmony_cibool AppScheduler::Init(const std::weak_ptr<AppStateCallback> &callback) 33eace7efcSopenharmony_ci{ 34eace7efcSopenharmony_ci CHECK_POINTER_RETURN_BOOL(callback.lock()); 35eace7efcSopenharmony_ci CHECK_POINTER_RETURN_BOOL(appMgrClient_); 36eace7efcSopenharmony_ci 37eace7efcSopenharmony_ci std::lock_guard<std::mutex> guard(lock_); 38eace7efcSopenharmony_ci if (isInit_) { 39eace7efcSopenharmony_ci return true; 40eace7efcSopenharmony_ci } 41eace7efcSopenharmony_ci 42eace7efcSopenharmony_ci callback_ = callback; 43eace7efcSopenharmony_ci /* because the errcode type of AppMgr Client API will be changed to int, 44eace7efcSopenharmony_ci * so must to covert the return result */ 45eace7efcSopenharmony_ci int result = static_cast<int>(appMgrClient_->ConnectAppMgrService()); 46eace7efcSopenharmony_ci if (result != ERR_OK) { 47eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "failed to ConnectAppMgrService"); 48eace7efcSopenharmony_ci return false; 49eace7efcSopenharmony_ci } 50eace7efcSopenharmony_ci this->IncStrongRef(this); 51eace7efcSopenharmony_ci result = static_cast<int>(appMgrClient_->RegisterAppStateCallback(sptr<AppScheduler>(this))); 52eace7efcSopenharmony_ci if (result != ERR_OK) { 53eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "failed to RegisterAppStateCallback"); 54eace7efcSopenharmony_ci return false; 55eace7efcSopenharmony_ci } 56eace7efcSopenharmony_ci 57eace7efcSopenharmony_ci startSpecifiedAbilityResponse_ = new (std::nothrow) StartSpecifiedAbilityResponse(); 58eace7efcSopenharmony_ci if (startSpecifiedAbilityResponse_ == nullptr) { 59eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "null startSpecifiedAbilityResponse_"); 60eace7efcSopenharmony_ci return false; 61eace7efcSopenharmony_ci } 62eace7efcSopenharmony_ci appMgrClient_->RegisterStartSpecifiedAbilityResponse(startSpecifiedAbilityResponse_); 63eace7efcSopenharmony_ci 64eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::ABILITYMGR, "success to ConnectAppMgrService"); 65eace7efcSopenharmony_ci isInit_ = true; 66eace7efcSopenharmony_ci return true; 67eace7efcSopenharmony_ci} 68eace7efcSopenharmony_ci 69eace7efcSopenharmony_ciint AppScheduler::LoadAbility(sptr<IRemoteObject> token, sptr<IRemoteObject> preToken, 70eace7efcSopenharmony_ci const AppExecFwk::AbilityInfo &abilityInfo, const AppExecFwk::ApplicationInfo &applicationInfo, 71eace7efcSopenharmony_ci const Want &want, int32_t abilityRecordId, const std::string &instanceKey) 72eace7efcSopenharmony_ci{ 73eace7efcSopenharmony_ci HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); 74eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::ABILITYMGR, "called"); 75eace7efcSopenharmony_ci CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR); 76eace7efcSopenharmony_ci /* because the errcode type of AppMgr Client API will be changed to int, 77eace7efcSopenharmony_ci * so must to covert the return result */ 78eace7efcSopenharmony_ci AbilityRuntime::LoadParam loadParam; 79eace7efcSopenharmony_ci loadParam.abilityRecordId = abilityRecordId; 80eace7efcSopenharmony_ci loadParam.isShellCall = AAFwk::PermissionVerification::GetInstance()->IsShellCall(); 81eace7efcSopenharmony_ci loadParam.token = token; 82eace7efcSopenharmony_ci loadParam.preToken = preToken; 83eace7efcSopenharmony_ci loadParam.instanceKey = instanceKey; 84eace7efcSopenharmony_ci int ret = static_cast<int>(IN_PROCESS_CALL( 85eace7efcSopenharmony_ci appMgrClient_->LoadAbility(abilityInfo, applicationInfo, want, loadParam))); 86eace7efcSopenharmony_ci if (ret != ERR_OK) { 87eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "AppScheduler fail to LoadAbility. ret %d", ret); 88eace7efcSopenharmony_ci return INNER_ERR; 89eace7efcSopenharmony_ci } 90eace7efcSopenharmony_ci return ERR_OK; 91eace7efcSopenharmony_ci} 92eace7efcSopenharmony_ci 93eace7efcSopenharmony_ciint AppScheduler::TerminateAbility(const sptr<IRemoteObject> &token, bool clearMissionFlag) 94eace7efcSopenharmony_ci{ 95eace7efcSopenharmony_ci HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); 96eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::ABILITYMGR, "Terminate ability."); 97eace7efcSopenharmony_ci CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR); 98eace7efcSopenharmony_ci /* because the errcode type of AppMgr Client API will be changed to int, 99eace7efcSopenharmony_ci * so must to covert the return result */ 100eace7efcSopenharmony_ci int ret = static_cast<int>(IN_PROCESS_CALL(appMgrClient_->TerminateAbility(token, clearMissionFlag))); 101eace7efcSopenharmony_ci if (ret != ERR_OK) { 102eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "AppScheduler fail to TerminateAbility. ret %d", ret); 103eace7efcSopenharmony_ci return INNER_ERR; 104eace7efcSopenharmony_ci } 105eace7efcSopenharmony_ci return ERR_OK; 106eace7efcSopenharmony_ci} 107eace7efcSopenharmony_ci 108eace7efcSopenharmony_ciint AppScheduler::UpdateApplicationInfoInstalled(const std::string &bundleName, const int32_t uid) 109eace7efcSopenharmony_ci{ 110eace7efcSopenharmony_ci CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR); 111eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::ABILITYMGR, "Start to update the application info after new module installed."); 112eace7efcSopenharmony_ci int ret = (int)appMgrClient_->UpdateApplicationInfoInstalled(bundleName, uid); 113eace7efcSopenharmony_ci if (ret != ERR_OK) { 114eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to UpdateApplicationInfoInstalled"); 115eace7efcSopenharmony_ci return INNER_ERR; 116eace7efcSopenharmony_ci } 117eace7efcSopenharmony_ci 118eace7efcSopenharmony_ci return ERR_OK; 119eace7efcSopenharmony_ci} 120eace7efcSopenharmony_ci 121eace7efcSopenharmony_civoid AppScheduler::MoveToForeground(const sptr<IRemoteObject> &token) 122eace7efcSopenharmony_ci{ 123eace7efcSopenharmony_ci HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); 124eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::ABILITYMGR, "Start to move the ability to foreground."); 125eace7efcSopenharmony_ci CHECK_POINTER(appMgrClient_); 126eace7efcSopenharmony_ci IN_PROCESS_CALL_WITHOUT_RET( 127eace7efcSopenharmony_ci appMgrClient_->UpdateAbilityState(token, AppExecFwk::AbilityState::ABILITY_STATE_FOREGROUND)); 128eace7efcSopenharmony_ci} 129eace7efcSopenharmony_ci 130eace7efcSopenharmony_civoid AppScheduler::MoveToBackground(const sptr<IRemoteObject> &token) 131eace7efcSopenharmony_ci{ 132eace7efcSopenharmony_ci HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); 133eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::ABILITYMGR, "Move the app to background."); 134eace7efcSopenharmony_ci CHECK_POINTER(appMgrClient_); 135eace7efcSopenharmony_ci IN_PROCESS_CALL_WITHOUT_RET( 136eace7efcSopenharmony_ci appMgrClient_->UpdateAbilityState(token, AppExecFwk::AbilityState::ABILITY_STATE_BACKGROUND)); 137eace7efcSopenharmony_ci} 138eace7efcSopenharmony_ci 139eace7efcSopenharmony_civoid AppScheduler::UpdateAbilityState(const sptr<IRemoteObject> &token, const AppExecFwk::AbilityState state) 140eace7efcSopenharmony_ci{ 141eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::ABILITYMGR, "UpdateAbilityState."); 142eace7efcSopenharmony_ci CHECK_POINTER(appMgrClient_); 143eace7efcSopenharmony_ci IN_PROCESS_CALL_WITHOUT_RET(appMgrClient_->UpdateAbilityState(token, state)); 144eace7efcSopenharmony_ci} 145eace7efcSopenharmony_ci 146eace7efcSopenharmony_civoid AppScheduler::UpdateExtensionState(const sptr<IRemoteObject> &token, const AppExecFwk::ExtensionState state) 147eace7efcSopenharmony_ci{ 148eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::ABILITYMGR, "UpdateExtensionState."); 149eace7efcSopenharmony_ci CHECK_POINTER(appMgrClient_); 150eace7efcSopenharmony_ci IN_PROCESS_CALL_WITHOUT_RET(appMgrClient_->UpdateExtensionState(token, state)); 151eace7efcSopenharmony_ci} 152eace7efcSopenharmony_ci 153eace7efcSopenharmony_civoid AppScheduler::KillProcessByAbilityToken(const sptr<IRemoteObject> &token) 154eace7efcSopenharmony_ci{ 155eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::ABILITYMGR, "kill process"); 156eace7efcSopenharmony_ci CHECK_POINTER(appMgrClient_); 157eace7efcSopenharmony_ci appMgrClient_->KillProcessByAbilityToken(token); 158eace7efcSopenharmony_ci} 159eace7efcSopenharmony_ci 160eace7efcSopenharmony_civoid AppScheduler::KillProcessesByUserId(int32_t userId) 161eace7efcSopenharmony_ci{ 162eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::ABILITYMGR, "user id: %{public}d", userId); 163eace7efcSopenharmony_ci CHECK_POINTER(appMgrClient_); 164eace7efcSopenharmony_ci appMgrClient_->KillProcessesByUserId(userId); 165eace7efcSopenharmony_ci} 166eace7efcSopenharmony_ci 167eace7efcSopenharmony_civoid AppScheduler::KillProcessesByPids(std::vector<int32_t> &pids) 168eace7efcSopenharmony_ci{ 169eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::ABILITYMGR, "call"); 170eace7efcSopenharmony_ci CHECK_POINTER(appMgrClient_); 171eace7efcSopenharmony_ci appMgrClient_->KillProcessesByPids(pids); 172eace7efcSopenharmony_ci} 173eace7efcSopenharmony_ci 174eace7efcSopenharmony_civoid AppScheduler::AttachPidToParent(const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &callerToken) 175eace7efcSopenharmony_ci{ 176eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::ABILITYMGR, "call"); 177eace7efcSopenharmony_ci CHECK_POINTER(appMgrClient_); 178eace7efcSopenharmony_ci appMgrClient_->AttachPidToParent(token, callerToken); 179eace7efcSopenharmony_ci} 180eace7efcSopenharmony_ci 181eace7efcSopenharmony_ciAppAbilityState AppScheduler::ConvertToAppAbilityState(const int32_t state) 182eace7efcSopenharmony_ci{ 183eace7efcSopenharmony_ci AppExecFwk::AbilityState abilityState = static_cast<AppExecFwk::AbilityState>(state); 184eace7efcSopenharmony_ci switch (abilityState) { 185eace7efcSopenharmony_ci case AppExecFwk::AbilityState::ABILITY_STATE_FOREGROUND: { 186eace7efcSopenharmony_ci return AppAbilityState::ABILITY_STATE_FOREGROUND; 187eace7efcSopenharmony_ci } 188eace7efcSopenharmony_ci case AppExecFwk::AbilityState::ABILITY_STATE_BACKGROUND: { 189eace7efcSopenharmony_ci return AppAbilityState::ABILITY_STATE_BACKGROUND; 190eace7efcSopenharmony_ci } 191eace7efcSopenharmony_ci default: 192eace7efcSopenharmony_ci return AppAbilityState::ABILITY_STATE_UNDEFINED; 193eace7efcSopenharmony_ci } 194eace7efcSopenharmony_ci} 195eace7efcSopenharmony_ci 196eace7efcSopenharmony_ciAppAbilityState AppScheduler::GetAbilityState() const 197eace7efcSopenharmony_ci{ 198eace7efcSopenharmony_ci return appAbilityState_; 199eace7efcSopenharmony_ci} 200eace7efcSopenharmony_ci 201eace7efcSopenharmony_civoid AppScheduler::OnAbilityRequestDone(const sptr<IRemoteObject> &token, const AppExecFwk::AbilityState state) 202eace7efcSopenharmony_ci{ 203eace7efcSopenharmony_ci HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); 204eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::ABILITYMGR, "state:%{public}d", static_cast<int32_t>(state)); 205eace7efcSopenharmony_ci auto callback = callback_.lock(); 206eace7efcSopenharmony_ci CHECK_POINTER(callback); 207eace7efcSopenharmony_ci appAbilityState_ = ConvertToAppAbilityState(static_cast<int32_t>(state)); 208eace7efcSopenharmony_ci callback->OnAbilityRequestDone(token, static_cast<int32_t>(state)); 209eace7efcSopenharmony_ci} 210eace7efcSopenharmony_ci 211eace7efcSopenharmony_civoid AppScheduler::NotifyConfigurationChange(const AppExecFwk::Configuration &config, int32_t userId) 212eace7efcSopenharmony_ci{ 213eace7efcSopenharmony_ci auto callback = callback_.lock(); 214eace7efcSopenharmony_ci CHECK_POINTER(callback); 215eace7efcSopenharmony_ci callback->NotifyConfigurationChange(config, userId); 216eace7efcSopenharmony_ci} 217eace7efcSopenharmony_ci 218eace7efcSopenharmony_civoid AppScheduler::NotifyStartResidentProcess(std::vector<AppExecFwk::BundleInfo> &bundleInfos) 219eace7efcSopenharmony_ci{ 220eace7efcSopenharmony_ci auto callback = callback_.lock(); 221eace7efcSopenharmony_ci CHECK_POINTER(callback); 222eace7efcSopenharmony_ci callback->NotifyStartResidentProcess(bundleInfos); 223eace7efcSopenharmony_ci} 224eace7efcSopenharmony_ci 225eace7efcSopenharmony_civoid AppScheduler::OnAppRemoteDied(const std::vector<sptr<IRemoteObject>> &abilityTokens) 226eace7efcSopenharmony_ci{ 227eace7efcSopenharmony_ci auto callback = callback_.lock(); 228eace7efcSopenharmony_ci CHECK_POINTER(callback); 229eace7efcSopenharmony_ci callback->OnAppRemoteDied(abilityTokens); 230eace7efcSopenharmony_ci} 231eace7efcSopenharmony_ci 232eace7efcSopenharmony_civoid AppScheduler::NotifyAppPreCache(int32_t pid, int32_t userId) 233eace7efcSopenharmony_ci{ 234eace7efcSopenharmony_ci auto callback = callback_.lock(); 235eace7efcSopenharmony_ci CHECK_POINTER(callback); 236eace7efcSopenharmony_ci callback->NotifyAppPreCache(pid, userId); 237eace7efcSopenharmony_ci} 238eace7efcSopenharmony_ci 239eace7efcSopenharmony_ciint AppScheduler::KillApplication(const std::string &bundleName, const bool clearPageStack) 240eace7efcSopenharmony_ci{ 241eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::ABILITYMGR, "call"); 242eace7efcSopenharmony_ci CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR); 243eace7efcSopenharmony_ci int ret = (int)appMgrClient_->KillApplication(bundleName, clearPageStack); 244eace7efcSopenharmony_ci if (ret != ERR_OK) { 245eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "failed kill app"); 246eace7efcSopenharmony_ci return INNER_ERR; 247eace7efcSopenharmony_ci } 248eace7efcSopenharmony_ci 249eace7efcSopenharmony_ci return ERR_OK; 250eace7efcSopenharmony_ci} 251eace7efcSopenharmony_ci 252eace7efcSopenharmony_ciint AppScheduler::ForceKillApplication(const std::string &bundleName, 253eace7efcSopenharmony_ci const int userId, const int appIndex) 254eace7efcSopenharmony_ci{ 255eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::ABILITYMGR, "call"); 256eace7efcSopenharmony_ci CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR); 257eace7efcSopenharmony_ci int ret = (int)appMgrClient_->ForceKillApplication(bundleName, userId, appIndex); 258eace7efcSopenharmony_ci if (ret != ERR_OK) { 259eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "failed force kill app"); 260eace7efcSopenharmony_ci return INNER_ERR; 261eace7efcSopenharmony_ci } 262eace7efcSopenharmony_ci 263eace7efcSopenharmony_ci return ERR_OK; 264eace7efcSopenharmony_ci} 265eace7efcSopenharmony_ci 266eace7efcSopenharmony_ciint AppScheduler::KillProcessesByAccessTokenId(const uint32_t accessTokenId) 267eace7efcSopenharmony_ci{ 268eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::ABILITYMGR, "call"); 269eace7efcSopenharmony_ci CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR); 270eace7efcSopenharmony_ci int ret = (int)appMgrClient_->KillProcessesByAccessTokenId(accessTokenId); 271eace7efcSopenharmony_ci if (ret != ERR_OK) { 272eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "failed force kill app"); 273eace7efcSopenharmony_ci return INNER_ERR; 274eace7efcSopenharmony_ci } 275eace7efcSopenharmony_ci 276eace7efcSopenharmony_ci return ERR_OK; 277eace7efcSopenharmony_ci} 278eace7efcSopenharmony_ci 279eace7efcSopenharmony_ciint AppScheduler::KillApplicationByUid(const std::string &bundleName, int32_t uid, 280eace7efcSopenharmony_ci const std::string& reason) 281eace7efcSopenharmony_ci{ 282eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::ABILITYMGR, "[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__); 283eace7efcSopenharmony_ci CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR); 284eace7efcSopenharmony_ci int ret = (int)appMgrClient_->KillApplicationByUid(bundleName, uid, reason); 285eace7efcSopenharmony_ci if (ret != ERR_OK) { 286eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "fail kill app"); 287eace7efcSopenharmony_ci return INNER_ERR; 288eace7efcSopenharmony_ci } 289eace7efcSopenharmony_ci 290eace7efcSopenharmony_ci return ERR_OK; 291eace7efcSopenharmony_ci} 292eace7efcSopenharmony_ci 293eace7efcSopenharmony_civoid AppScheduler::AttachTimeOut(const sptr<IRemoteObject> &token) 294eace7efcSopenharmony_ci{ 295eace7efcSopenharmony_ci CHECK_POINTER(appMgrClient_); 296eace7efcSopenharmony_ci IN_PROCESS_CALL_WITHOUT_RET(appMgrClient_->AbilityAttachTimeOut(token)); 297eace7efcSopenharmony_ci} 298eace7efcSopenharmony_ci 299eace7efcSopenharmony_civoid AppScheduler::PrepareTerminate(const sptr<IRemoteObject> &token, bool clearMissionFlag) 300eace7efcSopenharmony_ci{ 301eace7efcSopenharmony_ci CHECK_POINTER(appMgrClient_); 302eace7efcSopenharmony_ci IN_PROCESS_CALL_WITHOUT_RET(appMgrClient_->PrepareTerminate(token, clearMissionFlag)); 303eace7efcSopenharmony_ci} 304eace7efcSopenharmony_ci 305eace7efcSopenharmony_civoid AppScheduler::OnAppStateChanged(const AppExecFwk::AppProcessData &appData) 306eace7efcSopenharmony_ci{ 307eace7efcSopenharmony_ci HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); 308eace7efcSopenharmony_ci auto callback = callback_.lock(); 309eace7efcSopenharmony_ci CHECK_POINTER(callback); 310eace7efcSopenharmony_ci AppInfo info; 311eace7efcSopenharmony_ci for (const auto &list : appData.appDatas) { 312eace7efcSopenharmony_ci AppData data; 313eace7efcSopenharmony_ci data.appName = list.appName; 314eace7efcSopenharmony_ci data.uid = list.uid; 315eace7efcSopenharmony_ci info.appData.push_back(data); 316eace7efcSopenharmony_ci } 317eace7efcSopenharmony_ci info.processName = appData.processName; 318eace7efcSopenharmony_ci info.state = static_cast<AppState>(appData.appState); 319eace7efcSopenharmony_ci info.pid = appData.pid; 320eace7efcSopenharmony_ci callback->OnAppStateChanged(info); 321eace7efcSopenharmony_ci} 322eace7efcSopenharmony_ci 323eace7efcSopenharmony_civoid AppScheduler::GetRunningProcessInfoByToken(const sptr<IRemoteObject> &token, AppExecFwk::RunningProcessInfo &info) 324eace7efcSopenharmony_ci{ 325eace7efcSopenharmony_ci HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); 326eace7efcSopenharmony_ci CHECK_POINTER(appMgrClient_); 327eace7efcSopenharmony_ci IN_PROCESS_CALL_WITHOUT_RET(appMgrClient_->GetRunningProcessInfoByToken(token, info)); 328eace7efcSopenharmony_ci} 329eace7efcSopenharmony_ci 330eace7efcSopenharmony_civoid AppScheduler::GetRunningProcessInfoByPid(const pid_t pid, OHOS::AppExecFwk::RunningProcessInfo &info) const 331eace7efcSopenharmony_ci{ 332eace7efcSopenharmony_ci CHECK_POINTER(appMgrClient_); 333eace7efcSopenharmony_ci IN_PROCESS_CALL_WITHOUT_RET(appMgrClient_->GetRunningProcessInfoByPid(pid, info)); 334eace7efcSopenharmony_ci} 335eace7efcSopenharmony_ci 336eace7efcSopenharmony_civoid AppScheduler::SetAbilityForegroundingFlagToAppRecord(const pid_t pid) const 337eace7efcSopenharmony_ci{ 338eace7efcSopenharmony_ci CHECK_POINTER(appMgrClient_); 339eace7efcSopenharmony_ci IN_PROCESS_CALL_WITHOUT_RET(appMgrClient_->SetAbilityForegroundingFlagToAppRecord(pid)); 340eace7efcSopenharmony_ci} 341eace7efcSopenharmony_ci 342eace7efcSopenharmony_civoid AppScheduler::StartupResidentProcess(const std::vector<AppExecFwk::BundleInfo> &bundleInfos) 343eace7efcSopenharmony_ci{ 344eace7efcSopenharmony_ci CHECK_POINTER(appMgrClient_); 345eace7efcSopenharmony_ci appMgrClient_->StartupResidentProcess(bundleInfos); 346eace7efcSopenharmony_ci} 347eace7efcSopenharmony_ci 348eace7efcSopenharmony_civoid AppScheduler::StartSpecifiedAbility(const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo, 349eace7efcSopenharmony_ci int32_t requestId) 350eace7efcSopenharmony_ci{ 351eace7efcSopenharmony_ci CHECK_POINTER(appMgrClient_); 352eace7efcSopenharmony_ci IN_PROCESS_CALL_WITHOUT_RET(appMgrClient_->StartSpecifiedAbility(want, abilityInfo, requestId)); 353eace7efcSopenharmony_ci} 354eace7efcSopenharmony_ci 355eace7efcSopenharmony_civoid StartSpecifiedAbilityResponse::OnAcceptWantResponse( 356eace7efcSopenharmony_ci const AAFwk::Want &want, const std::string &flag, int32_t requestId) 357eace7efcSopenharmony_ci{ 358eace7efcSopenharmony_ci DelayedSingleton<AbilityManagerService>::GetInstance()->OnAcceptWantResponse(want, flag, requestId); 359eace7efcSopenharmony_ci} 360eace7efcSopenharmony_ci 361eace7efcSopenharmony_civoid StartSpecifiedAbilityResponse::OnTimeoutResponse(const AAFwk::Want &want, int32_t requestId) 362eace7efcSopenharmony_ci{ 363eace7efcSopenharmony_ci DelayedSingleton<AbilityManagerService>::GetInstance()->OnStartSpecifiedAbilityTimeoutResponse(want, requestId); 364eace7efcSopenharmony_ci} 365eace7efcSopenharmony_ci 366eace7efcSopenharmony_civoid AppScheduler::StartSpecifiedProcess( 367eace7efcSopenharmony_ci const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo, int32_t requestId) 368eace7efcSopenharmony_ci{ 369eace7efcSopenharmony_ci CHECK_POINTER(appMgrClient_); 370eace7efcSopenharmony_ci IN_PROCESS_CALL_WITHOUT_RET(appMgrClient_->StartSpecifiedProcess(want, abilityInfo, requestId)); 371eace7efcSopenharmony_ci} 372eace7efcSopenharmony_ci 373eace7efcSopenharmony_civoid StartSpecifiedAbilityResponse::OnNewProcessRequestResponse( 374eace7efcSopenharmony_ci const AAFwk::Want &want, const std::string &flag, int32_t requestId) 375eace7efcSopenharmony_ci{ 376eace7efcSopenharmony_ci DelayedSingleton<AbilityManagerService>::GetInstance()->OnStartSpecifiedProcessResponse(want, flag, requestId); 377eace7efcSopenharmony_ci} 378eace7efcSopenharmony_ci 379eace7efcSopenharmony_civoid StartSpecifiedAbilityResponse::OnNewProcessRequestTimeoutResponse(const AAFwk::Want &want, int32_t requestId) 380eace7efcSopenharmony_ci{ 381eace7efcSopenharmony_ci DelayedSingleton<AbilityManagerService>::GetInstance()->OnStartSpecifiedProcessTimeoutResponse(want, requestId); 382eace7efcSopenharmony_ci} 383eace7efcSopenharmony_ci 384eace7efcSopenharmony_ciint AppScheduler::GetProcessRunningInfos(std::vector<AppExecFwk::RunningProcessInfo> &info) 385eace7efcSopenharmony_ci{ 386eace7efcSopenharmony_ci CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR); 387eace7efcSopenharmony_ci return static_cast<int>(appMgrClient_->GetAllRunningProcesses(info)); 388eace7efcSopenharmony_ci} 389eace7efcSopenharmony_ci 390eace7efcSopenharmony_ciint AppScheduler::GetProcessRunningInfosByUserId(std::vector<AppExecFwk::RunningProcessInfo> &info, int32_t userId) 391eace7efcSopenharmony_ci{ 392eace7efcSopenharmony_ci CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR); 393eace7efcSopenharmony_ci return static_cast<int>(appMgrClient_->GetProcessRunningInfosByUserId(info, userId)); 394eace7efcSopenharmony_ci} 395eace7efcSopenharmony_ci 396eace7efcSopenharmony_cistd::string AppScheduler::ConvertAppState(const AppState &state) 397eace7efcSopenharmony_ci{ 398eace7efcSopenharmony_ci return StateUtils::AppStateToStrMap(state); 399eace7efcSopenharmony_ci} 400eace7efcSopenharmony_ci 401eace7efcSopenharmony_ciint AppScheduler::StartUserTest( 402eace7efcSopenharmony_ci const Want &want, const sptr<IRemoteObject> &observer, const AppExecFwk::BundleInfo &bundleInfo, int32_t userId) 403eace7efcSopenharmony_ci{ 404eace7efcSopenharmony_ci CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR); 405eace7efcSopenharmony_ci int ret = appMgrClient_->StartUserTestProcess(want, observer, bundleInfo, userId); 406eace7efcSopenharmony_ci if (ret != ERR_OK) { 407eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "failed start user test"); 408eace7efcSopenharmony_ci return INNER_ERR; 409eace7efcSopenharmony_ci } 410eace7efcSopenharmony_ci return ERR_OK; 411eace7efcSopenharmony_ci} 412eace7efcSopenharmony_ci 413eace7efcSopenharmony_ciint AppScheduler::FinishUserTest(const std::string &msg, const int64_t &resultCode, const std::string &bundleName) 414eace7efcSopenharmony_ci{ 415eace7efcSopenharmony_ci CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR); 416eace7efcSopenharmony_ci int ret = appMgrClient_->FinishUserTest(msg, resultCode, bundleName); 417eace7efcSopenharmony_ci if (ret != ERR_OK) { 418eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "failed start user test"); 419eace7efcSopenharmony_ci return INNER_ERR; 420eace7efcSopenharmony_ci } 421eace7efcSopenharmony_ci return ERR_OK; 422eace7efcSopenharmony_ci} 423eace7efcSopenharmony_ci 424eace7efcSopenharmony_ciint AppScheduler::UpdateConfiguration(const AppExecFwk::Configuration &config) 425eace7efcSopenharmony_ci{ 426eace7efcSopenharmony_ci CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR); 427eace7efcSopenharmony_ci auto ret = static_cast<int>(appMgrClient_->UpdateConfiguration(config)); 428eace7efcSopenharmony_ci if (ret != ERR_OK) { 429eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "updateConfiguration failed"); 430eace7efcSopenharmony_ci return INNER_ERR; 431eace7efcSopenharmony_ci } 432eace7efcSopenharmony_ci 433eace7efcSopenharmony_ci return ERR_OK; 434eace7efcSopenharmony_ci} 435eace7efcSopenharmony_ci 436eace7efcSopenharmony_ciint AppScheduler::GetConfiguration(AppExecFwk::Configuration &config) 437eace7efcSopenharmony_ci{ 438eace7efcSopenharmony_ci CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR); 439eace7efcSopenharmony_ci auto ret = static_cast<int>(appMgrClient_->GetConfiguration(config)); 440eace7efcSopenharmony_ci if (ret != ERR_OK) { 441eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "getConfiguration failed"); 442eace7efcSopenharmony_ci return INNER_ERR; 443eace7efcSopenharmony_ci } 444eace7efcSopenharmony_ci 445eace7efcSopenharmony_ci return ERR_OK; 446eace7efcSopenharmony_ci} 447eace7efcSopenharmony_ci 448eace7efcSopenharmony_ciint AppScheduler::GetAbilityRecordsByProcessID(const int pid, std::vector<sptr<IRemoteObject>> &tokens) 449eace7efcSopenharmony_ci{ 450eace7efcSopenharmony_ci CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR); 451eace7efcSopenharmony_ci auto ret = static_cast<int>(appMgrClient_->GetAbilityRecordsByProcessID(pid, tokens)); 452eace7efcSopenharmony_ci if (ret != ERR_OK) { 453eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "getAbilityRecordsByProcessID failed"); 454eace7efcSopenharmony_ci return INNER_ERR; 455eace7efcSopenharmony_ci } 456eace7efcSopenharmony_ci 457eace7efcSopenharmony_ci return ERR_OK; 458eace7efcSopenharmony_ci} 459eace7efcSopenharmony_ci 460eace7efcSopenharmony_ciint AppScheduler::GetApplicationInfoByProcessID(const int pid, AppExecFwk::ApplicationInfo &application, bool &debug) 461eace7efcSopenharmony_ci{ 462eace7efcSopenharmony_ci CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR); 463eace7efcSopenharmony_ci auto ret = static_cast<int>(appMgrClient_->GetApplicationInfoByProcessID(pid, application, debug)); 464eace7efcSopenharmony_ci if (ret != ERR_OK) { 465eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "getApplicationInfoByProcessID failed"); 466eace7efcSopenharmony_ci return ret; 467eace7efcSopenharmony_ci } 468eace7efcSopenharmony_ci 469eace7efcSopenharmony_ci return ERR_OK; 470eace7efcSopenharmony_ci} 471eace7efcSopenharmony_ci 472eace7efcSopenharmony_ciint32_t AppScheduler::NotifyAppMgrRecordExitReason(int32_t pid, int32_t reason, const std::string &exitMsg) 473eace7efcSopenharmony_ci{ 474eace7efcSopenharmony_ci if (pid < 0) { 475eace7efcSopenharmony_ci TAG_LOGW(AAFwkTag::ABILITYMGR, "pid<0"); 476eace7efcSopenharmony_ci return ERR_INVALID_VALUE; 477eace7efcSopenharmony_ci } 478eace7efcSopenharmony_ci CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR); 479eace7efcSopenharmony_ci auto ret = static_cast<int32_t>(IN_PROCESS_CALL(appMgrClient_->NotifyAppMgrRecordExitReason(pid, reason, exitMsg))); 480eace7efcSopenharmony_ci if (ret != ERR_OK) { 481eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "failed"); 482eace7efcSopenharmony_ci return ret; 483eace7efcSopenharmony_ci } 484eace7efcSopenharmony_ci return ERR_OK; 485eace7efcSopenharmony_ci} 486eace7efcSopenharmony_ci 487eace7efcSopenharmony_ciint32_t AppScheduler::GetBundleNameByPid(const int pid, std::string &bundleName, int32_t &uid) 488eace7efcSopenharmony_ci{ 489eace7efcSopenharmony_ci CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR); 490eace7efcSopenharmony_ci int32_t ret = static_cast<int32_t>(IN_PROCESS_CALL(appMgrClient_->GetBundleNameByPid(pid, bundleName, uid))); 491eace7efcSopenharmony_ci if (ret != ERR_OK) { 492eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "get bundle name failed"); 493eace7efcSopenharmony_ci return INNER_ERR; 494eace7efcSopenharmony_ci } 495eace7efcSopenharmony_ci return ERR_OK; 496eace7efcSopenharmony_ci} 497eace7efcSopenharmony_ci 498eace7efcSopenharmony_civoid AppScheduler::SetCurrentUserId(const int32_t userId) 499eace7efcSopenharmony_ci{ 500eace7efcSopenharmony_ci CHECK_POINTER(appMgrClient_); 501eace7efcSopenharmony_ci IN_PROCESS_CALL_WITHOUT_RET(appMgrClient_->SetCurrentUserId(userId)); 502eace7efcSopenharmony_ci} 503eace7efcSopenharmony_ci 504eace7efcSopenharmony_civoid AppScheduler::SetEnableStartProcessFlagByUserId(int32_t userId, bool enableStartProcess) 505eace7efcSopenharmony_ci{ 506eace7efcSopenharmony_ci CHECK_POINTER(appMgrClient_); 507eace7efcSopenharmony_ci IN_PROCESS_CALL_WITHOUT_RET(appMgrClient_->SetEnableStartProcessFlagByUserId(userId, enableStartProcess)); 508eace7efcSopenharmony_ci} 509eace7efcSopenharmony_ci 510eace7efcSopenharmony_ciint32_t AppScheduler::NotifyFault(const AppExecFwk::FaultData &faultData) 511eace7efcSopenharmony_ci{ 512eace7efcSopenharmony_ci CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR); 513eace7efcSopenharmony_ci auto ret = static_cast<int>(appMgrClient_->NotifyAppFault(faultData)); 514eace7efcSopenharmony_ci if (ret != ERR_OK) { 515eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "notifyAppFault failed"); 516eace7efcSopenharmony_ci return INNER_ERR; 517eace7efcSopenharmony_ci } 518eace7efcSopenharmony_ci 519eace7efcSopenharmony_ci return ERR_OK; 520eace7efcSopenharmony_ci} 521eace7efcSopenharmony_ci 522eace7efcSopenharmony_ciint32_t AppScheduler::RegisterAppDebugListener(const sptr<AppExecFwk::IAppDebugListener> &listener) 523eace7efcSopenharmony_ci{ 524eace7efcSopenharmony_ci CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR); 525eace7efcSopenharmony_ci auto ret = static_cast<int32_t>(appMgrClient_->RegisterAppDebugListener(listener)); 526eace7efcSopenharmony_ci if (ret != ERR_OK) { 527eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "register app debug listener failed"); 528eace7efcSopenharmony_ci return INNER_ERR; 529eace7efcSopenharmony_ci } 530eace7efcSopenharmony_ci return ERR_OK; 531eace7efcSopenharmony_ci} 532eace7efcSopenharmony_ci 533eace7efcSopenharmony_ciint32_t AppScheduler::UnregisterAppDebugListener(const sptr<AppExecFwk::IAppDebugListener> &listener) 534eace7efcSopenharmony_ci{ 535eace7efcSopenharmony_ci CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR); 536eace7efcSopenharmony_ci auto ret = static_cast<int32_t>(appMgrClient_->UnregisterAppDebugListener(listener)); 537eace7efcSopenharmony_ci if (ret != ERR_OK) { 538eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "unregister app debug listener failed"); 539eace7efcSopenharmony_ci return INNER_ERR; 540eace7efcSopenharmony_ci } 541eace7efcSopenharmony_ci return ERR_OK; 542eace7efcSopenharmony_ci} 543eace7efcSopenharmony_ci 544eace7efcSopenharmony_ciint32_t AppScheduler::AttachAppDebug(const std::string &bundleName) 545eace7efcSopenharmony_ci{ 546eace7efcSopenharmony_ci CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR); 547eace7efcSopenharmony_ci auto ret = static_cast<int32_t>(appMgrClient_->AttachAppDebug(bundleName)); 548eace7efcSopenharmony_ci if (ret != ERR_OK) { 549eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "attach app debug failed"); 550eace7efcSopenharmony_ci return INNER_ERR; 551eace7efcSopenharmony_ci } 552eace7efcSopenharmony_ci return ERR_OK; 553eace7efcSopenharmony_ci} 554eace7efcSopenharmony_ci 555eace7efcSopenharmony_ciint32_t AppScheduler::DetachAppDebug(const std::string &bundleName) 556eace7efcSopenharmony_ci{ 557eace7efcSopenharmony_ci CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR); 558eace7efcSopenharmony_ci auto ret = static_cast<int32_t>(appMgrClient_->DetachAppDebug(bundleName)); 559eace7efcSopenharmony_ci if (ret != ERR_OK) { 560eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "detach app debug failed"); 561eace7efcSopenharmony_ci return INNER_ERR; 562eace7efcSopenharmony_ci } 563eace7efcSopenharmony_ci return ERR_OK; 564eace7efcSopenharmony_ci} 565eace7efcSopenharmony_ci 566eace7efcSopenharmony_ciint32_t AppScheduler::RegisterAbilityDebugResponse(const sptr<AppExecFwk::IAbilityDebugResponse> &response) 567eace7efcSopenharmony_ci{ 568eace7efcSopenharmony_ci CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR); 569eace7efcSopenharmony_ci auto ret = static_cast<int32_t>(appMgrClient_->RegisterAbilityDebugResponse(response)); 570eace7efcSopenharmony_ci if (ret != ERR_OK) { 571eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "register ability debug response failed"); 572eace7efcSopenharmony_ci return INNER_ERR; 573eace7efcSopenharmony_ci } 574eace7efcSopenharmony_ci return ERR_OK; 575eace7efcSopenharmony_ci} 576eace7efcSopenharmony_ci 577eace7efcSopenharmony_cibool AppScheduler::IsAttachDebug(const std::string &bundleName) 578eace7efcSopenharmony_ci{ 579eace7efcSopenharmony_ci CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR); 580eace7efcSopenharmony_ci auto ret = static_cast<int32_t>(appMgrClient_->IsAttachDebug(bundleName)); 581eace7efcSopenharmony_ci if (ret != ERR_OK) { 582eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "call attach debug failed"); 583eace7efcSopenharmony_ci return INNER_ERR; 584eace7efcSopenharmony_ci } 585eace7efcSopenharmony_ci return ERR_OK; 586eace7efcSopenharmony_ci} 587eace7efcSopenharmony_ci 588eace7efcSopenharmony_civoid AppScheduler::ClearProcessByToken(sptr<IRemoteObject> token) const 589eace7efcSopenharmony_ci{ 590eace7efcSopenharmony_ci HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); 591eace7efcSopenharmony_ci CHECK_POINTER(appMgrClient_); 592eace7efcSopenharmony_ci appMgrClient_->ClearProcessByToken(token); 593eace7efcSopenharmony_ci} 594eace7efcSopenharmony_ci 595eace7efcSopenharmony_cibool AppScheduler::IsMemorySizeSufficent() const 596eace7efcSopenharmony_ci{ 597eace7efcSopenharmony_ci if (!appMgrClient_) { 598eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "null appMgrClient"); 599eace7efcSopenharmony_ci return true; 600eace7efcSopenharmony_ci } 601eace7efcSopenharmony_ci return appMgrClient_->IsMemorySizeSufficent(); 602eace7efcSopenharmony_ci} 603eace7efcSopenharmony_ci 604eace7efcSopenharmony_civoid AppScheduler::AttachedToStatusBar(const sptr<IRemoteObject> &token) 605eace7efcSopenharmony_ci{ 606eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::ABILITYMGR, "call"); 607eace7efcSopenharmony_ci CHECK_POINTER(appMgrClient_); 608eace7efcSopenharmony_ci appMgrClient_->AttachedToStatusBar(token); 609eace7efcSopenharmony_ci} 610eace7efcSopenharmony_ci 611eace7efcSopenharmony_civoid AppScheduler::BlockProcessCacheByPids(const std::vector<int32_t> &pids) 612eace7efcSopenharmony_ci{ 613eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::ABILITYMGR, "call"); 614eace7efcSopenharmony_ci CHECK_POINTER(appMgrClient_); 615eace7efcSopenharmony_ci appMgrClient_->BlockProcessCacheByPids(pids); 616eace7efcSopenharmony_ci} 617eace7efcSopenharmony_ci 618eace7efcSopenharmony_cibool AppScheduler::CleanAbilityByUserRequest(const sptr<IRemoteObject> &token) 619eace7efcSopenharmony_ci{ 620eace7efcSopenharmony_ci HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); 621eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::ABILITYMGR, "called"); 622eace7efcSopenharmony_ci if (!appMgrClient_) { 623eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "null appMgrClient"); 624eace7efcSopenharmony_ci return false; 625eace7efcSopenharmony_ci } 626eace7efcSopenharmony_ci return IN_PROCESS_CALL(appMgrClient_->CleanAbilityByUserRequest(token)); 627eace7efcSopenharmony_ci} 628eace7efcSopenharmony_ci 629eace7efcSopenharmony_cibool AppScheduler::IsKilledForUpgradeWeb(const std::string &bundleName) 630eace7efcSopenharmony_ci{ 631eace7efcSopenharmony_ci if (!appMgrClient_) { 632eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "null appMgrClient"); 633eace7efcSopenharmony_ci return false; 634eace7efcSopenharmony_ci } 635eace7efcSopenharmony_ci return appMgrClient_->IsKilledForUpgradeWeb(bundleName); 636eace7efcSopenharmony_ci} 637eace7efcSopenharmony_cibool AppScheduler::IsProcessContainsOnlyUIAbility(const pid_t pid) 638eace7efcSopenharmony_ci{ 639eace7efcSopenharmony_ci if (!appMgrClient_) { 640eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "null appMgrClient"); 641eace7efcSopenharmony_ci return false; 642eace7efcSopenharmony_ci } 643eace7efcSopenharmony_ci return appMgrClient_->IsProcessContainsOnlyUIAbility(pid); 644eace7efcSopenharmony_ci} 645eace7efcSopenharmony_ci 646eace7efcSopenharmony_cibool AppScheduler::IsProcessAttached(sptr<IRemoteObject> token) const 647eace7efcSopenharmony_ci{ 648eace7efcSopenharmony_ci if (!appMgrClient_) { 649eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "null appMgrClient"); 650eace7efcSopenharmony_ci return false; 651eace7efcSopenharmony_ci } 652eace7efcSopenharmony_ci return appMgrClient_->IsProcessAttached(token); 653eace7efcSopenharmony_ci} 654eace7efcSopenharmony_ci 655eace7efcSopenharmony_cibool AppScheduler::IsAppKilling(sptr<IRemoteObject> token) const 656eace7efcSopenharmony_ci{ 657eace7efcSopenharmony_ci if (!appMgrClient_) { 658eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "appMgrClient is nullptr"); 659eace7efcSopenharmony_ci return false; 660eace7efcSopenharmony_ci } 661eace7efcSopenharmony_ci return appMgrClient_->IsAppKilling(token); 662eace7efcSopenharmony_ci} 663eace7efcSopenharmony_ci 664eace7efcSopenharmony_civoid AppScheduler::SetProcessCacheStatus(int32_t pid, bool isSupport) 665eace7efcSopenharmony_ci{ 666eace7efcSopenharmony_ci if (!appMgrClient_) { 667eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "appMgrClient is nullptr"); 668eace7efcSopenharmony_ci return; 669eace7efcSopenharmony_ci } 670eace7efcSopenharmony_ci appMgrClient_->SetSupportedProcessCache(pid, isSupport); 671eace7efcSopenharmony_ci} 672eace7efcSopenharmony_ci} // namespace AAFwk 673eace7efcSopenharmony_ci} // namespace OHOS 674