1 /* 2 * Copyright (c) 2021-2023 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 27 namespace OHOS { 28 namespace AppExecFwk { 29 class AppLifeCycleDeal { 30 public: 31 AppLifeCycleDeal(); 32 virtual ~AppLifeCycleDeal(); 33 34 /** 35 * LaunchApplication, call ScheduleLaunchApplication() through proxy project, 36 * Notify application to launch application. 37 * 38 * @param launchData The app data when launch. 39 * @param config The app config when launch. 40 * @return 41 */ 42 void LaunchApplication(const AppLaunchData &launchData, const Configuration &config); 43 44 /** 45 * update the application info after new module installed. 46 * 47 * @param appInfo The latest application info obtained from bms for update abilityRuntimeContext. 48 * 49 * @return 50 */ 51 void UpdateApplicationInfoInstalled(const ApplicationInfo &appInfo); 52 53 /** 54 * AddAbilityStageInfo, call ScheduleAbilityStageInfo() through proxy project, 55 * Notify application to launch application. 56 * 57 * @param abilityStage The app data value. 58 * 59 * @return 60 */ 61 void AddAbilityStage(const HapModuleInfo &abilityStage); 62 63 /** 64 * LaunchAbility, call ScheduleLaunchAbility() through proxy project, 65 * Notify application to launch ability. 66 * 67 * @param ability The ability info. 68 * @return 69 */ 70 void LaunchAbility(const std::shared_ptr<AbilityRunningRecord> &ability); 71 72 /** 73 * ScheduleTerminate, call ScheduleTerminateApplication() through proxy project, 74 * Notify application to terminate. 75 * 76 * @param isLastProcess When it is the last application process, pass in true. 77 * 78 * @return 79 */ 80 void ScheduleTerminate(bool isLastProcess = false); 81 82 /** 83 * ScheduleForegroundRunning, call ScheduleForegroundApplication() through proxy project, 84 * Notify application to switch to foreground. 85 * 86 * @return 87 */ 88 void ScheduleForegroundRunning(); 89 90 /** 91 * ScheduleBackgroundRunning, call ScheduleBackgroundApplication() through proxy project, 92 * Notify application to switch to background. 93 * 94 * @return 95 */ 96 void ScheduleBackgroundRunning(); 97 98 /** 99 * ScheduleTrimMemory, call ScheduleShrinkMemory() through proxy project, 100 * Notifies the application of the memory seen. 101 * 102 * @param timeLevel The memory value. 103 * 104 * @return 105 */ 106 void ScheduleTrimMemory(int32_t timeLevel); 107 108 /** 109 * ScheduleMemoryLevel, call ScheduleMemoryLevel() through proxy project, 110 * Notifies the application of the current memory. 111 * 112 * @param The memory level. 113 * 114 * @return 115 */ 116 void ScheduleMemoryLevel(int32_t Level); 117 118 /** 119 * ScheduleHeapMemory, call ScheduleHeapMemory() through proxy project, 120 * Get the application's memory allocation info. 121 * 122 * @param pid, pid input. 123 * @param mallocInfo, dynamic storage information output. 124 * 125 * @return 126 */ 127 void ScheduleHeapMemory(const int32_t pid, OHOS::AppExecFwk::MallocInfo &mallocInfo); 128 129 /** 130 * LowMemoryWarning, call ScheduleLowMemory() through proxy project, 131 * Notify application to low memory. 132 * 133 * @return 134 */ 135 void LowMemoryWarning(); 136 137 /** 138 * ScheduleCleanAbility, call ScheduleCleanAbility() through proxy project, 139 * Notify application to clean ability. 140 * 141 * @param token, The ability token. 142 * @return 143 */ 144 void ScheduleCleanAbility(const sptr<IRemoteObject> &token); 145 146 /** 147 * ScheduleProcessSecurityExit, call ScheduleTerminateApplication() through proxy project, 148 * Notify application process exit safely. 149 * 150 * @return 151 */ 152 void ScheduleProcessSecurityExit(); 153 154 /** 155 * @brief Setting client for application record. 156 * 157 * @param thread, the application client. 158 */ 159 void SetApplicationClient(const sptr<IAppScheduler> &thread); 160 161 /** 162 * @brief Obtains the client of the application record. 163 * 164 * @return Returns the application client. 165 */ 166 sptr<IAppScheduler> GetApplicationClient() const; 167 168 void ScheduleAcceptWant(const AAFwk::Want &want, const std::string &moduleName); 169 170 void ScheduleNewProcessRequest(const AAFwk::Want &want, const std::string &moduleName); 171 172 /** 173 * UpdateConfiguration, ANotify application update system environment changes. 174 * 175 * @param config, System environment change parameters. 176 * @return Returns ERR_OK on success, others on failure. 177 */ 178 int32_t UpdateConfiguration(const Configuration &config); 179 180 int32_t NotifyLoadRepairPatch(const std::string &bundleName, const sptr<IQuickFixCallback> &callback, 181 const int32_t recordId); 182 183 int32_t NotifyHotReloadPage(const sptr<IQuickFixCallback> &callback, const int32_t recordId); 184 185 int32_t NotifyUnLoadRepairPatch(const std::string &bundleName, const sptr<IQuickFixCallback> &callback, 186 const int32_t recordId); 187 188 int32_t NotifyAppFault(const FaultData &faultData); 189 190 /** 191 * @brief Notify NativeEngine GC of status change. 192 * 193 * @param state GC state 194 * 195 * @return Is the status change completed. 196 */ 197 int32_t ChangeAppGcState(int32_t state); 198 199 int32_t AttachAppDebug(); 200 int32_t DetachAppDebug(); 201 202 /** 203 * Whether the current application process is the last surviving process. 204 * 205 * @return Returns true is final application process, others return false. 206 */ 207 bool IsFinalAppProcess(); 208 209 private: 210 mutable std::mutex schedulerMutex_; 211 sptr<IAppScheduler> appThread_ = nullptr; 212 }; 213 } // namespace AppExecFwk 214 } // namespace OHOS 215 216 #endif // OHOS_ABILITY_RUNTIME_APP_LIFECYCLE_DEAL_H 217