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