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_CLIENT_H 17 #define OHOS_ABILITY_RUNTIME_ABILITY_MANAGER_CLIENT_H 18 19 #include <mutex> 20 21 #include "ability_connect_callback_interface.h" 22 #include "ability_manager_errors.h" 23 #include "ability_scheduler_interface.h" 24 #include "ability_manager_interface.h" 25 #include "snapshot.h" 26 #include "want.h" 27 28 #include "iremote_object.h" 29 #include "system_memory_attr.h" 30 31 namespace OHOS { 32 namespace AAFwk { 33 /** 34 * @class AbilityManagerClient 35 * AbilityManagerClient is used to access ability manager services. 36 */ 37 class AbilityManagerClient { 38 public: 39 AbilityManagerClient(); 40 virtual ~AbilityManagerClient(); 41 static std::shared_ptr<AbilityManagerClient> GetInstance(); 42 43 /** 44 * AttachAbilityThread, ability call this interface after loaded. 45 * 46 * @param scheduler,.the interface handler of kit ability. 47 * @param token,.ability's token. 48 * @return Returns ERR_OK on success, others on failure. 49 */ 50 ErrCode AttachAbilityThread(const sptr<IAbilityScheduler> &scheduler, const sptr<IRemoteObject> &token); 51 52 /** 53 * AbilityTransitionDone, ability call this interface after lift cycle was changed. 54 * 55 * @param token,.ability's token. 56 * @param state,.the state of ability lift cycle. 57 * @return Returns ERR_OK on success, others on failure. 58 */ 59 ErrCode AbilityTransitionDone(const sptr<IRemoteObject> &token, int state, const PacMap &saveData); 60 61 /** 62 * ScheduleConnectAbilityDone, service ability call this interface while session was connected. 63 * 64 * @param token,.service ability's token. 65 * @param remoteObject,.the session proxy of service ability. 66 * @return Returns ERR_OK on success, others on failure. 67 */ 68 ErrCode ScheduleConnectAbilityDone(const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &remoteObject); 69 70 /** 71 * ScheduleDisconnectAbilityDone, service ability call this interface while session was disconnected. 72 * 73 * @param token,.service ability's token. 74 * @return Returns ERR_OK on success, others on failure. 75 */ 76 ErrCode ScheduleDisconnectAbilityDone(const sptr<IRemoteObject> &token); 77 78 /** 79 * ScheduleCommandAbilityDone, service ability call this interface while session was commanded. 80 * 81 * @param token,.service ability's token. 82 * @return Returns ERR_OK on success, others on failure. 83 */ 84 ErrCode ScheduleCommandAbilityDone(const sptr<IRemoteObject> &token); 85 86 /** 87 * Get top ability. 88 * 89 * @return Returns front desk focus ability elementName. 90 */ 91 AppExecFwk::ElementName GetTopAbility(); 92 93 /** 94 * StartAbility with want, send want to ability manager service. 95 * 96 * @param want Ability want. 97 * @param requestCode Ability request code. 98 * @return Returns ERR_OK on success, others on failure. 99 */ 100 ErrCode StartAbility(const Want &want, int requestCode = DEFAULT_INVAL_VALUE, 101 int32_t userId = DEFAULT_INVAL_VALUE); 102 103 /** 104 * StartAbility with want, send want to ability manager service. 105 * 106 * @param want Ability want. 107 * @param callerToken, caller ability token. 108 * @param requestCode Ability request code. 109 * @return Returns ERR_OK on success, others on failure. 110 */ 111 ErrCode StartAbility( 112 const Want &want, 113 const sptr<IRemoteObject> &callerToken, 114 int requestCode = DEFAULT_INVAL_VALUE, 115 int32_t userId = DEFAULT_INVAL_VALUE); 116 117 /** 118 * Starts a new ability with specific start settings. 119 * 120 * @param want Indicates the ability to start. 121 * @param requestCode the resultCode of the ability to start. 122 * @param abilityStartSetting Indicates the setting ability used to start. 123 * @return Returns ERR_OK on success, others on failure. 124 */ 125 ErrCode StartAbility( 126 const Want &want, 127 const AbilityStartSetting &abilityStartSetting, 128 const sptr<IRemoteObject> &callerToken, 129 int requestCode = DEFAULT_INVAL_VALUE, 130 int32_t userId = DEFAULT_INVAL_VALUE); 131 132 /** 133 * Starts a new ability with specific start options. 134 * 135 * @param want, the want of the ability to start. 136 * @param startOptions Indicates the options used to start. 137 * @param callerToken, caller ability token. 138 * @param requestCode the resultCode of the ability to start. 139 * @return Returns ERR_OK on success, others on failure. 140 */ 141 ErrCode StartAbility( 142 const Want &want, 143 const StartOptions &startOptions, 144 const sptr<IRemoteObject> &callerToken, 145 int requestCode = DEFAULT_INVAL_VALUE, 146 int32_t userId = DEFAULT_INVAL_VALUE); 147 148 /** 149 * Start extension ability with want, send want to ability manager service. 150 * 151 * @param want, the want of the ability to start. 152 * @param callerToken, caller ability token. 153 * @param userId, Designation User ID. 154 * @param extensionType If an ExtensionAbilityType is set, only extension of that type can be started. 155 * @return Returns ERR_OK on success, others on failure. 156 */ 157 ErrCode StartExtensionAbility( 158 const Want &want, 159 const sptr<IRemoteObject> &callerToken, 160 int32_t userId = DEFAULT_INVAL_VALUE, 161 AppExecFwk::ExtensionAbilityType extensionType = AppExecFwk::ExtensionAbilityType::UNSPECIFIED); 162 163 /** 164 * Stop extension ability with want, send want to ability manager service. 165 * 166 * @param want, the want of the ability to stop. 167 * @param callerToken, caller ability token. 168 * @param userId, Designation User ID. 169 * @param extensionType If an ExtensionAbilityType is set, only extension of that type can be stopped. 170 * @return Returns ERR_OK on success, others on failure. 171 */ 172 ErrCode StopExtensionAbility( 173 const Want& want, 174 const sptr<IRemoteObject>& callerToken, 175 int32_t userId = DEFAULT_INVAL_VALUE, 176 AppExecFwk::ExtensionAbilityType extensionType = AppExecFwk::ExtensionAbilityType::UNSPECIFIED); 177 178 /** 179 * TerminateAbility with want, return want from ability manager service. 180 * 181 * @param token Ability token. 182 * @param resultCode resultCode. 183 * @param Want Ability want returned. 184 * @return Returns ERR_OK on success, others on failure. 185 */ 186 ErrCode TerminateAbility(const sptr<IRemoteObject> &token, int resultCode, const Want *resultWant); 187 188 /** 189 * SendResultToAbility with want, return resultWant from ability manager service. 190 * 191 * @param requestCode requestCode. 192 * @param resultCode resultCode. 193 * @param resultWant Ability want returned. 194 * @return Returns ERR_OK on success, others on failure. 195 */ 196 ErrCode SendResultToAbility(int requestCode, int resultCode, Want& resultWant); 197 198 /** 199 * CloseAbility with want, return want from ability manager service. 200 * 201 * @param token Ability token. 202 * @param resultCode resultCode. 203 * @param Want Ability want returned. 204 * @return Returns ERR_OK on success, others on failure. 205 */ 206 ErrCode CloseAbility(const sptr<IRemoteObject> &token, int resultCode = DEFAULT_INVAL_VALUE, 207 const Want *resultWant = nullptr); 208 209 /** 210 * TerminateAbility, terminate the special ability. 211 * 212 * @param callerToken, caller ability token. 213 * @param requestCode Ability request code. 214 * @return Returns ERR_OK on success, others on failure. 215 */ 216 ErrCode TerminateAbility(const sptr<IRemoteObject> &callerToken, int requestCode); 217 218 /** 219 * Destroys this Service ability if the number of times it 220 * has been started equals the number represented by 221 * the given startId. 222 * 223 * @param token ability's token. 224 * @param startId is incremented by 1 every time this ability is started. 225 * @return Returns true if the startId matches the number of startup times 226 * and this Service ability will be destroyed; returns false otherwise. 227 */ 228 ErrCode TerminateAbilityResult(const sptr<IRemoteObject> &token, int startId); 229 230 /** 231 * MinimizeAbility, minimize the special ability. 232 * 233 * @param token, ability token. 234 * @param fromUser mark the minimize operation source. 235 * @return Returns ERR_OK on success, others on failure. 236 */ 237 ErrCode MinimizeAbility(const sptr<IRemoteObject> &token, bool fromUser = false); 238 239 /** 240 * ConnectAbility, connect session with service ability. 241 * 242 * @param want, Special want for service type's ability. 243 * @param connect, Callback used to notify caller the result of connecting or disconnecting. 244 * @return Returns ERR_OK on success, others on failure. 245 */ 246 ErrCode ConnectAbility(const Want &want, const sptr<IAbilityConnection> &connect, int32_t userId); 247 248 /** 249 * ConnectAbility, connect session with service ability. 250 * 251 * @param want, Special want for service type's ability. 252 * @param connect, Callback used to notify caller the result of connecting or disconnecting. 253 * @param callerToken, caller ability token. 254 * @return Returns ERR_OK on success, others on failure. 255 */ 256 ErrCode ConnectAbility( 257 const Want &want, 258 const sptr<IAbilityConnection> &connect, 259 const sptr<IRemoteObject> &callerToken, 260 int32_t userId = DEFAULT_INVAL_VALUE); 261 262 /** 263 * Connect data share extension ability. 264 * 265 * @param want, special want for the data share extension ability. 266 * @param connect, callback used to notify caller the result of connecting or disconnecting. 267 * @param userId, the extension runs in. 268 * @return Returns ERR_OK on success, others on failure. 269 */ 270 ErrCode ConnectDataShareExtensionAbility(const Want &want, const sptr<IAbilityConnection> &connect, 271 int32_t userId = DEFAULT_INVAL_VALUE); 272 273 /** 274 * Connect extension ability. 275 * 276 * @param want, special want for the extension ability. 277 * @param connect, callback used to notify caller the result of connecting or disconnecting. 278 * @param userId, the extension runs in. 279 * @return Returns ERR_OK on success, others on failure. 280 */ 281 ErrCode ConnectExtensionAbility(const Want &want, const sptr<IAbilityConnection> &connect, 282 int32_t userId = DEFAULT_INVAL_VALUE); 283 284 /** 285 * DisconnectAbility, disconnect session with service ability. 286 * 287 * @param connect, Callback used to notify caller the result of connecting or disconnecting. 288 * @return Returns ERR_OK on success, others on failure. 289 */ 290 ErrCode DisconnectAbility(const sptr<IAbilityConnection> &connect); 291 292 /** 293 * AcquireDataAbility, acquire a data ability by its authority, if it not existed, 294 * AMS loads it synchronously. 295 * 296 * @param uri, data ability uri. 297 * @param tryBind, true: when a data ability is died, ams will kill this client, or do nothing. 298 * @param callerToken, specifies the caller ability token. 299 * @return returns the data ability ipc object, or nullptr for failed. 300 */ 301 sptr<IAbilityScheduler> AcquireDataAbility(const Uri &uri, bool tryBind, const sptr<IRemoteObject> &callerToken); 302 303 /** 304 * ReleaseDataAbility, release the data ability that referenced by 'dataAbilityToken'. 305 * 306 * @param dataAbilityToken, specifies the data ability that will be released. 307 * @param callerToken, specifies the caller ability token. 308 * @return returns ERR_OK if succeeded, or error codes for failed. 309 */ 310 ErrCode ReleaseDataAbility(sptr<IAbilityScheduler> dataAbilityScheduler, const sptr<IRemoteObject> &callerToken); 311 312 /** 313 * dump ability stack info, about userID, mission stack info, 314 * mission record info and ability info. 315 * 316 * @param state Ability stack info. 317 * @return Returns ERR_OK on success, others on failure. 318 */ 319 ErrCode DumpState(const std::string &args, std::vector<std::string> &state); 320 ErrCode DumpSysState( 321 const std::string& args, std::vector<std::string>& state, bool isClient, bool isUserID, int UserID); 322 /** 323 * Connect ability manager service. 324 * 325 * @return Returns ERR_OK on success, others on failure. 326 */ 327 ErrCode Connect(); 328 329 /** 330 * Destroys this Service ability by Want. 331 * 332 * @param want, Special want for service type's ability. 333 * @return Returns true if this Service ability will be destroyed; returns false otherwise. 334 */ 335 ErrCode StopServiceAbility(const Want &want); 336 337 /** 338 * Kill the process immediately. 339 * 340 * @param bundleName. 341 * @return Returns ERR_OK on success, others on failure. 342 */ 343 ErrCode KillProcess(const std::string &bundleName); 344 345 #ifdef ABILITY_COMMAND_FOR_TEST 346 /** 347 * Force ability timeout. 348 * 349 * @param abilityName. 350 * @param state. ability lifecycle state. 351 * @return Returns ERR_OK on success, others on failure. 352 */ 353 ErrCode ForceTimeoutForTest(const std::string &abilityName, const std::string &state); 354 #endif 355 356 /** 357 * ClearUpApplicationData, call ClearUpApplicationData() through proxy project, 358 * clear the application data. 359 * 360 * @param bundleName, bundle name in Application record. 361 * @return 362 */ 363 ErrCode ClearUpApplicationData(const std::string &bundleName); 364 365 sptr<IWantSender> GetWantSender(const WantSenderInfo &wantSenderInfo, const sptr<IRemoteObject> &callerToken); 366 367 ErrCode SendWantSender(const sptr<IWantSender> &target, const SenderInfo &senderInfo); 368 369 void CancelWantSender(const sptr<IWantSender> &sender); 370 371 ErrCode GetPendingWantUid(const sptr<IWantSender> &target, int32_t &uid); 372 373 ErrCode GetPendingWantUserId(const sptr<IWantSender> &target, int32_t &userId); 374 375 ErrCode GetPendingWantBundleName(const sptr<IWantSender> &target, std::string &bundleName); 376 377 ErrCode GetPendingWantCode(const sptr<IWantSender> &target, int32_t &code); 378 379 ErrCode GetPendingWantType(const sptr<IWantSender> &target, int32_t &type); 380 381 void RegisterCancelListener(const sptr<IWantSender> &sender, const sptr<IWantReceiver> &recevier); 382 383 void UnregisterCancelListener(const sptr<IWantSender> &sender, const sptr<IWantReceiver> &recevier); 384 385 ErrCode GetPendingRequestWant(const sptr<IWantSender> &target, std::shared_ptr<Want> &want); 386 387 ErrCode GetWantSenderInfo(const sptr<IWantSender> &target, std::shared_ptr<WantSenderInfo> &info); 388 389 ErrCode GetAppMemorySize(); 390 391 bool IsRamConstrainedDevice(); 392 /** 393 * ContinueMission, continue ability from mission center. 394 * 395 * @param srcDeviceId, origin deviceId. 396 * @param dstDeviceId, target deviceId. 397 * @param missionId, indicates which ability to continue. 398 * @param callBack, notify result back. 399 * @param wantParams, extended params. 400 * @return Returns ERR_OK on success, others on failure. 401 */ 402 ErrCode ContinueMission(const std::string &srcDeviceId, const std::string &dstDeviceId, int32_t missionId, 403 const sptr<IRemoteObject> &callback, AAFwk::WantParams &wantParams); 404 405 /** 406 * start continuation. 407 * @param want, used to start a ability. 408 * @param abilityToken, ability token. 409 * @param status, continue status. 410 * @return Returns ERR_OK on success, others on failure. 411 */ 412 ErrCode StartContinuation(const Want &want, const sptr<IRemoteObject> &abilityToken, int32_t status); 413 414 /** 415 * notify continuation complete to dms. 416 * @param deviceId, source device which start a continuation. 417 * @param sessionId, represent a continuaion. 418 * @param isSuccess, continuation result. 419 * @return 420 */ 421 void NotifyCompleteContinuation(const std::string &deviceId, int32_t sessionId, bool isSuccess); 422 423 /** 424 * ContinueMission, continue ability from mission center. 425 * @param deviceId, target deviceId. 426 * @param missionId, indicates which ability to continue. 427 * @param versionCode, version of the remote target ability. 428 * @return Returns ERR_OK on success, others on failure. 429 */ 430 ErrCode ContinueAbility(const std::string &deviceId, int32_t missionId, uint32_t versionCode); 431 432 /** 433 * notify continuation result to application. 434 * @param missionId, indicates which ability to notify. 435 * @param result, continuation result. 436 * @return 437 */ 438 ErrCode NotifyContinuationResult(int32_t missionId, int32_t result); 439 440 /** 441 * @brief Lock specified mission. 442 * @param missionId The id of target mission. 443 * 444 * @return Returns ERR_OK on success, others on failure. 445 */ 446 ErrCode LockMissionForCleanup(int32_t missionId); 447 448 /** 449 * @brief Unlock specified mission. 450 * @param missionId The id of target mission. 451 * 452 * @return Returns ERR_OK on success, others on failure. 453 */ 454 ErrCode UnlockMissionForCleanup(int32_t missionId); 455 456 /** 457 * @brief Register mission listener to ams. 458 * @param listener The handler of listener. 459 * 460 * @return Returns ERR_OK on success, others on failure. 461 */ 462 ErrCode RegisterMissionListener(const sptr<IMissionListener> &listener); 463 464 /** 465 * @brief UnRegister mission listener from ams. 466 * @param listener The handler of listener. 467 * 468 * @return Returns ERR_OK on success, others on failure. 469 */ 470 ErrCode UnRegisterMissionListener(const sptr<IMissionListener> &listener); 471 472 /** 473 * @brief Register mission listener to ability manager service. 474 * @param deviceId The remote device Id. 475 * @param listener The handler of listener. 476 * 477 * @return Returns ERR_OK on success, others on failure. 478 */ 479 ErrCode RegisterMissionListener(const std::string &deviceId, const sptr<IRemoteMissionListener> &listener); 480 481 /** 482 * @brief UnRegister mission listener from ability manager service. 483 * @param deviceId The remote device Id. 484 * @param listener The handler of listener. 485 * 486 * @return Returns ERR_OK on success, others on failure. 487 */ 488 ErrCode UnRegisterMissionListener(const std::string &deviceId, const sptr<IRemoteMissionListener> &listener); 489 490 /** 491 * @brief Get mission infos from ams. 492 * @param deviceId local or remote deviceid. 493 * @param numMax max number of missions. 494 * @param missionInfos mission info result. 495 * 496 * @return Returns ERR_OK on success, others on failure. 497 */ 498 ErrCode GetMissionInfos(const std::string &deviceId, int32_t numMax, std::vector<MissionInfo> &missionInfos); 499 500 /** 501 * @brief Get mission info by id. 502 * @param deviceId local or remote deviceid. 503 * @param missionId Id of target mission. 504 * @param missionInfo mision info of target mission. 505 * 506 * @return Returns ERR_OK on success, others on failure. 507 */ 508 ErrCode GetMissionInfo(const std::string &deviceId, int32_t missionId, MissionInfo &missionInfo); 509 510 /** 511 * @brief Get the Mission Snapshot Info object 512 * @param deviceId local or remote deviceid. 513 * @param missionId Id of target mission. 514 * @param snapshot snapshot of target mission. 515 * @param isLowResolution get low resolution snapshot. 516 * @return Returns ERR_OK on success, others on failure. 517 */ 518 ErrCode GetMissionSnapshot(const std::string& deviceId, int32_t missionId, 519 MissionSnapshot& snapshot, bool isLowResolution = false); 520 521 /** 522 * @brief Clean mission by id. 523 * @param missionId Id of target mission. 524 * 525 * @return Returns ERR_OK on success, others on failure. 526 */ 527 ErrCode CleanMission(int32_t missionId); 528 529 /** 530 * @brief Clean all missions in system. 531 * 532 * @return Returns ERR_OK on success, others on failure. 533 */ 534 ErrCode CleanAllMissions(); 535 536 /** 537 * @brief Move a mission to front. 538 * @param missionId Id of target mission. 539 * @param startOptions Special startOptions for target mission. 540 * 541 * @return Returns ERR_OK on success, others on failure. 542 */ 543 ErrCode MoveMissionToFront(int32_t missionId); 544 ErrCode MoveMissionToFront(int32_t missionId, const StartOptions &startOptions); 545 546 /** 547 * @brief Get mission id by ability token. 548 * 549 * @param token ability token. 550 * @param missionId output mission id. 551 * @return Returns ERR_OK on success, others on failure. 552 */ 553 ErrCode GetMissionIdByToken(const sptr<IRemoteObject> &token, int32_t &missionId); 554 555 /** 556 * Start Ability, connect session with common ability. 557 * 558 * @param want, Special want for service type's ability. 559 * @param connect, Callback used to notify caller the result of connecting or disconnecting. 560 * @return Returns ERR_OK on success, others on failure. 561 */ 562 ErrCode StartAbilityByCall(const Want &want, const sptr<IAbilityConnection> &connect); 563 564 /** 565 * Start Ability, connect session with common ability. 566 * 567 * @param want, Special want for service type's ability. 568 * @param connect, Callback used to notify caller the result of connecting or disconnecting. 569 * @return Returns ERR_OK on success, others on failure. 570 */ 571 ErrCode StartAbilityByCall( 572 const Want &want, const sptr<IAbilityConnection> &connect, const sptr<IRemoteObject> &callToken); 573 574 /** 575 * CallRequestDone, after invoke callRequest, ability will call this interface to return callee. 576 * 577 * @param token, ability's token. 578 * @param callStub, ability's callee. 579 */ 580 void CallRequestDone(const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &callStub); 581 582 /** 583 * Release the call between Ability, disconnect session with common ability. 584 * 585 * @param connect, Callback used to notify caller the result of connecting or disconnecting. 586 * @return Returns ERR_OK on success, others on failure. 587 */ 588 ErrCode ReleaseCall(const sptr<IAbilityConnection> &connect, const AppExecFwk::ElementName &element); 589 590 ErrCode GetAbilityRunningInfos(std::vector<AbilityRunningInfo> &info); 591 592 ErrCode GetExtensionRunningInfos(int upperLimit, std::vector<ExtensionRunningInfo> &info); 593 594 ErrCode GetProcessRunningInfos(std::vector<AppExecFwk::RunningProcessInfo> &info); 595 596 /** 597 * Start synchronizing remote device mission 598 * @param devId, deviceId. 599 * @param fixConflict, resolve synchronizing conflicts flag. 600 * @param tag, call tag. 601 * @return Returns ERR_OK on success, others on failure. 602 */ 603 ErrCode StartSyncRemoteMissions(const std::string &devId, bool fixConflict, int64_t tag); 604 605 /** 606 * Stop synchronizing remote device mission 607 * @param devId, deviceId. 608 * @return Returns ERR_OK on success, others on failure. 609 */ 610 ErrCode StopSyncRemoteMissions(const std::string &devId); 611 612 /** 613 * @brief start user. 614 * @param accountId accountId. 615 * 616 * @return Returns ERR_OK on success, others on failure. 617 */ 618 ErrCode StartUser(int accountId); 619 620 /** 621 * @brief stop user. 622 * @param accountId accountId. 623 * @param callback callback. 624 * 625 * @return Returns ERR_OK on success, others on failure. 626 */ 627 ErrCode StopUser(int accountId, const sptr<IStopUserCallback> &callback); 628 629 /** 630 * @brief Register the snapshot handler 631 * @param handler snapshot handler 632 * @return ErrCode Returns ERR_OK on success, others on failure. 633 */ 634 ErrCode RegisterSnapshotHandler(const sptr<ISnapshotHandler>& handler); 635 636 #ifdef SUPPORT_GRAPHICS 637 /** 638 * Set mission label of this ability. 639 * 640 * @param abilityToken Indidate token of ability. 641 * @param label Indidate the label showed of the ability in recent missions. 642 * @return Returns ERR_OK on success, others on failure. 643 */ 644 ErrCode SetMissionLabel(const sptr<IRemoteObject> &abilityToken, const std::string &label); 645 646 /** 647 * Set mission icon of this ability. 648 * 649 * @param abilityToken Indidate token of ability. 650 * @param icon Indidate the icon showed of the ability in recent missions. 651 * @return Returns ERR_OK on success, others on failure. 652 */ 653 ErrCode SetMissionIcon(const sptr<IRemoteObject> &abilityToken, 654 const std::shared_ptr<OHOS::Media::PixelMap> &icon); 655 656 /** 657 * Register the WindowManagerService handler 658 * 659 * @param handler Indidate handler of WindowManagerService. 660 * @return ErrCode Returns ERR_OK on success, others on failure. 661 */ 662 ErrCode RegisterWindowManagerServiceHandler(const sptr<IWindowManagerServiceHandler>& handler); 663 664 /** 665 * WindowManager notification AbilityManager after the first frame is drawn. 666 * 667 * @param abilityToken Indidate token of ability. 668 */ 669 void CompleteFirstFrameDrawing(const sptr<IRemoteObject> &abilityToken); 670 #endif 671 672 /** 673 * @brief start user test. 674 * @param want the want of the ability user test to start. 675 * @param observer test observer callback. 676 * 677 * @return Returns ERR_OK on success, others on failure. 678 */ 679 ErrCode StartUserTest(const Want &want, const sptr<IRemoteObject> &observer); 680 681 /** 682 * @brief Finish user test. 683 * @param msg user test message. 684 * @param resultCode user test result Code. 685 * @param bundleName user test bundleName. 686 * 687 * @return Returns ERR_OK on success, others on failure. 688 */ 689 ErrCode FinishUserTest(const std::string &msg, const int64_t &resultCode, const std::string &bundleName); 690 691 /** 692 * GetTopAbility, get the token of top ability. 693 * 694 * @param token, the token of top ability. 695 * @return Returns ERR_OK on success, others on failure. 696 */ 697 ErrCode GetTopAbility(sptr<IRemoteObject> &token); 698 699 /** 700 * DelegatorDoAbilityForeground, the delegator calls this interface to move the ability to the foreground. 701 * 702 * @param token, ability's token. 703 * @return Returns ERR_OK on success, others on failure. 704 */ 705 ErrCode DelegatorDoAbilityForeground(const sptr<IRemoteObject> &token); 706 707 /** 708 * DelegatorDoAbilityBackground, the delegator calls this interface to move the ability to the background. 709 * 710 * @param token, ability's token. 711 * @return Returns ERR_OK on success, others on failure. 712 */ 713 ErrCode DelegatorDoAbilityBackground(const sptr<IRemoteObject> &token); 714 715 /** 716 * Calls this interface to move the ability to the foreground. 717 * 718 * @param token, ability's token. 719 * @param flag, use for lock or unlock flag and so on. 720 * @return Returns ERR_OK on success, others on failure. 721 */ 722 ErrCode DoAbilityForeground(const sptr<IRemoteObject> &token, uint32_t flag); 723 724 /** 725 * Calls this interface to move the ability to the background. 726 * 727 * @param token, ability's token. 728 * @param flag, use for lock or unlock flag and so on. 729 * @return Returns ERR_OK on success, others on failure. 730 */ 731 ErrCode DoAbilityBackground(const sptr<IRemoteObject> &token, uint32_t flag); 732 733 /** 734 * Set ability controller. 735 * 736 * @param abilityController, The ability controller. 737 * @return Returns ERR_OK on success, others on failure. 738 */ 739 virtual int SetAbilityController(const sptr<AppExecFwk::IAbilityController> &abilityController, 740 bool imAStabilityTest); 741 742 /** 743 * Send not response process ID to ability manager service. 744 * 745 * @param pid The not response process ID. 746 * @return Returns ERR_OK on success, others on failure. 747 */ 748 ErrCode SendANRProcessID(int pid); 749 750 #ifdef ABILITY_COMMAND_FOR_TEST 751 /** 752 * Block ability manager service. 753 * 754 * @return Returns ERR_OK on success, others on failure. 755 */ 756 ErrCode BlockAmsService(); 757 758 /** 759 * Block ability. 760 * 761 * @param abilityRecordId The Ability Record Id. 762 * @return Returns ERR_OK on success, others on failure. 763 */ 764 ErrCode BlockAbility(int32_t abilityRecordId); 765 766 /** 767 * Block app service. 768 * 769 * @return Returns ERR_OK on success, others on failure. 770 */ 771 ErrCode BlockAppService(); 772 #endif 773 774 /** 775 * Free install ability from remote DMS. 776 * 777 * @param want Ability want. 778 * @param callback Callback used to notify free install result. 779 * @param userId User ID. 780 * @param requestCode Ability request code. 781 * @return Returns ERR_OK on success, others on failure. 782 */ 783 ErrCode FreeInstallAbilityFromRemote(const Want &want, const sptr<IRemoteObject> &callback, int32_t userId, 784 int requestCode = DEFAULT_INVAL_VALUE); 785 786 /** 787 * Called when client complete dump. 788 * 789 * @param infos The dump info. 790 * @param callerToken The caller ability token. 791 * @return Returns ERR_OK on success, others on failure. 792 */ 793 ErrCode DumpAbilityInfoDone(std::vector<std::string> &infos, const sptr<IRemoteObject> &callerToken); 794 795 /** 796 * Called to update mission snapshot. 797 * @param token The target ability. 798 */ 799 void UpdateMissionSnapShot(const sptr<IRemoteObject>& token); 800 void EnableRecoverAbility(const sptr<IRemoteObject>& token); 801 void ScheduleRecoverAbility(const sptr<IRemoteObject> &token, int32_t reason); 802 private: 803 class AbilityMgrDeathRecipient : public IRemoteObject::DeathRecipient { 804 public: 805 AbilityMgrDeathRecipient() = default; 806 ~AbilityMgrDeathRecipient() = default; 807 void OnRemoteDied(const wptr<IRemoteObject>& remote) override; 808 private: 809 DISALLOW_COPY_AND_MOVE(AbilityMgrDeathRecipient); 810 }; 811 812 sptr<IAbilityManager> GetAbilityManager(); 813 void ResetProxy(const wptr<IRemoteObject>& remote); 814 void HandleDlpApp(Want &want); 815 816 static std::recursive_mutex mutex_; 817 static std::shared_ptr<AbilityManagerClient> instance_; 818 sptr<IAbilityManager> proxy_; 819 sptr<IRemoteObject::DeathRecipient> deathRecipient_; 820 }; 821 } // namespace AAFwk 822 } // namespace OHOS 823 #endif // OHOS_ABILITY_RUNTIME_ABILITY_MANAGER_CLIENT_H 824