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