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 OHOS_AAFWK_ABILITY_MANAGER_INTERFACE_H 17 #define OHOS_AAFWK_ABILITY_MANAGER_INTERFACE_H 18 19 #include <vector> 20 21 #include <ipc_types.h> 22 #include <iremote_broker.h> 23 24 #include "ability_connect_callback_interface.h" 25 #include "ability_scheduler_interface.h" 26 #include "ability_start_setting.h" 27 #include "mission_snapshot_info.h" 28 #include "ability_mission_info.h" 29 #include "mission_option.h" 30 #include "stack_info.h" 31 #include "stack_setting.h" 32 #include "uri.h" 33 #include "want.h" 34 #include "want_sender_info.h" 35 #include "sender_info.h" 36 #include "want_sender_interface.h" 37 #include "want_receiver_interface.h" 38 #include "aafwk_dummy_configuration.h" 39 40 namespace OHOS { 41 namespace AAFwk { 42 const std::string ABILITY_MANAGER_SERVICE_NAME = "AbilityManagerService"; 43 const int DEFAULT_INVAL_VALUE = -1; 44 /** 45 * @class IAbilityManager 46 * IAbilityManager interface is used to access ability manager services. 47 */ 48 class IAbilityManager : public OHOS::IRemoteBroker { 49 public: 50 DECLARE_INTERFACE_DESCRIPTOR(u"ohos.aafwk.AbilityManager") 51 52 /** 53 * StartAbility with want, send want to ability manager service. 54 * 55 * @param want, the want of the ability to start. 56 * @param requestCode, Ability request code. 57 * @return Returns ERR_OK on success, others on failure. 58 */ 59 virtual int StartAbility(const Want &want, int requestCode = DEFAULT_INVAL_VALUE) = 0; 60 61 /** 62 * StartAbility with want, send want to ability manager service. 63 * 64 * @param want, the want of the ability to start. 65 * @param callerToken, caller ability token. 66 * @param requestCode, Ability request code. 67 * @return Returns ERR_OK on success, others on failure. 68 */ 69 virtual int StartAbility( 70 const Want &want, const sptr<IRemoteObject> &callerToken, int requestCode = DEFAULT_INVAL_VALUE) = 0; 71 72 /** 73 * Starts a new ability with specific start settings. 74 * 75 * @param want Indicates the ability to start. 76 * @param requestCode the resultCode of the ability to start. 77 * @param abilityStartSetting Indicates the setting ability used to start. 78 * @return Returns ERR_OK on success, others on failure. 79 */ 80 virtual int StartAbility(const Want &want, const AbilityStartSetting &abilityStartSetting, 81 const sptr<IRemoteObject> &callerToken, int requestCode = DEFAULT_INVAL_VALUE) = 0; 82 83 /** 84 * TerminateAbility, terminate the special ability. 85 * 86 * @param token, the token of the ability to terminate. 87 * @param resultCode, the resultCode of the ability to terminate. 88 * @param resultWant, the Want of the ability to return. 89 * @return Returns ERR_OK on success, others on failure. 90 */ 91 virtual int TerminateAbility( 92 const sptr<IRemoteObject> &token, int resultCode, const Want *resultWant = nullptr) = 0; 93 94 /** 95 * TerminateAbility, terminate the special ability. 96 * 97 * @param callerToken, caller ability token. 98 * @param requestCode, Ability request code. 99 * @return Returns ERR_OK on success, others on failure. 100 */ 101 virtual int TerminateAbilityByCaller(const sptr<IRemoteObject> &callerToken, int requestCode) = 0; 102 103 /** 104 * ConnectAbility, connect session with service ability. 105 * 106 * @param want, Special want for service type's ability. 107 * @param connect, Callback used to notify caller the result of connecting or disconnecting. 108 * @param callerToken, caller ability token. 109 * @return Returns ERR_OK on success, others on failure. 110 */ 111 virtual int ConnectAbility( 112 const Want &want, const sptr<IAbilityConnection> &connect, const sptr<IRemoteObject> &callerToken) = 0; 113 114 /** 115 * DisconnectAbility, disconnect session with service ability. 116 * 117 * @param connect, Callback used to notify caller the result of connecting or disconnecting. 118 * @return Returns ERR_OK on success, others on failure. 119 */ 120 virtual int DisconnectAbility(const sptr<IAbilityConnection> &connect) = 0; 121 122 /** 123 * AcquireDataAbility, acquire a data ability by its authority, if it not existed, 124 * AMS loads it synchronously. 125 * 126 * @param authority, a string to identify a data ability, decoded from uri. 127 * @param tryBind, true: when a data ability is died, ams will kill this client, or do nothing. 128 * @param callerToken, specifies the caller ability token. 129 * @return returns the data ability ipc object, or nullptr for failed. 130 */ 131 virtual sptr<IAbilityScheduler> AcquireDataAbility( 132 const Uri &uri, bool tryBind, const sptr<IRemoteObject> &callerToken) = 0; 133 134 /** 135 * ReleaseDataAbility, release the data ability that referenced by 'dataAbilityToken'. 136 * 137 * @param dataAbilityScheduler, specifies the data ability that will be released. 138 * @param callerToken, specifies the caller ability token. 139 * @return returns ERR_OK if succeeded, or error codes for failed. 140 */ 141 virtual int ReleaseDataAbility( 142 sptr<IAbilityScheduler> dataAbilityScheduler, const sptr<IRemoteObject> &callerToken) = 0; 143 144 /** 145 * AddWindowInfo, add windowToken to AbilityRecord. 146 * 147 * @param token, the token of the ability. 148 * @param windowToken, window id of the ability. 149 */ 150 virtual void AddWindowInfo(const sptr<IRemoteObject> &token, int32_t windowToken) = 0; 151 152 /** 153 * AttachAbilityThread, ability call this interface after loaded. 154 * 155 * @param scheduler,.the interface handler of kit ability. 156 * @param token,.ability's token. 157 * @return Returns ERR_OK on success, others on failure. 158 */ 159 virtual int AttachAbilityThread(const sptr<IAbilityScheduler> &scheduler, const sptr<IRemoteObject> &token) = 0; 160 161 /** 162 * AbilityTransitionDone, ability call this interface after lift cycle was changed. 163 * 164 * @param token,.ability's token. 165 * @param state,.the state of ability lift cycle. 166 * @return Returns ERR_OK on success, others on failure. 167 */ 168 virtual int AbilityTransitionDone(const sptr<IRemoteObject> &token, int state) = 0; 169 170 /** 171 * ScheduleConnectAbilityDone, service ability call this interface while session was connected. 172 * 173 * @param token,.service ability's token. 174 * @param remoteObject,.the session proxy of service ability. 175 * @return Returns ERR_OK on success, others on failure. 176 */ 177 virtual int ScheduleConnectAbilityDone( 178 const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &remoteObject) = 0; 179 180 /** 181 * ScheduleDisconnectAbilityDone, service ability call this interface while session was disconnected. 182 * 183 * @param token,.service ability's token. 184 * @return Returns ERR_OK on success, others on failure. 185 */ 186 virtual int ScheduleDisconnectAbilityDone(const sptr<IRemoteObject> &token) = 0; 187 188 /** 189 * ScheduleCommandAbilityDone, service ability call this interface while session was commanded. 190 * 191 * @param token,.service ability's token. 192 * @return Returns ERR_OK on success, others on failure. 193 */ 194 virtual int ScheduleCommandAbilityDone(const sptr<IRemoteObject> &token) = 0; 195 196 /** 197 * dump ability stack info, about userID, mission stack info, 198 * mission record info and ability info. 199 * 200 * @param state Ability stack info. 201 * @return Returns ERR_OK on success, others on failure. 202 */ 203 virtual void DumpState(const std::string &args, std::vector<std::string> &state) = 0; 204 205 /** 206 * Destroys this Service ability if the number of times it 207 * has been started equals the number represented by 208 * the given startId. 209 * 210 * @param token ability's token. 211 * @param startId is incremented by 1 every time this ability is started. 212 * @return Returns true if the startId matches the number of startup times 213 * and this Service ability will be destroyed; returns false otherwise. 214 */ 215 virtual int TerminateAbilityResult(const sptr<IRemoteObject> &token, int startId) = 0; 216 217 /** 218 * Destroys this Service ability by Want. 219 * 220 * @param want, Special want for service type's ability. 221 * @return Returns true if this Service ability will be destroyed; returns false otherwise. 222 */ 223 virtual int StopServiceAbility(const Want &want) = 0; 224 225 /** 226 * Obtains information about ability stack that are running on the device. 227 * 228 * @param stackInfo Ability stack info. 229 * @return Returns ERR_OK on success, others on failure. 230 */ 231 virtual int GetAllStackInfo(StackInfo &stackInfo) = 0; 232 233 /** 234 * Get the list of the missions that the user has recently launched, 235 * with the most recent being first and older ones after in order. 236 * 237 * @param recentList recent mission info 238 * @param numMax The maximum number of entries to return in the list. The 239 * actual number returned may be smaller, depending on how many tasks the 240 * user has started and the maximum number the system can remember. 241 * @param falgs Information about what to return. May be any combination 242 * of {@link #RECENT_WITH_EXCLUDED} and {@link #RECENT_IGNORE_UNAVAILABLE}. 243 * @return Returns ERR_OK on success, others on failure. 244 */ 245 virtual int GetRecentMissions( 246 const int32_t numMax, const int32_t flags, std::vector<AbilityMissionInfo> &recentList) = 0; 247 248 /** 249 * Get mission snapshot by mission id 250 * 251 * @param missionId the id of the mission to retrieve the sAutoapshots 252 * @return Returns ERR_OK on success, others on failure. 253 */ 254 virtual int GetMissionSnapshot(const int32_t missionId, MissionSnapshotInfo &snapshot) = 0; 255 256 /** 257 * Ask that the mission associated with a given mission ID be moved to the 258 * front of the stack, so it is now visible to the user. 259 * 260 * @param missionId. 261 * @return Returns ERR_OK on success, others on failure. 262 */ 263 virtual int MoveMissionToTop(int32_t missionId) = 0; 264 265 /** 266 * Requires that tasks associated with a given capability token be moved to the background 267 * 268 * @param token ability token 269 * @param nonFirst If nonfirst is false and not the lowest ability of the mission, you cannot move mission to end 270 * @return Returns ERR_OK on success, others on failure. 271 */ 272 virtual int MoveMissionToEnd(const sptr<IRemoteObject> &token, const bool nonFirst) = 0; 273 274 /** 275 * Remove the specified mission from the stack by missionid 276 * 277 * @param id. 278 * @return Returns ERR_OK on success, others on failure. 279 */ 280 virtual int RemoveMission(int id) = 0; 281 282 /** 283 * Remove the specified mission stack by stack id 284 * 285 * @param id. 286 * @return Returns ERR_OK on success, others on failure. 287 */ 288 virtual int RemoveStack(int id) = 0; 289 290 /** 291 * Kill the process immediately. 292 * 293 * @param bundleName. 294 * @return Returns ERR_OK on success, others on failure. 295 */ 296 virtual int KillProcess(const std::string &bundleName) = 0; 297 298 /** 299 * Uninstall app 300 * 301 * @param bundleName. 302 * @return Returns ERR_OK on success, others on failure. 303 */ 304 virtual int UninstallApp(const std::string &bundleName) = 0; 305 306 /** 307 * Moving mission to the specified stack by mission option(Enter floating window mode). 308 * @param missionOption, target mission option 309 * @return Returns ERR_OK on success, others on failure. 310 */ 311 virtual int MoveMissionToFloatingStack(const MissionOption &missionOption) = 0; 312 313 /** 314 * Moving mission to the specified stack by mission option(Enter floating window mode). 315 * @param missionOption, target mission option 316 * @return Returns ERR_OK on success, others on failure. 317 */ 318 virtual int MoveMissionToSplitScreenStack(const MissionOption &missionOption) = 0; 319 320 /** 321 * Change the focus of ability in the mission stack. 322 * @param lostToken, the token of lost focus ability 323 * @param getToken, the token of get focus ability 324 * @return Returns ERR_OK on success, others on failure. 325 */ 326 virtual int ChangeFocusAbility( 327 const sptr<IRemoteObject> &lostFocusToken, const sptr<IRemoteObject> &getFocusToken) = 0; 328 329 /** 330 * minimize multiwindow by mission id. 331 * @param missionId, the id of target mission 332 * @return Returns ERR_OK on success, others on failure. 333 */ 334 virtual int MinimizeMultiWindow(int missionId) = 0; 335 336 /** 337 * maximize multiwindow by mission id. 338 * @param missionId, the id of target mission 339 * @return Returns ERR_OK on success, others on failure. 340 */ 341 virtual int MaximizeMultiWindow(int missionId) = 0; 342 343 /** 344 * get missions info of floating mission stack. 345 * @param list, mission info. 346 * @return Returns ERR_OK on success, others on failure. 347 */ 348 virtual int GetFloatingMissions(std::vector<AbilityMissionInfo> &list) = 0; 349 350 /** 351 * close multiwindow by mission id. 352 * @param missionId, the id of target mission. 353 * @return Returns ERR_OK on success, others on failure. 354 */ 355 virtual int CloseMultiWindow(int missionId) = 0; 356 357 /** 358 * set special mission stack default settings. 359 * @param stackSetting, mission stack default settings. 360 * @return Returns ERR_OK on success, others on failure. 361 */ 362 virtual int SetMissionStackSetting(const StackSetting &stackSetting) = 0; 363 364 /** Checks whether this ability is the first ability in a mission. 365 * @param lostToken, the token of ability 366 * @return Returns true is first in Mission. 367 */ 368 virtual bool IsFirstInMission(const sptr<IRemoteObject> &token) = 0; 369 370 /** 371 * Checks whether a specified permission has been granted to the process identified by pid and uid 372 * 373 * @param permission Indicates the permission to check. 374 * @param pid Indicates the ID of the process to check. 375 * @param uid Indicates the UID of the process to check. 376 * @param message Describe success or failure 377 * 378 * @return Returns ERR_OK on success, others on failure. 379 */ 380 virtual int CompelVerifyPermission(const std::string &permission, int pid, int uid, std::string &message) = 0; 381 382 /** 383 * Save the top ability States and move them to the background 384 * @return Returns ERR_OK on success, others on failure. 385 */ 386 virtual int PowerOff() = 0; 387 388 /** 389 * Restore the state before top ability poweroff 390 * @return Returns ERR_OK on success, others on failure. 391 */ 392 virtual int PowerOn() = 0; 393 394 /** 395 * Sets the application to start its ability in lock mission mode. 396 * @param missionId luck mission id 397 * @return Returns ERR_OK on success, others on failure. 398 */ 399 virtual int LockMission(int missionId) = 0; 400 401 /** 402 * Unlocks this ability by exiting the lock mission mode. 403 * @param missionId unluck mission id 404 * @return Returns ERR_OK on success, others on failure. 405 */ 406 virtual int UnlockMission(int missionId) = 0; 407 408 /** 409 * Sets description information about the mission containing this ability. 410 * 411 * @param description Indicates the object containing information about the 412 * mission. This parameter cannot be null. 413 * @return Returns ERR_OK on success, others on failure. 414 */ 415 virtual int SetMissionDescriptionInfo( 416 const sptr<IRemoteObject> &token, const MissionDescriptionInfo &description) = 0; 417 418 /** 419 * get current system mission lock mode state. 420 * 421 * @return Returns 0: LOCK_MISSION_STATE_NONE, 1: LOCK_MISSION_STATE_LOCKED 422 */ 423 virtual int GetMissionLockModeState() = 0; 424 425 /** 426 * Updates the configuration by modifying the configuration. 427 * 428 * @param config Indicates the new configuration 429 * @return Returns ERR_OK on success, others on failure. 430 */ 431 virtual int UpdateConfiguration(const DummyConfiguration &config) = 0; 432 433 virtual sptr<IWantSender> GetWantSender( 434 const WantSenderInfo &wantSenderInfo, const sptr<IRemoteObject> &callerToken) = 0; 435 436 virtual int SendWantSender(const sptr<IWantSender> &target, const SenderInfo &senderInfo) = 0; 437 438 virtual void CancelWantSender(const sptr<IWantSender> &sender) = 0; 439 440 virtual int GetPendingWantUid(const sptr<IWantSender> &target) = 0; 441 442 virtual int GetPendingWantUserId(const sptr<IWantSender> &target) = 0; 443 444 virtual std::string GetPendingWantBundleName(const sptr<IWantSender> &target) = 0; 445 446 virtual int GetPendingWantCode(const sptr<IWantSender> &target) = 0; 447 448 virtual int GetPendingWantType(const sptr<IWantSender> &target) = 0; 449 450 virtual void RegisterCancelListener(const sptr<IWantSender> &sender, const sptr<IWantReceiver> &receiver) = 0; 451 452 virtual void UnregisterCancelListener(const sptr<IWantSender> &sender, const sptr<IWantReceiver> &receiver) = 0; 453 454 virtual int GetPendingRequestWant(const sptr<IWantSender> &target, std::shared_ptr<Want> &want) = 0; 455 456 enum { 457 // ipc id 1-1000 for kit 458 // ipc id for terminating ability (1) 459 TERMINATE_ABILITY = 1, 460 461 // ipc id for attaching ability thread (2) 462 ATTACH_ABILITY_THREAD, 463 464 // ipc id for ability transition done (3) 465 ABILITY_TRANSITION_DONE, 466 467 // ipc id for connecting ability done (4) 468 CONNECT_ABILITY_DONE, 469 470 // ipc id for disconnecting ability done (5) 471 DISCONNECT_ABILITY_DONE, 472 473 // ipc id for add window token (6) 474 ADD_WINDOW_INFO, 475 476 // ipc id for terminating ability for result (7) 477 TERMINATE_ABILITY_RESULT, 478 479 // ipc id for list stack info (8) 480 LIST_STACK_INFO, 481 482 // ipc id for get recent mission (9) 483 GET_RECENT_MISSION, 484 485 // ipc id for removing mission (10) 486 REMOVE_MISSION, 487 488 // ipc id for removing mission (11) 489 REMOVE_STACK, 490 491 // ipc id for removing mission (12) 492 COMMAND_ABILITY_DONE, 493 494 // ipc id for get mission snapshot (13) 495 GET_MISSION_SNAPSHOT, 496 497 // ipc id for acquire data ability (14) 498 ACQUIRE_DATA_ABILITY, 499 500 // ipc id for release data ability (15) 501 RELEASE_DATA_ABILITY, 502 503 // ipc id for move mission to top (16) 504 MOVE_MISSION_TO_TOP, 505 506 // ipc id for kill process (17) 507 KILL_PROCESS, 508 509 // ipc id for uninstall app (18) 510 UNINSTALL_APP, 511 512 // ipc id for terminate ability by callerToken and request code (19) 513 TERMINATE_ABILITY_BY_CALLER, 514 515 // ipc id for move mission to floating stack (20) 516 MOVE_MISSION_TO_FLOATING_STACK, 517 518 // ipc id for move mission to floating stack (21) 519 MOVE_MISSION_TO_SPLITSCREEN_STACK, 520 521 // ipc id for change focus ability (22) 522 CHANGE_FOCUS_ABILITY, 523 524 // ipc id for Minimize MultiWindow (23) 525 MINIMIZE_MULTI_WINDOW, 526 527 // ipc id for Maximize MultiWindow (24) 528 MAXIMIZE_MULTI_WINDOW, 529 530 // ipc id for get floating missions (25) 531 GET_FLOATING_MISSIONS, 532 533 // ipc id for get floating missions (26) 534 CLOSE_MULTI_WINDOW, 535 536 // ipc id for set mission stack setting (27) 537 SET_STACK_SETTING, 538 539 // ipc id for isfirstinmission app (28) 540 IS_FIRST_IN_MISSION, 541 542 // ipc id for move mission to end (29) 543 MOVE_MISSION_TO_END, 544 545 // ipc id for compel verify permission (30) 546 COMPEL_VERIFY_PERMISSION, 547 548 // ipc id for power off (31) 549 POWER_OFF, 550 551 // ipc id for power off (32) 552 POWER_ON, 553 554 // ipc id for luck mission (33) 555 LUCK_MISSION, 556 557 // ipc id for unluck mission (34) 558 UNLUCK_MISSION, 559 560 // ipc id for set mission info (35) 561 SET_MISSION_INFO, 562 563 // ipc id for get mission lock mode state (36) 564 GET_MISSION_LOCK_MODE_STATE, 565 566 // ipc id for update configuration (37) 567 UPDATE_CONFIGURATION, 568 569 // ipc id 1001-2000 for DMS 570 // ipc id for starting ability (1001) 571 START_ABILITY = 1001, 572 573 // ipc id for connecting ability (1002) 574 CONNECT_ABILITY, 575 576 // ipc id for disconnecting ability (1003) 577 DISCONNECT_ABILITY, 578 579 // ipc id for disconnecting ability (1004) 580 STOP_SERVICE_ABILITY, 581 582 // ipc id for starting ability by caller(1005) 583 START_ABILITY_ADD_CALLER, 584 585 GET_PENDING_WANT_SENDER, 586 587 SEND_PENDING_WANT_SENDER, 588 589 CANCEL_PENDING_WANT_SENDER, 590 591 GET_PENDING_WANT_UID, 592 593 GET_PENDING_WANT_BUNDLENAME, 594 595 GET_PENDING_WANT_USERID, 596 597 GET_PENDING_WANT_TYPE, 598 599 GET_PENDING_WANT_CODE, 600 601 REGISTER_CANCEL_LISTENER, 602 603 UNREGISTER_CANCEL_LISTENER, 604 605 GET_PENDING_REQUEST_WANT, 606 607 // ipc id for starting ability by settings(1006) 608 START_ABILITY_FOR_SETTINGS, 609 610 // ipc id 2001-3000 for tools 611 // ipc id for dumping state (2001) 612 DUMP_STATE = 2001, 613 }; 614 }; 615 } // namespace AAFwk 616 } // namespace OHOS 617 #endif // OHOS_AAFWK_ABILITY_MANAGER_INTERFACE_H 618