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