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