1 /* 2 * Copyright (c) 2021-2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_ABILITY_RUNTIME_APP_LIFECYCLE_DEAL_H 17 #define OHOS_ABILITY_RUNTIME_APP_LIFECYCLE_DEAL_H 18 19 #include "app_scheduler_proxy.h" 20 #include "app_launch_data.h" 21 #include "ability_running_record.h" 22 #include "fault_data.h" 23 #include "hap_module_info.h" 24 #include "want.h" 25 #include "app_malloc_info.h" 26 #include "app_jsheap_mem_info.h" 27 28 namespace OHOS { 29 namespace AppExecFwk { 30 class AppLifeCycleDeal { 31 public: 32 AppLifeCycleDeal(); 33 virtual ~AppLifeCycleDeal(); 34 35 /** 36 * LaunchApplication, call ScheduleLaunchApplication() through proxy project, 37 * Notify application to launch application. 38 * 39 * @param launchData The app data when launch. 40 * @param config The app config when launch. 41 * @return 42 */ 43 void LaunchApplication(const AppLaunchData &launchData, const Configuration &config); 44 45 /** 46 * update the application info after new module installed. 47 * 48 * @param appInfo The latest application info obtained from bms for update abilityRuntimeContext. 49 * 50 * @return 51 */ 52 void UpdateApplicationInfoInstalled(const ApplicationInfo &appInfo, const std::string &moduleName); 53 54 /** 55 * AddAbilityStageInfo, call ScheduleAbilityStageInfo() through proxy project, 56 * Notify application to launch application. 57 * 58 * @param abilityStage The app data value. 59 * 60 * @return 61 */ 62 void AddAbilityStage(const HapModuleInfo &abilityStage); 63 64 /** 65 * LaunchAbility, call ScheduleLaunchAbility() through proxy project, 66 * Notify application to launch ability. 67 * 68 * @param ability The ability info. 69 * @return 70 */ 71 void LaunchAbility(const std::shared_ptr<AbilityRunningRecord> &ability); 72 73 /** 74 * ScheduleTerminate, call ScheduleTerminateApplication() through proxy project, 75 * Notify application to terminate. 76 * 77 * @param isLastProcess When it is the last application process, pass in true. 78 * 79 * @return 80 */ 81 void ScheduleTerminate(bool isLastProcess = false); 82 83 /** 84 * ScheduleForegroundRunning, call ScheduleForegroundApplication() through proxy project, 85 * Notify application to switch to foreground. 86 * 87 * @return bool operation status 88 */ 89 bool ScheduleForegroundRunning(); 90 91 /** 92 * ScheduleBackgroundRunning, call ScheduleBackgroundApplication() through proxy project, 93 * Notify application to switch to background. 94 * 95 * @return 96 */ 97 void ScheduleBackgroundRunning(); 98 99 /** 100 * ScheduleTrimMemory, call ScheduleShrinkMemory() through proxy project, 101 * Notifies the application of the memory seen. 102 * 103 * @param timeLevel The memory value. 104 * 105 * @return 106 */ 107 void ScheduleTrimMemory(int32_t timeLevel); 108 109 /** 110 * ScheduleMemoryLevel, call ScheduleMemoryLevel() through proxy project, 111 * Notifies the application of the current memory. 112 * 113 * @param The memory level. 114 * 115 * @return 116 */ 117 void ScheduleMemoryLevel(int32_t Level); 118 119 /** 120 * ScheduleHeapMemory, call ScheduleHeapMemory() through proxy project, 121 * Get the application's memory allocation info. 122 * 123 * @param pid, pid input. 124 * @param mallocInfo, dynamic storage information output. 125 * 126 * @return 127 */ 128 void ScheduleHeapMemory(const int32_t pid, OHOS::AppExecFwk::MallocInfo &mallocInfo); 129 130 /** 131 * ScheduleJsHeapMemory, call ScheduleJsHeapMemory() through proxy project, 132 * triggerGC and dump the application's jsheap memory info. 133 * 134 * @param info, pid, tid, needGc, needSnapshot 135 * 136 * @return 137 */ 138 void ScheduleJsHeapMemory(OHOS::AppExecFwk::JsHeapDumpInfo &info); 139 140 /** 141 * LowMemoryWarning, call ScheduleLowMemory() through proxy project, 142 * Notify application to low memory. 143 * 144 * @return 145 */ 146 void LowMemoryWarning(); 147 148 /** 149 * ScheduleCleanAbility, call ScheduleCleanAbility() through proxy project, 150 * Notify application to clean ability. 151 * 152 * @param token, The ability token. 153 * @return 154 */ 155 void ScheduleCleanAbility(const sptr<IRemoteObject> &token, bool isCacheProcess = false); 156 157 /** 158 * ScheduleProcessSecurityExit, call ScheduleTerminateApplication() through proxy project, 159 * Notify application process exit safely. 160 * 161 * @return 162 */ 163 void ScheduleProcessSecurityExit(); 164 165 /** 166 * scheduleClearPageStack, call scheduleClearPageStack() through proxy project, 167 * Notify application clear recovery page stack. 168 * 169 * @return 170 */ 171 void ScheduleClearPageStack(); 172 173 /** 174 * @brief Setting client for application record. 175 * 176 * @param thread, the application client. 177 */ 178 void SetApplicationClient(const sptr<IAppScheduler> &thread); 179 180 /** 181 * @brief Obtains the client of the application record. 182 * 183 * @return Returns the application client. 184 */ 185 sptr<IAppScheduler> GetApplicationClient() const; 186 187 /** 188 * @brief Schedule the given module the onAcceptWant lifecycle call. 189 * 190 * @param want the param passed to onAcceptWant lifecycle. 191 * @param want the moduleName of which being scheduled. 192 */ 193 void ScheduleAcceptWant(const AAFwk::Want &want, const std::string &moduleName); 194 195 void SchedulePrepareTerminate(const std::string &moduleName); 196 197 void ScheduleNewProcessRequest(const AAFwk::Want &want, const std::string &moduleName); 198 199 /** 200 * UpdateConfiguration, ANotify application update system environment changes. 201 * 202 * @param config, System environment change parameters. 203 * @return Returns ERR_OK on success, others on failure. 204 */ 205 int32_t UpdateConfiguration(const Configuration &config); 206 207 /** 208 * @brief Notify application load patch. 209 * 210 * @param bundleName Bundle name 211 * @param callback called when LoadPatch finished. 212 * @param recordId callback data 213 * @return Returns 0 on success, error code on failure. 214 */ 215 int32_t NotifyLoadRepairPatch(const std::string &bundleName, const sptr<IQuickFixCallback> &callback, 216 const int32_t recordId); 217 218 /** 219 * @brief Notify application reload page. 220 * 221 * @param callback called when HotReload finished. 222 * @param recordId callback data 223 * @return Returns 0 on success, error code on failure. 224 */ 225 int32_t NotifyHotReloadPage(const sptr<IQuickFixCallback> &callback, const int32_t recordId); 226 227 /** 228 * @brief Notify application unload patch. 229 * 230 * @param bundleName Bundle name 231 * @param callback called when UnloadPatch finished. 232 * @param recordId callback data 233 * @return Returns 0 on success, error code on failure. 234 */ 235 int32_t NotifyUnLoadRepairPatch(const std::string &bundleName, const sptr<IQuickFixCallback> &callback, 236 const int32_t recordId); 237 238 /** 239 * Notify Fault Data 240 * 241 * @param faultData the fault data. 242 * @return Returns ERR_OK on success, others on failure. 243 */ 244 int32_t NotifyAppFault(const FaultData &faultData); 245 246 /** 247 * @brief Notify NativeEngine GC of status change. 248 * 249 * @param state GC state 250 * 251 * @return Is the status change completed. 252 */ 253 int32_t ChangeAppGcState(int32_t state); 254 255 /** 256 * @brief attach to a process to debug. 257 * 258 * @return ERR_OK, return back success, others fail. 259 */ 260 int32_t AttachAppDebug(bool isDebugFromLocal); 261 262 /** 263 * @brief detach a debugging process. 264 * 265 * @return ERR_OK, return back success, others fail. 266 */ 267 int32_t DetachAppDebug(); 268 269 /** 270 * Whether the current application process is the last surviving process. 271 * 272 * @return Returns true is final application process, others return false. 273 */ 274 bool IsFinalAppProcess(); 275 276 int DumpIpcStart(std::string& result); 277 278 int DumpIpcStop(std::string& result); 279 280 int DumpIpcStat(std::string& result); 281 282 /** 283 * Notifies the application of process caching. 284 */ 285 void ScheduleCacheProcess(); 286 287 int DumpFfrt(std::string& result); 288 289 /** 290 * SetWatchdogBackgroundStatusRunning , call SetWatchdogBackgroundStatusRunning(bool status) through proxy project, 291 * Notify application to set watchdog background status. 292 * 293 * @return 294 */ 295 void SetWatchdogBackgroundStatusRunning(bool status); 296 297 private: 298 mutable std::mutex schedulerMutex_; 299 sptr<IAppScheduler> appThread_ = nullptr; 300 }; 301 } // namespace AppExecFwk 302 } // namespace OHOS 303 304 #endif // OHOS_ABILITY_RUNTIME_APP_LIFECYCLE_DEAL_H 305