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#ifndef OHOS_ABILITY_RUNTIME_APP_SCHEDULER_H 17eace7efcSopenharmony_ci#define OHOS_ABILITY_RUNTIME_APP_SCHEDULER_H 18eace7efcSopenharmony_ci 19eace7efcSopenharmony_ci#include <memory> 20eace7efcSopenharmony_ci#include <unordered_set> 21eace7efcSopenharmony_ci 22eace7efcSopenharmony_ci#include "ability_debug_response_interface.h" 23eace7efcSopenharmony_ci#include "ability_info.h" 24eace7efcSopenharmony_ci#include "ability_manager_client.h" 25eace7efcSopenharmony_ci#include "app_debug_listener_interface.h" 26eace7efcSopenharmony_ci#include "application_info.h" 27eace7efcSopenharmony_ci#include "appmgr/app_mgr_client.h" 28eace7efcSopenharmony_ci#include "appmgr/app_state_callback_host.h" 29eace7efcSopenharmony_ci#include "appmgr/start_specified_ability_response_stub.h" 30eace7efcSopenharmony_ci#include "bundle_info.h" 31eace7efcSopenharmony_ci#include "fault_data.h" 32eace7efcSopenharmony_ci#include "iremote_object.h" 33eace7efcSopenharmony_ci#include "refbase.h" 34eace7efcSopenharmony_ci#include "running_process_info.h" 35eace7efcSopenharmony_ci#include "singleton.h" 36eace7efcSopenharmony_ci#include "system_memory_attr.h" 37eace7efcSopenharmony_ci#include "want.h" 38eace7efcSopenharmony_ci 39eace7efcSopenharmony_cinamespace OHOS { 40eace7efcSopenharmony_cinamespace AppExecFwk { 41eace7efcSopenharmony_ciclass Configuration; 42eace7efcSopenharmony_ci} 43eace7efcSopenharmony_cinamespace AAFwk { 44eace7efcSopenharmony_ci/** 45eace7efcSopenharmony_ci * @enum AppAbilityState 46eace7efcSopenharmony_ci * AppAbilityState defines the life cycle state of app ability. 47eace7efcSopenharmony_ci */ 48eace7efcSopenharmony_cienum class AppAbilityState { 49eace7efcSopenharmony_ci ABILITY_STATE_UNDEFINED = 0, 50eace7efcSopenharmony_ci ABILITY_STATE_FOREGROUND, 51eace7efcSopenharmony_ci ABILITY_STATE_BACKGROUND, 52eace7efcSopenharmony_ci ABILITY_STATE_END, 53eace7efcSopenharmony_ci}; 54eace7efcSopenharmony_ci 55eace7efcSopenharmony_cienum class AppState { 56eace7efcSopenharmony_ci BEGIN = 0, 57eace7efcSopenharmony_ci READY, 58eace7efcSopenharmony_ci FOREGROUND, 59eace7efcSopenharmony_ci FOCUS, 60eace7efcSopenharmony_ci BACKGROUND, 61eace7efcSopenharmony_ci TERMINATED, 62eace7efcSopenharmony_ci END, 63eace7efcSopenharmony_ci SUSPENDED, 64eace7efcSopenharmony_ci COLD_START = 99, 65eace7efcSopenharmony_ci}; 66eace7efcSopenharmony_ci 67eace7efcSopenharmony_cistruct AppData { 68eace7efcSopenharmony_ci std::string appName; 69eace7efcSopenharmony_ci int32_t uid; 70eace7efcSopenharmony_ci}; 71eace7efcSopenharmony_ci 72eace7efcSopenharmony_cistruct AppInfo { 73eace7efcSopenharmony_ci std::vector<AppData> appData; 74eace7efcSopenharmony_ci std::string processName; 75eace7efcSopenharmony_ci AppState state; 76eace7efcSopenharmony_ci pid_t pid = 0; 77eace7efcSopenharmony_ci}; 78eace7efcSopenharmony_ci/** 79eace7efcSopenharmony_ci * @class AppStateCallback 80eace7efcSopenharmony_ci * AppStateCallback. 81eace7efcSopenharmony_ci */ 82eace7efcSopenharmony_ciclass AppStateCallback { 83eace7efcSopenharmony_cipublic: 84eace7efcSopenharmony_ci AppStateCallback() 85eace7efcSopenharmony_ci {} 86eace7efcSopenharmony_ci virtual ~AppStateCallback() 87eace7efcSopenharmony_ci {} 88eace7efcSopenharmony_ci 89eace7efcSopenharmony_ci virtual void OnAbilityRequestDone(const sptr<IRemoteObject> &token, const int32_t state) = 0; 90eace7efcSopenharmony_ci 91eace7efcSopenharmony_ci virtual void OnAppStateChanged(const AppInfo &info) = 0; 92eace7efcSopenharmony_ci 93eace7efcSopenharmony_ci virtual void NotifyConfigurationChange(const AppExecFwk::Configuration &config, int32_t userId) {} 94eace7efcSopenharmony_ci 95eace7efcSopenharmony_ci virtual void NotifyStartResidentProcess(std::vector<AppExecFwk::BundleInfo> &bundleInfos) {} 96eace7efcSopenharmony_ci 97eace7efcSopenharmony_ci /** 98eace7efcSopenharmony_ci * @brief Notify abilityms app process pre cache 99eace7efcSopenharmony_ci * @param pid process pid. 100eace7efcSopenharmony_ci * @param userId userId Designation User ID. 101eace7efcSopenharmony_ci */ 102eace7efcSopenharmony_ci virtual void NotifyAppPreCache(int32_t pid, int32_t userId) {} 103eace7efcSopenharmony_ci 104eace7efcSopenharmony_ci /** 105eace7efcSopenharmony_ci * @brief Notify abilityms app process OnRemoteDied 106eace7efcSopenharmony_ci * @param abilityTokens abilities in died process. 107eace7efcSopenharmony_ci */ 108eace7efcSopenharmony_ci virtual void OnAppRemoteDied(const std::vector<sptr<IRemoteObject>> &abilityTokens) {} 109eace7efcSopenharmony_ci}; 110eace7efcSopenharmony_ci 111eace7efcSopenharmony_ciclass StartSpecifiedAbilityResponse : public AppExecFwk::StartSpecifiedAbilityResponseStub { 112eace7efcSopenharmony_cipublic: 113eace7efcSopenharmony_ci StartSpecifiedAbilityResponse() = default; 114eace7efcSopenharmony_ci virtual ~StartSpecifiedAbilityResponse() = default; 115eace7efcSopenharmony_ci 116eace7efcSopenharmony_ci virtual void OnAcceptWantResponse(const AAFwk::Want &want, const std::string &flag, 117eace7efcSopenharmony_ci int32_t requestId) override; 118eace7efcSopenharmony_ci virtual void OnTimeoutResponse(const AAFwk::Want &want, int32_t requestId) override; 119eace7efcSopenharmony_ci 120eace7efcSopenharmony_ci virtual void OnNewProcessRequestResponse(const AAFwk::Want &want, const std::string &flag, 121eace7efcSopenharmony_ci int32_t requestId) override; 122eace7efcSopenharmony_ci virtual void OnNewProcessRequestTimeoutResponse(const AAFwk::Want &want, int32_t requestId) override; 123eace7efcSopenharmony_ci}; 124eace7efcSopenharmony_ci 125eace7efcSopenharmony_ci/** 126eace7efcSopenharmony_ci * @class AppScheduler 127eace7efcSopenharmony_ci * AppScheduler , access app manager service. 128eace7efcSopenharmony_ci */ 129eace7efcSopenharmony_ciclass AppScheduler : virtual RefBase, public AppExecFwk::AppStateCallbackHost { 130eace7efcSopenharmony_ci DECLARE_DELAYED_SINGLETON(AppScheduler) 131eace7efcSopenharmony_cipublic: 132eace7efcSopenharmony_ci /** 133eace7efcSopenharmony_ci * init app scheduler. 134eace7efcSopenharmony_ci * @param callback, app state call back. 135eace7efcSopenharmony_ci * @return true on success ,false on failure. 136eace7efcSopenharmony_ci */ 137eace7efcSopenharmony_ci bool Init(const std::weak_ptr<AppStateCallback> &callback); 138eace7efcSopenharmony_ci 139eace7efcSopenharmony_ci /** 140eace7efcSopenharmony_ci * load ability with token, ability info and application info. 141eace7efcSopenharmony_ci * 142eace7efcSopenharmony_ci * @param token, the token of ability. 143eace7efcSopenharmony_ci * @param preToken, the token of ability's caller. 144eace7efcSopenharmony_ci * @param abilityInfo, ability info. 145eace7efcSopenharmony_ci * @param applicationInfo, application info. 146eace7efcSopenharmony_ci * @param want ability want 147eace7efcSopenharmony_ci * @return true on success ,false on failure. 148eace7efcSopenharmony_ci */ 149eace7efcSopenharmony_ci int LoadAbility(sptr<IRemoteObject> token, sptr<IRemoteObject> preToken, 150eace7efcSopenharmony_ci const AppExecFwk::AbilityInfo &abilityInfo, const AppExecFwk::ApplicationInfo &applicationInfo, 151eace7efcSopenharmony_ci const Want &want, int32_t abilityRecordId, const std::string &instanceKey); 152eace7efcSopenharmony_ci 153eace7efcSopenharmony_ci /** 154eace7efcSopenharmony_ci * terminate ability with token. 155eace7efcSopenharmony_ci * 156eace7efcSopenharmony_ci * @param token, the token of ability. 157eace7efcSopenharmony_ci * @param clearMissionFlag, indicates whether terminate the ability when clearMission. 158eace7efcSopenharmony_ci * @return true on success ,false on failure. 159eace7efcSopenharmony_ci */ 160eace7efcSopenharmony_ci int TerminateAbility(const sptr<IRemoteObject> &token, bool clearMissionFlag); 161eace7efcSopenharmony_ci 162eace7efcSopenharmony_ci /** 163eace7efcSopenharmony_ci * move ability to foreground. 164eace7efcSopenharmony_ci * 165eace7efcSopenharmony_ci * @param token, the token of ability. 166eace7efcSopenharmony_ci */ 167eace7efcSopenharmony_ci void MoveToForeground(const sptr<IRemoteObject> &token); 168eace7efcSopenharmony_ci 169eace7efcSopenharmony_ci /** 170eace7efcSopenharmony_ci * move ability to background. 171eace7efcSopenharmony_ci * 172eace7efcSopenharmony_ci * @param token, the token of ability. 173eace7efcSopenharmony_ci */ 174eace7efcSopenharmony_ci void MoveToBackground(const sptr<IRemoteObject> &token); 175eace7efcSopenharmony_ci 176eace7efcSopenharmony_ci /** 177eace7efcSopenharmony_ci * Update ability state. 178eace7efcSopenharmony_ci * 179eace7efcSopenharmony_ci * @param token, the token of ability. 180eace7efcSopenharmony_ci * @param state, ability state. 181eace7efcSopenharmony_ci */ 182eace7efcSopenharmony_ci void UpdateAbilityState(const sptr<IRemoteObject> &token, const AppExecFwk::AbilityState state); 183eace7efcSopenharmony_ci 184eace7efcSopenharmony_ci /** 185eace7efcSopenharmony_ci * UpdateExtensionState, call UpdateExtensionState() through the proxy object, update the extension status. 186eace7efcSopenharmony_ci * 187eace7efcSopenharmony_ci * @param token, the unique identification to update the extension. 188eace7efcSopenharmony_ci * @param state, extension status that needs to be updated. 189eace7efcSopenharmony_ci * @return 190eace7efcSopenharmony_ci */ 191eace7efcSopenharmony_ci void UpdateExtensionState(const sptr<IRemoteObject> &token, const AppExecFwk::ExtensionState state); 192eace7efcSopenharmony_ci 193eace7efcSopenharmony_ci /** 194eace7efcSopenharmony_ci * KillProcessByAbilityToken, call KillProcessByAbilityToken() through proxy object, 195eace7efcSopenharmony_ci * kill the process by ability token. 196eace7efcSopenharmony_ci * 197eace7efcSopenharmony_ci * @param token, the unique identification to the ability. 198eace7efcSopenharmony_ci */ 199eace7efcSopenharmony_ci void KillProcessByAbilityToken(const sptr<IRemoteObject> &token); 200eace7efcSopenharmony_ci 201eace7efcSopenharmony_ci /** 202eace7efcSopenharmony_ci * KillProcessesByUserId, call KillProcessesByUserId() through proxy object, 203eace7efcSopenharmony_ci * kill the process by user id. 204eace7efcSopenharmony_ci * 205eace7efcSopenharmony_ci * @param userId, the user id. 206eace7efcSopenharmony_ci */ 207eace7efcSopenharmony_ci void KillProcessesByUserId(int32_t userId); 208eace7efcSopenharmony_ci 209eace7efcSopenharmony_ci /** 210eace7efcSopenharmony_ci * KillProcessesByPids, only in process call is allowed, 211eace7efcSopenharmony_ci * kill the processes by pid list given. 212eace7efcSopenharmony_ci * 213eace7efcSopenharmony_ci * @param pids, the pid list of processes are going to be killed. 214eace7efcSopenharmony_ci */ 215eace7efcSopenharmony_ci void KillProcessesByPids(std::vector<int32_t> &pids); 216eace7efcSopenharmony_ci 217eace7efcSopenharmony_ci /** 218eace7efcSopenharmony_ci * Set child and parent relationship 219eace7efcSopenharmony_ci * @param token child process 220eace7efcSopenharmony_ci * @param callerToken parent process 221eace7efcSopenharmony_ci */ 222eace7efcSopenharmony_ci void AttachPidToParent(const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &callerToken); 223eace7efcSopenharmony_ci 224eace7efcSopenharmony_ci /** 225eace7efcSopenharmony_ci * convert ability state to app ability state. 226eace7efcSopenharmony_ci * 227eace7efcSopenharmony_ci * @param state, the state of ability. 228eace7efcSopenharmony_ci */ 229eace7efcSopenharmony_ci AppAbilityState ConvertToAppAbilityState(const int32_t state); 230eace7efcSopenharmony_ci 231eace7efcSopenharmony_ci /** 232eace7efcSopenharmony_ci * get ability state. 233eace7efcSopenharmony_ci * 234eace7efcSopenharmony_ci * @return state, the state of app ability. 235eace7efcSopenharmony_ci */ 236eace7efcSopenharmony_ci AppAbilityState GetAbilityState() const; 237eace7efcSopenharmony_ci 238eace7efcSopenharmony_ci /** 239eace7efcSopenharmony_ci * kill the application 240eace7efcSopenharmony_ci * 241eace7efcSopenharmony_ci * @param bundleName. 242eace7efcSopenharmony_ci */ 243eace7efcSopenharmony_ci int KillApplication(const std::string &bundleName, const bool clearPageStack = false); 244eace7efcSopenharmony_ci 245eace7efcSopenharmony_ci /** 246eace7efcSopenharmony_ci * ForceKillApplication, force kill the application. 247eace7efcSopenharmony_ci * 248eace7efcSopenharmony_ci * @param bundleName, bundle name in Application record. 249eace7efcSopenharmony_ci * @param userId, userId. 250eace7efcSopenharmony_ci * @param appIndex, appIndex. 251eace7efcSopenharmony_ci * @return ERR_OK, return back success, others fail. 252eace7efcSopenharmony_ci */ 253eace7efcSopenharmony_ci int ForceKillApplication(const std::string &bundleName, const int userId = -1, 254eace7efcSopenharmony_ci const int appIndex = 0); 255eace7efcSopenharmony_ci 256eace7efcSopenharmony_ci /** 257eace7efcSopenharmony_ci * KillProcessesByAccessTokenId. 258eace7efcSopenharmony_ci * 259eace7efcSopenharmony_ci * @param accessTokenId, accessTokenId. 260eace7efcSopenharmony_ci * @return ERR_OK, return back success, others fail. 261eace7efcSopenharmony_ci */ 262eace7efcSopenharmony_ci int KillProcessesByAccessTokenId(const uint32_t accessTokenId); 263eace7efcSopenharmony_ci 264eace7efcSopenharmony_ci /** 265eace7efcSopenharmony_ci * kill the application by uid 266eace7efcSopenharmony_ci * 267eace7efcSopenharmony_ci * @param bundleName name of bundle. 268eace7efcSopenharmony_ci * @param uid uid of bundle. 269eace7efcSopenharmony_ci * @param reason, caller function name. 270eace7efcSopenharmony_ci * @return 0 if success. 271eace7efcSopenharmony_ci */ 272eace7efcSopenharmony_ci int KillApplicationByUid(const std::string &bundleName, int32_t uid, 273eace7efcSopenharmony_ci const std::string& reason = "KillApplicationByUid"); 274eace7efcSopenharmony_ci 275eace7efcSopenharmony_ci /** 276eace7efcSopenharmony_ci * update the application info after new module installed. 277eace7efcSopenharmony_ci * 278eace7efcSopenharmony_ci * @param bundleName, bundle name in Application record. 279eace7efcSopenharmony_ci * @param uid, uid. 280eace7efcSopenharmony_ci * @return 0 if success. 281eace7efcSopenharmony_ci */ 282eace7efcSopenharmony_ci int UpdateApplicationInfoInstalled(const std::string &bundleName, const int32_t uid); 283eace7efcSopenharmony_ci 284eace7efcSopenharmony_ci /** 285eace7efcSopenharmony_ci * Ability attach timeout. If start ability encounter failure, attach timeout to terminate. 286eace7efcSopenharmony_ci * 287eace7efcSopenharmony_ci * @param token Ability identify. 288eace7efcSopenharmony_ci */ 289eace7efcSopenharmony_ci void AttachTimeOut(const sptr<IRemoteObject> &token); 290eace7efcSopenharmony_ci 291eace7efcSopenharmony_ci /** 292eace7efcSopenharmony_ci * Prepare terminate. 293eace7efcSopenharmony_ci * 294eace7efcSopenharmony_ci * @param token Ability identify. 295eace7efcSopenharmony_ci * @param clearMissionFlag Clear mission flag. 296eace7efcSopenharmony_ci */ 297eace7efcSopenharmony_ci void PrepareTerminate(const sptr<IRemoteObject> &token, bool clearMissionFlag = false); 298eace7efcSopenharmony_ci 299eace7efcSopenharmony_ci /** 300eace7efcSopenharmony_ci * Get running process information by ability token. 301eace7efcSopenharmony_ci * 302eace7efcSopenharmony_ci * @param token Ability identify. 303eace7efcSopenharmony_ci * @param info Running process info. 304eace7efcSopenharmony_ci */ 305eace7efcSopenharmony_ci void GetRunningProcessInfoByToken(const sptr<IRemoteObject> &token, AppExecFwk::RunningProcessInfo &info); 306eace7efcSopenharmony_ci 307eace7efcSopenharmony_ci /** 308eace7efcSopenharmony_ci * Get running process information by pid. 309eace7efcSopenharmony_ci * 310eace7efcSopenharmony_ci * @param pid process id. 311eace7efcSopenharmony_ci * @param info Output parameters, return runningProcessInfo. 312eace7efcSopenharmony_ci * @return Returns ERR_OK on success, others on failure. 313eace7efcSopenharmony_ci */ 314eace7efcSopenharmony_ci void GetRunningProcessInfoByPid(const pid_t pid, OHOS::AppExecFwk::RunningProcessInfo &info) const; 315eace7efcSopenharmony_ci 316eace7efcSopenharmony_ci /** 317eace7efcSopenharmony_ci * Set AbilityForegroundingFlag of an app-record to true. 318eace7efcSopenharmony_ci * 319eace7efcSopenharmony_ci * @param pid, pid. 320eace7efcSopenharmony_ci * 321eace7efcSopenharmony_ci */ 322eace7efcSopenharmony_ci void SetAbilityForegroundingFlagToAppRecord(const pid_t pid) const; 323eace7efcSopenharmony_ci 324eace7efcSopenharmony_ci /** 325eace7efcSopenharmony_ci * Start a resident process 326eace7efcSopenharmony_ci */ 327eace7efcSopenharmony_ci void StartupResidentProcess(const std::vector<AppExecFwk::BundleInfo> &bundleInfos); 328eace7efcSopenharmony_ci 329eace7efcSopenharmony_ci /** 330eace7efcSopenharmony_ci * Start specified ability. 331eace7efcSopenharmony_ci * 332eace7efcSopenharmony_ci * @param want Want contains information of the ability to start. 333eace7efcSopenharmony_ci * @param abilityInfo Ability information. 334eace7efcSopenharmony_ci * @param requestId request id to callback 335eace7efcSopenharmony_ci */ 336eace7efcSopenharmony_ci void StartSpecifiedAbility(const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo, 337eace7efcSopenharmony_ci int32_t requestId = 0); 338eace7efcSopenharmony_ci 339eace7efcSopenharmony_ci /** 340eace7efcSopenharmony_ci * @brief Get running process information. 341eace7efcSopenharmony_ci * 342eace7efcSopenharmony_ci * @param info Running process information. 343eace7efcSopenharmony_ci * @return Returns ERR_OK on success, others on failure. 344eace7efcSopenharmony_ci */ 345eace7efcSopenharmony_ci int GetProcessRunningInfos(std::vector<AppExecFwk::RunningProcessInfo> &info); 346eace7efcSopenharmony_ci 347eace7efcSopenharmony_ci /** 348eace7efcSopenharmony_ci * Start specified process. 349eace7efcSopenharmony_ci * 350eace7efcSopenharmony_ci * @param want Want contains information wish to start. 351eace7efcSopenharmony_ci * @param abilityInfo Ability information. 352eace7efcSopenharmony_ci * @param requestId for callback 353eace7efcSopenharmony_ci */ 354eace7efcSopenharmony_ci void StartSpecifiedProcess(const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo, 355eace7efcSopenharmony_ci int32_t requestId = 0); 356eace7efcSopenharmony_ci 357eace7efcSopenharmony_ci /** 358eace7efcSopenharmony_ci * Start a user test 359eace7efcSopenharmony_ci */ 360eace7efcSopenharmony_ci int StartUserTest(const Want &want, const sptr<IRemoteObject> &observer, const AppExecFwk::BundleInfo &bundleInfo, 361eace7efcSopenharmony_ci int32_t userId); 362eace7efcSopenharmony_ci 363eace7efcSopenharmony_ci /** 364eace7efcSopenharmony_ci * @brief Finish user test. 365eace7efcSopenharmony_ci * @param msg user test message. 366eace7efcSopenharmony_ci * @param resultCode user test result Code. 367eace7efcSopenharmony_ci * @param bundleName user test bundleName. 368eace7efcSopenharmony_ci * 369eace7efcSopenharmony_ci * @return Returns ERR_OK on success, others on failure. 370eace7efcSopenharmony_ci */ 371eace7efcSopenharmony_ci int FinishUserTest(const std::string &msg, const int64_t &resultCode, const std::string &bundleName); 372eace7efcSopenharmony_ci 373eace7efcSopenharmony_ci /** 374eace7efcSopenharmony_ci * GetProcessRunningInfosByUserId, call GetProcessRunningInfosByUserId() through proxy project. 375eace7efcSopenharmony_ci * Obtains information about application processes that are running on the device. 376eace7efcSopenharmony_ci * 377eace7efcSopenharmony_ci * @param info, app name in Application record. 378eace7efcSopenharmony_ci * @param userId, user Id in Application record. 379eace7efcSopenharmony_ci * @return ERR_OK ,return back success,others fail. 380eace7efcSopenharmony_ci */ 381eace7efcSopenharmony_ci int GetProcessRunningInfosByUserId(std::vector<AppExecFwk::RunningProcessInfo> &info, int32_t userId); 382eace7efcSopenharmony_ci std::string ConvertAppState(const AppState &state); 383eace7efcSopenharmony_ci 384eace7efcSopenharmony_ci /** 385eace7efcSopenharmony_ci * ANotify application update system environment changes. 386eace7efcSopenharmony_ci * 387eace7efcSopenharmony_ci * @param config System environment change parameters. 388eace7efcSopenharmony_ci * @return Returns ERR_OK on success, others on failure. 389eace7efcSopenharmony_ci */ 390eace7efcSopenharmony_ci int UpdateConfiguration(const AppExecFwk::Configuration &config); 391eace7efcSopenharmony_ci 392eace7efcSopenharmony_ci /** 393eace7efcSopenharmony_ci * GetConfiguration 394eace7efcSopenharmony_ci * 395eace7efcSopenharmony_ci * @param info to retrieve configuration data. 396eace7efcSopenharmony_ci * @return ERR_OK ,return back success,others fail. 397eace7efcSopenharmony_ci */ 398eace7efcSopenharmony_ci int GetConfiguration(AppExecFwk::Configuration &config); 399eace7efcSopenharmony_ci 400eace7efcSopenharmony_ci /** 401eace7efcSopenharmony_ci * Get the token of ability records by process ID. 402eace7efcSopenharmony_ci * 403eace7efcSopenharmony_ci * @param pid The process id. 404eace7efcSopenharmony_ci * @param tokens The token of ability records. 405eace7efcSopenharmony_ci * @return Returns ERR_OK on success, others on failure. 406eace7efcSopenharmony_ci */ 407eace7efcSopenharmony_ci int GetAbilityRecordsByProcessID(const int pid, std::vector<sptr<IRemoteObject>> &tokens); 408eace7efcSopenharmony_ci 409eace7efcSopenharmony_ci /** 410eace7efcSopenharmony_ci * Get the application info by process ID. 411eace7efcSopenharmony_ci * 412eace7efcSopenharmony_ci * @param pid The process id. 413eace7efcSopenharmony_ci * @param application The application info. 414eace7efcSopenharmony_ci * @param debug The app is or not debug. 415eace7efcSopenharmony_ci * @return Returns ERR_OK on success, others on failure. 416eace7efcSopenharmony_ci */ 417eace7efcSopenharmony_ci int GetApplicationInfoByProcessID(const int pid, AppExecFwk::ApplicationInfo &application, bool &debug); 418eace7efcSopenharmony_ci 419eace7efcSopenharmony_ci /** 420eace7efcSopenharmony_ci * Set the process cache status by process ID. 421eace7efcSopenharmony_ci * 422eace7efcSopenharmony_ci * @param pid The process id. 423eace7efcSopenharmony_ci * @param isSupport The process is support cache. 424eace7efcSopenharmony_ci * @return Returns ERR_OK on success, others on failure. 425eace7efcSopenharmony_ci */ 426eace7efcSopenharmony_ci void SetProcessCacheStatus(int32_t pid, bool isSupport); 427eace7efcSopenharmony_ci 428eace7efcSopenharmony_ci /** 429eace7efcSopenharmony_ci * Record process exit reason to appRunningRecord 430eace7efcSopenharmony_ci * @param pid pid 431eace7efcSopenharmony_ci * @param reason reason enum 432eace7efcSopenharmony_ci * @param exitMsg exitMsg 433eace7efcSopenharmony_ci * @return Returns ERR_OK on success, others on failure. 434eace7efcSopenharmony_ci */ 435eace7efcSopenharmony_ci virtual int32_t NotifyAppMgrRecordExitReason(int32_t pid, int32_t reason, const std::string &exitMsg); 436eace7efcSopenharmony_ci 437eace7efcSopenharmony_ci /** 438eace7efcSopenharmony_ci * Set the current userId of appMgr, only used by abilityMgr. 439eace7efcSopenharmony_ci * 440eace7efcSopenharmony_ci * @param userId the user id. 441eace7efcSopenharmony_ci * 442eace7efcSopenharmony_ci * @return 443eace7efcSopenharmony_ci */ 444eace7efcSopenharmony_ci void SetCurrentUserId(int32_t userId); 445eace7efcSopenharmony_ci 446eace7efcSopenharmony_ci /** 447eace7efcSopenharmony_ci * Set enable start process flag by userId 448eace7efcSopenharmony_ci * @param userId the user id. 449eace7efcSopenharmony_ci * @param enableStartProcess enable start process. 450eace7efcSopenharmony_ci * @return 451eace7efcSopenharmony_ci */ 452eace7efcSopenharmony_ci void SetEnableStartProcessFlagByUserId(int32_t userId, bool enableStartProcess); 453eace7efcSopenharmony_ci 454eace7efcSopenharmony_ci /** 455eace7efcSopenharmony_ci * Get bundleName by pid. 456eace7efcSopenharmony_ci * 457eace7efcSopenharmony_ci * @param pid process id. 458eace7efcSopenharmony_ci * @param bundleName Output parameters, return bundleName. 459eace7efcSopenharmony_ci * @param uid Output parameters, return userId. 460eace7efcSopenharmony_ci * @return Returns ERR_OK on success, others on failure. 461eace7efcSopenharmony_ci */ 462eace7efcSopenharmony_ci int32_t GetBundleNameByPid(const int pid, std::string &bundleName, int32_t &uid); 463eace7efcSopenharmony_ci 464eace7efcSopenharmony_ci /** 465eace7efcSopenharmony_ci * Notify Fault Data 466eace7efcSopenharmony_ci * 467eace7efcSopenharmony_ci * @param faultData the fault data. 468eace7efcSopenharmony_ci * @return Returns ERR_OK on success, others on failure. 469eace7efcSopenharmony_ci */ 470eace7efcSopenharmony_ci int32_t NotifyFault(const AppExecFwk::FaultData &faultData); 471eace7efcSopenharmony_ci 472eace7efcSopenharmony_ci /** 473eace7efcSopenharmony_ci * @brief Register app debug listener. 474eace7efcSopenharmony_ci * @param listener App debug listener. 475eace7efcSopenharmony_ci * @return Returns ERR_OK on success, others on failure. 476eace7efcSopenharmony_ci */ 477eace7efcSopenharmony_ci int32_t RegisterAppDebugListener(const sptr<AppExecFwk::IAppDebugListener> &listener); 478eace7efcSopenharmony_ci 479eace7efcSopenharmony_ci /** 480eace7efcSopenharmony_ci * @brief Unregister app debug listener. 481eace7efcSopenharmony_ci * @param listener App debug listener. 482eace7efcSopenharmony_ci * @return Returns ERR_OK on success, others on failure. 483eace7efcSopenharmony_ci */ 484eace7efcSopenharmony_ci int32_t UnregisterAppDebugListener(const sptr<AppExecFwk::IAppDebugListener> &listener); 485eace7efcSopenharmony_ci 486eace7efcSopenharmony_ci /** 487eace7efcSopenharmony_ci * @brief Attach app debug. 488eace7efcSopenharmony_ci * @param bundleName The application bundle name. 489eace7efcSopenharmony_ci * @return Returns ERR_OK on success, others on failure. 490eace7efcSopenharmony_ci */ 491eace7efcSopenharmony_ci int32_t AttachAppDebug(const std::string &bundleName); 492eace7efcSopenharmony_ci 493eace7efcSopenharmony_ci /** 494eace7efcSopenharmony_ci * @brief Detach app debug. 495eace7efcSopenharmony_ci * @param bundleName The application bundle name. 496eace7efcSopenharmony_ci * @return Returns ERR_OK on success, others on failure. 497eace7efcSopenharmony_ci */ 498eace7efcSopenharmony_ci int32_t DetachAppDebug(const std::string &bundleName); 499eace7efcSopenharmony_ci 500eace7efcSopenharmony_ci /** 501eace7efcSopenharmony_ci * @brief Register ability debug response to set debug mode. 502eace7efcSopenharmony_ci * @param bundleName The application bundle name. 503eace7efcSopenharmony_ci * @return Returns ERR_OK on success, others on failure. 504eace7efcSopenharmony_ci */ 505eace7efcSopenharmony_ci int32_t RegisterAbilityDebugResponse(const sptr<AppExecFwk::IAbilityDebugResponse> &response); 506eace7efcSopenharmony_ci 507eace7efcSopenharmony_ci /** 508eace7efcSopenharmony_ci * @brief Determine whether it is an attachment debug application based on the bundle name. 509eace7efcSopenharmony_ci * @param bundleName The application bundle name. 510eace7efcSopenharmony_ci * @return Returns true if it is an attach debug application, otherwise it returns false. 511eace7efcSopenharmony_ci */ 512eace7efcSopenharmony_ci bool IsAttachDebug(const std::string &bundleName); 513eace7efcSopenharmony_ci 514eace7efcSopenharmony_ci /** 515eace7efcSopenharmony_ci * To clear the process by ability token. 516eace7efcSopenharmony_ci * 517eace7efcSopenharmony_ci * @param token the unique identification to the ability. 518eace7efcSopenharmony_ci */ 519eace7efcSopenharmony_ci void ClearProcessByToken(sptr<IRemoteObject> token) const; 520eace7efcSopenharmony_ci 521eace7efcSopenharmony_ci /** 522eace7efcSopenharmony_ci * whether memory size is sufficient. 523eace7efcSopenharmony_ci * @return Returns true is sufficient memory size, others return false. 524eace7efcSopenharmony_ci */ 525eace7efcSopenharmony_ci virtual bool IsMemorySizeSufficent() const; 526eace7efcSopenharmony_ci 527eace7efcSopenharmony_ci /** 528eace7efcSopenharmony_ci * Notifies that one ability is attached to status bar. 529eace7efcSopenharmony_ci * 530eace7efcSopenharmony_ci * @param token the token of the abilityRecord that is attached to status bar. 531eace7efcSopenharmony_ci */ 532eace7efcSopenharmony_ci void AttachedToStatusBar(const sptr<IRemoteObject> &token); 533eace7efcSopenharmony_ci 534eace7efcSopenharmony_ci /** 535eace7efcSopenharmony_ci * Temporarily block the process cache feature. 536eace7efcSopenharmony_ci * 537eace7efcSopenharmony_ci * @param pids the pids of the processes that should be blocked. 538eace7efcSopenharmony_ci */ 539eace7efcSopenharmony_ci void BlockProcessCacheByPids(const std::vector<int32_t>& pids); 540eace7efcSopenharmony_ci 541eace7efcSopenharmony_ci /** 542eace7efcSopenharmony_ci * Request to clean uiability from user. 543eace7efcSopenharmony_ci * 544eace7efcSopenharmony_ci * @param token the token of ability. 545eace7efcSopenharmony_ci * @return Returns true if clean success, others return false. 546eace7efcSopenharmony_ci */ 547eace7efcSopenharmony_ci bool CleanAbilityByUserRequest(const sptr<IRemoteObject> &token); 548eace7efcSopenharmony_ci 549eace7efcSopenharmony_ci /** 550eace7efcSopenharmony_ci * whether killed for upgrade web. 551eace7efcSopenharmony_ci * 552eace7efcSopenharmony_ci * @param bundleName the bundle name is killed for upgrade web. 553eace7efcSopenharmony_ci * @return Returns true is killed for upgrade web, others return false. 554eace7efcSopenharmony_ci */ 555eace7efcSopenharmony_ci bool IsKilledForUpgradeWeb(const std::string &bundleName); 556eace7efcSopenharmony_ci 557eace7efcSopenharmony_ci /** 558eace7efcSopenharmony_ci * whether the abilities of process specified by pid type only UIAbility. 559eace7efcSopenharmony_ci * @return Returns true is only UIAbility, otherwise return false 560eace7efcSopenharmony_ci */ 561eace7efcSopenharmony_ci bool IsProcessContainsOnlyUIAbility(const pid_t pid); 562eace7efcSopenharmony_ci 563eace7efcSopenharmony_ci bool IsProcessAttached(sptr<IRemoteObject> token) const; 564eace7efcSopenharmony_ci 565eace7efcSopenharmony_ci bool IsAppKilling(sptr<IRemoteObject> token) const; 566eace7efcSopenharmony_ci 567eace7efcSopenharmony_ciprotected: 568eace7efcSopenharmony_ci /** 569eace7efcSopenharmony_ci * OnAbilityRequestDone, app manager service call this interface after ability request done. 570eace7efcSopenharmony_ci * 571eace7efcSopenharmony_ci * @param token,ability's token. 572eace7efcSopenharmony_ci * @param state,the state of ability lift cycle. 573eace7efcSopenharmony_ci */ 574eace7efcSopenharmony_ci virtual void OnAbilityRequestDone(const sptr<IRemoteObject> &token, const AppExecFwk::AbilityState state) override; 575eace7efcSopenharmony_ci 576eace7efcSopenharmony_ci /** 577eace7efcSopenharmony_ci * Application state changed callback. 578eace7efcSopenharmony_ci * 579eace7efcSopenharmony_ci * @param appProcessData Process data 580eace7efcSopenharmony_ci */ 581eace7efcSopenharmony_ci virtual void OnAppStateChanged(const AppExecFwk::AppProcessData &appData) override; 582eace7efcSopenharmony_ci 583eace7efcSopenharmony_ci /** 584eace7efcSopenharmony_ci * @brief Notify application update system environment changes. 585eace7efcSopenharmony_ci * @param config System environment change parameters. 586eace7efcSopenharmony_ci * @param userId userId Designation User ID. 587eace7efcSopenharmony_ci */ 588eace7efcSopenharmony_ci virtual void NotifyConfigurationChange(const AppExecFwk::Configuration &config, int32_t userId) override; 589eace7efcSopenharmony_ci 590eace7efcSopenharmony_ci /** 591eace7efcSopenharmony_ci * @brief Notify abilityms start resident process. 592eace7efcSopenharmony_ci * @param bundleInfos resident process bundle infos. 593eace7efcSopenharmony_ci */ 594eace7efcSopenharmony_ci virtual void NotifyStartResidentProcess(std::vector<AppExecFwk::BundleInfo> &bundleInfos) override; 595eace7efcSopenharmony_ci 596eace7efcSopenharmony_ci /** 597eace7efcSopenharmony_ci * @brief Notify abilityms app process OnRemoteDied 598eace7efcSopenharmony_ci * @param abilityTokens abilities in died process. 599eace7efcSopenharmony_ci */ 600eace7efcSopenharmony_ci virtual void OnAppRemoteDied(const std::vector<sptr<IRemoteObject>> &abilityTokens) override; 601eace7efcSopenharmony_ci 602eace7efcSopenharmony_ci /** 603eace7efcSopenharmony_ci * @brief Notify abilityms app process pre cache 604eace7efcSopenharmony_ci * @param pid process pid. 605eace7efcSopenharmony_ci * @param userId userId Designation User ID. 606eace7efcSopenharmony_ci */ 607eace7efcSopenharmony_ci virtual void NotifyAppPreCache(int32_t pid, int32_t userId) override; 608eace7efcSopenharmony_ci 609eace7efcSopenharmony_ciprivate: 610eace7efcSopenharmony_ci std::mutex lock_; 611eace7efcSopenharmony_ci bool isInit_ {false}; 612eace7efcSopenharmony_ci std::weak_ptr<AppStateCallback> callback_; 613eace7efcSopenharmony_ci std::unique_ptr<AppExecFwk::AppMgrClient> appMgrClient_; 614eace7efcSopenharmony_ci AppAbilityState appAbilityState_ = AppAbilityState::ABILITY_STATE_UNDEFINED; 615eace7efcSopenharmony_ci sptr<StartSpecifiedAbilityResponse> startSpecifiedAbilityResponse_; 616eace7efcSopenharmony_ci}; 617eace7efcSopenharmony_ci} // namespace AAFwk 618eace7efcSopenharmony_ci} // namespace OHOS 619eace7efcSopenharmony_ci#endif // OHOS_ABILITY_RUNTIME_APP_SCHEDULER_H 620