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_ABILITY_MANAGER_PROXY_H 17 #define OHOS_ABILITY_RUNTIME_ABILITY_MANAGER_PROXY_H 18 19 #include "ability_manager_interface.h" 20 #include "hilog_wrapper.h" 21 #include "iremote_proxy.h" 22 23 namespace OHOS { 24 namespace AAFwk { 25 /** 26 * @class AbilityManagerProxy 27 * AbilityManagerProxy. 28 */ 29 class AbilityManagerProxy : public IRemoteProxy<IAbilityManager> { 30 public: AbilityManagerProxy(const sptr<IRemoteObject> & impl)31 explicit AbilityManagerProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IAbilityManager>(impl) 32 {} 33 ~AbilityManagerProxy()34 virtual ~AbilityManagerProxy() 35 {} 36 37 /** 38 * StartAbility with want, send want to ability manager service. 39 * 40 * @param want, the want of the ability to start. 41 * @param requestCode, Ability request code. 42 * @param userId, Designation User ID. 43 * @return Returns ERR_OK on success, others on failure. 44 */ 45 virtual int StartAbility( 46 const Want &want, 47 int32_t userId = DEFAULT_INVAL_VALUE, 48 int requestCode = DEFAULT_INVAL_VALUE) override; 49 50 /** 51 * StartAbility with want, send want to ability manager service. 52 * 53 * @param want, the want of the ability to start. 54 * @param callerToken, caller ability token. 55 * @param requestCode the resultCode of the ability to start. 56 * @param userId, Designation User ID. 57 * @return Returns ERR_OK on success, others on failure. 58 */ 59 virtual int StartAbility( 60 const Want &want, 61 const sptr<IRemoteObject> &callerToken, 62 int32_t userId = DEFAULT_INVAL_VALUE, 63 int requestCode = DEFAULT_INVAL_VALUE) override; 64 65 /** 66 * Starts a new ability with specific start settings. 67 * 68 * @param want Indicates the ability to start. 69 * @param callerToken caller ability token. 70 * @param abilityStartSetting Indicates the setting ability used to start. 71 * @param userId, Designation User ID. 72 * @return Returns ERR_OK on success, others on failure. 73 */ 74 virtual int StartAbility( 75 const Want &want, 76 const AbilityStartSetting &abilityStartSetting, 77 const sptr<IRemoteObject> &callerToken, 78 int32_t userId = DEFAULT_INVAL_VALUE, 79 int requestCode = DEFAULT_INVAL_VALUE) override; 80 81 /** 82 * Starts a new ability with specific start options. 83 * 84 * @param want, the want of the ability to start. 85 * @param startOptions Indicates the options used to start. 86 * @param callerToken, caller ability token. 87 * @param userId, Designation User ID. 88 * @param requestCode the resultCode of the ability to start. 89 * @return Returns ERR_OK on success, others on failure. 90 */ 91 virtual int StartAbility( 92 const Want &want, 93 const StartOptions &startOptions, 94 const sptr<IRemoteObject> &callerToken, 95 int32_t userId = DEFAULT_INVAL_VALUE, 96 int requestCode = DEFAULT_INVAL_VALUE) override; 97 98 /** 99 * Start extension ability with want, send want to ability manager service. 100 * 101 * @param want, the want of the ability to start. 102 * @param callerToken, caller ability token. 103 * @param userId, Designation User ID. 104 * @param extensionType If an ExtensionAbilityType is set, only extension of that type can be started. 105 * @return Returns ERR_OK on success, others on failure. 106 */ 107 virtual int StartExtensionAbility( 108 const Want &want, 109 const sptr<IRemoteObject> &callerToken, 110 int32_t userId = DEFAULT_INVAL_VALUE, 111 AppExecFwk::ExtensionAbilityType extensionType = AppExecFwk::ExtensionAbilityType::UNSPECIFIED) override; 112 113 /** 114 * Stop extension ability with want, send want to ability manager service. 115 * 116 * @param want, the want of the ability to stop. 117 * @param callerToken, caller ability token. 118 * @param userId, Designation User ID. 119 * @param extensionType If an ExtensionAbilityType is set, only extension of that type can be stopped. 120 * @return Returns ERR_OK on success, others on failure. 121 */ 122 virtual int StopExtensionAbility( 123 const Want& want, 124 const sptr<IRemoteObject>& callerToken, 125 int32_t userId = DEFAULT_INVAL_VALUE, 126 AppExecFwk::ExtensionAbilityType extensionType = AppExecFwk::ExtensionAbilityType::UNSPECIFIED) override; 127 /** 128 * TerminateAbility, terminate the special ability. 129 * 130 * @param token, the token of the ability to terminate. 131 * @param resultCode, the resultCode of the ability to terminate. 132 * @param resultWant, the Want of the ability to return. 133 * @return Returns ERR_OK on success, others on failure. 134 */ 135 virtual int TerminateAbility( 136 const sptr<IRemoteObject> &token, int resultCode, const Want *resultWant = nullptr) override; 137 138 /** 139 * SendResultToAbility with want, return want from ability manager service.(Only used for dms) 140 * 141 * @param requestCode, request code. 142 * @param resultCode, resultCode to return. 143 * @param resultWant, the Want of the ability to return. 144 * @return Returns ERR_OK on success, others on failure. 145 */ 146 virtual int SendResultToAbility(int32_t requestCode, int32_t resultCode, Want& resultWant) override; 147 148 /** 149 * TerminateAbility, terminate the special ability. 150 * 151 * @param callerToken, caller ability token. 152 * @param requestCode, Ability request code. 153 * @return Returns ERR_OK on success, others on failure. 154 */ 155 virtual int TerminateAbilityByCaller(const sptr<IRemoteObject> &callerToken, int requestCode) override; 156 157 /** 158 * CloseAbility, close the special ability. 159 * 160 * @param token, the token of the ability to terminate. 161 * @param resultCode, the resultCode of the ability to terminate. 162 * @param resultWant, the Want of the ability to return. 163 * @return Returns ERR_OK on success, others on failure. 164 */ 165 virtual int CloseAbility( 166 const sptr<IRemoteObject> &token, int resultCode, const Want *resultWant = nullptr) override; 167 168 /** 169 * MinimizeAbility, minimize the special ability. 170 * 171 * @param token, ability token. 172 * @param fromUser mark the minimize operation source. 173 * @return Returns ERR_OK on success, others on failure. 174 */ 175 virtual int MinimizeAbility(const sptr<IRemoteObject> &token, bool fromUser = false) override; 176 177 /** 178 * ConnectAbility, connect session with service ability. 179 * 180 * @param want, Special want for service type's ability. 181 * @param connect, Callback used to notify caller the result of connecting or disconnecting. 182 * @param callerToken, caller ability token. 183 * @param userId, Designation User ID. 184 * @return Returns ERR_OK on success, others on failure. 185 */ 186 virtual int ConnectAbility( 187 const Want &want, 188 const sptr<IAbilityConnection> &connect, 189 const sptr<IRemoteObject> &callerToken, 190 int32_t userId = DEFAULT_INVAL_VALUE) override; 191 192 virtual int ConnectAbilityCommon( 193 const Want &want, 194 const sptr<IAbilityConnection> &connect, 195 const sptr<IRemoteObject> &callerToken, 196 AppExecFwk::ExtensionAbilityType extensionType, 197 int32_t userId = DEFAULT_INVAL_VALUE) override; 198 199 /** 200 * DisconnectAbility, connect session with service ability. 201 * 202 * @param connect, Callback used to notify caller the result of connecting or disconnecting. 203 * @return Returns ERR_OK on success, others on failure. 204 */ 205 virtual int DisconnectAbility(const sptr<IAbilityConnection> &connect) override; 206 207 /** 208 * AcquireDataAbility, acquire a data ability by its authority, if it not existed, 209 * AMS loads it synchronously. 210 * 211 * @param uri, data ability uri. 212 * @param isKill, true: when a data ability is died, ams will kill this client, or do nothing. 213 * @param callerToken, specifies the caller ability token. 214 * @return returns the data ability ipc object, or nullptr for failed. 215 */ 216 virtual sptr<IAbilityScheduler> AcquireDataAbility( 217 const Uri &uri, bool isKill, const sptr<IRemoteObject> &callerToken) override; 218 219 /** 220 * ReleaseDataAbility, release the data ability that referenced by 'dataAbilityToken'. 221 * 222 * @param dataAbilityScheduler, specifies the data ability that will be released. 223 * @param callerToken, specifies the caller ability token. 224 * @return returns ERR_OK if succeeded, or error codes for failed. 225 */ 226 virtual int ReleaseDataAbility( 227 sptr<IAbilityScheduler> dataAbilityScheduler, const sptr<IRemoteObject> &callerToken) override; 228 229 /** 230 * AttachAbilityThread, ability call this interface after loaded. 231 * 232 * @param scheduler,.the interface handler of kit ability. 233 * @param token,.ability's token. 234 * @return Returns ERR_OK on success, others on failure. 235 */ 236 virtual int AttachAbilityThread( 237 const sptr<IAbilityScheduler> &scheduler, const sptr<IRemoteObject> &token) override; 238 239 /** 240 * AbilityTransitionDone, ability call this interface after lift cycle was changed. 241 * 242 * @param token,.ability's token. 243 * @param state,.the state of ability lift cycle. 244 * @return Returns ERR_OK on success, others on failure. 245 */ 246 virtual int AbilityTransitionDone(const sptr<IRemoteObject> &token, int state, const PacMap &saveData) override; 247 248 /** 249 * ScheduleConnectAbilityDone, service ability call this interface while session was connected. 250 * 251 * @param token,.service ability's token. 252 * @param remoteObject,.the session proxy of service ability. 253 * @return Returns ERR_OK on success, others on failure. 254 */ 255 virtual int ScheduleConnectAbilityDone( 256 const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &remoteObject) override; 257 258 /** 259 * ScheduleDisconnectAbilityDone, service ability call this interface while session was disconnected. 260 * 261 * @param token,.service ability's token. 262 * @return Returns ERR_OK on success, others on failure. 263 */ 264 virtual int ScheduleDisconnectAbilityDone(const sptr<IRemoteObject> &token) override; 265 266 /** 267 * ScheduleCommandAbilityDone, service ability call this interface while session was commanded. 268 * 269 * @param token,.service ability's token. 270 * @return Returns ERR_OK on success, others on failure. 271 */ 272 virtual int ScheduleCommandAbilityDone(const sptr<IRemoteObject> &token) override; 273 274 /** 275 * dump ability stack info, about userID, mission stack info, 276 * mission record info and ability info. 277 * 278 * @param state Ability stack info. 279 * @return Returns ERR_OK on success, others on failure. 280 */ 281 virtual void DumpState(const std::string &args, std::vector<std::string> &state) override; 282 virtual void DumpSysState( 283 const std::string& args, std::vector<std::string>& state, bool isClient, bool isUserID, int UserID) override; 284 /** 285 * Destroys this Service ability if the number of times it 286 * has been started equals the number represented by 287 * the given startId. 288 * 289 * @param token ability's token. 290 * @param startId is incremented by 1 every time this ability is started. 291 * @return Returns true if the startId matches the number of startup times 292 * and this Service ability will be destroyed; returns false otherwise. 293 */ 294 virtual int TerminateAbilityResult(const sptr<IRemoteObject> &token, int startId) override; 295 296 /** 297 * Destroys this Service ability by Want. 298 * 299 * @param want, Special want for service type's ability. 300 * @return Returns true if this Service ability will be destroyed; returns false otherwise. 301 */ 302 virtual int StopServiceAbility(const Want &want, int32_t userId = DEFAULT_INVAL_VALUE) override; 303 304 /** 305 * Get top ability. 306 * 307 * @return Returns front desk focus ability elementName. 308 */ 309 virtual AppExecFwk::ElementName GetTopAbility() override; 310 311 /** 312 * Kill the process immediately. 313 * 314 * @param bundleName. 315 * @return Returns ERR_OK on success, others on failure. 316 */ 317 virtual int KillProcess(const std::string &bundleName) override; 318 319 #ifdef ABILITY_COMMAND_FOR_TEST 320 /** 321 * force timeout ability. 322 * 323 * @param abilityName. 324 * @param state. 325 * @return Returns ERR_OK on success, others on failure. 326 */ 327 virtual int ForceTimeoutForTest(const std::string &abilityName, const std::string &state) override; 328 #endif 329 330 /** 331 * ClearUpApplicationData, call ClearUpApplicationData() through proxy project, 332 * clear the application data. 333 * 334 * @param bundleName, bundle name in Application record. 335 * @return 336 */ 337 virtual int ClearUpApplicationData(const std::string &bundleName) override; 338 339 /** 340 * Uninstall app 341 * 342 * @param bundleName bundle name of uninstalling app. 343 * @param uid uid of bundle. 344 * @return Returns ERR_OK on success, others on failure. 345 */ 346 virtual int UninstallApp(const std::string &bundleName, int32_t uid) override; 347 348 virtual sptr<IWantSender> GetWantSender( 349 const WantSenderInfo &wantSenderInfo, const sptr<IRemoteObject> &callerToken) override; 350 351 virtual int SendWantSender(const sptr<IWantSender> &target, const SenderInfo &senderInfo) override; 352 353 virtual void CancelWantSender(const sptr<IWantSender> &sender) override; 354 355 virtual int GetPendingWantUid(const sptr<IWantSender> &target) override; 356 357 virtual int GetPendingWantUserId(const sptr<IWantSender> &target) override; 358 359 virtual std::string GetPendingWantBundleName(const sptr<IWantSender> &target) override; 360 361 virtual int GetPendingWantCode(const sptr<IWantSender> &target) override; 362 363 virtual int GetPendingWantType(const sptr<IWantSender> &target) override; 364 365 virtual void RegisterCancelListener(const sptr<IWantSender> &sender, const sptr<IWantReceiver> &receiver) override; 366 367 virtual void UnregisterCancelListener( 368 const sptr<IWantSender> &sender, const sptr<IWantReceiver> &receiver) override; 369 370 virtual int GetPendingRequestWant(const sptr<IWantSender> &target, std::shared_ptr<Want> &want) override; 371 372 virtual int GetWantSenderInfo(const sptr<IWantSender> &target, std::shared_ptr<WantSenderInfo> &info) override; 373 374 virtual int GetAppMemorySize() override; 375 376 virtual bool IsRamConstrainedDevice() override; 377 virtual int ContinueMission(const std::string &srcDeviceId, const std::string &dstDeviceId, 378 int32_t missionId, const sptr<IRemoteObject> &callBack, AAFwk::WantParams &wantParams) override; 379 380 virtual int ContinueAbility(const std::string &deviceId, int32_t missionId, uint32_t versionCode) override; 381 382 virtual int StartContinuation(const Want &want, const sptr<IRemoteObject> &abilityToken, int32_t status) override; 383 384 virtual void NotifyCompleteContinuation(const std::string &deviceId, int32_t sessionId, bool isSuccess) override; 385 386 virtual int NotifyContinuationResult(int32_t missionId, int32_t result) override; 387 388 virtual int StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override; 389 390 virtual int StopSyncRemoteMissions(const std::string& devId) override; 391 392 virtual int LockMissionForCleanup(int32_t missionId) override; 393 394 virtual int UnlockMissionForCleanup(int32_t missionId) override; 395 396 virtual int RegisterMissionListener(const sptr<IMissionListener> &listener) override; 397 398 virtual int UnRegisterMissionListener(const sptr<IMissionListener> &listener) override; 399 400 virtual int GetMissionInfos(const std::string& deviceId, int32_t numMax, 401 std::vector<MissionInfo> &missionInfos) override; 402 403 virtual int GetMissionInfo(const std::string& deviceId, int32_t missionId, 404 MissionInfo &missionInfos) override; 405 406 virtual int CleanMission(int32_t missionId) override; 407 408 virtual int CleanAllMissions() override; 409 410 virtual int MoveMissionToFront(int32_t missionId) override; 411 412 virtual int MoveMissionToFront(int32_t missionId, const StartOptions &startOptions) override; 413 414 /** 415 * Start Ability, connect session with common ability. 416 * 417 * @param want, Special want for service type's ability. 418 * @param connect, Callback used to notify caller the result of connecting or disconnecting. 419 * @return Returns ERR_OK on success, others on failure. 420 */ 421 virtual int StartAbilityByCall( 422 const Want &want, const sptr<IAbilityConnection> &connect, const sptr<IRemoteObject> &callerToken) override; 423 424 /** 425 * CallRequestDone, after invoke callRequest, ability will call this interface to return callee. 426 * 427 * @param token, ability's token. 428 * @param callStub, ability's callee. 429 */ 430 void CallRequestDone(const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &callStub) override; 431 432 /** 433 * Release the call between Ability, disconnect session with common ability. 434 * 435 * @param connect, Callback used to notify caller the result of connecting or disconnecting. 436 * @param element, the element of target service. 437 * @return Returns ERR_OK on success, others on failure. 438 */ 439 virtual int ReleaseCall( 440 const sptr<IAbilityConnection> &connect, const AppExecFwk::ElementName &element) override; 441 442 virtual int StartUser(int userId) override; 443 444 virtual int StopUser(int userId, const sptr<IStopUserCallback> &callback) override; 445 446 #ifdef SUPPORT_GRAPHICS 447 virtual int SetMissionLabel(const sptr<IRemoteObject> &abilityToken, const std::string &label) override; 448 449 virtual int SetMissionIcon(const sptr<IRemoteObject> &token, 450 const std::shared_ptr<OHOS::Media::PixelMap> &icon) override; 451 452 virtual int RegisterWindowManagerServiceHandler(const sptr<IWindowManagerServiceHandler>& handler) override; 453 454 virtual void CompleteFirstFrameDrawing(const sptr<IRemoteObject> &abilityToken) override; 455 #endif 456 457 virtual int GetAbilityRunningInfos(std::vector<AbilityRunningInfo> &info) override; 458 459 virtual int GetExtensionRunningInfos(int upperLimit, std::vector<ExtensionRunningInfo> &info) override; 460 461 virtual int GetProcessRunningInfos(std::vector<AppExecFwk::RunningProcessInfo> &info) override; 462 463 virtual int RegisterMissionListener(const std::string &deviceId, 464 const sptr<IRemoteMissionListener> &listener) override; 465 466 virtual int UnRegisterMissionListener(const std::string &deviceId, 467 const sptr<IRemoteMissionListener> &listener) override; 468 469 /** 470 * Set ability controller. 471 * 472 * @param abilityController, The ability controller. 473 * @return Returns ERR_OK on success, others on failure. 474 */ 475 virtual int SetAbilityController(const sptr<AppExecFwk::IAbilityController> &abilityController, 476 bool imAStabilityTest) override; 477 478 virtual int SetComponentInterception( 479 const sptr<AppExecFwk::IComponentInterception> &componentInterception) override; 480 481 virtual int32_t SendResultToAbilityByToken(const Want &want, const sptr<IRemoteObject> &abilityToken, 482 int32_t requestCode, int32_t resultCode, int32_t userId) override; 483 484 /** 485 * Is user a stability test. 486 * 487 * @return Returns true if user is a stability test. 488 */ 489 virtual bool IsRunningInStabilityTest() override; 490 491 virtual int RegisterSnapshotHandler(const sptr<ISnapshotHandler>& handler) override; 492 493 virtual int GetMissionSnapshot(const std::string& deviceId, int32_t missionId, 494 MissionSnapshot& snapshot, bool isLowResolution) override; 495 496 virtual int StartUserTest(const Want &want, const sptr<IRemoteObject> &observer) override; 497 498 virtual int FinishUserTest( 499 const std::string &msg, const int64_t &resultCode, const std::string &bundleName) override; 500 501 /** 502 * GetTopAbility, get the token of top ability. 503 * 504 * @param token, the token of top ability. 505 * @return Returns ERR_OK on success, others on failure. 506 */ 507 virtual int GetTopAbility(sptr<IRemoteObject> &token) override; 508 509 /** 510 * The delegator calls this interface to move the ability to the foreground. 511 * 512 * @param token, ability's token. 513 * @return Returns ERR_OK on success, others on failure. 514 */ 515 virtual int DelegatorDoAbilityForeground(const sptr<IRemoteObject> &token) override; 516 517 /** 518 * The delegator calls this interface to move the ability to the background. 519 * 520 * @param token, ability's token. 521 * @return Returns ERR_OK on success, others on failure. 522 */ 523 virtual int DelegatorDoAbilityBackground(const sptr<IRemoteObject> &token) override; 524 525 /** 526 * Calls this interface to move the ability to the foreground. 527 * 528 * @param token, ability's token. 529 * @param flag, use for lock or unlock flag and so on. 530 * @return Returns ERR_OK on success, others on failure. 531 */ 532 virtual int DoAbilityForeground(const sptr<IRemoteObject> &token, uint32_t flag) override; 533 534 /** 535 * Calls this interface to move the ability to the background. 536 * 537 * @param token, ability's token. 538 * @param flag, use for lock or unlock flag and so on. 539 * @return Returns ERR_OK on success, others on failure. 540 */ 541 virtual int DoAbilityBackground(const sptr<IRemoteObject> &token, uint32_t flag) override; 542 543 /** 544 * Send not response process ID to ability manager service. 545 * 546 * @param pid The not response process ID. 547 * @return Returns ERR_OK on success, others on failure. 548 */ 549 virtual int SendANRProcessID(int pid) override; 550 551 /** 552 * Get mission id by ability token. 553 * 554 * @param token The token of ability. 555 * @return Returns -1 if do not find mission, otherwise return mission id. 556 */ 557 virtual int32_t GetMissionIdByToken(const sptr<IRemoteObject> &token) override; 558 559 #ifdef ABILITY_COMMAND_FOR_TEST 560 /** 561 * Block ability manager service. 562 * 563 * @return Returns ERR_OK on success, others on failure. 564 */ 565 virtual int BlockAmsService() override; 566 567 /** 568 * Block ability. 569 * 570 * @param abilityRecordId The Ability Record Id. 571 * @return Returns ERR_OK on success, others on failure. 572 */ 573 virtual int BlockAbility(int32_t abilityRecordId) override; 574 575 /** 576 * Block app service. 577 * 578 * @return Returns ERR_OK on success, others on failure. 579 */ 580 virtual int BlockAppService() override; 581 #endif 582 583 /** 584 * Call free install from remote. 585 * 586 * @param want, the want of the ability to start. 587 * @param userId, Designation User ID. 588 * @param requestCode, Ability request code. 589 * @param callback, Callback from remote. 590 * @return Returns ERR_OK on success, others on failure. 591 */ 592 virtual int FreeInstallAbilityFromRemote(const Want &want, const sptr<IRemoteObject> &callback, 593 int32_t userId, int requestCode = DEFAULT_INVAL_VALUE) override; 594 595 /** 596 * Called when client complete dump. 597 * 598 * @param infos The dump info. 599 * @return Returns ERR_OK on success, others on failure. 600 */ 601 virtual int DumpAbilityInfoDone(std::vector<std::string> &infos, const sptr<IRemoteObject> &callerToken) override; 602 603 /** 604 * Called to update mission snapshot. 605 * @param token The target ability. 606 */ 607 virtual void UpdateMissionSnapShot(const sptr<IRemoteObject>& token) override; 608 virtual void EnableRecoverAbility(const sptr<IRemoteObject>& token) override; 609 virtual void ScheduleRecoverAbility(const sptr<IRemoteObject> &token, int32_t reason) override; 610 611 private: 612 template <typename T> 613 int GetParcelableInfos(MessageParcel &reply, std::vector<T> &parcelableInfos); 614 bool WriteInterfaceToken(MessageParcel &data); 615 // flag = true : terminate; flag = false : close 616 int TerminateAbility(const sptr<IRemoteObject> &token, int resultCode, const Want *resultWant, bool flag); 617 618 private: 619 static inline BrokerDelegator<AbilityManagerProxy> delegator_; 620 }; 621 } // namespace AAFwk 622 } // namespace OHOS 623 #endif 624