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 * @return 77 */ 78 void ScheduleTerminate(); 79 80 /** 81 * ScheduleForegroundRunning, call ScheduleForegroundApplication() through proxy project, 82 * Notify application to switch to foreground. 83 * 84 * @return 85 */ 86 void ScheduleForegroundRunning(); 87 88 /** 89 * ScheduleBackgroundRunning, call ScheduleBackgroundApplication() through proxy project, 90 * Notify application to switch to background. 91 * 92 * @return 93 */ 94 void ScheduleBackgroundRunning(); 95 96 /** 97 * ScheduleTrimMemory, call ScheduleShrinkMemory() through proxy project, 98 * Notifies the application of the memory seen. 99 * 100 * @param timeLevel The memory value. 101 * 102 * @return 103 */ 104 void ScheduleTrimMemory(int32_t timeLevel); 105 106 /** 107 * ScheduleMemoryLevel, call ScheduleMemoryLevel() through proxy project, 108 * Notifies the application of the current memory. 109 * 110 * @param The memory level. 111 * 112 * @return 113 */ 114 void ScheduleMemoryLevel(int32_t Level); 115 116 /** 117 * ScheduleHeapMemory, call ScheduleHeapMemory() through proxy project, 118 * Get the application's memory allocation info. 119 * 120 * @param pid, pid input. 121 * @param mallocInfo, dynamic storage information output. 122 * 123 * @return 124 */ 125 void ScheduleHeapMemory(const int32_t pid, OHOS::AppExecFwk::MallocInfo &mallocInfo); 126 127 /** 128 * LowMemoryWarning, call ScheduleLowMemory() through proxy project, 129 * Notify application to low memory. 130 * 131 * @return 132 */ 133 void LowMemoryWarning(); 134 135 /** 136 * ScheduleCleanAbility, call ScheduleCleanAbility() through proxy project, 137 * Notify application to clean ability. 138 * 139 * @param token, The ability token. 140 * @return 141 */ 142 void ScheduleCleanAbility(const sptr<IRemoteObject> &token); 143 144 /** 145 * ScheduleProcessSecurityExit, call ScheduleTerminateApplication() through proxy project, 146 * Notify application process exit safely. 147 * 148 * @return 149 */ 150 void ScheduleProcessSecurityExit(); 151 152 /** 153 * @brief Setting client for application record. 154 * 155 * @param thread, the application client. 156 */ 157 void SetApplicationClient(const sptr<IAppScheduler> &thread); 158 159 /** 160 * @brief Obtains the client of the application record. 161 * 162 * @return Returns the application client. 163 */ 164 sptr<IAppScheduler> GetApplicationClient() const; 165 166 void ScheduleAcceptWant(const AAFwk::Want &want, const std::string &moduleName); 167 168 /** 169 * UpdateConfiguration, ANotify application update system environment changes. 170 * 171 * @param config, System environment change parameters. 172 * @return Returns ERR_OK on success, others on failure. 173 */ 174 int32_t UpdateConfiguration(const Configuration &config); 175 176 int32_t NotifyLoadRepairPatch(const std::string &bundleName, const sptr<IQuickFixCallback> &callback, 177 const int32_t recordId); 178 179 int32_t NotifyHotReloadPage(const sptr<IQuickFixCallback> &callback, const int32_t recordId); 180 181 int32_t NotifyUnLoadRepairPatch(const std::string &bundleName, const sptr<IQuickFixCallback> &callback, 182 const int32_t recordId); 183 184 int32_t NotifyAppFault(const FaultData &faultData); 185 186 private: 187 sptr<IAppScheduler> appThread_ = nullptr; 188 }; 189 } // namespace AppExecFwk 190 } // namespace OHOS 191 192 #endif // OHOS_ABILITY_RUNTIME_APP_LIFECYCLE_DEAL_H 193