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); 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 * cheduleClearPageStack, call cheduleClearPageStack() 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 void ScheduleAcceptWant(const AAFwk::Want &want, const std::string &moduleName); 188 189 void ScheduleNewProcessRequest(const AAFwk::Want &want, const std::string &moduleName); 190 191 /** 192 * UpdateConfiguration, ANotify application update system environment changes. 193 * 194 * @param config, System environment change parameters. 195 * @return Returns ERR_OK on success, others on failure. 196 */ 197 int32_t UpdateConfiguration(const Configuration &config); 198 199 int32_t NotifyLoadRepairPatch(const std::string &bundleName, const sptr<IQuickFixCallback> &callback, 200 const int32_t recordId); 201 202 int32_t NotifyHotReloadPage(const sptr<IQuickFixCallback> &callback, const int32_t recordId); 203 204 int32_t NotifyUnLoadRepairPatch(const std::string &bundleName, const sptr<IQuickFixCallback> &callback, 205 const int32_t recordId); 206 207 int32_t NotifyAppFault(const FaultData &faultData); 208 209 /** 210 * @brief Notify NativeEngine GC of status change. 211 * 212 * @param state GC state 213 * 214 * @return Is the status change completed. 215 */ 216 int32_t ChangeAppGcState(int32_t state); 217 218 int32_t AttachAppDebug(); 219 int32_t DetachAppDebug(); 220 221 /** 222 * Whether the current application process is the last surviving process. 223 * 224 * @return Returns true is final application process, others return false. 225 */ 226 bool IsFinalAppProcess(); 227 228 int DumpIpcStart(std::string& result); 229 230 int DumpIpcStop(std::string& result); 231 232 int DumpIpcStat(std::string& result); 233 234 /** 235 * Notifies the application of process caching. 236 * 237 * 238 * @return 239 */ 240 void ScheduleCacheProcess(); 241 242 int DumpFfrt(std::string& result); 243 244 private: 245 mutable std::mutex schedulerMutex_; 246 sptr<IAppScheduler> appThread_ = nullptr; 247 }; 248 } // namespace AppExecFwk 249 } // namespace OHOS 250 251 #endif // OHOS_ABILITY_RUNTIME_APP_LIFECYCLE_DEAL_H 252