• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "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 private:
34     AbilityManagerAdapter();
35     virtual ~AbilityManagerAdapter();
36     DISALLOW_COPY_AND_MOVE(AbilityManagerAdapter);
37 
38 public:
39     static AbilityManagerAdapter* GetInstance();
40 
41     /**
42      * ConnectAbility, connect session with service ability.
43      *
44      * @param want, Special want for service type's ability.
45      * @param connect, Callback used to notify caller the result of connecting or disconnecting.
46      * @param callerToken, caller ability token.
47      * @return Returns ERR_OK on success, others on failure.
48      */
49     ErrCode ConnectAbility(
50         const Want &want,
51         const sptr<IAbilityConnection> &connect,
52         const sptr<IRemoteObject> &callerToken,
53         int32_t userId = -1);
54 
55     /**
56      * DisconnectAbility, disconnect session with service ability.
57      *
58      * @param connect, Callback used to notify caller the result of connecting or disconnecting.
59      * @return Returns ERR_OK on success, others on failure.
60      */
61     ErrCode DisconnectAbility(const sptr<IAbilityConnection> &connect);
62 
63     /**
64      * @brief start user.
65      * @param accountId accountId.
66      *
67      * @return Returns ERR_OK on success, others on failure.
68      */
69     ErrCode StartUser(int32_t accountId, const sptr<IUserCallback> &callback, bool isAppRecovery = false);
70 
71     /**
72      * @brief stop user.
73      * @param accountId accountId.
74      * @param callback callback.
75      *
76      * @return Returns ERR_OK on success, others on failure.
77      */
78     ErrCode StopUser(int32_t accountId, const sptr<IUserCallback> &callback);
79 
80     /**
81      * @brief logout user.
82      * @param accountId accountId.
83      *
84      * @return Returns ERR_OK on success, others on failure.
85      */
86     ErrCode LogoutUser(int32_t accountId, const sptr<IUserCallback> &callback);
87 
88     /**
89      * @brief all app is died.
90      * @param accountId accountId.
91      *
92      * @return Returns true on success, false on failure.
93      */
94     bool IsAllAppDied(int32_t accountId);
95 
96 private:
97     void Connect();
98     ErrCode DoConnectAbility(
99         const sptr<IRemoteObject> proxy,
100         const Want &want,
101         const sptr<IAbilityConnection> &connect,
102         const sptr<IRemoteObject> &callerToken,
103         int32_t userId = -1);
104 
105     class AbilityMgrDeathRecipient : public IRemoteObject::DeathRecipient {
106         public:
107             AbilityMgrDeathRecipient() = default;
108             ~AbilityMgrDeathRecipient() override = default;
109             void OnRemoteDied(const wptr<IRemoteObject>& remote) override;
110         private:
111             DISALLOW_COPY_AND_MOVE(AbilityMgrDeathRecipient);
112     };
113 
114     sptr<IRemoteObject> GetAbilityManager();
115     void ResetProxy(const wptr<IRemoteObject>& remote);
116 
117     std::mutex proxyMutex_;
118     sptr<IRemoteObject> proxy_;
119     sptr<IRemoteObject::DeathRecipient> deathRecipient_;
120 };
121 }  // namespace AAFwk
122 }  // namespace OHOS
123 #endif  // OS_ACCOUNT_SERVICE_ABILITY_MANAGER_ADAPTER_H
124