• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 /**
17  * @addtogroup DomainAccount
18  * @{
19  *
20  * @brief Provides domain account management.
21  *
22  * Provides the capability to manage domain accounts.
23  *
24  * @since 10.0
25  * @version 10.0
26  */
27 
28 /**
29  * @file domain_account_client.h
30  *
31  * @brief Declares domain account manager interfaces.
32  *
33  * @since 10.0
34  * @version 10.0
35  */
36 #ifndef OS_ACCOUNT_INTERFACES_INNERKITS_DOMAIN_ACCOUNT_INCLUDE_DOMAIN_ACCOUNT_CLIENT_H
37 #define OS_ACCOUNT_INTERFACES_INNERKITS_DOMAIN_ACCOUNT_INCLUDE_DOMAIN_ACCOUNT_CLIENT_H
38 
39 #include <map>
40 #include <mutex>
41 #include <set>
42 #include "account_error_no.h"
43 #include "domain_account_callback.h"
44 #include "domain_account_plugin.h"
45 #include "idomain_account_plugin.h"
46 #include "domain_account_status_listener.h"
47 #include "domain_account_status_listener_manager.h"
48 #include "domain_account_callback_service.h"
49 #include "get_access_token_callback.h"
50 #include "idomain_account.h"
51 #include "want.h"
52 
53 namespace OHOS {
54 namespace AccountSA {
55 class DomainAccountClient {
56 public:
57     /**
58      * Gets the instance of DomainAccountClient.
59      *
60      * @return the instance of DomainAccountClient.
61      */
62     static DomainAccountClient &GetInstance();
63 
64     /**
65      * @brief Registers the domain plugin, which provides the capabilities for domain authentication.
66      * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS
67      * @param plugin - Indicates the domain plugin.
68      * @return error code, see account_error_no.h
69      */
70     ErrCode RegisterPlugin(const std::shared_ptr<DomainAccountPlugin> &plugin);
71 
72     /**
73      * @brief Unregisters domain plugin.
74      * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS
75      * @return error code, see account_error_no.h
76      */
77     ErrCode UnregisterPlugin();
78 
79     /**
80      * @brief Authenticates the specified domain account with a credential.
81      * @permission ohos.permission.ACCESS_USER_AUTH_INTERNAL
82      * @param domainAccountInfo - Indicates the domain account information.
83      * @param password - Indicates the credential for authentication.
84      * @param callback - Indicates the callback for getting the authentication result.
85      * @return error code, see account_error_no.h
86      */
87     ErrCode Auth(const DomainAccountInfo &info, const std::vector<uint8_t> &password,
88         const std::shared_ptr<DomainAccountCallback> &callback);
89 
90     /**
91      * @brief Authenticates a domain account bound with the specified userId with a credential.
92      * @permission ohos.permission.ACCESS_USER_AUTH_INTERNAL
93      * @param domainAccountInfo - Indicates the domain account information.
94      * @param password - Indicates the credential for authentication.
95      * @param callback - Indicates the callback for getting the authentication result.
96      * @return error code, see account_error_no.h
97      */
98     ErrCode AuthUser(int32_t userId, const std::vector<uint8_t> &password,
99         const std::shared_ptr<DomainAccountCallback> &callback);
100 
101     /**
102      * @brief Authenticates the domain account bound to the specified OS account with a popup.
103      * @permission ohos.permission.ACCESS_USER_AUTH_INTERNAL
104      * @param localId - Indicates the local ID of the specified OS account.
105      * @param callback - Indicates the callback for getting the authentication result.
106      * @return error code, see account_error_no.h
107      */
108     ErrCode AuthWithPopup(int32_t userId, const std::shared_ptr<DomainAccountCallback> &callback);
109 
110     /**
111      * @brief Checks whether the specified domain account exists.
112      * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS
113      * @param domainAccountInfo - Indicates the domain account information.
114      * @param callback - Indicates the callback for checking whether the specified domain account exists.
115      * @return error code, see account_error_no.h
116      */
117     ErrCode HasAccount(const DomainAccountInfo &info, const std::shared_ptr<DomainAccountCallback> &callback);
118     ErrCode UpdateAccountToken(const DomainAccountInfo &info, const std::vector<uint8_t> &token);
119     ErrCode GetAccessToken(const DomainAccountInfo &info, const AAFwk::WantParams &parameters,
120         const std::shared_ptr<GetAccessTokenCallback> &callback);
121     ErrCode GetAccountStatus(const DomainAccountInfo &info, DomainAccountStatus &status);
122     ErrCode GetDomainAccountInfo(const DomainAccountInfo &info, const std::shared_ptr<DomainAccountCallback> &callback);
123     ErrCode RegisterAccountStatusListener(const std::shared_ptr<DomainAccountStatusListener> &listener);
124     ErrCode UnregisterAccountStatusListener(const std::shared_ptr<DomainAccountStatusListener> &listener);
125     friend std::function<void(int32_t, const std::string &)> callbackFunc();
126 
127 private:
128     DomainAccountClient();
129     ~DomainAccountClient() = default;
130     void RestoreListenerRecords();
131     void RestorePlugin();
132     DISALLOW_COPY_AND_MOVE(DomainAccountClient);
133 
134 private:
135     class DomainAccountDeathRecipient : public IRemoteObject::DeathRecipient {
136     public:
137         DomainAccountDeathRecipient() = default;
138         ~DomainAccountDeathRecipient() override = default;
139         void OnRemoteDied(const wptr<IRemoteObject>& remote) override;
140 
141     private:
142         DISALLOW_COPY_AND_MOVE(DomainAccountDeathRecipient);
143     };
144     sptr<IDomainAccount> GetDomainAccountProxy();
145     void ResetDomainAccountProxy(const wptr<IRemoteObject> &remote);
146     ErrCode AuthProxyInit(const std::shared_ptr<DomainAccountCallback> &callback,
147         sptr<DomainAccountCallbackService> &callbackService, sptr<IDomainAccount> &proxy);
148 
149 private:
150     std::mutex mutex_;
151     std::mutex recordMutex_;
152     sptr<IDomainAccount> proxy_ = nullptr;
153     sptr<DomainAccountDeathRecipient> deathRecipient_ = nullptr;
154     sptr<IDomainAccountPlugin> pluginService_ = nullptr;
155     sptr<IDomainAccountCallback> callback_ = nullptr;
156     std::shared_ptr<DomainAccountStatusListenerManager> listenerManager_ = nullptr;
157 };
158 }  // namespace AccountSA
159 }  // namespace OHOS
160 #endif  // OS_ACCOUNT_INTERFACES_INNERKITS_DOMAIN_ACCOUNT_INCLUDE_DOMAIN_ACCOUNT_CLIENT_H