1 /*
2  * Copyright (c) 2021-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 OhosAccount
18  * @{
19  *
20  * @brief Provides ohos account management.
21  *
22  * Provides the capability to manage ohos accounts.
23  *
24  * @since 7.0
25  * @version 7.0
26  */
27 
28 /**
29  * @file ohos_account_kits.h
30  *
31  * @brief Declares ohos account interfaces.
32  *
33  * @since 7.0
34  * @version 7.0
35  */
36 #ifndef BASE_ACCOUNT_OHOS_ACCOUNT_KITS_H
37 #define BASE_ACCOUNT_OHOS_ACCOUNT_KITS_H
38 
39 #include "account_info.h"
40 #include "distributed_account_subscribe_callback.h"
41 #include "nocopyable.h"
42 
43 namespace OHOS {
44 namespace AccountSA {
45 /**
46  * Interfaces for ohos account subsystem.
47  */
48 class OhosAccountKits {
49 public:
50     virtual ~OhosAccountKits() = default;
51     DISALLOW_COPY_AND_MOVE(OhosAccountKits);
52 
53     /**
54      * Get instance of ohos account manager.
55      *
56      * @return Instance of ohos account manager.
57      */
58     static OhosAccountKits& GetInstance();
59 
60     /**
61      * Query OHOS Account Info.
62      *
63      * @param VOID.
64      * @return Return a pair of operation result and ohos account info.
65      */
66     virtual std::pair<bool, OhosAccountInfo> QueryOhosAccountInfo() = 0;
67 
68     /**
69      * Query OHOS Account Info.
70      *
71      * @param OhosAccountInfo. ohos account info
72      * @return Return error code.
73      */
74     virtual ErrCode GetOhosAccountInfo(OhosAccountInfo &accountInfo) = 0;
75 
76     /**
77      * Get OHOS account info by user id.
78      *
79      * @param OhosAccountInfo. ohos account info
80      * @return Return error code.
81      */
82     virtual ErrCode GetOhosAccountInfoByUserId(int32_t userId, OhosAccountInfo &accountInfo) = 0;
83 
84     /**
85      * Query OHOS Account Info By user ID.
86      *
87      * @param userId. target local user id
88      * @return Return a pair of operation result and ohos account info.
89      */
90     virtual std::pair<bool, OhosAccountInfo> QueryOhosAccountInfoByUserId(std::int32_t userId) = 0;
91 
92     /**
93      * Update OHOS Account Info.
94      *
95      * @param accountName Indicates the name of the OS account used for a distributed system.
96      * @param uid Uniquely identifies the OS account used for a distributed system.
97      * @param eventStr Indicates the event of the OS account used for a distributed system.
98      * @return Returns {@code true} if the distributed information of the account is updated;
99      *     returns {@code false} otherwise.
100      */
101     virtual bool UpdateOhosAccountInfo(const std::string& accountName, const std::string& uid,
102         const std::string& eventStr) = 0;
103 
104     /**
105      * Update OHOS Account Info.
106      *
107      * @param ohosAccountInfo Indicates the information of the distributed account.
108      * Update OHOS Account Info.
109      * @param eventStr Indicates the event of the OS account used for a distributed system.
110      * @return Returns {@code true} if the distributed information of the account is updated;
111      *     returns {@code false} otherwise.
112      */
113     virtual std::int32_t SetOhosAccountInfo(const OhosAccountInfo &ohosAccountInfo,
114         const std::string &eventStr) = 0;
115 
116     /**
117      * Sets OHOS Account Info.
118      *
119      * @param userId target local account id.
120      * @param ohosAccountInfo Indicates the information of the distributed account.
121      * Update OHOS Account Info.
122      * @param eventStr Indicates the event of the OS account used for a distributed system.
123      * @return Returns {@code true} if the distributed information of the account is updated;
124      *     returns {@code false} otherwise.
125      */
126     virtual ErrCode SetOhosAccountInfoByUserId(
127         const int32_t userId, const OhosAccountInfo& ohosAccountInfo, const std::string& eventStr) = 0;
128 
129     /**
130      * Query Device Account Id.
131      *
132      * @param device account id.
133      * @return if succeed, return ERR_OK and device account Id.
134      */
135     virtual ErrCode QueryDeviceAccountId(std::int32_t& accountId) = 0;
136 
137     /**
138      * Transform uid to device account id.
139      *
140      * @param process calling uid.
141      * @return transformed device account Id
142      */
143     virtual std::int32_t GetDeviceAccountIdByUID(std::int32_t& uid) = 0;
144 
145     /**
146      * @brief Subscribes the event of a distributed account by type and callback.
147      * @param type subscribe type
148      * @param callback subscribe callback
149      * @return error code, see account_error_no.h
150      */
151     virtual ErrCode SubscribeDistributedAccountEvent(const DISTRIBUTED_ACCOUNT_SUBSCRIBE_TYPE type,
152         const std::shared_ptr<DistributedAccountSubscribeCallback> &callback) = 0;
153 
154     /**
155      * @brief Unsubscribes the event of a distributed account by type and callback.
156      * @param type subscribe type
157      * @param callback subscribe callback
158      * @return error code, see account_error_no.h
159      */
160     virtual ErrCode UnsubscribeDistributedAccountEvent(const DISTRIBUTED_ACCOUNT_SUBSCRIBE_TYPE type,
161         const std::shared_ptr<DistributedAccountSubscribeCallback> &callback) = 0;
162 protected:
163     OhosAccountKits() = default;
164 };
165 } // namespace AccountSA
166 } // namespace OHOS
167 
168 #endif // BASE_ACCOUNT_OHOS_ACCOUNT_KITS_H
169