1 /* 2 * Copyright (c) 2021-2022 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 "hap_module_info.h" 23 #include "want.h" 24 25 namespace OHOS { 26 namespace AppExecFwk { 27 class AppLifeCycleDeal { 28 public: 29 AppLifeCycleDeal(); 30 virtual ~AppLifeCycleDeal(); 31 32 /** 33 * LaunchApplication, call ScheduleLaunchApplication() through proxy project, 34 * Notify application to launch application. 35 * 36 * @param launchData The app data when launch. 37 * @param config The app config when launch. 38 * @return 39 */ 40 void LaunchApplication(const AppLaunchData &launchData, const Configuration &config); 41 42 /** 43 * update the application info after new module installed. 44 * 45 * @param appInfo The latest application info obtained from bms for update abilityRuntimeContext. 46 * 47 * @return 48 */ 49 void UpdateApplicationInfoInstalled(const ApplicationInfo &appInfo); 50 51 /** 52 * AddAbilityStageInfo, call ScheduleAbilityStageInfo() through proxy project, 53 * Notify application to launch application. 54 * 55 * @param abilityStage The app data value. 56 * 57 * @return 58 */ 59 void AddAbilityStage(const HapModuleInfo &abilityStage); 60 61 /** 62 * LaunchAbility, call ScheduleLaunchAbility() through proxy project, 63 * Notify application to launch ability. 64 * 65 * @param ability The ability info. 66 * @return 67 */ 68 void LaunchAbility(const std::shared_ptr<AbilityRunningRecord> &ability); 69 70 /** 71 * ScheduleTerminate, call ScheduleTerminateApplication() through proxy project, 72 * Notify application to terminate. 73 * 74 * @return 75 */ 76 void ScheduleTerminate(); 77 78 /** 79 * ScheduleForegroundRunning, call ScheduleForegroundApplication() through proxy project, 80 * Notify application to switch to foreground. 81 * 82 * @return 83 */ 84 void ScheduleForegroundRunning(); 85 86 /** 87 * ScheduleBackgroundRunning, call ScheduleBackgroundApplication() through proxy project, 88 * Notify application to switch to background. 89 * 90 * @return 91 */ 92 void ScheduleBackgroundRunning(); 93 94 /** 95 * ScheduleTrimMemory, call ScheduleShrinkMemory() through proxy project, 96 * Notifies the application of the memory seen. 97 * 98 * @param timeLevel The memory value. 99 * 100 * @return 101 */ 102 void ScheduleTrimMemory(int32_t timeLevel); 103 104 /** 105 * ScheduleMemoryLevel, call ScheduleMemoryLevel() through proxy project, 106 * Notifies the application of the current memory. 107 * 108 * @param The memory level. 109 * 110 * @return 111 */ 112 void ScheduleMemoryLevel(int32_t Level); 113 114 /** 115 * LowMemoryWarning, call ScheduleLowMemory() through proxy project, 116 * Notify application to low memory. 117 * 118 * @return 119 */ 120 void LowMemoryWarning(); 121 122 /** 123 * ScheduleCleanAbility, call ScheduleCleanAbility() through proxy project, 124 * Notify application to clean ability. 125 * 126 * @param token, The ability token. 127 * @return 128 */ 129 void ScheduleCleanAbility(const sptr<IRemoteObject> &token); 130 131 /** 132 * ScheduleProcessSecurityExit, call ScheduleTerminateApplication() through proxy project, 133 * Notify application process exit safely. 134 * 135 * @return 136 */ 137 void ScheduleProcessSecurityExit(); 138 139 /** 140 * @brief Setting client for application record. 141 * 142 * @param thread, the application client. 143 */ 144 void SetApplicationClient(const sptr<IAppScheduler> &thread); 145 146 /** 147 * @brief Obtains the client of the application record. 148 * 149 * @return Returns the application client. 150 */ 151 sptr<IAppScheduler> GetApplicationClient() const; 152 153 void ScheduleAcceptWant(const AAFwk::Want &want, const std::string &moduleName); 154 155 /** 156 * UpdateConfiguration, ANotify application update system environment changes. 157 * 158 * @param config, System environment change parameters. 159 * @return Returns ERR_OK on success, others on failure. 160 */ 161 int32_t UpdateConfiguration(const Configuration &config); 162 163 int32_t NotifyLoadRepairPatch(const std::string &bundleName, const sptr<IQuickFixCallback> &callback, 164 const int32_t recordId); 165 166 int32_t NotifyHotReloadPage(const sptr<IQuickFixCallback> &callback, const int32_t recordId); 167 168 int32_t NotifyUnLoadRepairPatch(const std::string &bundleName, const sptr<IQuickFixCallback> &callback, 169 const int32_t recordId); 170 171 private: 172 sptr<IAppScheduler> appThread_ = nullptr; 173 }; 174 } // namespace AppExecFwk 175 } // namespace OHOS 176 177 #endif // OHOS_ABILITY_RUNTIME_APP_LIFECYCLE_DEAL_H 178