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_AMS_MGR_SCHEDULER_H 17 #define OHOS_ABILITY_RUNTIME_AMS_MGR_SCHEDULER_H 18 19 #include "ability_info.h" 20 #include "ability_running_record.h" 21 #include "ams_mgr_stub.h" 22 #include "appexecfwk_errors.h" 23 #include "application_info.h" 24 #include "app_mgr_constants.h" 25 #include "app_mgr_service_event_handler.h" 26 #include "app_mgr_service_inner.h" 27 #include "app_record_id.h" 28 #include "app_running_record.h" 29 #include "app_scheduler_proxy.h" 30 #include "if_system_ability_manager.h" 31 #include "nocopyable.h" 32 #include "system_ability.h" 33 34 namespace OHOS { 35 namespace AppExecFwk { 36 class AmsMgrScheduler : public AmsMgrStub { 37 public: 38 AmsMgrScheduler( 39 const std::shared_ptr<AppMgrServiceInner> &MgrServiceInner_, const std::shared_ptr<AMSEventHandler> &Handler_); 40 virtual ~AmsMgrScheduler() override; 41 42 /** 43 * LoadAbility, call LoadAbility() through proxy project, load the ability that needed to be started. 44 * 45 * @param token, the unique identification to start the ability. 46 * @param preToken, the unique identification to call the ability. 47 * @param abilityInfo, the ability information. 48 * @param appInfo, the app information. 49 * @param want, the starting information. 50 */ 51 virtual void LoadAbility(const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &preToken, 52 const std::shared_ptr<AbilityInfo> &abilityInfo, const std::shared_ptr<ApplicationInfo> &appInfo, 53 const std::shared_ptr<AAFwk::Want> &want) override; 54 55 /** 56 * TerminateAbility, call TerminateAbility() through the proxy object, terminate the token ability. 57 * 58 * @param token, token, he unique identification to terminate the ability. 59 * @param clearMissionFlag, indicates whether terminate the ability when clearMission. 60 * @return 61 */ 62 virtual void TerminateAbility(const sptr<IRemoteObject> &token, bool clearMissionFlag) override; 63 64 /** 65 * UpdateAbilityState, call UpdateAbilityState() through the proxy object, update the ability status. 66 * 67 * @param token, the unique identification to update the ability. 68 * @param state, ability status that needs to be updated. 69 * @return 70 */ 71 virtual void UpdateAbilityState(const sptr<IRemoteObject> &token, const AbilityState state) override; 72 73 /** 74 * UpdateExtensionState, call UpdateExtensionState() through the proxy object, update the extension status. 75 * 76 * @param token, the unique identification to update the extension. 77 * @param state, extension status that needs to be updated. 78 * @return 79 */ 80 virtual void UpdateExtensionState(const sptr<IRemoteObject> &token, const ExtensionState state) override; 81 82 /** 83 * RegisterAppStateCallback, call RegisterAppStateCallback() through the proxy object, register the callback. 84 * 85 * @param callback, Ams register the callback. 86 * @return 87 */ 88 virtual void RegisterAppStateCallback(const sptr<IAppStateCallback> &callback) override; 89 90 /** 91 * AbilityBehaviorAnalysis, ability behavior analysis assistant process optimization. 92 * 93 * @param token, the unique identification to start the ability. 94 * @param preToken, the unique identification to call the ability. 95 * @param visibility, the visibility information about windows info. 96 * @param perceptibility, the Perceptibility information about windows info. 97 * @param connectionState, the service ability connection state. 98 * @return 99 */ 100 virtual void AbilityBehaviorAnalysis(const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &preToken, 101 const int32_t visibility, const int32_t perceptibility, const int32_t connectionState) override; 102 103 /** 104 * KillProcessByAbilityToken, call KillProcessByAbilityToken() through proxy object, 105 * kill the process by ability token. 106 * 107 * @param token, the unique identification to the ability. 108 * @return 109 */ 110 virtual void KillProcessByAbilityToken(const sptr<IRemoteObject> &token) override; 111 112 /** 113 * KillProcessesByUserId, call KillProcessesByUserId() through proxy object, 114 * kill the processes by userId. 115 * 116 * @param userId, the user id. 117 * @return 118 */ 119 virtual void KillProcessesByUserId(int32_t userId) override; 120 121 /** 122 * KillProcessWithAccount, call KillProcessWithAccount() through proxy object, kill the 123 * process. 124 * 125 * @param bundleName, bundle name in Application record. 126 * @param accountId, account ID. 127 * @return ERR_OK, return back success, others fail. 128 */ 129 virtual int32_t KillProcessWithAccount(const std::string &bundleName, const int accountId) override; 130 131 /** 132 * UpdateApplicationInfoInstalled, call UpdateApplicationInfoInstalled() through proxy object, 133 * update the application info after new module installed. 134 * 135 * @param bundleName, bundle name in Application record. 136 * @param uid, uid. 137 * @return ERR_OK, return back success, others fail. 138 */ 139 virtual int32_t UpdateApplicationInfoInstalled(const std::string &bundleName, const int uid) override; 140 141 /** 142 * KillApplication, call KillApplication() through proxy object, kill the application. 143 * 144 * @param bundleName, bundle name in Application record. 145 * @return ERR_OK, return back success, others fail. 146 */ 147 virtual int32_t KillApplication(const std::string &bundleName) override; 148 149 /** 150 * KillApplicationByUid, call KillApplicationByUid() through proxy object, kill the application. 151 * 152 * @param bundleName, bundle name in Application record. 153 * @param uid, uid. 154 * @return ERR_OK, return back success, others fail. 155 */ 156 virtual int KillApplicationByUid(const std::string &bundleName, const int uid) override; 157 158 virtual int KillApplicationSelf() override; 159 160 int GetApplicationInfoByProcessID(const int pid, AppExecFwk::ApplicationInfo &application, bool &debug) override; 161 162 virtual void AbilityAttachTimeOut(const sptr<IRemoteObject> &token) override; 163 164 virtual void PrepareTerminate(const sptr<IRemoteObject> &token) override; 165 166 virtual void GetRunningProcessInfoByToken( 167 const sptr<IRemoteObject> &token, AppExecFwk::RunningProcessInfo &info) override; 168 169 void GetRunningProcessInfoByPid(const pid_t pid, OHOS::AppExecFwk::RunningProcessInfo &info) override; 170 171 virtual void StartSpecifiedAbility( 172 const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo) override; 173 174 virtual void RegisterStartSpecifiedAbilityResponse(const sptr<IStartSpecifiedAbilityResponse> &response) override; 175 176 virtual void SetCurrentUserId(const int32_t userId) override; 177 178 private: 179 /** 180 * @brief Judge whether the application service is ready. 181 * 182 * @return Returns true means service is ready, otherwise service is not ready. 183 */ 184 bool IsReady() const; 185 186 private: 187 std::shared_ptr<AppMgrServiceInner> amsMgrServiceInner_; 188 std::shared_ptr<AMSEventHandler> amsHandler_; 189 sptr<ISystemAbilityManager> systemAbilityMgr_; 190 191 DISALLOW_COPY_AND_MOVE(AmsMgrScheduler); 192 }; 193 } // namespace AppExecFwk 194 } // namespace OHOS 195 #endif // OHOS_ABILITY_RUNTIME_AMS_MGR_SCHEDULER_H 196