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_ABILITY_MANAGER_SERVICE_H 17 #define OHOS_ABILITY_RUNTIME_ABILITY_MANAGER_SERVICE_H 18 19 #include <future> 20 #include <memory> 21 #include <shared_mutex> 22 #include <singleton.h> 23 #include <thread_ex.h> 24 #include <unordered_map> 25 #include <map> 26 27 #include "ability_bundle_event_callback.h" 28 #include "ability_connect_manager.h" 29 #include "task_handler_wrap.h" 30 #include "ability_event_handler.h" 31 #include "ability_interceptor_executer.h" 32 #include "ability_manager_stub.h" 33 #include "app_mgr_interface.h" 34 #include "app_scheduler.h" 35 #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE 36 #include "background_task_observer.h" 37 #endif 38 #include "bundlemgr/bundle_mgr_interface.h" 39 #include "bundle_constants.h" 40 #include "data_ability_manager.h" 41 #include "free_install_manager.h" 42 #include "hilog_wrapper.h" 43 #include "iremote_object.h" 44 #include "mission_list_manager.h" 45 #include "permission_verification.h" 46 #include "system_ability.h" 47 #include "uri.h" 48 #include "ability_config.h" 49 #include "parameter.h" 50 #include "pending_want_manager.h" 51 #include "ams_configuration_parameter.h" 52 #include "scene_board/ui_ability_lifecycle_manager.h" 53 #include "user_controller.h" 54 #include "resident_process_manager.h" 55 #include "start_ability_handler.h" 56 #ifdef SUPPORT_GRAPHICS 57 #include "implicit_start_processor.h" 58 #include "system_dialog_scheduler.h" 59 #include "window_focus_changed_listener.h" 60 #endif 61 #include "event_report.h" 62 #include "iacquire_share_data_callback_interface.h" 63 64 namespace OHOS { 65 namespace AAFwk { 66 enum class ServiceRunningState { STATE_NOT_START, STATE_RUNNING }; 67 constexpr int32_t BASE_USER_RANGE = 200000; 68 constexpr int32_t U0_USER_ID = 0; 69 constexpr int32_t INVALID_USER_ID = -1; 70 using OHOS::AppExecFwk::IAbilityController; 71 class PendingWantManager; 72 /** 73 * @class AbilityManagerService 74 * AbilityManagerService provides a facility for managing ability life cycle. 75 */ 76 class AbilityManagerService : public SystemAbility, 77 public AbilityManagerStub, 78 public AppStateCallback, 79 public std::enable_shared_from_this<AbilityManagerService> { 80 DECLARE_DELAYED_SINGLETON(AbilityManagerService) 81 DECLEAR_SYSTEM_ABILITY(AbilityManagerService) 82 public: 83 void OnStart() override; 84 void OnStop() override; 85 86 virtual void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 87 88 virtual void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 89 90 ServiceRunningState QueryServiceState() const; 91 92 /** 93 * StartAbility with want, send want to ability manager service. 94 * 95 * @param want, the want of the ability to start. 96 * @param requestCode, Ability request code. 97 * @param userId, Designation User ID. 98 * @return Returns ERR_OK on success, others on failure. 99 */ 100 virtual int StartAbility( 101 const Want &want, int32_t userId = DEFAULT_INVAL_VALUE, int requestCode = DEFAULT_INVAL_VALUE) override; 102 103 /** 104 * StartAbility with want, send want to ability manager service. 105 * 106 * @param want, the want of the ability to start. 107 * @param callerToken, caller ability token. 108 * @param userId, Designation User ID. 109 * @param requestCode the resultCode of the ability to start. 110 * @return Returns ERR_OK on success, others on failure. 111 */ 112 virtual int StartAbility( 113 const Want &want, 114 const sptr<IRemoteObject> &callerToken, 115 int32_t userId = DEFAULT_INVAL_VALUE, 116 int requestCode = DEFAULT_INVAL_VALUE) override; 117 118 /** 119 * Starts a new ability with specific start settings. 120 * 121 * @param want Indicates the ability to start. 122 * @param abilityStartSetting Indicates the setting ability used to start. 123 * @param callerToken, caller ability token. 124 * @param userId, Designation User ID. 125 * @param requestCode the resultCode of the ability to start. 126 * @return Returns ERR_OK on success, others on failure. 127 */ 128 virtual int StartAbility( 129 const Want &want, 130 const AbilityStartSetting &abilityStartSetting, 131 const sptr<IRemoteObject> &callerToken, 132 int32_t userId = DEFAULT_INVAL_VALUE, 133 int requestCode = DEFAULT_INVAL_VALUE) override; 134 135 /** 136 * Starts a new ability with specific start options. 137 * 138 * @param want the want of the ability to start. 139 * @param startOptions Indicates the options used to start. 140 * @param callerToken caller ability token. 141 * @param userId Designation User ID. 142 * @param requestCode the resultCode of the ability to start. 143 * @return Returns ERR_OK on success, others on failure. 144 */ 145 virtual int StartAbility( 146 const Want &want, 147 const StartOptions &startOptions, 148 const sptr<IRemoteObject> &callerToken, 149 int32_t userId = DEFAULT_INVAL_VALUE, 150 int requestCode = DEFAULT_INVAL_VALUE) override; 151 152 /** 153 * Starts a new ability using the original caller information. 154 * 155 * @param want the want of the ability to start. 156 * @param callerToken caller ability token. 157 * @param userId Designation User ID. 158 * @param requestCode the resultCode of the ability to start. 159 * @return Returns ERR_OK on success, others on failure. 160 */ 161 virtual int StartAbilityAsCaller( 162 const Want &want, 163 const sptr<IRemoteObject> &callerToken, 164 int32_t userId = DEFAULT_INVAL_VALUE, 165 int requestCode = DEFAULT_INVAL_VALUE) override; 166 167 /** 168 * Starts a new ability using the original caller information. 169 * 170 * @param want the want of the ability to start. 171 * @param startOptions Indicates the options used to start. 172 * @param callerToken caller ability token. 173 * @param userId Designation User ID. 174 * @param requestCode the resultCode of the ability to start. 175 * @return Returns ERR_OK on success, others on failure. 176 */ 177 virtual int StartAbilityAsCaller( 178 const Want &want, 179 const StartOptions &startOptions, 180 const sptr<IRemoteObject> &callerToken, 181 int32_t userId = DEFAULT_INVAL_VALUE, 182 int requestCode = DEFAULT_INVAL_VALUE) override; 183 184 /** 185 * Start ui session ability with extension session info, send session info to ability manager service. 186 * 187 * @param want, the want of the ability to start. 188 * @param callerToken, caller ability token. 189 * @param sessionInfo the information of UIExtensionContentSession. 190 * @param userId, Designation User ID. 191 * @param requestCode, Ability request code. 192 * @return Returns ERR_OK on success, others on failure. 193 */ 194 virtual int StartAbilityByUIContentSession( 195 const Want &want, 196 const sptr<IRemoteObject> &callerToken, 197 const sptr<SessionInfo> &sessionInfo, 198 int32_t userId, 199 int requestCode) override; 200 201 /** 202 * Start ui session ability with extension session info, send session info to ability manager service. 203 * 204 * @param want, the want of the ability to start. 205 * @param startOptions Indicates the options used to start. 206 * @param callerToken, caller ability token. 207 * @param sessionInfo the information of UIExtensionContentSession. 208 * @param userId, Designation User ID. 209 * @param requestCode the resultCode of the ability to start. 210 * @return Returns ERR_OK on success, others on failure. 211 */ 212 virtual int StartAbilityByUIContentSession( 213 const Want &want, 214 const StartOptions &startOptions, 215 const sptr<IRemoteObject> &callerToken, 216 const sptr<SessionInfo> &sessionInfo, 217 int32_t userId, 218 int requestCode) override; 219 220 /** 221 * Start extension ability with want, send want to ability manager service. 222 * 223 * @param want, the want of the ability to start. 224 * @param callerToken, caller ability token. 225 * @param userId, Designation User ID. 226 * @param extensionType If an ExtensionAbilityType is set, only extension of that type can be started. 227 * @return Returns ERR_OK on success, others on failure. 228 */ 229 virtual int StartExtensionAbility( 230 const Want &want, 231 const sptr<IRemoteObject> &callerToken, 232 int32_t userId = DEFAULT_INVAL_VALUE, 233 AppExecFwk::ExtensionAbilityType extensionType = AppExecFwk::ExtensionAbilityType::UNSPECIFIED) override; 234 235 /** 236 * Start ui extension ability with extension session info, send extension session info to ability manager service. 237 * 238 * @param extensionSessionInfo the extension session info of the ability to start. 239 * @param userId, Designation User ID. 240 * @return Returns ERR_OK on success, others on failure. 241 */ 242 virtual int StartUIExtensionAbility( 243 const sptr<SessionInfo> &extensionSessionInfo, 244 int32_t userId = DEFAULT_INVAL_VALUE) override; 245 246 /** 247 * Start ui ability with want, send want to ability manager service. 248 * 249 * @param sessionInfo the session info of the ability to start. 250 * @return Returns ERR_OK on success, others on failure. 251 */ 252 virtual int StartUIAbilityBySCB(sptr<SessionInfo> sessionInfo) override; 253 254 /** 255 * Stop extension ability with want, send want to ability manager service. 256 * 257 * @param want, the want of the ability to stop. 258 * @param callerToken, caller ability token. 259 * @param userId, Designation User ID. 260 * @param extensionType If an ExtensionAbilityType is set, only extension of that type can be stopped. 261 * @return Returns ERR_OK on success, others on failure. 262 */ 263 virtual int StopExtensionAbility( 264 const Want& want, 265 const sptr<IRemoteObject>& callerToken, 266 int32_t userId = DEFAULT_INVAL_VALUE, 267 AppExecFwk::ExtensionAbilityType extensionType = AppExecFwk::ExtensionAbilityType::UNSPECIFIED) override; 268 269 /** 270 * TerminateAbility, terminate the special ability. 271 * 272 * @param token, the token of the ability to terminate. 273 * @param resultCode, the resultCode of the ability to terminate. 274 * @param resultWant, the Want of the ability to return. 275 * @return Returns ERR_OK on success, others on failure. 276 */ 277 virtual int TerminateAbility(const sptr<IRemoteObject> &token, int resultCode = DEFAULT_INVAL_VALUE, 278 const Want *resultWant = nullptr) override; 279 280 /** 281 * TerminateAbility, terminate the special ui extension ability. 282 * 283 * @param extensionSessionInfo the extension session info of the ability to terminate. 284 * @param resultCode, the resultCode of the ui extension ability to terminate. 285 * @param resultWant, the Want of the ui extension ability to return. 286 * @return Returns ERR_OK on success, others on failure. 287 */ 288 virtual int TerminateUIExtensionAbility(const sptr<SessionInfo> &extensionSessionInfo, 289 int resultCode = DEFAULT_INVAL_VALUE, const Want *resultWant = nullptr) override; 290 291 /** 292 * CloseUIAbilityBySCB, close the special ability by scb. 293 * 294 * @param sessionInfo the session info of the ability to terminate. 295 * @return Returns ERR_OK on success, others on failure. 296 */ 297 virtual int CloseUIAbilityBySCB(const sptr<SessionInfo> &sessionInfo) override; 298 299 /** 300 * SendResultToAbility with want, return want from ability manager service. 301 * 302 * @param requestCode, request code. 303 * @param resultCode, resultCode to return. 304 * @param resultWant, the Want of the ability to return. 305 * @return Returns ERR_OK on success, others on failure. 306 */ 307 virtual int SendResultToAbility(int32_t requestCode, int32_t resultCode, Want& resultWant) override; 308 309 /** 310 * MoveAbilityToBackground. 311 * 312 * @param token, the token of the ability to move background. 313 * @return Returns ERR_OK on success, others on failure. 314 */ 315 virtual int MoveAbilityToBackground(const sptr<IRemoteObject> &token) override; 316 317 /** 318 * CloseAbility, close the special ability. 319 * 320 * @param token, the token of the ability to terminate. 321 * @param resultCode, the resultCode of the ability to terminate. 322 * @param resultWant, the Want of the ability to return. 323 * @return Returns ERR_OK on success, others on failure. 324 */ 325 virtual int CloseAbility(const sptr<IRemoteObject> &token, int resultCode = DEFAULT_INVAL_VALUE, 326 const Want *resultWant = nullptr) override; 327 328 /** 329 * MinimizeAbility, minimize the special ability. 330 * 331 * @param token, ability token. 332 * @param fromUser mark the minimize operation source. 333 * @return Returns ERR_OK on success, others on failure. 334 */ 335 virtual int MinimizeAbility(const sptr<IRemoteObject> &token, bool fromUser = false) override; 336 337 /** 338 * MinimizeUIExtensionAbility, minimize the special ui extension ability. 339 * 340 * @param extensionSessionInfo the extension session info of the ability to minimize. 341 * @param fromUser mark the minimize operation source. 342 * @return Returns ERR_OK on success, others on failure. 343 */ 344 virtual int MinimizeUIExtensionAbility(const sptr<SessionInfo> &extensionSessionInfo, 345 bool fromUser = false) override; 346 347 /** 348 * MinimizeUIAbilityBySCB, minimize the special ability by scb. 349 * 350 * @param sessionInfo the extension session info of the ability to minimize. 351 * @param fromUser, Whether form user. 352 * @return Returns ERR_OK on success, others on failure. 353 */ 354 virtual int MinimizeUIAbilityBySCB(const sptr<SessionInfo> &sessionInfo, bool fromUser = false) override; 355 356 /** 357 * ConnectAbility, connect session with service ability. 358 * 359 * @param want, Special want for service type's ability. 360 * @param connect, Callback used to notify caller the result of connecting or disconnecting. 361 * @param callerToken, caller ability token. 362 * @param userId, Designation User ID. 363 * @return Returns ERR_OK on success, others on failure. 364 */ 365 virtual int ConnectAbility( 366 const Want &want, 367 const sptr<IAbilityConnection> &connect, 368 const sptr<IRemoteObject> &callerToken, 369 int32_t userId = DEFAULT_INVAL_VALUE) override; 370 371 virtual int ConnectAbilityCommon( 372 const Want &want, 373 const sptr<IAbilityConnection> &connect, 374 const sptr<IRemoteObject> &callerToken, 375 AppExecFwk::ExtensionAbilityType extensionType, 376 int32_t userId = DEFAULT_INVAL_VALUE) override; 377 378 virtual int ConnectUIExtensionAbility( 379 const Want &want, 380 const sptr<IAbilityConnection> &connect, 381 const sptr<SessionInfo> &sessionInfo, 382 int32_t userId = DEFAULT_INVAL_VALUE) override; 383 384 /** 385 * ContinueMission, continue ability from mission center. 386 * 387 * @param srcDeviceId, origin deviceId. 388 * @param dstDeviceId, target deviceId. 389 * @param missionId, indicates which ability to continue. 390 * @param callBack, notify result back. 391 * @param wantParams, extended params. 392 * @return Returns ERR_OK on success, others on failure. 393 */ 394 virtual int ContinueMission(const std::string &srcDeviceId, const std::string &dstDeviceId, 395 int32_t missionId, const sptr<IRemoteObject> &callBack, AAFwk::WantParams &wantParams) override; 396 397 /** 398 * ContinueMission, continue ability from mission center. 399 * 400 * @param srcDeviceId, origin deviceId. 401 * @param dstDeviceId, target deviceId. 402 * @param bundleName, indicates which ability to continue. 403 * @param callBack, notify result back. 404 * @param wantParams, extended params. 405 * @return Returns ERR_OK on success, others on failure. 406 */ 407 virtual int ContinueMission(const std::string &srcDeviceId, const std::string &dstDeviceId, 408 const std::string &bundleName, const sptr<IRemoteObject> &callBack, AAFwk::WantParams &wantParams) override; 409 410 /** 411 * ContinueAbility, continue ability to ability. 412 * 413 * @param deviceId, target deviceId. 414 * @param missionId, indicates which ability to continue. 415 * @param versionCode, target bundle version. 416 * @return Returns ERR_OK on success, others on failure. 417 */ 418 virtual int ContinueAbility(const std::string &deviceId, int32_t missionId, uint32_t versionCode) override; 419 420 /** 421 * StartContinuation, continue ability to remote. 422 * 423 * @param want, Indicates the ability to start. 424 * @param abilityToken, Caller ability token. 425 * @param status, continue status. 426 * @return Returns ERR_OK on success, others on failure. 427 */ 428 virtual int StartContinuation(const Want &want, const sptr<IRemoteObject> &abilityToken, int32_t status) override; 429 430 /** 431 * NotifyCompleteContinuation, notify continuation complete to dms. 432 * @param deviceId, source device which start a continuation. 433 * @param sessionId, represent a continuaion. 434 * @param isSuccess, continuation result. 435 * @return 436 */ 437 virtual void NotifyCompleteContinuation(const std::string &deviceId, int32_t sessionId, bool isSuccess) override; 438 439 /** 440 * NotifyContinuationResult, notify continue result to ability. 441 * 442 * @param missionId, Caller mission id. 443 * @param result, continuation result. 444 * @return Returns ERR_OK on success, others on failure. 445 */ 446 virtual int NotifyContinuationResult(int32_t missionId, int32_t result) override; 447 448 /** 449 * RegisterMissionListener, register remote device mission listener. 450 * 451 * @param deviceId, Indicates the remote device Id. 452 * @param listener, listener. 453 * @return Returns ERR_OK on success, others on failure. 454 */ 455 virtual int RegisterMissionListener(const std::string &deviceId, 456 const sptr<IRemoteMissionListener> &listener) override; 457 458 /** 459 * RegisterOnListener, register on notify mission listener. 460 * 461 * @param type, Indicates the notify type. 462 * @param listener, listener. 463 * @return Returns ERR_OK on success, others on failure. 464 */ 465 virtual int RegisterOnListener(const std::string &type, 466 const sptr<IRemoteOnListener> &listener) override; 467 468 /** 469 * RegisterOffListener, register on notify mission listener. 470 * 471 * @param type, Indicates the notify type. 472 * @param listener, listener. 473 * @return Returns ERR_OK on success, others on failure. 474 */ 475 virtual int RegisterOffListener(const std::string &type, 476 const sptr<IRemoteOnListener> &listener) override; 477 478 /** 479 * UnRegisterMissionListener, unregister remote device mission listener. 480 * 481 * @param deviceId, Indicates the remote device Id. 482 * @param listener, listener. 483 * @return Returns ERR_OK on success, others on failure. 484 */ 485 virtual int UnRegisterMissionListener(const std::string &deviceId, 486 const sptr<IRemoteMissionListener> &listener)override; 487 488 virtual int DisconnectAbility(const sptr<IAbilityConnection> &connect) override; 489 490 /** 491 * AcquireDataAbility, acquire a data ability by its authority, if it not existed, 492 * AMS loads it synchronously. 493 * 494 * @param uri, data ability uri. 495 * @param tryBind, true: when a data ability is died, ams will kill this client, or do nothing. 496 * @param callerToken, specifies the caller ability token. 497 * @return returns the data ability ipc object, or nullptr for failed. 498 */ 499 virtual sptr<IAbilityScheduler> AcquireDataAbility( 500 const Uri &uri, bool tryBind, const sptr<IRemoteObject> &callerToken) override; 501 502 /** 503 * ReleaseDataAbility, release the data ability that referenced by 'dataAbilityToken'. 504 * 505 * @param dataAbilityToken, specifies the data ability that will be released. 506 * @param callerToken, specifies the caller ability token. 507 * @return returns ERR_OK if succeeded, or error codes for failed. 508 */ 509 virtual int ReleaseDataAbility( 510 sptr<IAbilityScheduler> dataAbilityScheduler, const sptr<IRemoteObject> &callerToken) override; 511 512 /** 513 * AttachAbilityThread, ability call this interface after loaded. 514 * 515 * @param scheduler,.the interface handler of kit ability. 516 * @param token,.ability's token. 517 * @return Returns ERR_OK on success, others on failure. 518 */ 519 virtual int AttachAbilityThread( 520 const sptr<IAbilityScheduler> &scheduler, const sptr<IRemoteObject> &token) override; 521 522 /** 523 * AbilityTransitionDone, ability call this interface after lift cycle was changed. 524 * 525 * @param token,.ability's token. 526 * @param state,.the state of ability lift cycle. 527 * @return Returns ERR_OK on success, others on failure. 528 */ 529 virtual int AbilityTransitionDone(const sptr<IRemoteObject> &token, int state, const PacMap &saveData) override; 530 531 /** 532 * ScheduleConnectAbilityDone, service ability call this interface while session was connected. 533 * 534 * @param token,.service ability's token. 535 * @param remoteObject,.the session proxy of service ability. 536 * @return Returns ERR_OK on success, others on failure. 537 */ 538 virtual int ScheduleConnectAbilityDone( 539 const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &remoteObject) override; 540 541 /** 542 * ScheduleDisconnectAbilityDone, service ability call this interface while session was disconnected. 543 * 544 * @param token,.service ability's token. 545 * @return Returns ERR_OK on success, others on failure. 546 */ 547 virtual int ScheduleDisconnectAbilityDone(const sptr<IRemoteObject> &token) override; 548 549 /** 550 * ScheduleCommandAbilityDone, service ability call this interface while session was commanded. 551 * 552 * @param token,.service ability's token. 553 * @return Returns ERR_OK on success, others on failure. 554 */ 555 virtual int ScheduleCommandAbilityDone(const sptr<IRemoteObject> &token) override; 556 557 virtual int ScheduleCommandAbilityWindowDone( 558 const sptr<IRemoteObject> &token, 559 const sptr<SessionInfo> &sessionInfo, 560 WindowCommand winCmd, 561 AbilityCommand abilityCmd) override; 562 GetTaskHandler()563 std::shared_ptr<TaskHandlerWrap> GetTaskHandler() const 564 { 565 return taskHandler_; 566 } 567 568 /** 569 * GetEventHandler, get the ability manager service's handler. 570 * 571 * @return Returns AbilityEventHandler ptr. 572 */ 573 std::shared_ptr<AbilityEventHandler> GetEventHandler(); 574 575 /** 576 * @brief Ability hidump. 577 * @param fd Indicates the fd. 578 * @param args Indicates the params. 579 * @return Returns the dump result. 580 */ 581 int Dump(int fd, const std::vector<std::u16string>& args) override; 582 583 /** 584 * dump ability stack info, about userID, mission stack info, 585 * mission record info and ability info. 586 * 587 * @param state Ability stack info. 588 * @return Returns ERR_OK on success, others on failure. 589 */ 590 virtual void DumpState(const std::string &args, std::vector<std::string> &info) override; 591 virtual void DumpSysState( 592 const std::string& args, std::vector<std::string>& info, bool isClient, bool isUserID, int UserID) override; 593 594 /** 595 * Destroys this Service ability by Want. 596 * 597 * @param want, Special want for service type's ability. 598 * @param token ability's token. 599 * @return Returns true if this Service ability will be destroyed; returns false otherwise. 600 */ 601 virtual int StopServiceAbility(const Want &want, int32_t userId = DEFAULT_INVAL_VALUE, 602 const sptr<IRemoteObject> &token = nullptr) override; 603 604 /** 605 * Kill the process immediately. 606 * 607 * @param bundleName. 608 * @return Returns ERR_OK on success, others on failure. 609 */ 610 virtual int KillProcess(const std::string &bundleName) override; 611 612 /** 613 * ClearUpApplicationData, call ClearUpApplicationData() through proxy project, 614 * clear the application data. 615 * 616 * @param bundleName, bundle name in Application record. 617 * @return ERR_OK, return back success, others fail. 618 */ 619 virtual int ClearUpApplicationData(const std::string &bundleName) override; 620 621 /** 622 * Uninstall app 623 * 624 * @param bundleName bundle name of uninstalling app. 625 * @param uid uid of bundle. 626 * @return Returns ERR_OK on success, others on failure. 627 */ 628 virtual int UninstallApp(const std::string &bundleName, int32_t uid) override; 629 /** 630 * InitMissionListManager, set the user id of mission list manager. 631 * 632 * @param userId, user id. 633 */ 634 void InitMissionListManager(int userId, bool switchUser); 635 636 virtual sptr<IWantSender> GetWantSender( 637 const WantSenderInfo &wantSenderInfo, const sptr<IRemoteObject> &callerToken) override; 638 639 virtual int SendWantSender(const sptr<IWantSender> &target, const SenderInfo &senderInfo) override; 640 641 virtual void CancelWantSender(const sptr<IWantSender> &sender) override; 642 643 virtual int GetPendingWantUid(const sptr<IWantSender> &target) override; 644 645 virtual int GetPendingWantUserId(const sptr<IWantSender> &target) override; 646 647 virtual std::string GetPendingWantBundleName(const sptr<IWantSender> &target) override; 648 649 virtual int GetPendingWantCode(const sptr<IWantSender> &target) override; 650 651 virtual int GetPendingWantType(const sptr<IWantSender> &target) override; 652 653 virtual void RegisterCancelListener(const sptr<IWantSender> &sender, const sptr<IWantReceiver> &receiver) override; 654 655 virtual void UnregisterCancelListener( 656 const sptr<IWantSender> &sender, const sptr<IWantReceiver> &receiver) override; 657 658 virtual int GetPendingRequestWant(const sptr<IWantSender> &target, std::shared_ptr<Want> &want) override; 659 660 virtual int GetWantSenderInfo(const sptr<IWantSender> &target, std::shared_ptr<WantSenderInfo> &info) override; 661 662 virtual int RegisterObserver(const sptr<AbilityRuntime::IConnectionObserver> &observer) override; 663 664 virtual int UnregisterObserver(const sptr<AbilityRuntime::IConnectionObserver> &observer) override; 665 666 virtual int GetDlpConnectionInfos(std::vector<AbilityRuntime::DlpConnectionInfo> &infos) override; 667 668 virtual int LockMissionForCleanup(int32_t missionId) override; 669 670 virtual int UnlockMissionForCleanup(int32_t missionId) override; 671 672 virtual int RegisterMissionListener(const sptr<IMissionListener> &listener) override; 673 674 virtual int UnRegisterMissionListener(const sptr<IMissionListener> &listener) override; 675 676 virtual int GetMissionInfos(const std::string& deviceId, int32_t numMax, 677 std::vector<MissionInfo> &missionInfos) override; 678 679 virtual int GetMissionInfo(const std::string& deviceId, int32_t missionId, 680 MissionInfo &missionInfo) override; 681 682 virtual int CleanMission(int32_t missionId) override; 683 684 virtual int CleanAllMissions() override; 685 686 virtual int MoveMissionToFront(int32_t missionId) override; 687 688 virtual int MoveMissionToFront(int32_t missionId, const StartOptions &startOptions) override; 689 690 virtual int MoveMissionsToForeground(const std::vector<int32_t>& missionIds, int32_t topMissionId) override; 691 692 virtual int MoveMissionsToBackground(const std::vector<int32_t>& missionIds, 693 std::vector<int32_t>& result) override; 694 695 virtual int32_t GetMissionIdByToken(const sptr<IRemoteObject> &token) override; 696 697 void GetAbilityTokenByCalleeObj(const sptr<IRemoteObject> &callStub, sptr<IRemoteObject> &token) override; 698 699 virtual int StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override; 700 701 virtual int StopSyncRemoteMissions(const std::string& devId) override; 702 703 virtual int GetAppMemorySize() override; 704 705 virtual bool IsRamConstrainedDevice() override; 706 /** 707 * Start Ability, connect session with common ability. 708 * 709 * @param want, Special want for service type's ability. 710 * @param connect, Callback used to notify caller the result of connecting or disconnecting. 711 * @param accountId Indicates the account to start. 712 * @return Returns ERR_OK on success, others on failure. 713 */ 714 virtual int StartAbilityByCall(const Want &want, const sptr<IAbilityConnection> &connect, 715 const sptr<IRemoteObject> &callerToken, int32_t accountId = DEFAULT_INVAL_VALUE) override; 716 717 /** 718 * CallRequestDone, after invoke callRequest, ability will call this interface to return callee. 719 * 720 * @param token, ability's token. 721 * @param callStub, ability's callee. 722 */ 723 void CallRequestDone(const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &callStub) override; 724 725 /** 726 * Release the call between Ability, disconnect session with common ability. 727 * 728 * @param connect, Callback used to notify caller the result of connecting or disconnecting. 729 * @param element, the element of target service. 730 * @return Returns ERR_OK on success, others on failure. 731 */ 732 virtual int ReleaseCall( 733 const sptr<IAbilityConnection> &connect, const AppExecFwk::ElementName &element) override; 734 735 /** 736 * get service record by element name. 737 * 738 */ 739 std::shared_ptr<AbilityRecord> GetServiceRecordByElementName(const std::string &element); 740 std::list<std::shared_ptr<ConnectionRecord>> GetConnectRecordListByCallback(sptr<IAbilityConnection> callback); 741 742 void OnAbilityDied(std::shared_ptr<AbilityRecord> abilityRecord); 743 void OnCallConnectDied(std::shared_ptr<CallRecord> callRecord); 744 void HandleLoadTimeOut(int64_t abilityRecordId, bool isHalf = false); 745 void HandleActiveTimeOut(int64_t abilityRecordId); 746 void HandleInactiveTimeOut(int64_t abilityRecordId); 747 void HandleForegroundTimeOut(int64_t abilityRecordId, bool isHalf = false); 748 void HandleShareDataTimeOut(int64_t uniqueId); 749 int32_t GetShareDataPairAndReturnData(std::shared_ptr<AbilityRecord> abilityRecord, 750 const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam); 751 752 int StartAbilityWrap( 753 const Want &want, 754 const sptr<IRemoteObject> &callerToken, 755 int requestCode, 756 int32_t userId = DEFAULT_INVAL_VALUE, 757 bool isStartAsCaller = false); 758 759 int StartAbilityInner( 760 const Want &want, 761 const sptr<IRemoteObject> &callerToken, 762 int requestCode, 763 int32_t userId = DEFAULT_INVAL_VALUE, 764 bool isStartAsCaller = false); 765 766 int StartAbilityForOptionWrap( 767 const Want &want, 768 const StartOptions &startOptions, 769 const sptr<IRemoteObject> &callerToken, 770 int32_t userId = DEFAULT_INVAL_VALUE, 771 int requestCode = DEFAULT_INVAL_VALUE, 772 bool isStartAsCaller = false); 773 774 int StartAbilityForOptionInner( 775 const Want &want, 776 const StartOptions &startOptions, 777 const sptr<IRemoteObject> &callerToken, 778 int32_t userId = DEFAULT_INVAL_VALUE, 779 int requestCode = DEFAULT_INVAL_VALUE, 780 bool isStartAsCaller = false); 781 782 int CheckPermission(const std::string &bundleName, const std::string &permission); 783 784 void OnAcceptWantResponse(const AAFwk::Want &want, const std::string &flag); 785 void OnStartSpecifiedAbilityTimeoutResponse(const AAFwk::Want &want); 786 787 virtual int GetAbilityRunningInfos(std::vector<AbilityRunningInfo> &info) override; 788 virtual int GetExtensionRunningInfos(int upperLimit, std::vector<ExtensionRunningInfo> &info) override; 789 virtual int GetProcessRunningInfos(std::vector<AppExecFwk::RunningProcessInfo> &info) override; 790 int GetProcessRunningInfosByUserId(std::vector<AppExecFwk::RunningProcessInfo> &info, int32_t userId); 791 void GetAbilityRunningInfo(std::vector<AbilityRunningInfo> &info, std::shared_ptr<AbilityRecord> &abilityRecord); 792 void GetExtensionRunningInfo(std::shared_ptr<AbilityRecord> &abilityRecord, const int32_t userId, 793 std::vector<ExtensionRunningInfo> &info); 794 795 int GetMissionSaveTime() const; 796 797 /** 798 * generate ability request. 799 * 800 */ 801 int GenerateAbilityRequest( 802 const Want &want, 803 int requestCode, 804 AbilityRequest &request, 805 const sptr<IRemoteObject> &callerToken, 806 int32_t userId); 807 808 /** 809 * Get mission id by target ability token. 810 * 811 * @param token target ability token. 812 * @return the missionId of target mission. 813 */ 814 int32_t GetMissionIdByAbilityToken(const sptr<IRemoteObject> &token); 815 816 /** 817 * Get ability token by target mission id. 818 * 819 * @param missionId target missionId. 820 * @return the ability token of target mission. 821 */ 822 sptr<IRemoteObject> GetAbilityTokenByMissionId(int32_t missionId); 823 824 virtual int StartUser(int userId) override; 825 826 virtual int StopUser(int userId, const sptr<IStopUserCallback> &callback) override; 827 828 /** 829 * Called when client complete dump. 830 * 831 * @param infos The dump info. 832 * @param callerToken The caller ability token. 833 * @return Returns ERR_OK on success, others on failure. 834 */ 835 virtual int DumpAbilityInfoDone(std::vector<std::string> &infos, const sptr<IRemoteObject> &callerToken) override; 836 837 virtual int SetMissionContinueState(const sptr<IRemoteObject> &abilityToken, 838 const AAFwk::ContinueState &state) override; 839 840 #ifdef SUPPORT_GRAPHICS 841 virtual int SetMissionLabel(const sptr<IRemoteObject> &abilityToken, const std::string &label) override; 842 843 virtual int SetMissionIcon(const sptr<IRemoteObject> &token, 844 const std::shared_ptr<OHOS::Media::PixelMap> &icon) override; 845 846 virtual int RegisterWindowManagerServiceHandler(const sptr<IWindowManagerServiceHandler>& handler) override; 847 848 virtual void CompleteFirstFrameDrawing(const sptr<IRemoteObject> &abilityToken) override; 849 850 sptr<IWindowManagerServiceHandler> GetWMSHandler() const; 851 852 virtual int PrepareTerminateAbility(const sptr<IRemoteObject> &token, 853 sptr<IPrepareTerminateCallback> &callback) override; 854 855 void HandleFocused(const sptr<OHOS::Rosen::FocusChangeInfo> &focusChangeInfo); 856 857 void HandleUnfocused(const sptr<OHOS::Rosen::FocusChangeInfo> &focusChangeInfo); 858 #endif 859 860 void ClearUserData(int32_t userId); 861 862 virtual int RegisterSnapshotHandler(const sptr<ISnapshotHandler>& handler) override; 863 864 virtual int32_t GetMissionSnapshot(const std::string& deviceId, int32_t missionId, 865 MissionSnapshot& snapshot, bool isLowResolution) override; 866 867 /** 868 * Set ability controller. 869 * 870 * @param abilityController, The ability controller. 871 * @return Returns ERR_OK on success, others on failure. 872 */ 873 virtual int SetAbilityController(const sptr<IAbilityController> &abilityController, bool imAStabilityTest) override; 874 875 /** 876 * Is user a stability test. 877 * 878 * @return Returns true if user is a stability test. 879 */ 880 virtual bool IsRunningInStabilityTest() override; 881 882 virtual int StartUserTest(const Want &want, const sptr<IRemoteObject> &observer) override; 883 884 virtual int FinishUserTest( 885 const std::string &msg, const int64_t &resultCode, const std::string &bundleName) override; 886 887 /** 888 * GetTopAbility, get the token of top ability. 889 * 890 * @param token, the token of top ability. 891 * @return Returns ERR_OK on success, others on failure. 892 */ 893 virtual int GetTopAbility(sptr<IRemoteObject> &token) override; 894 895 virtual int CheckUIExtensionIsFocused(uint32_t uiExtensionTokenId, bool& isFocused) override; 896 897 /** 898 * The delegator calls this interface to move the ability to the foreground. 899 * 900 * @param token, ability's token. 901 * @return Returns ERR_OK on success, others on failure. 902 */ 903 virtual int DelegatorDoAbilityForeground(const sptr<IRemoteObject> &token) override; 904 905 /** 906 * The delegator calls this interface to move the ability to the background. 907 * 908 * @param token, ability's token. 909 * @return Returns ERR_OK on success, others on failure. 910 */ 911 virtual int DelegatorDoAbilityBackground(const sptr<IRemoteObject> &token) override; 912 913 /** 914 * Calls this interface to move the ability to the foreground. 915 * 916 * @param token, ability's token. 917 * @param flag, use for lock or unlock flag and so on. 918 * @return Returns ERR_OK on success, others on failure. 919 */ 920 virtual int DoAbilityForeground(const sptr<IRemoteObject> &token, uint32_t flag) override; 921 922 /** 923 * Calls this interface to move the ability to the background. 924 * 925 * @param token, ability's token. 926 * @param flag, use for lock or unlock flag and so on. 927 * @return Returns ERR_OK on success, others on failure. 928 */ 929 virtual int DoAbilityBackground(const sptr<IRemoteObject> &token, uint32_t flag) override; 930 931 /** 932 * Set component interception. 933 * 934 * @param componentInterception, component interception. 935 * @return Returns ERR_OK on success, others on failure. 936 */ 937 virtual int SetComponentInterception( 938 const sptr<AppExecFwk::IComponentInterception> &componentInterception) override; 939 940 virtual int32_t SendResultToAbilityByToken(const Want &want, const sptr<IRemoteObject> &abilityToken, 941 int32_t requestCode, int32_t resultCode, int32_t userId) override; 942 943 bool IsAbilityControllerStart(const Want &want, const std::string &bundleName); 944 945 bool IsAbilityControllerForeground(const std::string &bundleName); 946 947 bool IsAbilityControllerStartById(int32_t missionId); 948 949 bool IsComponentInterceptionStart(const Want &want, ComponentRequest &componentRequest, AbilityRequest &request); 950 951 void NotifyHandleAbilityStateChange(const sptr<IRemoteObject> &abilityToken, int opCode); 952 953 /** 954 * Send not response process ID to ability manager service. 955 * @param pid The not response process ID. 956 * @return Returns ERR_OK on success, others on failure. 957 */ 958 virtual int SendANRProcessID(int pid) override; 959 960 #ifdef ABILITY_COMMAND_FOR_TEST 961 /** 962 * Block ability manager service. 963 * @return Returns ERR_OK on success, others on failure. 964 */ 965 virtual int BlockAmsService() override; 966 967 /** 968 * Block ability. 969 * 970 * @param abilityRecordId The Ability Record Id. 971 * @return Returns ERR_OK on success, others on failure. 972 */ 973 virtual int BlockAbility(int32_t abilityRecordId) override; 974 975 /** 976 * Block app manager service. 977 * @return Returns ERR_OK on success, others on failure. 978 */ 979 virtual int BlockAppService() override; 980 981 /** 982 * force timeout ability. 983 * 984 * @param abilityName. 985 * @param state. 986 * @return Returns ERR_OK on success, others on failure. 987 */ 988 virtual int ForceTimeoutForTest(const std::string &abilityName, const std::string &state) override; 989 #endif 990 991 bool GetDataAbilityUri(const std::vector<AppExecFwk::AbilityInfo> &abilityInfos, 992 const std::string &mainAbility, std::string &uri); 993 994 virtual AppExecFwk::ElementName GetTopAbility() override; 995 996 virtual AppExecFwk::ElementName GetElementNameByToken(const sptr<IRemoteObject> &token) override; 997 998 /** 999 * AtomicServiceStatusCallback OnInstallFinished callback. 1000 * 1001 * @param resultCode FreeInstall result code. 1002 * @param want Want has been installed. 1003 * @param userId User id. 1004 */ 1005 void OnInstallFinished(int resultCode, const Want &want, int32_t userId); 1006 1007 /** 1008 * AtomicServiceStatusCallback OnRemoteInstallFinished callback. 1009 * 1010 * @param resultCode FreeInstall result code. 1011 * @param want Want has been installed. 1012 * @param userId User id. 1013 */ 1014 void OnRemoteInstallFinished(int resultCode, const Want &want, int32_t userId); 1015 1016 /** 1017 * FreeInstall form remote call. 1018 * 1019 * @param want Want need to install. 1020 * @param callback DMS callback. 1021 * @param userId User id. 1022 * @param requestCode Ability request code. 1023 * @return Returns ERR_OK on success, others on failure. 1024 */ 1025 virtual int FreeInstallAbilityFromRemote(const Want &want, const sptr<IRemoteObject> &callback, 1026 int32_t userId, int requestCode = DEFAULT_INVAL_VALUE) override; 1027 1028 /** 1029 * Add FreeInstall Observer 1030 * 1031 * @param observer the observer of ability free install start. 1032 * @return Returns ERR_OK on success, others on failure. 1033 */ 1034 virtual int AddFreeInstallObserver(const sptr<AbilityRuntime::IFreeInstallObserver> &observer) override; 1035 1036 /** 1037 * Check the uid is background task uid. 1038 * 1039 * @param uid userId. 1040 * @return Returns whether the uid is background task uid. 1041 */ 1042 bool IsBackgroundTaskUid(const int uid); 1043 1044 bool GetLocalDeviceId(std::string& localDeviceId); 1045 1046 int JudgeAbilityVisibleControl(const AppExecFwk::AbilityInfo &abilityInfo); 1047 1048 /** 1049 * Called to update mission snapshot. 1050 * @param token The target ability. 1051 * @param pixelMap The snapshot. 1052 */ 1053 virtual void UpdateMissionSnapShot(const sptr<IRemoteObject> &token, 1054 const std::shared_ptr<Media::PixelMap> &pixelMap) override; 1055 1056 virtual void EnableRecoverAbility(const sptr<IRemoteObject>& token) override; 1057 virtual void ScheduleRecoverAbility(const sptr<IRemoteObject> &token, int32_t reason, 1058 const Want *want = nullptr) override; 1059 1060 /** 1061 * Called to verify that the MissionId is valid. 1062 * @param missionIds Query mission list. 1063 * @param results Output parameters, return results up to 20 query results. 1064 * @return Returns ERR_OK on success, others on failure. 1065 */ 1066 int32_t IsValidMissionIds( 1067 const std::vector<int32_t> &missionIds, std::vector<MissionVaildResult> &results) override; 1068 1069 virtual int32_t RequestDialogService(const Want &want, const sptr<IRemoteObject> &callerToken) override; 1070 1071 int32_t ReportDrawnCompleted(const sptr<IRemoteObject> &callerToken) override; 1072 1073 virtual int32_t AcquireShareData( 1074 const int32_t &missionId, const sptr<IAcquireShareDataCallback> &shareData) override; 1075 virtual int32_t ShareDataDone(const sptr<IRemoteObject>& token, 1076 const int32_t &requestCode, const int32_t &uniqueId, WantParams &wantParam) override; 1077 1078 bool GetStartUpNewRuleFlag() const; 1079 1080 std::shared_ptr<AbilityRecord> GetFocusAbility(); 1081 1082 /** 1083 * Query whether the application of the specified PID and UID has been granted a certain permission 1084 * @param permission 1085 * @param pid Process id 1086 * @param uid 1087 * @return Returns ERR_OK if the current process has the permission, others on failure. 1088 */ 1089 virtual int VerifyPermission(const std::string &permission, int pid, int uid) override; 1090 1091 bool IsDmsAlive() const; 1092 1093 /** 1094 * Upgrade app completed event. 1095 * @param bundleName. 1096 * @param uid. 1097 */ 1098 void AppUpgradeCompleted(const std::string &bundleName, int32_t uid); 1099 1100 /** 1101 * Record app exit reason. 1102 * @param exitReason The reason of app exit. 1103 * @return Returns ERR_OK on success, others on failure. 1104 */ 1105 virtual int32_t RecordAppExitReason(Reason exitReason) override; 1106 1107 /** 1108 * Force app exit and record exit reason. 1109 * @param pid Process id . 1110 * @param exitReason The reason of app exit. 1111 * @return Returns ERR_OK on success, others on failure. 1112 */ 1113 virtual int32_t ForceExitApp(const int32_t pid, Reason exitReason) override; 1114 1115 int32_t GetConfiguration(AppExecFwk::Configuration& config); 1116 1117 /** 1118 * Set rootSceneSession by SCB. 1119 * 1120 * @param rootSceneSession Indicates root scene session of SCB. 1121 */ 1122 virtual void SetRootSceneSession(const sptr<IRemoteObject> &rootSceneSession) override; 1123 1124 /** 1125 * Call UIAbility by SCB. 1126 * 1127 * @param sessionInfo the session info of the ability to be called. 1128 */ 1129 virtual void CallUIAbilityBySCB(const sptr<SessionInfo> &sessionInfo) override; 1130 1131 /** 1132 * Start specified ability by SCB. 1133 * 1134 * @param want Want information. 1135 */ 1136 virtual void StartSpecifiedAbilityBySCB(const Want &want) override; 1137 1138 /** 1139 * Notify sandbox app the result of saving file. 1140 * @param want Result of saving file, which contains the file's uri if success. 1141 * @param resultCode Indicates the action's result. 1142 * @param requestCode Pass the requestCode to match request. 1143 * @return Returns ERR_OK on success, others on failure. 1144 */ 1145 virtual int32_t NotifySaveAsResult(const Want &want, int resultCode, int requestCode) override; 1146 1147 /** 1148 * Set sessionManagerService 1149 * @param sessionManagerService the point of sessionManagerService. 1150 * 1151 * @return Returns ERR_OK on success, others on failure. 1152 */ 1153 virtual int32_t SetSessionManagerService(const sptr<IRemoteObject> &sessionManagerService) override; 1154 1155 /** 1156 * @brief Register collaborator. 1157 * @param type collaborator type. 1158 * @param impl collaborator. 1159 * @return 0 or else. 1160 */ 1161 virtual int32_t RegisterIAbilityManagerCollaborator( 1162 int32_t type, const sptr<IAbilityManagerCollaborator> &impl) override; 1163 1164 /** 1165 * @brief Unregister collaborator. 1166 * @param type collaborator type. 1167 * @return 0 or else. 1168 */ 1169 virtual int32_t UnregisterIAbilityManagerCollaborator(int32_t type) override; 1170 1171 /** 1172 * @brief Notify to move mission to backround. 1173 * @param missionId missionId. 1174 * @return 0 or else. 1175 */ 1176 virtual int32_t MoveMissionToBackground(int32_t missionId) override; 1177 1178 /** 1179 * @brief Notify to terminate mission. it is not clear. 1180 * @param missionId missionId. 1181 * @return 0 or else. 1182 */ 1183 virtual int32_t TerminateMission(int32_t missionId) override; 1184 1185 /** 1186 * @brief Get collaborator. 1187 * @param type collaborator type. 1188 * @return nullptr or IAbilityManagerCollaborator stpr. 1189 */ 1190 sptr<IAbilityManagerCollaborator> GetCollaborator(int32_t type); 1191 1192 /** 1193 * get the user id. 1194 * 1195 */ 1196 int32_t GetUserId() const; 1197 1198 /** 1199 * PrepareTerminateAbilityBySCB, prepare to terminate ability by scb. 1200 * 1201 * @param sessionInfo the session info of the ability to start. 1202 * @param isTerminate the result of ability onPrepareToTermiante. 1203 * @return Returns ERR_OK on success, others on failure. 1204 */ 1205 virtual int PrepareTerminateAbilityBySCB(const sptr<SessionInfo> &sessionInfo, bool &isTerminate) override; 1206 1207 // MSG 0 - 20 represents timeout message 1208 static constexpr uint32_t LOAD_TIMEOUT_MSG = 0; 1209 static constexpr uint32_t ACTIVE_TIMEOUT_MSG = 1; 1210 static constexpr uint32_t INACTIVE_TIMEOUT_MSG = 2; 1211 static constexpr uint32_t TERMINATE_TIMEOUT_MSG = 4; 1212 static constexpr uint32_t FOREGROUND_TIMEOUT_MSG = 5; 1213 static constexpr uint32_t BACKGROUND_TIMEOUT_MSG = 6; 1214 static constexpr uint32_t SHAREDATA_TIMEOUT_MSG = 7; 1215 1216 #ifdef SUPPORT_ASAN 1217 static constexpr uint32_t LOAD_TIMEOUT = 150000; // ms 1218 static constexpr uint32_t ACTIVE_TIMEOUT = 75000; // ms 1219 static constexpr uint32_t INACTIVE_TIMEOUT = 7500; // ms 1220 #else 1221 static constexpr uint32_t LOAD_TIMEOUT = 10000; // ms 1222 static constexpr uint32_t ACTIVE_TIMEOUT = 5000; // ms 1223 static constexpr uint32_t INACTIVE_TIMEOUT = 500; // ms 1224 #endif 1225 1226 static constexpr uint32_t MIN_DUMP_ARGUMENT_NUM = 2; 1227 static constexpr uint32_t MAX_WAIT_SYSTEM_UI_NUM = 600; 1228 static constexpr uint32_t MAX_WAIT_SETTINGS_DATA_NUM = 300; 1229 1230 enum DumpKey { 1231 KEY_DUMP_ALL = 0, 1232 KEY_DUMP_STACK_LIST, 1233 KEY_DUMP_STACK, 1234 KEY_DUMP_MISSION, 1235 KEY_DUMP_TOP_ABILITY, 1236 KEY_DUMP_WAIT_QUEUE, 1237 KEY_DUMP_SERVICE, 1238 KEY_DUMP_DATA, 1239 KEY_DUMP_FOCUS_ABILITY, 1240 KEY_DUMP_WINDOW_MODE, 1241 KEY_DUMP_MISSION_LIST, 1242 KEY_DUMP_MISSION_INFOS, 1243 }; 1244 1245 enum DumpsysKey { 1246 KEY_DUMPSYS_ALL = 0, 1247 KEY_DUMPSYS_MISSION_LIST, 1248 KEY_DUMPSYS_ABILITY, 1249 KEY_DUMPSYS_SERVICE, 1250 KEY_DUMPSYS_PENDING, 1251 KEY_DUMPSYS_PROCESS, 1252 KEY_DUMPSYS_DATA, 1253 }; 1254 1255 enum { 1256 ABILITY_MOVE_TO_FOREGROUND_CODE = 0, 1257 ABILITY_MOVE_TO_BACKGROUND_CODE, 1258 TERMINATE_ABILITY_CODE 1259 }; 1260 1261 friend class UserController; 1262 1263 protected: 1264 void OnAbilityRequestDone(const sptr<IRemoteObject> &token, const int32_t state) override; 1265 int GetUidByBundleName(std::string bundleName); 1266 1267 void OnAppStateChanged(const AppInfo &info) override; 1268 1269 private: 1270 int TerminateAbilityWithFlag(const sptr<IRemoteObject> &token, int resultCode = DEFAULT_INVAL_VALUE, 1271 const Want *resultWant = nullptr, bool flag = true); 1272 /** 1273 * initialization of ability manager service. 1274 * 1275 */ 1276 bool Init(); 1277 /** 1278 * initialization of u0 user. 1279 * 1280 */ 1281 void InitU0User(); 1282 void InitStartAbilityChain(); 1283 /** 1284 * start highest priority ability. 1285 * 1286 */ 1287 void StartHighestPriorityAbility(int32_t userId, bool isBoot); 1288 /** 1289 * connet bms. 1290 * 1291 */ 1292 void ConnectBmsService(); 1293 1294 /** 1295 * Determine whether it is a system APP 1296 * 1297 */ 1298 bool IsSystemUiApp(const AppExecFwk::AbilityInfo &info) const; 1299 /** 1300 * Init parameters from the global 1301 * 1302 */ 1303 void InitGlobalConfiguration(); 1304 1305 sptr<AppExecFwk::IBundleMgr> GetBundleManager(); 1306 1307 sptr<OHOS::AppExecFwk::IAppMgr> GetAppMgr(); 1308 1309 int StartRemoteAbility(const Want &want, int requestCode, int32_t validUserId, 1310 const sptr<IRemoteObject> &callerToken); 1311 int ConnectLocalAbility( 1312 const Want &want, 1313 const int32_t userId, 1314 const sptr<IAbilityConnection> &connect, 1315 const sptr<IRemoteObject> &callerToken, 1316 AppExecFwk::ExtensionAbilityType extensionType, 1317 const sptr<SessionInfo> &sessionInfo = nullptr); 1318 int DisconnectLocalAbility(const sptr<IAbilityConnection> &connect); 1319 int ConnectRemoteAbility(Want &want, const sptr<IRemoteObject> &callerToken, const sptr<IRemoteObject> &connect); 1320 int DisconnectRemoteAbility(const sptr<IRemoteObject> &connect); 1321 int PreLoadAppDataAbilities(const std::string &bundleName, const int32_t userId); 1322 void UpdateCallerInfo(Want& want, const sptr<IRemoteObject> &callerToken); 1323 int StartAbilityPublicPrechainCheck(StartAbilityParams ¶ms); 1324 int StartAbilityPrechainInterceptor(StartAbilityParams ¶ms); 1325 bool StartAbilityInChain(StartAbilityParams ¶ms, int &result); 1326 1327 bool CheckIfOperateRemote(const Want &want); 1328 std::string AnonymizeDeviceId(const std::string& deviceId); 1329 bool VerificationToken(const sptr<IRemoteObject> &token); 1330 void RequestPermission(const Want *resultWant); 1331 1332 bool CheckIsRemote(const std::string& deviceId); 1333 int GetRemoteMissionInfos(const std::string& deviceId, int32_t numMax, 1334 std::vector<MissionInfo> &missionInfos); 1335 int GetRemoteMissionInfo(const std::string& deviceId, int32_t missionId, 1336 MissionInfo &missionInfo); 1337 int32_t GetRemoteMissionSnapshotInfo(const std::string& deviceId, int32_t missionId, 1338 MissionSnapshot& missionSnapshot); 1339 int StartRemoteAbilityByCall(const Want &want, const sptr<IRemoteObject> &callerToken, 1340 const sptr<IRemoteObject> &connect); 1341 int ReleaseRemoteAbility(const sptr<IRemoteObject> &connect, const AppExecFwk::ElementName &element); 1342 1343 void DumpInner(const std::string &args, std::vector<std::string> &info); 1344 void DumpMissionInner(const std::string &args, std::vector<std::string> &info); 1345 void DumpStateInner(const std::string &args, std::vector<std::string> &info); 1346 void DataDumpStateInner(const std::string &args, std::vector<std::string> &info); 1347 void DumpMissionListInner(const std::string &args, std::vector<std::string> &info); 1348 void DumpMissionInfosInner(const std::string &args, std::vector<std::string> &info); 1349 void DumpFuncInit(); 1350 1351 bool JudgeMultiUserConcurrency(const int32_t userId); 1352 /** 1353 * dumpsys info 1354 * 1355 */ 1356 void DumpSysFuncInit(); 1357 void DumpSysInner( 1358 const std::string &args, std::vector<std::string> &info, bool isClient, bool isUserID, int userId); 1359 void DumpSysMissionListInner( 1360 const std::string &args, std::vector<std::string> &info, bool isClient, bool isUserID, int userId); 1361 void DumpSysAbilityInner( 1362 const std::string &args, std::vector<std::string> &info, bool isClient, bool isUserID, int userId); 1363 void DumpSysStateInner( 1364 const std::string &args, std::vector<std::string> &info, bool isClient, bool isUserID, int userId); 1365 void DumpSysPendingInner( 1366 const std::string &args, std::vector<std::string> &info, bool isClient, bool isUserID, int userId); 1367 void DumpSysProcess( 1368 const std::string &args, std::vector<std::string> &info, bool isClient, bool isUserID, int userId); 1369 void DataDumpSysStateInner( 1370 const std::string &args, std::vector<std::string> &info, bool isClient, bool isUserID, int userId); 1371 ErrCode ProcessMultiParam(std::vector<std::string>& argsStr, std::string& result); 1372 void ShowHelp(std::string& result); 1373 void ShowIllegalInfomation(std::string& result); 1374 int Dump(const std::vector<std::u16string>& args, std::string& result); 1375 1376 void InitConnectManager(int32_t userId, bool switchUser); 1377 void InitDataAbilityManager(int32_t userId, bool switchUser); 1378 void InitPendWantManager(int32_t userId, bool switchUser); 1379 1380 int32_t InitAbilityInfoFromExtension(AppExecFwk::ExtensionAbilityInfo &extensionInfo, 1381 AppExecFwk::AbilityInfo &abilityInfo); 1382 1383 // multi user 1384 void StartFreezingScreen(); 1385 void StopFreezingScreen(); 1386 void UserStarted(int32_t userId); 1387 void SwitchToUser(int32_t userId); 1388 void SwitchToUser(int32_t oldUserId, int32_t userId); 1389 void SwitchManagers(int32_t userId, bool switchUser = true); 1390 void StartUserApps(int32_t userId, bool isBoot); 1391 void PauseOldUser(int32_t userId); 1392 void PauseOldMissionListManager(int32_t userId); 1393 void PauseOldConnectManager(int32_t userId); 1394 bool IsSystemUI(const std::string &bundleName) const; 1395 1396 bool VerificationAllToken(const sptr<IRemoteObject> &token); 1397 std::shared_ptr<DataAbilityManager> GetDataAbilityManager(const sptr<IAbilityScheduler> &scheduler); 1398 std::shared_ptr<MissionListManager> GetListManagerByUserId(int32_t userId); 1399 std::shared_ptr<AbilityConnectManager> GetConnectManagerByUserId(int32_t userId); 1400 std::shared_ptr<DataAbilityManager> GetDataAbilityManagerByUserId(int32_t userId); 1401 std::shared_ptr<MissionListManager> GetListManagerByToken(const sptr<IRemoteObject> &token); 1402 std::shared_ptr<AbilityConnectManager> GetConnectManagerByToken(const sptr<IRemoteObject> &token); 1403 std::shared_ptr<DataAbilityManager> GetDataAbilityManagerByToken(const sptr<IRemoteObject> &token); 1404 bool JudgeSelfCalled(const std::shared_ptr<AbilityRecord> &abilityRecord); 1405 1406 int32_t GetValidUserId(const int32_t userId); 1407 1408 int DelegatorMoveMissionToFront(int32_t missionId); 1409 1410 bool IsNeedTimeoutForTest(const std::string &abilityName, const std::string &state) const; 1411 1412 void StartResidentApps(); 1413 1414 int VerifyAccountPermission(int32_t userId); 1415 1416 using DumpFuncType = void (AbilityManagerService::*)(const std::string &args, std::vector<std::string> &info); 1417 std::map<uint32_t, DumpFuncType> dumpFuncMap_; 1418 1419 using DumpSysFuncType = void (AbilityManagerService::*)( 1420 const std::string& args, std::vector<std::string>& state, bool isClient, bool isUserID, int UserID); 1421 std::map<uint32_t, DumpSysFuncType> dumpsysFuncMap_; 1422 1423 int CheckStaticCfgPermission(AppExecFwk::AbilityInfo &abilityInfo, bool isStartAsCaller, 1424 uint32_t callerTokenId, bool isData = false, bool isSaCall = false); 1425 1426 bool GetValidDataAbilityUri(const std::string &abilityInfoUri, std::string &adjustUri); 1427 1428 int GenerateExtensionAbilityRequest(const Want &want, AbilityRequest &request, 1429 const sptr<IRemoteObject> &callerToken, int32_t userId); 1430 int CheckOptExtensionAbility(const Want &want, AbilityRequest &abilityRequest, 1431 int32_t validUserId, AppExecFwk::ExtensionAbilityType extensionType); 1432 1433 void SubscribeBackgroundTask(); 1434 1435 void UnSubscribeBackgroundTask(); 1436 1437 void SubscribeBundleEventCallback(); 1438 1439 void UnsubscribeBundleEventCallback(); 1440 1441 void ReportAbilitStartInfoToRSS(const AppExecFwk::AbilityInfo &abilityInfo); 1442 1443 void ReportEventToSuspendManager(const AppExecFwk::AbilityInfo &abilityInfo); 1444 1445 void ReportAppRecoverResult(const int32_t appId, const AppExecFwk::ApplicationInfo &appInfo, 1446 const std::string& abilityName, const std::string& result); 1447 1448 void AppRecoverKill(pid_t pid, int32_t reason); 1449 1450 /** 1451 * Check if Caller is allowed to start ServiceAbility(FA) or ServiceExtension(Stage) or DataShareExtension(Stage). 1452 * 1453 * @param abilityRequest, abilityRequest. 1454 * @return Returns whether the caller is allowed to start Service. 1455 */ 1456 int CheckCallServicePermission(const AbilityRequest &abilityRequest); 1457 1458 /** 1459 * Check if Caller is allowed to start DataAbility(FA) 1460 * 1461 * @param abilityRequest, abilityRequest. 1462 * @return Returns whether the caller is allowed to start DataAbility. 1463 */ 1464 int CheckCallDataAbilityPermission(AbilityRequest &abilityRequest, bool isShell, bool IsSACall = false); 1465 1466 /** 1467 * Check if Caller is allowed to start ServiceExtension(Stage) or DataShareExtension(Stage). 1468 * 1469 * @param abilityRequest, abilityRequest. 1470 * @return Returns whether the caller is allowed to start ServiceExtension. 1471 */ 1472 int CheckCallServiceExtensionPermission(const AbilityRequest &abilityRequest); 1473 1474 /** 1475 * Check if Caller is allowed to start other Extension(Stage). 1476 * 1477 * @param abilityRequest, abilityRequest. 1478 * @return Returns whether the caller is allowed to start OtherExtension. 1479 */ 1480 int CheckCallOtherExtensionPermission(const AbilityRequest &abilityRequest); 1481 1482 /** 1483 * Check if Caller is allowed to start ServiceAbility(FA). 1484 * 1485 * @param abilityRequest, abilityRequest. 1486 * @return Returns whether the caller is allowed to start ServiceAbility. 1487 */ 1488 int CheckCallServiceAbilityPermission(const AbilityRequest &abilityRequest); 1489 1490 /** 1491 * Check if Caller is allowed to start PageAbility(FA) or Ability(Stage). 1492 * 1493 * @param abilityRequest, abilityRequest. 1494 * @return Returns whether the caller is allowed to start Ability. 1495 */ 1496 int CheckCallAbilityPermission(const AbilityRequest &abilityRequest); 1497 1498 /** 1499 * Check if Caller is allowed to start Ability(Stage) by call. 1500 * 1501 * @param abilityRequest, abilityRequest. 1502 * @return Returns whether the caller is allowed to start Ability by call. 1503 */ 1504 int CheckStartByCallPermission(const AbilityRequest &abilityRequest); 1505 1506 /** 1507 * Judge if Caller-Application is in background state. 1508 * 1509 * @param abilityRequest, abilityRequest. 1510 * @param isBackgroundCall, Indicates the Caller-Application state. 1511 * TRUE: The Caller-Application is not in focus and not in foreground state. 1512 * FALSE: The Caller-Application is in focus or in foreground state. 1513 * @return Returns ERR_OK on check success, others on check failure. 1514 */ 1515 int IsCallFromBackground(const AbilityRequest &abilityRequest, bool &isBackgroundCall, bool isData = false); 1516 1517 bool IsTargetPermission(const Want &want) const; 1518 1519 bool IsDelegatorCall(const AppExecFwk::RunningProcessInfo &processInfo, const AbilityRequest &abilityRequest); 1520 1521 bool IsAbilityVisible(const AbilityRequest &abilityRequest) const; 1522 1523 bool CheckNewRuleSwitchState(const std::string ¶m); 1524 1525 void UpdateFocusState(std::vector<AbilityRunningInfo> &info); 1526 1527 AAFwk::PermissionVerification::VerificationInfo CreateVerificationInfo( 1528 const AbilityRequest &abilityRequest, bool isData = false, bool isShell = false, bool isSA = false); 1529 1530 int AddStartControlParam(Want &want, const sptr<IRemoteObject> &callerToken); 1531 1532 void RecoverAbilityRestart(const Want &want); 1533 1534 AAFwk::EventInfo BuildEventInfo(const Want &want, int32_t userId); 1535 1536 int CheckDlpForExtension( 1537 const Want &want, const sptr<IRemoteObject> &callerToken, 1538 int32_t userId, AAFwk::EventInfo &eventInfo, const EventName &eventName); 1539 1540 void InitStartupFlag(); 1541 1542 void UpdateAbilityRequestInfo(const sptr<Want> &want, AbilityRequest &request); 1543 1544 ComponentRequest initComponentRequest(const sptr<IRemoteObject> &callerToken = nullptr, 1545 const int requestCode = -1, const int componentStatus = 0); 1546 IsCrossUserCall(int32_t userId)1547 inline bool IsCrossUserCall(int32_t userId) 1548 { 1549 return (userId != INVALID_USER_ID && userId != U0_USER_ID && userId != GetUserId()); 1550 } 1551 1552 bool CheckProxyComponent(const Want &want, const int result); 1553 1554 int32_t RequestDialogServiceInner(const Want &want, const sptr<IRemoteObject> &callerToken, 1555 int requestCode, int32_t userId); 1556 1557 bool IsReleaseCallInterception(const sptr<IAbilityConnection> &connect, const AppExecFwk::ElementName &element, 1558 int &result); 1559 1560 bool CheckCallingTokenId(const std::string &bundleName, int32_t userId); 1561 1562 void ReleaseAbilityTokenMap(const sptr<IRemoteObject> &token); 1563 1564 void RecordAppExitReasonAtUpgrade(const AppExecFwk::BundleInfo &bundleInfo); 1565 1566 bool CheckPrepareTerminateEnable(); 1567 1568 bool CheckCollaboratorType(int32_t type); 1569 1570 void GetConnectManagerAndUIExtensionBySessionInfo(const sptr<SessionInfo> &sessionInfo, 1571 std::shared_ptr<AbilityConnectManager> &connectManager, std::shared_ptr<AbilityRecord> &targetAbility); 1572 1573 virtual int RegisterSessionHandler(const sptr<IRemoteObject> &object) override; 1574 1575 bool CheckSenderWantInfo(int32_t callerUid, const WantSenderInfo &wantSenderInfo); 1576 1577 constexpr static int REPOLL_TIME_MICRO_SECONDS = 1000000; 1578 constexpr static int WAITING_BOOT_ANIMATION_TIMER = 5; 1579 1580 std::shared_ptr<TaskHandlerWrap> taskHandler_; 1581 std::shared_ptr<AbilityEventHandler> eventHandler_; 1582 ServiceRunningState state_; 1583 std::unordered_map<int, std::shared_ptr<AbilityConnectManager>> connectManagers_; 1584 std::shared_ptr<AbilityConnectManager> connectManager_; 1585 sptr<AppExecFwk::IBundleMgr> iBundleManager_; 1586 sptr<OHOS::AppExecFwk::IAppMgr> appMgr_ { nullptr }; 1587 std::unordered_map<int, std::shared_ptr<DataAbilityManager>> dataAbilityManagers_; 1588 std::shared_ptr<DataAbilityManager> dataAbilityManager_; 1589 std::shared_ptr<DataAbilityManager> systemDataAbilityManager_; 1590 std::unordered_map<int, std::shared_ptr<PendingWantManager>> pendingWantManagers_; 1591 std::shared_ptr<PendingWantManager> pendingWantManager_; 1592 const static std::map<std::string, AbilityManagerService::DumpKey> dumpMap; 1593 const static std::map<std::string, AbilityManagerService::DumpsysKey> dumpsysMap; 1594 const static std::map<int32_t, AppExecFwk::SupportWindowMode> windowModeMap; 1595 1596 std::unordered_map<int, std::shared_ptr<MissionListManager>> missionListManagers_; 1597 std::shared_ptr<MissionListManager> currentMissionListManager_; 1598 1599 std::shared_ptr<FreeInstallManager> freeInstallManager_; 1600 1601 std::shared_ptr<UIAbilityLifecycleManager> uiAbilityLifecycleManager_; 1602 1603 std::shared_ptr<UserController> userController_; 1604 sptr<AppExecFwk::IAbilityController> abilityController_ = nullptr; 1605 bool controllerIsAStabilityTest_ = false; 1606 ffrt::mutex globalLock_; 1607 ffrt::mutex managersMutex_; 1608 ffrt::mutex bgtaskObserverMutex_; 1609 ffrt::mutex abilityTokenLock_; 1610 sptr<AppExecFwk::IComponentInterception> componentInterception_ = nullptr; 1611 1612 std::multimap<std::string, std::string> timeoutMap_; 1613 1614 static sptr<AbilityManagerService> instance_; 1615 int32_t uniqueId_ = 0; 1616 std::map<int32_t, std::pair<int64_t, const sptr<IAcquireShareDataCallback>>> iAcquireShareDataMap_; 1617 // first is callstub, second is ability token 1618 std::map<sptr<IRemoteObject>, sptr<IRemoteObject>> callStubTokenMap_; 1619 sptr<WindowFocusChangedListener> focusListener_; 1620 // Component StartUp rule switch 1621 bool startUpNewRule_ = true; 1622 /** It only takes effect when startUpNewRule_ is TRUE 1623 * TRUE: When Caller-Application is Launcher or SystemUI, use old rule. 1624 * FALSE: Apply new rule to all application 1625 */ 1626 bool newRuleExceptLauncherSystemUI_ = true; 1627 /** Indicates the criteria for judging whether the Caller-Application is in the background 1628 * TRUE: Determine the state by AAFwk::AppState::FOREGROUND. 1629 * FALSE: Determine the state by AppExecFwk::AppProcessState::APP_STATE_FOCUS. 1630 */ 1631 bool backgroundJudgeFlag_ = true; 1632 /** The applications in white list can associatedWakeUp 1633 * TRUE: white list enable. 1634 * FALSE: white list unable. 1635 */ 1636 bool whiteListassociatedWakeUpFlag_ = true; 1637 1638 #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE 1639 std::shared_ptr<BackgroundTaskObserver> bgtaskObserver_; 1640 #endif 1641 1642 sptr<AbilityBundleEventCallback> abilityBundleEventCallback_; 1643 1644 #ifdef SUPPORT_GRAPHICS 1645 int32_t ShowPickerDialog(const Want& want, int32_t userId, const sptr<IRemoteObject> &token); 1646 bool CheckWindowMode(int32_t windowMode, const std::vector<AppExecFwk::SupportWindowMode>& windowModes) const; 1647 void InitFocusListener(); 1648 void RegisterFocusListener(); 1649 void InitPrepareTerminateConfig(); 1650 std::shared_ptr<ImplicitStartProcessor> implicitStartProcessor_; 1651 sptr<IWindowManagerServiceHandler> wmsHandler_; 1652 #endif 1653 std::shared_ptr<AbilityInterceptorExecuter> interceptorExecuter_; 1654 #ifdef SUPPORT_ERMS 1655 std::shared_ptr<AbilityInterceptorExecuter> afterCheckExecuter_; 1656 #endif 1657 std::unordered_map<int32_t, int64_t> appRecoveryHistory_; // uid:time 1658 bool isPrepareTerminateEnable_ = false; 1659 std::multimap<int, std::shared_ptr<StartAbilityHandler>, std::greater<int>> startAbilityChain_; 1660 1661 ffrt::mutex collaboratorMapLock_; 1662 std::unordered_map<int32_t, sptr<IAbilityManagerCollaborator>> collaboratorMap_; 1663 }; 1664 } // namespace AAFwk 1665 } // namespace OHOS 1666 #endif // OHOS_ABILITY_RUNTIME_ABILITY_MANAGER_SERVICE_H 1667