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_SCHEDULER_PROXY_H 17 #define OHOS_ABILITY_RUNTIME_APP_SCHEDULER_PROXY_H 18 19 #include "iremote_proxy.h" 20 #include "app_scheduler_interface.h" 21 #include "app_malloc_info.h" 22 #include "app_jsheap_mem_info.h" 23 24 namespace OHOS { 25 namespace AppExecFwk { 26 class AppSchedulerProxy : public IRemoteProxy<IAppScheduler> { 27 public: 28 explicit AppSchedulerProxy(const sptr<IRemoteObject> &impl); 29 virtual ~AppSchedulerProxy() = default; 30 31 /** 32 * ScheduleForegroundApplication, call ScheduleForegroundApplication() through proxy project, 33 * Notify application to switch to foreground. 34 * 35 * @return 36 */ 37 virtual bool ScheduleForegroundApplication() override; 38 39 /** 40 * ScheduleBackgroundApplication, call ScheduleBackgroundApplication() through proxy project, 41 * Notify application to switch to background. 42 * 43 * @return 44 */ 45 virtual void ScheduleBackgroundApplication() override; 46 47 /** 48 * ScheduleTerminateApplication, call ScheduleTerminateApplication() through proxy project, 49 * Notify application to terminate. 50 * 51 * @param isLastProcess When it is the last application process, pass in true. 52 */ 53 virtual void ScheduleTerminateApplication(bool isLastProcess = false) override; 54 55 /** 56 * ScheduleShrinkMemory, call ScheduleShrinkMemory() through proxy project, 57 * Notifies the application of the memory seen. 58 * 59 * @param The memory value. 60 * 61 * @return 62 */ 63 virtual void ScheduleShrinkMemory(const int32_t level) override; 64 65 /** 66 * ScheduleLowMemory, call ScheduleLowMemory() through proxy project, 67 * Notify application to low memory. 68 * 69 * @return 70 */ 71 virtual void ScheduleLowMemory() override; 72 73 /** 74 * ScheduleMemoryLevel, call ScheduleMemoryLevel() through proxy project, 75 * Notify applications background the current memory level. 76 * 77 * @return 78 */ 79 virtual void ScheduleMemoryLevel(int32_t level) override; 80 81 /** 82 * ScheduleHeapMemory, call ScheduleHeapMemory() through proxy project, 83 * Get the application's memory allocation info. 84 * 85 * @param pid, pid input. 86 * @param mallocInfo, dynamic storage information output. 87 * 88 * @return 89 */ 90 virtual void ScheduleHeapMemory(const int32_t pid, OHOS::AppExecFwk::MallocInfo &mallocInfo) override; 91 92 /** 93 * ScheduleJsHeapMemory, call ScheduleJsHeapMemory() through proxy project, 94 * triggerGC and dump the application's jsheap memory info. 95 * 96 * @param info, pid, tid, needGc, needSnapshot 97 * 98 * @return 99 */ 100 virtual void ScheduleJsHeapMemory(OHOS::AppExecFwk::JsHeapDumpInfo &info) override; 101 102 /** 103 * ScheduleLaunchApplication, call ScheduleLaunchApplication() through proxy project, 104 * Notify application to launch application. 105 * 106 * @param The app data value. 107 * 108 * @return 109 */ 110 virtual void ScheduleLaunchApplication(const AppLaunchData &launchData, const Configuration &config) override; 111 112 /** 113 * ScheduleUpdateApplicationInfoInstalled, call ScheduleUpdateApplicationInfoInstalled() through proxy object, 114 * update the application info after new module installed. 115 * 116 * @param appInfo The latest application info obtained from bms for update abilityRuntimeContext. 117 * 118 * @return 119 */ 120 virtual void ScheduleUpdateApplicationInfoInstalled(const ApplicationInfo &, const std::string &) override; 121 122 /** 123 * Notify application to launch ability stage. 124 * 125 * @param The resident process data value. 126 */ 127 virtual void ScheduleAbilityStage(const HapModuleInfo &abilityStage) override; 128 129 /** 130 * ScheduleLaunchAbility, call ScheduleLaunchAbility() through proxy project, 131 * Notify application to launch ability. 132 * 133 * @param The ability info. 134 * @param The ability token. 135 * @param The ability want. 136 * @return 137 */ 138 virtual void ScheduleLaunchAbility(const AbilityInfo &, const sptr<IRemoteObject> &, 139 const std::shared_ptr<AAFwk::Want> &want, int32_t abilityRecordId) override; 140 141 /** 142 * ScheduleCleanAbility, call ScheduleCleanAbility() through proxy project, 143 * Notify application to clean ability. 144 * 145 * @param The ability token. 146 * @return 147 */ 148 virtual void ScheduleCleanAbility(const sptr<IRemoteObject> &token, bool isCacheProcess = false) override; 149 150 /** 151 * ScheduleProfileChanged, call ScheduleProfileChanged() through proxy project, 152 * Notify application to profile update. 153 * 154 * @param The profile data. 155 * @return 156 */ 157 virtual void ScheduleProfileChanged(const Profile &profile) override; 158 159 /** 160 * ScheduleConfigurationUpdated, call ScheduleConfigurationUpdated() through proxy project, 161 * Notify application to configuration update. 162 * 163 * @param The configuration data. 164 * @return 165 */ 166 virtual void ScheduleConfigurationUpdated(const Configuration &config) override; 167 168 /** 169 * ScheduleProcessSecurityExit, call ScheduleProcessSecurityExit() through proxy project, 170 * Notify application process exit safely. 171 * 172 * @return 173 */ 174 virtual void ScheduleProcessSecurityExit() override; 175 176 /** 177 * scheduleClearPageStack, call scheduleClearPageStack() through proxy project, 178 * Notify application clear recovery page stack. 179 * 180 */ 181 virtual void ScheduleClearPageStack() override; 182 183 /** 184 * @brief Schedule the given module the onAcceptWant lifecycle call. 185 * 186 * @param want the param passed to onAcceptWant lifecycle. 187 * @param want the moduleName of which being scheduled. 188 */ 189 virtual void ScheduleAcceptWant(const AAFwk::Want &want, const std::string &moduleName) override; 190 191 /** 192 * @brief Schedule prepare terminate application 193 * 194 * @param moduleName module name 195 */ 196 virtual void SchedulePrepareTerminate(const std::string &moduleName) override; 197 198 virtual void ScheduleNewProcessRequest(const AAFwk::Want &want, const std::string &moduleName) override; 199 200 /** 201 * @brief Notify application load patch. 202 * 203 * @param bundleName Bundle name 204 * @param callback called when LoadPatch finished. 205 * @param recordId callback data 206 * @return Returns 0 on success, error code on failure. 207 */ 208 int32_t ScheduleNotifyLoadRepairPatch(const std::string &bundleName, 209 const sptr<IQuickFixCallback> &callback, const int32_t recordId) override; 210 211 /** 212 * @brief Notify application reload page. 213 * 214 * @param callback called when HotReload finished. 215 * @param recordId callback data 216 * @return Returns 0 on success, error code on failure. 217 */ 218 int32_t ScheduleNotifyHotReloadPage(const sptr<IQuickFixCallback> &callback, const int32_t recordId) override; 219 220 /** 221 * @brief Notify application unload patch. 222 * 223 * @param bundleName Bundle name 224 * @param callback called when UnloadPatch finished. 225 * @param recordId callback data 226 * @return Returns 0 on success, error code on failure. 227 */ 228 int32_t ScheduleNotifyUnLoadRepairPatch(const std::string &bundleName, 229 const sptr<IQuickFixCallback> &callback, const int32_t recordId) override; 230 231 /** 232 * @brief Schedule Notify App Fault Data. 233 * 234 * @param faultData fault data 235 * @return Returns ERR_OK on success, error code on failure. 236 */ 237 int32_t ScheduleNotifyAppFault(const FaultData &faultData) override; 238 239 /** 240 * @brief Notify NativeEngine GC of status change. 241 * 242 * @param state GC state 243 * @param pid pid 244 * 245 * @return Is the status change completed. 246 */ 247 virtual int32_t ScheduleChangeAppGcState(int32_t state) override; 248 249 /** 250 * @brief Attach app debug. 251 */ 252 void AttachAppDebug(bool isDebugFromLocal) override; 253 254 /** 255 * @brief Detach app debug. 256 */ 257 void DetachAppDebug() override; 258 259 /** 260 * ScheduleDumpIpcStart, call ScheduleDumpIpcStart(std::string& result) through proxy project, 261 * Start querying the application's IPC payload info. 262 * 263 * @param result, start IPC dump result output. 264 * 265 * @return Returns 0 on success, error code on failure. 266 */ 267 virtual int32_t ScheduleDumpIpcStart(std::string& result) override; 268 269 /** 270 * ScheduleDumpIpcStop, call ScheduleDumpIpcStop(std::string& result) through proxy project, 271 * Stop querying the application's IPC payload info. 272 * 273 * @param result, stop IPC dump result output. 274 * 275 * @return Returns 0 on success, error code on failure. 276 */ 277 virtual int32_t ScheduleDumpIpcStop(std::string& result) override; 278 279 /** 280 * ScheduleDumpIpcStat, call ScheduleDumpIpcStat(std::string& result) through proxy project, 281 * Collect the application's IPC payload info. 282 * 283 * @param result, IPC payload result output. 284 * 285 * @return Returns 0 on success, error code on failure. 286 */ 287 virtual int32_t ScheduleDumpIpcStat(std::string& result) override; 288 289 /** 290 * @brief Notify application to prepare for process caching. 291 */ 292 virtual void ScheduleCacheProcess() override; 293 294 /** 295 * ScheduleDumpFfrt, call ScheduleDumpFfrt(std::string& result) through proxy project, 296 * Start querying the application's ffrt usage. 297 * 298 * @param result, ffrt dump result output. 299 * 300 * @return Returns 0 on success, error code on failure. 301 */ 302 virtual int32_t ScheduleDumpFfrt(std::string& result) override; 303 304 /** 305 * SetWatchdogBackgroundStatus, call SetWatchdogBackgroundStatus(bool status) through proxy project, 306 * Notify application to set watchdog background status. 307 * 308 * @return 309 */ 310 virtual void SetWatchdogBackgroundStatus(bool status) override; 311 312 private: 313 bool WriteInterfaceToken(MessageParcel &data); 314 void ScheduleMemoryCommon(const int32_t level, const uint32_t operation); 315 int32_t SendTransactCmd(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); 316 static inline BrokerDelegator<AppSchedulerProxy> delegator_; 317 }; 318 } // namespace AppExecFwk 319 } // namespace OHOS 320 #endif // OHOS_ABILITY_RUNTIME_APP_SCHEDULER_PROXY_H 321