1 /* 2 * Copyright (c) 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_IABILITY_MANAGER_COLLABORATOR_H 17 #define OHOS_ABILITY_RUNTIME_IABILITY_MANAGER_COLLABORATOR_H 18 19 #include "ability_info.h" 20 #include "iremote_broker.h" 21 #include "iremote_object.h" 22 #include "mission_info.h" 23 #include "session_info.h" 24 #include "want.h" 25 26 namespace OHOS { 27 namespace AppExecFwk { 28 class Configuration; 29 } 30 } 31 32 namespace OHOS { 33 namespace AAFwk { 34 class SessionInfo; 35 36 class IAbilityManagerCollaborator : public IRemoteBroker { 37 public: 38 DECLARE_INTERFACE_DESCRIPTOR(u"ohos.aafwk.IAbilityManagerCollaborator"); 39 40 /** 41 * @brief Notify collaborator to StartAbility. 42 * @param AbilityInfo ability info from bms 43 * @param userId userId. 44 * @param want targert info, will modify by collaborator. 45 * @param accessTokenIDEx accessToken 46 * @return 0 when notify start ability success or else failed. 47 */ 48 virtual int32_t NotifyStartAbility(const AppExecFwk::AbilityInfo &abilityInfo, 49 int32_t userId, Want &want, uint64_t accessTokenIDEx, int32_t windowMode) = 0; 50 51 /** 52 * @brief Notify collaborator to app preload. 53 * @param bundleName bundlName. 54 * @return 0 means success or else failed. 55 */ NotifyPreloadAbility(const std::string & bundleName)56 virtual int32_t NotifyPreloadAbility(const std::string &bundleName) 57 { 58 return 0; 59 } 60 61 /** 62 * @brief Notify when mission is created. 63 * @param missionId missionId. 64 * @param want target info. 65 * @return 0 when notify mission created success or else failed. 66 */ 67 virtual int32_t NotifyMissionCreated(int32_t missionId, const Want &want) = 0; 68 69 /** 70 * @brief Notify when mission is created. 71 * @param sessionInfo sessionInfo. 72 * @return 0 when notify mission created success or else failed. 73 */ 74 virtual int32_t NotifyMissionCreated(const sptr<SessionInfo> &sessionInfo) = 0; 75 76 /** 77 * @brief Notify when start loading ability record. 78 * @param AbilityInfo ability info from bms. 79 * @param missionId missionId. 80 * @param want target info. 81 * @return 0 when notify load ability success or else failed. 82 */ 83 virtual int32_t NotifyLoadAbility( 84 const AppExecFwk::AbilityInfo &abilityInfo, int32_t missionId, const Want &want) = 0; 85 86 /** 87 * @brief Notify when start loading ability record. 88 * @param AbilityInfo ability info from bms. 89 * @param sessionInfo sessionInfo. 90 * @return 0 when notify load ability success or else failed. 91 */ 92 virtual int32_t NotifyLoadAbility( 93 const AppExecFwk::AbilityInfo &abilityInfo, const sptr<SessionInfo> &sessionInfo) = 0; 94 95 /** 96 * @brief Notify when notify app to background. 97 * @param missionId missionId. 98 * @return 0 when notify move mission to background success or else failed. 99 */ 100 virtual int32_t NotifyMoveMissionToBackground(int32_t missionId) = 0; 101 102 /** 103 * @brief Notify when notify app to foreground. 104 * @param missionId missionId. 105 * @return 0 when notify move mission to foreground success or else failed. 106 */ 107 virtual int32_t NotifyMoveMissionToForeground(int32_t missionId) = 0; 108 109 /** 110 * @brief Notify when notify ability is terminated, but mission is not cleared. 111 * @param missionId missionId. 112 * @return 0 when notify terminate mission success or else failed. 113 */ 114 virtual int32_t NotifyTerminateMission(int32_t missionId) = 0; 115 116 /** 117 * @brief Notify to broker when clear mission. 118 * @param missionId missionId. 119 * @return 0 when notify clear mission success or else failed. 120 */ 121 virtual int32_t NotifyClearMission(int32_t missionId) = 0; 122 123 /** 124 * @brief Notify to broker when clear mission. 125 * @param pid pid of shell process. 126 * @param type died type. 127 * @param reason addational message for died reason. 128 * @return 0 when notify remove shell process success or else failed. 129 */ 130 virtual int32_t NotifyRemoveShellProcess(int32_t pid, int32_t type, const std::string &reason) = 0; 131 132 /** 133 * @brief Update mission info to real element by broker. 134 * @param sessionInfo sessionInfo. 135 */ 136 virtual void UpdateMissionInfo(sptr<SessionInfo> &sessionInfo) = 0; 137 138 /** 139 * @brief Check the call permission from shell assistant. 140 * @param want target info. 141 */ CheckCallAbilityPermission(const Want & want)142 virtual int32_t CheckCallAbilityPermission(const Want &want) 143 { 144 return -1; 145 } 146 147 /** 148 * @brief Notify application update system environment changes. 149 * @param config System environment change parameters. 150 * @param userId userId Designation User ID. 151 * @return Return true to notify changes successfully, or false to failed. 152 */ UpdateConfiguration(const AppExecFwk::Configuration & config,int32_t userId)153 virtual bool UpdateConfiguration(const AppExecFwk::Configuration &config, int32_t userId) 154 { 155 return true; 156 } 157 158 /** 159 * @brief Open file by uri. 160 * @param uri The file uri. 161 * @param flag Want::FLAG_AUTH_READ_URI_PERMISSION or Want::FLAG_AUTH_WRITE_URI_PERMISSION. 162 * @param tokenId caller tokenId. 163 * @return int The file descriptor. 164 */ OpenFile(const Uri & uri,uint32_t flag,uint32_t tokenId)165 virtual int32_t OpenFile(const Uri& uri, uint32_t flag, uint32_t tokenId) 166 { 167 return -1; 168 } 169 170 /** 171 * @brief grant uri permission 172 * @param flag Want::FLAG_AUTH_READ_URI_PERMISSION or Want::FLAG_AUTH_WRITE_URI_PERMISSION. 173 * @param targetTokenId the tokenId of target application. 174 * @param targetBundleName the bundleName of target application. 175 * @return 0 when on success or else failed. 176 */ GrantUriPermission(const std::vector<std::string> & uriVec,uint32_t flag,uint32_t targetTokenId,const std::string & targetBundleName)177 virtual int32_t GrantUriPermission(const std::vector<std::string> &uriVec, uint32_t flag, uint32_t targetTokenId, 178 const std::string &targetBundleName) 179 { 180 return -1; 181 } 182 183 /** 184 * @brief grant uri permission 185 * @param tokenId the tokenId of target application. 186 * @return 0 when on success or else failed. 187 */ RevokeUriPermission(uint32_t tokenId)188 virtual int32_t RevokeUriPermission(uint32_t tokenId) 189 { 190 return -1; 191 } 192 NotifyMissionBindPid(int32_t missionId,int32_t pid)193 virtual void NotifyMissionBindPid(int32_t missionId, int32_t pid) 194 { 195 return; 196 } 197 CheckStaticCfgPermission(const Want & want,bool isImplicit)198 virtual int32_t CheckStaticCfgPermission(const Want &want, bool isImplicit) 199 { 200 return 0; 201 } 202 203 /** 204 * @brief Update caller if need. 205 * @param want to start ability 206 * @return 0 when update caller successfully or else failed. 207 */ UpdateCallerIfNeed(Want & want)208 virtual int32_t UpdateCallerIfNeed(Want &want) 209 { 210 return 0; 211 } 212 213 /** 214 * @brief Update target if need. 215 * @param want to start ability 216 * @return 0 when update target successfully or else failed. 217 */ UpdateTargetIfNeed(Want & want)218 virtual int32_t UpdateTargetIfNeed(Want &want) 219 { 220 return 0; 221 } 222 223 /** 224 * @brief kill processes by bundleName. 225 * @param bundleName the bundleName of processes to be killed. 226 * @param userId the user id of processes to be killed. 227 * @return 0 when on success or else failed. 228 */ NotifyKillProcesses(const std::string & bundleName,int32_t userId)229 virtual int32_t NotifyKillProcesses(const std::string &bundleName, int32_t userId) 230 { 231 return 0; 232 } 233 234 enum { 235 NOTIFY_START_ABILITY = 1, 236 NOTIFY_MISSION_CREATED, 237 NOTIFY_LOAD_ABILITY, 238 NOTIFY_MOVE_MISSION_TO_BACKGROUND, 239 NOTIFY_MOVE_MISSION_TO_FOREGROUND, 240 NOTIFY_TERMINATE_MISSION, 241 NOTIFY_CLEAR_MISSION, 242 NOTIFY_REMOVE_SHELL_PROCESS, 243 NOTIFY_MISSION_CREATED_BY_SCB = 10, 244 NOTIFY_LOAD_ABILITY_BY_SCB, 245 UPDATE_MISSION_INFO_BY_SCB, 246 NOTIFY_PRELOAD_ABILITY, 247 CHECK_CALL_ABILITY_PERMISSION, 248 UPDATE_CONFIGURATION, 249 OPEN_FILE, 250 NOTIFY_MISSION_BIND_PID, 251 CHECK_STATIC_CFG_PERMISSION, 252 UPDATE_CALLER_IF_NEED, 253 UPDATE_TARGET_IF_NEED, 254 NOTIFY_KILL_PROCESSES, 255 GRANT_URI_PERMISSION, 256 REVOKE_URI_PERMISSION, 257 }; 258 }; 259 } // namespace AAFwk 260 } // namespace OHOS 261 #endif // OHOS_ABILITY_RUNTIME_IABILITY_MANAGER_COLLABORATOR_H