• 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 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.
79     * <br> 2. Incorrect parameter types.
80     * @throws { BusinessError } 12300001 - System service exception.
81     * @syscap SystemCapability.Account.OsAccount
82     * @since 9
83     */
84    getOsAccountDistributedInfo(callback: AsyncCallback<DistributedInfo>): void;
85
86    /**
87     * Gets the distributed information of the current OS account.
88     *
89     * @permission ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS or ohos.permission.GET_DISTRIBUTED_ACCOUNTS or ohos.permission.DISTRIBUTED_DATASYNC
90     * @returns { Promise<DistributedInfo> } The distributed information of the current OS account.
91     * @throws { BusinessError } 201 - Permission denied.
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 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.
107     * <br> 2. Incorrect parameter types.
108     * @throws { BusinessError } 12300001 - System service exception.
109     * @throws { BusinessError } 12300003 - Account not found.
110     * @syscap SystemCapability.Account.OsAccount
111     * @systemapi Hide this for inner system use.
112     * @since 10
113     */
114    /**
115     * Gets the distributed information of the specified OS account.
116     *
117     * @permission ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS or (ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS and
118     * ohos.permission.GET_DISTRIBUTED_ACCOUNTS)
119     * @param { number } localId - Indicates the local ID of the specified OS account.
120     * @param { AsyncCallback<DistributedInfo> } callback - Asynchronous callback interface.
121     * @throws { BusinessError } 201 - Permission denied.
122     * @throws { BusinessError } 202 - Not system application.
123     * @throws { BusinessError } 12300001 - System service exception.
124     * @throws { BusinessError } 12300003 - Account not found.
125     * @syscap SystemCapability.Account.OsAccount
126     * @systemapi
127     * @since 20
128     */
129    getOsAccountDistributedInfoByLocalId(localId: number, callback: AsyncCallback<DistributedInfo>): void;
130
131    /**
132     * Gets the distributed information of the specified OS account.
133     *
134     * @permission ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
135     * @param { number } localId - Indicates the local ID of the specified OS account.
136     * @returns { Promise<DistributedInfo> } The distributed information of the specified OS account.
137     * @throws { BusinessError } 201 - Permission denied.
138     * @throws { BusinessError } 202 - Not system application.
139     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.
140     * <br> 2. Incorrect parameter types.
141     * @throws { BusinessError } 12300001 - System service exception.
142     * @throws { BusinessError } 12300003 - Account not found.
143     * @syscap SystemCapability.Account.OsAccount
144     * @systemapi Hide this for inner system use.
145     * @since 10
146     */
147    /**
148     * Gets the distributed information of the specified OS account.
149     *
150     * @permission ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS or (ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS and
151     * ohos.permission.GET_DISTRIBUTED_ACCOUNTS)
152     * @param { number } localId - Indicates the local ID of the specified OS account.
153     * @returns { Promise<DistributedInfo> } The distributed information of the specified OS account.
154     * @throws { BusinessError } 201 - Permission denied.
155     * @throws { BusinessError } 202 - Not system application.
156     * @throws { BusinessError } 12300001 - System service exception.
157     * @throws { BusinessError } 12300003 - Account not found.
158     * @syscap SystemCapability.Account.OsAccount
159     * @systemapi
160     * @since 20
161     */
162    getOsAccountDistributedInfoByLocalId(localId: number): Promise<DistributedInfo>;
163
164    /**
165     * Updates the distributed information of the OS account.
166     *
167     * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS
168     * @param { DistributedInfo } accountInfo - Indicates the information of the OS account used for a distributed system.
169     * @param { AsyncCallback<void> } callback - Asynchronous callback interface.
170     * @syscap SystemCapability.Account.OsAccount
171     * @since 7
172     * @deprecated since 9
173     * @useinstead distributedAccount.DistributedAccountAbility#setOsAccountDistributedInfo
174     */
175    updateOsAccountDistributedInfo(accountInfo: DistributedInfo, callback: AsyncCallback<void>): void;
176
177    /**
178     * Updates the distributed information of the OS account.
179     *
180     * @permission ohos.permission.MANAGE_LOCAL_ACCOUNTS
181     * @param { DistributedInfo } accountInfo - Indicates the information of the OS account used for a distributed system.
182     * @returns { Promise<void> } The promise returned by the function.
183     * @syscap SystemCapability.Account.OsAccount
184     * @since 7
185     * @deprecated since 9
186     * @useinstead distributedAccount.DistributedAccountAbility#setOsAccountDistributedInfo
187     */
188    updateOsAccountDistributedInfo(accountInfo: DistributedInfo): Promise<void>;
189
190    /**
191     * Sets the distributed information of the OS account.
192     *
193     * @permission ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS
194     * @param { DistributedInfo } accountInfo - Indicates the information of the OS account used for a distributed system.
195     * @param { AsyncCallback<void> } callback - Asynchronous callback interface.
196     * @throws { BusinessError } 201 - Permission denied.
197     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.
198     * <br> 2. Incorrect parameter types.
199     * @throws { BusinessError } 12300001 - System service exception.
200     * @throws { BusinessError } 12300002 - Invalid accountInfo.
201     * @throws { BusinessError } 12300003 - Account not found.
202     * @syscap SystemCapability.Account.OsAccount
203     * This API can be called only by system applications.
204     * @since 9
205     */
206    setOsAccountDistributedInfo(accountInfo: DistributedInfo, callback: AsyncCallback<void>): void;
207
208    /**
209     * Sets the distributed information of the OS account.
210     *
211     * @permission ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS
212     * @param { DistributedInfo } accountInfo - Indicates the information of the OS account used for a distributed system.
213     * @returns { Promise<void> } The promise returned by the function.
214     * @throws { BusinessError } 201 - Permission denied.
215     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.
216     * <br> 2. Incorrect parameter types.
217     * @throws { BusinessError } 12300001 - System service exception.
218     * @throws { BusinessError } 12300002 - Invalid accountInfo.
219     * @throws { BusinessError } 12300003 - Account not found.
220     * @syscap SystemCapability.Account.OsAccount
221     * This API can be called only by system applications.
222     * @since 9
223     */
224    setOsAccountDistributedInfo(accountInfo: DistributedInfo): Promise<void>;
225
226    /**
227     * Sets the distributed information of the specified OS account.
228     *
229     * @permission ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS
230     * @param { number } localId - Indicates the local ID of the OS account.
231     * @param { DistributedInfo } distributedInfo - Indicates the distributed information.
232     * @param { AsyncCallback<void> } callback - Asynchronous callback interface.
233     * @throws { BusinessError } 201 - Permission denied.
234     * @throws { BusinessError } 202 - Not system application.
235     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.
236     * <br> 2. Incorrect parameter types.
237     * @throws { BusinessError } 12300001 - System service exception.
238     * @throws { BusinessError } 12300002 - Invalid distributedInfo.
239     * @throws { BusinessError } 12300003 - Account identified by localId or by distributedInfo not found.
240     * @throws { BusinessError } 12300008 - Restricted OS account.
241     * @syscap SystemCapability.Account.OsAccount
242     * @systemapi Hide this for inner system use.
243     * @since 10
244     */
245    setOsAccountDistributedInfoByLocalId(
246      localId: number,
247      distributedInfo: DistributedInfo,
248      callback: AsyncCallback<void>
249    ): void;
250
251    /**
252     * Sets the distributed information of the specified OS account.
253     *
254     * @permission ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS
255     * @param { number } localId - Indicates the local ID of the OS account.
256     * @param { DistributedInfo } distributedInfo - Indicates the distributed information.
257     * @returns { Promise<void> } The promise returned by the function.
258     * @throws { BusinessError } 201 - Permission denied.
259     * @throws { BusinessError } 202 - Not system application.
260     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.
261     * <br> 2. Incorrect parameter types.
262     * @throws { BusinessError } 12300001 - System service exception.
263     * @throws { BusinessError } 12300002 - Invalid distributedInfo.
264     * @throws { BusinessError } 12300003 - Account identified by localId or by distributedInfo not found.
265     * @throws { BusinessError } 12300008 - Restricted OS account.
266     * @syscap SystemCapability.Account.OsAccount
267     * @systemapi Hide this for inner system use.
268     * @since 10
269     */
270    setOsAccountDistributedInfoByLocalId(localId: number, distributedInfo: DistributedInfo): Promise<void>;
271  }
272
273  /**
274   * Enum for distributed account status.
275   *
276   * @enum { number }
277   * @syscap SystemCapability.Account.OsAccount
278   * @since 10
279   */
280  enum DistributedAccountStatus {
281    /**
282     * Indicates that the account is not logged in.
283     *
284     * @syscap SystemCapability.Account.OsAccount
285     * @since 10
286     */
287    NOT_LOGGED_IN = 0,
288
289    /**
290     * Indicates that the account is logged in.
291     *
292     * @syscap SystemCapability.Account.OsAccount
293     * @since 10
294     */
295    LOGGED_IN = 1
296  }
297
298  /**
299   * Provides the distributed information of the OS account.
300   *
301   * @interface DistributedInfo
302   * @syscap SystemCapability.Account.OsAccount
303   * @since 7
304   */
305  interface DistributedInfo {
306    /**
307     * The name in the distributed information of the OS account.
308     *
309     * @type { string }
310     * @syscap SystemCapability.Account.OsAccount
311     * @since 7
312     */
313    name: string;
314
315    /**
316     * The ID in the distributed information of the OS account.
317     *
318     * @type { string }
319     * @syscap SystemCapability.Account.OsAccount
320     * @since 7
321     */
322    id: string;
323
324    /**
325     * The event string in the distributed information of the OS account.
326     *
327     * @type { string }
328     * @syscap SystemCapability.Account.OsAccount
329     * @since 7
330     */
331    event: string;
332
333    /**
334     * The nickname in the distributed information of the OS account.
335     *
336     * @type { ?string }
337     * @syscap SystemCapability.Account.OsAccount
338     * @since 9
339     */
340    nickname?: string;
341
342    /**
343     * The avatar in the distributed information of the OS account.
344     *
345     * @type { ?string }
346     * @syscap SystemCapability.Account.OsAccount
347     * @since 9
348     */
349    avatar?: string;
350
351    /**
352     * The status in the distributed information of the OS account.
353     *
354     * @type { ?DistributedAccountStatus }
355     * @readonly
356     * @syscap SystemCapability.Account.OsAccount
357     * @since 10
358     */
359    readonly status?: DistributedAccountStatus;
360
361    /**
362     * The scalable data in the distributed information of the OS account.
363     *
364     * @type { ?object }
365     * @syscap SystemCapability.Account.OsAccount
366     * @since 8
367     */
368    scalableData?: object;
369  }
370}
371
372export default distributedAccount;