• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 * @file
18 * @kit BasicServicesKit
19 */
20
21import type { AsyncCallback } from './@ohos.base';
22
23/**
24 * This module provides the capability to manage distributed accounts.
25 *
26 * @namespace distributedAccount
27 * @syscap SystemCapability.Account.OsAccount
28 * @since 7
29 */
30declare namespace distributedAccount {
31  /**
32   * Gets the ability of the distributed account.
33   *
34   * @returns { DistributedAccountAbility } Ability to manage operations of distributed account.
35   * @syscap SystemCapability.Account.OsAccount
36   * @since 7
37   */
38  function getDistributedAccountAbility(): DistributedAccountAbility;
39
40  /**
41   * Defines distributed account functions and interfaces.
42   *
43   * @interface DistributedAccountAbility
44   * @syscap SystemCapability.Account.OsAccount
45   * @since 7
46   */
47  interface DistributedAccountAbility {
48    /**
49     * Queries the distributed information of the current OS account.
50     *
51     * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.DISTRIBUTED_DATASYNC
52     * @param { AsyncCallback<DistributedInfo> } callback - Asynchronous callback interface.
53     * @syscap SystemCapability.Account.OsAccount
54     * @since 7
55     * @deprecated since 9
56     * @useinstead distributedAccount.DistributedAccountAbility#getOsAccountDistributedInfo
57     */
58    queryOsAccountDistributedInfo(callback: AsyncCallback<DistributedInfo>): void;
59
60    /**
61     * Queries the distributed information of the current OS account.
62     *
63     * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.DISTRIBUTED_DATASYNC
64     * @returns { Promise<DistributedInfo> } The distributed information of the current OS account.
65     * @syscap SystemCapability.Account.OsAccount
66     * @since 7
67     * @deprecated since 9
68     * @useinstead distributedAccount.DistributedAccountAbility#getOsAccountDistributedInfo
69     */
70    queryOsAccountDistributedInfo(): Promise<DistributedInfo>;
71
72    /**
73     * Gets the distributed information of the current OS account.
74     *
75     * @permission ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS or ohos.permission.GET_DISTRIBUTED_ACCOUNTS or ohos.permission.DISTRIBUTED_DATASYNC
76     * @param { AsyncCallback<DistributedInfo> } callback - Asynchronous callback interface.
77     * @throws { BusinessError } 201 - Permission denied.
78     * @throws { BusinessError } 401 - The parameter check failed.
79     * @throws { BusinessError } 12300001 - System service exception.
80     * @syscap SystemCapability.Account.OsAccount
81     * @since 9
82     */
83    getOsAccountDistributedInfo(callback: AsyncCallback<DistributedInfo>): void;
84
85    /**
86     * Gets the distributed information of the current OS account.
87     *
88     * @permission ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS or ohos.permission.GET_DISTRIBUTED_ACCOUNTS or ohos.permission.DISTRIBUTED_DATASYNC
89     * @returns { Promise<DistributedInfo> } The distributed information of the current OS account.
90     * @throws { BusinessError } 201 - Permission denied.
91     * @throws { BusinessError } 401 - The parameter check failed.
92     * @throws { BusinessError } 12300001 - System service exception.
93     * @syscap SystemCapability.Account.OsAccount
94     * @since 9
95     */
96    getOsAccountDistributedInfo(): Promise<DistributedInfo>;
97
98    /**
99     * Gets the distributed information of the specified OS account.
100     *
101     * @permission ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
102     * @param { number } localId - Indicates the local ID of the specified OS account.
103     * @param { AsyncCallback<DistributedInfo> } callback - Asynchronous callback interface.
104     * @throws { BusinessError } 201 - Permission denied.
105     * @throws { BusinessError } 202 - Not system application.
106     * @throws { BusinessError } 401 - The parameter check failed.
107     * @throws { BusinessError } 12300001 - System service exception.
108     * @throws { BusinessError } 12300003 - Account not found.
109     * @syscap SystemCapability.Account.OsAccount
110     * @systemapi Hide this for inner system use.
111     * @since 10
112     */
113    getOsAccountDistributedInfoByLocalId(localId: number, callback: AsyncCallback<DistributedInfo>): void;
114
115    /**
116     * Gets the distributed information of the specified OS account.
117     *
118     * @permission ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
119     * @param { number } localId - Indicates the local ID of the specified OS account.
120     * @returns { Promise<DistributedInfo> } The distributed information of the specified OS account.
121     * @throws { BusinessError } 201 - Permission denied.
122     * @throws { BusinessError } 202 - Not system application.
123     * @throws { BusinessError } 401 - The parameter check failed.
124     * @throws { BusinessError } 12300001 - System service exception.
125     * @throws { BusinessError } 12300003 - Account not found.
126     * @syscap SystemCapability.Account.OsAccount
127     * @systemapi Hide this for inner system use.
128     * @since 10
129     */
130    getOsAccountDistributedInfoByLocalId(localId: number): Promise<DistributedInfo>;
131
132    /**
133     * Updates the distributed information of the OS account.
134     *
135     * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS
136     * @param { DistributedInfo } accountInfo - Indicates the information of the OS account used for a distributed system.
137     * @param { AsyncCallback<void> } callback - Asynchronous callback interface.
138     * @syscap SystemCapability.Account.OsAccount
139     * @since 7
140     * @deprecated since 9
141     * @useinstead distributedAccount.DistributedAccountAbility#setOsAccountDistributedInfo
142     */
143    updateOsAccountDistributedInfo(accountInfo: DistributedInfo, callback: AsyncCallback<void>): void;
144
145    /**
146     * Updates the distributed information of the OS account.
147     *
148     * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS
149     * @param { DistributedInfo } accountInfo - Indicates the information of the OS account used for a distributed system.
150     * @returns { Promise<void> } The promise returned by the function.
151     * @syscap SystemCapability.Account.OsAccount
152     * @since 7
153     * @deprecated since 9
154     * @useinstead distributedAccount.DistributedAccountAbility#setOsAccountDistributedInfo
155     */
156    updateOsAccountDistributedInfo(accountInfo: DistributedInfo): Promise<void>;
157
158    /**
159     * Sets the distributed information of the OS account.
160     *
161     * @permission ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS
162     * @param { DistributedInfo } accountInfo - Indicates the information of the OS account used for a distributed system.
163     * @param { AsyncCallback<void> } callback - Asynchronous callback interface.
164     * @throws { BusinessError } 201 - Permission denied.
165     * @throws { BusinessError } 401 - The parameter check failed.
166     * @throws { BusinessError } 12300001 - System service exception.
167     * @throws { BusinessError } 12300002 - Invalid accountInfo.
168     * @throws { BusinessError } 12300003 - Account not found.
169     * @syscap SystemCapability.Account.OsAccount
170     * @since 9
171     */
172    setOsAccountDistributedInfo(accountInfo: DistributedInfo, callback: AsyncCallback<void>): void;
173
174    /**
175     * Sets the distributed information of the OS account.
176     *
177     * @permission ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS
178     * @param { DistributedInfo } accountInfo - Indicates the information of the OS account used for a distributed system.
179     * @returns { Promise<void> } The promise returned by the function.
180     * @throws { BusinessError } 201 - Permission denied.
181     * @throws { BusinessError } 401 - The parameter check failed.
182     * @throws { BusinessError } 12300001 - System service exception.
183     * @throws { BusinessError } 12300002 - Invalid accountInfo.
184     * @throws { BusinessError } 12300003 - Account not found.
185     * @syscap SystemCapability.Account.OsAccount
186     * @since 9
187     */
188    setOsAccountDistributedInfo(accountInfo: DistributedInfo): Promise<void>;
189
190    /**
191     * Sets the distributed information of the specified OS account.
192     *
193     * @permission ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS
194     * @param { number } localId - Indicates the local ID of the OS account.
195     * @param { DistributedInfo } distributedInfo - Indicates the distributed information.
196     * @param { AsyncCallback<void> } callback - Asynchronous callback interface.
197     * @throws { BusinessError } 201 - Permission denied.
198     * @throws { BusinessError } 202 - Not system application.
199     * @throws { BusinessError } 401 - The parameter check failed.
200     * @throws { BusinessError } 12300001 - System service exception.
201     * @throws { BusinessError } 12300002 - Invalid distributedInfo.
202     * @throws { BusinessError } 12300003 - Account identified by localId or by distributedInfo not found.
203     * @throws { BusinessError } 12300008 - Restricted OS account.
204     * @syscap SystemCapability.Account.OsAccount
205     * @systemapi Hide this for inner system use.
206     * @since 10
207     */
208    setOsAccountDistributedInfoByLocalId(
209      localId: number,
210      distributedInfo: DistributedInfo,
211      callback: AsyncCallback<void>
212    ): void;
213
214    /**
215     * Sets the distributed information of the specified OS account.
216     *
217     * @permission ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS
218     * @param { number } localId - Indicates the local ID of the OS account.
219     * @param { DistributedInfo } distributedInfo - Indicates the distributed information.
220     * @returns { Promise<void> } The promise returned by the function.
221     * @throws { BusinessError } 201 - Permission denied.
222     * @throws { BusinessError } 202 - Not system application.
223     * @throws { BusinessError } 401 - The parameter check failed.
224     * @throws { BusinessError } 12300001 - System service exception.
225     * @throws { BusinessError } 12300002 - Invalid distributedInfo.
226     * @throws { BusinessError } 12300003 - Account identified by localId or by distributedInfo not found.
227     * @throws { BusinessError } 12300008 - Restricted OS account.
228     * @syscap SystemCapability.Account.OsAccount
229     * @systemapi Hide this for inner system use.
230     * @since 10
231     */
232    setOsAccountDistributedInfoByLocalId(localId: number, distributedInfo: DistributedInfo): Promise<void>;
233  }
234
235  /**
236   * Enum for distributed account status.
237   *
238   * @enum { number }
239   * @syscap SystemCapability.Account.OsAccount
240   * @since 10
241   */
242  enum DistributedAccountStatus {
243    /**
244     * Indicates that the account is not logged in.
245     *
246     * @syscap SystemCapability.Account.OsAccount
247     * @since 10
248     */
249    NOT_LOGGED_IN = 0,
250
251    /**
252     * Indicates that the account is logged in.
253     *
254     * @syscap SystemCapability.Account.OsAccount
255     * @since 10
256     */
257    LOGGED_IN = 1
258  }
259
260  /**
261   * Provides the distributed information of the OS account.
262   *
263   * @interface DistributedInfo
264   * @syscap SystemCapability.Account.OsAccount
265   * @since 7
266   */
267  interface DistributedInfo {
268    /**
269     * The name in the distributed information of the OS account.
270     *
271     * @type { string }
272     * @syscap SystemCapability.Account.OsAccount
273     * @since 7
274     */
275    name: string;
276
277    /**
278     * The ID in the distributed information of the OS account.
279     *
280     * @type { string }
281     * @syscap SystemCapability.Account.OsAccount
282     * @since 7
283     */
284    id: string;
285
286    /**
287     * The event string in the distributed information of the OS account.
288     *
289     * @type { string }
290     * @syscap SystemCapability.Account.OsAccount
291     * @since 7
292     */
293    event: string;
294
295    /**
296     * The nickname in the distributed information of the OS account.
297     *
298     * @type { ?string }
299     * @syscap SystemCapability.Account.OsAccount
300     * @since 9
301     */
302    nickname?: string;
303
304    /**
305     * The avatar in the distributed information of the OS account.
306     *
307     * @type { ?string }
308     * @syscap SystemCapability.Account.OsAccount
309     * @since 9
310     */
311    avatar?: string;
312
313    /**
314     * The status in the distributed information of the OS account.
315     *
316     * @type { ?DistributedAccountStatus }
317     * @readonly
318     * @syscap SystemCapability.Account.OsAccount
319     * @since 10
320     */
321    readonly status?: DistributedAccountStatus;
322
323    /**
324     * The scalable data in the distributed information of the OS account.
325     *
326     * @type { ?object }
327     * @syscap SystemCapability.Account.OsAccount
328     * @since 8
329     */
330    scalableData?: object;
331  }
332}
333
334export default distributedAccount;