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 * This API can be called only by system applications. 174 * @since 9 175 */ 176 setOsAccountDistributedInfo(accountInfo: DistributedInfo, callback: AsyncCallback<void>): void; 177 178 /** 179 * Sets the distributed information of the OS account. 180 * 181 * @permission ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS 182 * @param { DistributedInfo } accountInfo - Indicates the information of the OS account used for a distributed system. 183 * @returns { Promise<void> } The promise returned by the function. 184 * @throws { BusinessError } 201 - Permission denied. 185 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 186 * <br> 2. Incorrect parameter types. 187 * @throws { BusinessError } 12300001 - System service exception. 188 * @throws { BusinessError } 12300002 - Invalid accountInfo. 189 * @throws { BusinessError } 12300003 - Account not found. 190 * @syscap SystemCapability.Account.OsAccount 191 * This API can be called only by system applications. 192 * @since 9 193 */ 194 setOsAccountDistributedInfo(accountInfo: DistributedInfo): Promise<void>; 195 196 /** 197 * Sets the distributed information of the specified OS account. 198 * 199 * @permission ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS 200 * @param { number } localId - Indicates the local ID of the OS account. 201 * @param { DistributedInfo } distributedInfo - Indicates the distributed information. 202 * @param { AsyncCallback<void> } callback - Asynchronous callback interface. 203 * @throws { BusinessError } 201 - Permission denied. 204 * @throws { BusinessError } 202 - Not system application. 205 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 206 * <br> 2. Incorrect parameter types. 207 * @throws { BusinessError } 12300001 - System service exception. 208 * @throws { BusinessError } 12300002 - Invalid distributedInfo. 209 * @throws { BusinessError } 12300003 - Account identified by localId or by distributedInfo not found. 210 * @throws { BusinessError } 12300008 - Restricted OS account. 211 * @syscap SystemCapability.Account.OsAccount 212 * @systemapi Hide this for inner system use. 213 * @since 10 214 */ 215 setOsAccountDistributedInfoByLocalId( 216 localId: number, 217 distributedInfo: DistributedInfo, 218 callback: AsyncCallback<void> 219 ): void; 220 221 /** 222 * Sets the distributed information of the specified OS account. 223 * 224 * @permission ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS 225 * @param { number } localId - Indicates the local ID of the OS account. 226 * @param { DistributedInfo } distributedInfo - Indicates the distributed information. 227 * @returns { Promise<void> } The promise returned by the function. 228 * @throws { BusinessError } 201 - Permission denied. 229 * @throws { BusinessError } 202 - Not system application. 230 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 231 * <br> 2. Incorrect parameter types. 232 * @throws { BusinessError } 12300001 - System service exception. 233 * @throws { BusinessError } 12300002 - Invalid distributedInfo. 234 * @throws { BusinessError } 12300003 - Account identified by localId or by distributedInfo not found. 235 * @throws { BusinessError } 12300008 - Restricted OS account. 236 * @syscap SystemCapability.Account.OsAccount 237 * @systemapi Hide this for inner system use. 238 * @since 10 239 */ 240 setOsAccountDistributedInfoByLocalId(localId: number, distributedInfo: DistributedInfo): Promise<void>; 241 } 242 243 /** 244 * Enum for distributed account status. 245 * 246 * @enum { number } 247 * @syscap SystemCapability.Account.OsAccount 248 * @since 10 249 */ 250 enum DistributedAccountStatus { 251 /** 252 * Indicates that the account is not logged in. 253 * 254 * @syscap SystemCapability.Account.OsAccount 255 * @since 10 256 */ 257 NOT_LOGGED_IN = 0, 258 259 /** 260 * Indicates that the account is logged in. 261 * 262 * @syscap SystemCapability.Account.OsAccount 263 * @since 10 264 */ 265 LOGGED_IN = 1 266 } 267 268 /** 269 * Provides the distributed information of the OS account. 270 * 271 * @interface DistributedInfo 272 * @syscap SystemCapability.Account.OsAccount 273 * @since 7 274 */ 275 interface DistributedInfo { 276 /** 277 * The name in the distributed information of the OS account. 278 * 279 * @type { string } 280 * @syscap SystemCapability.Account.OsAccount 281 * @since 7 282 */ 283 name: string; 284 285 /** 286 * The ID in the distributed information of the OS account. 287 * 288 * @type { string } 289 * @syscap SystemCapability.Account.OsAccount 290 * @since 7 291 */ 292 id: string; 293 294 /** 295 * The event string in the distributed information of the OS account. 296 * 297 * @type { string } 298 * @syscap SystemCapability.Account.OsAccount 299 * @since 7 300 */ 301 event: string; 302 303 /** 304 * The nickname in the distributed information of the OS account. 305 * 306 * @type { ?string } 307 * @syscap SystemCapability.Account.OsAccount 308 * @since 9 309 */ 310 nickname?: string; 311 312 /** 313 * The avatar in the distributed information of the OS account. 314 * 315 * @type { ?string } 316 * @syscap SystemCapability.Account.OsAccount 317 * @since 9 318 */ 319 avatar?: string; 320 321 /** 322 * The status in the distributed information of the OS account. 323 * 324 * @type { ?DistributedAccountStatus } 325 * @readonly 326 * @syscap SystemCapability.Account.OsAccount 327 * @since 10 328 */ 329 readonly status?: DistributedAccountStatus; 330 331 /** 332 * The scalable data in the distributed information of the OS account. 333 * 334 * @type { ?object } 335 * @syscap SystemCapability.Account.OsAccount 336 * @since 8 337 */ 338 scalableData?: object; 339 } 340} 341 342export default distributedAccount;