1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OS_ACCOUNT_SERVICE_ABILITY_MANAGER_ADAPTER_H 17 #define OS_ACCOUNT_SERVICE_ABILITY_MANAGER_ADAPTER_H 18 19 #include <mutex> 20 21 #include "ability_connect_callback_interface.h" 22 #include "stop_user_callback.h" 23 #include "want.h" 24 25 namespace OHOS { 26 namespace AccountSA { 27 using namespace AAFwk; 28 /** 29 * @class AbilityManagerAdapter 30 * AbilityManagerAdapter is used to access ability manager services. 31 */ 32 class AbilityManagerAdapter { 33 public: 34 AbilityManagerAdapter(); 35 virtual ~AbilityManagerAdapter(); 36 static std::shared_ptr<AbilityManagerAdapter> GetInstance(); 37 38 /** 39 * ConnectAbility, connect session with service ability. 40 * 41 * @param want, Special want for service type's ability. 42 * @param connect, Callback used to notify caller the result of connecting or disconnecting. 43 * @param callerToken, caller ability token. 44 * @return Returns ERR_OK on success, others on failure. 45 */ 46 ErrCode ConnectAbility( 47 const Want &want, 48 const sptr<IAbilityConnection> &connect, 49 const sptr<IRemoteObject> &callerToken, 50 int32_t userId = -1); 51 52 /** 53 * DisconnectAbility, disconnect session with service ability. 54 * 55 * @param connect, Callback used to notify caller the result of connecting or disconnecting. 56 * @return Returns ERR_OK on success, others on failure. 57 */ 58 ErrCode DisconnectAbility(const sptr<IAbilityConnection> &connect); 59 60 /** 61 * @brief start user. 62 * @param accountId accountId. 63 * 64 * @return Returns ERR_OK on success, others on failure. 65 */ 66 ErrCode StartUser(int32_t accountId); 67 68 /** 69 * @brief stop user. 70 * @param accountId accountId. 71 * @param callback callback. 72 * 73 * @return Returns ERR_OK on success, others on failure. 74 */ 75 ErrCode StopUser(int32_t accountId, const sptr<IStopUserCallback> &callback); 76 77 private: 78 static std::mutex mockInstanceMutex_; 79 static std::shared_ptr<AbilityManagerAdapter> instance_; 80 }; 81 } // namespace AAFwk 82 } // namespace OHOS 83 #endif // OS_ACCOUNT_SERVICE_ABILITY_MANAGER_ADAPTER_H 84