1 /* 2 * Copyright (c) 2021 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 FOUNDATION_APPEXECFWK_SERVICES_APPMGR_INCLUDE_AMS_MGR_SCHEDULER_H 17 #define FOUNDATION_APPEXECFWK_SERVICES_APPMGR_INCLUDE_AMS_MGR_SCHEDULER_H 18 19 #include "if_system_ability_manager.h" 20 #include "nocopyable.h" 21 22 #include "system_ability.h" 23 #include "ability_info.h" 24 #include "ability_running_record.h" 25 #include "appexecfwk_errors.h" 26 #include "application_info.h" 27 #include "app_mgr_constants.h" 28 #include "ams_mgr_stub.h" 29 #include "app_mgr_service_event_handler.h" 30 #include "app_mgr_service_inner.h" 31 #include "app_record_id.h" 32 #include "app_running_record.h" 33 #include "app_scheduler_proxy.h" 34 35 namespace OHOS { 36 namespace AppExecFwk { 37 class AmsMgrScheduler : public AmsMgrStub { 38 public: 39 AmsMgrScheduler( 40 const std::shared_ptr<AppMgrServiceInner> &MgrServiceInner_, const std::shared_ptr<AMSEventHandler> &Handler_); 41 virtual ~AmsMgrScheduler() override; 42 43 /** 44 * LoadAbility, call LoadAbility() through proxy project, load the ability that needed to be started. 45 * 46 * @param token, the unique identification to start the ability. 47 * @param preToken, the unique identification to call the ability. 48 * @param abilityInfo, the ability information. 49 * @param appInfo, the app information. 50 * @return 51 */ 52 virtual void LoadAbility(const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &preToken, 53 const std::shared_ptr<AbilityInfo> &abilityInfo, const std::shared_ptr<ApplicationInfo> &appInfo) 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 * @return 60 */ 61 virtual void TerminateAbility(const sptr<IRemoteObject> &token) override; 62 63 /** 64 * UpdateAbilityState, call UpdateAbilityState() through the proxy object, update the ability status. 65 * 66 * @param token, the unique identification to update the ability. 67 * @param state, ability status that needs to be updated. 68 * @return 69 */ 70 virtual void UpdateAbilityState(const sptr<IRemoteObject> &token, const AbilityState state) override; 71 72 /** 73 * RegisterAppStateCallback, call RegisterAppStateCallback() through the proxy object, register the callback. 74 * 75 * @param callback, Ams register the callback. 76 * @return 77 */ 78 virtual void RegisterAppStateCallback(const sptr<IAppStateCallback> &callback) override; 79 80 /** 81 * Reset,call Reset() through the proxy object, reset DFX of AppMgr. 82 * 83 * @return 84 */ 85 virtual void Reset() override; 86 87 /** 88 * AbilityBehaviorAnalysis, ability behavior analysis assistant process optimization. 89 * 90 * @param token, the unique identification to start the ability. 91 * @param preToken, the unique identification to call the ability. 92 * @param visibility, the visibility information about windows info. 93 * @param perceptibility, the Perceptibility information about windows info. 94 * @param connectionState, the service ability connection state. 95 * @return 96 */ 97 virtual void AbilityBehaviorAnalysis(const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &preToken, 98 const int32_t visibility, const int32_t perceptibility, const int32_t connectionState) override; 99 100 /** 101 * KillProcessByAbilityToken, call KillProcessByAbilityToken() through proxy object, 102 * kill the process by ability token. 103 * 104 * @param token, the unique identification to the ability. 105 * @return 106 */ 107 virtual void KillProcessByAbilityToken(const sptr<IRemoteObject> &token) override; 108 109 /** 110 * KillApplication, call KillApplication() through proxy object, kill the application. 111 * 112 * @param bundleName, bundle name in Application record. 113 * @return ERR_OK, return back success, others fail. 114 */ 115 virtual int32_t KillApplication(const std::string &bundleName) override; 116 117 virtual void AbilityAttachTimeOut(const sptr<IRemoteObject> &token) override; 118 119 /** 120 * Checks whether a specified permission has been granted to the process identified by pid and uid 121 * 122 * @param permission Indicates the permission to check. 123 * @param pid Indicates the ID of the process to check. 124 * @param uid Indicates the UID of the process to check. 125 * @param message Describe success or failure 126 * 127 * @return Returns ERR_OK on success, others on failure. 128 */ 129 virtual int CompelVerifyPermission(const std::string &permission, int pid, int uid, std::string &message) override; 130 131 private: 132 /** 133 * @brief Judge whether the application service is ready. 134 * 135 * @return Returns true means service is ready, otherwise service is not ready. 136 */ 137 bool IsReady() const; 138 139 private: 140 std::shared_ptr<AppMgrServiceInner> amsMgrServiceInner_; 141 std::shared_ptr<AMSEventHandler> amsHandler_; 142 sptr<ISystemAbilityManager> systemAbilityMgr_; 143 144 DISALLOW_COPY_AND_MOVE(AmsMgrScheduler); 145 }; 146 } // namespace AppExecFwk 147 } // namespace OHOS 148 #endif // FOUNDATION_APPEXECFWK_SERVICES_APPMGR_INCLUDE_AMS_MGR_SCHEDULER_H 149