1/* 2 * Copyright (c) 2022 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 ArkData 19 */ 20 21import { AsyncCallback, Callback } from './@ohos.base'; 22import Context from './application/BaseContext'; 23 24/** 25 * Provides interfaces to obtain and modify preferences data. 26 * 27 * @namespace preferences 28 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 29 * @since 9 30 * @name preferences 31 */ 32/** 33 * Provides interfaces to obtain and modify preferences data. 34 * 35 * @namespace preferences 36 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 37 * @crossplatform 38 * @since 10 39 * @name preferences 40 */ 41/** 42 * Provides interfaces to obtain and modify preferences data. 43 * 44 * @namespace preferences 45 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 46 * @crossplatform 47 * @atomicservice 48 * @since 11 49 * @name preferences 50 */ 51declare namespace preferences { 52 /** 53 * Indicates possible value types 54 * 55 * @typedef {number | string | boolean | Array<number> | Array<string> | Array<boolean>} 56 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 57 * @since 9 58 */ 59 /** 60 * Indicates possible value types 61 * 62 * @typedef {number | string | boolean | Array<number> | Array<string> | Array<boolean>} 63 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 64 * @since 10 65 */ 66 /** 67 * Indicates possible value types 68 * 69 * @typedef {number | string | boolean | Array<number> | Array<string> | Array<boolean> | Uint8Array} 70 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 71 * @atomicservice 72 * @since 11 73 */ 74 /** 75 * Indicates possible value types 76 * 77 * @typedef {number | string | boolean | Array<number> | Array<string> | Array<boolean> | Uint8Array | object | bigint} 78 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 79 * @atomicservice 80 * @since 12 81 */ 82 type ValueType = number | string | boolean | Array<number> | Array<string> | Array<boolean> | Uint8Array | object | bigint; 83 84 /** 85 * Indicates the maximum length of a key (80 characters). 86 * 87 * @constant 88 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 89 * @since 9 90 */ 91 /** 92 * Indicates the maximum length of a key (80 characters). 93 * 94 * @constant 95 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 96 * @crossplatform 97 * @since 10 98 */ 99 /** 100 * Indicates the maximum length of a key (80 characters). 101 * 102 * @constant 103 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 104 * @crossplatform 105 * @atomicservice 106 * @since 11 107 */ 108 const MAX_KEY_LENGTH: 80; 109 110 /** 111 * Indicates the maximum length of a string (8192 characters). 112 * 113 * @constant 114 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 115 * @since 9 116 */ 117 /** 118 * Indicates the maximum length of a string (8192 characters). 119 * 120 * @constant 121 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 122 * @crossplatform 123 * @since 10 124 */ 125 /** 126 * Indicates the maximum length of a string (8192 characters). 127 * 128 * @constant 129 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 130 * @crossplatform 131 * @atomicservice 132 * @since 11 133 */ 134 const MAX_VALUE_LENGTH: 8192; 135 136 /** 137 * Manages preferences file configurations. 138 * 139 * @interface Options 140 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 141 * @crossplatform 142 * @since 10 143 */ 144 /** 145 * Manages preferences file configurations. 146 * 147 * @interface Options 148 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 149 * @crossplatform 150 * @atomicservice 151 * @since 11 152 */ 153 interface Options { 154 /** 155 * The preferences file name. 156 * 157 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 158 * @crossplatform 159 * @since 10 160 */ 161 /** 162 * The preferences file name. 163 * 164 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 165 * @crossplatform 166 * @atomicservice 167 * @since 11 168 */ 169 name: string; 170 171 /** 172 * Application Group Id. 173 * 174 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 175 * @StageModelOnly 176 * @since 10 177 */ 178 /** 179 * Application Group Id. 180 * 181 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 182 * @StageModelOnly 183 * @atomicservice 184 * @since 11 185 */ 186 dataGroupId?: string | null | undefined; 187 } 188 189 /** 190 * Obtains a {@link Preferences} instance matching a specified preferences file name. 191 * <p>The {@link references} instance loads all data of the preferences file and 192 * resides in the memory. You can use removePreferencesFromCache to remove the instance from the memory. 193 * 194 * @param { Context } context - Indicates the context of application or capability. 195 * @param { string } name - Indicates the preferences file name. 196 * @param { AsyncCallback<Preferences> } callback - The {@link Preferences} instance matching the specified 197 * preferences file name. 198 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 199 * 2. Incorrect parameter types; 200 * 3. Parameter verification failed. 201 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 202 * @since 9 203 */ 204 /** 205 * Obtains a {@link Preferences} instance matching a specified preferences file name. 206 * <p>The {@link references} instance loads all data of the preferences file and 207 * resides in the memory. You can use removePreferencesFromCache to remove the instance from the memory. 208 * 209 * @param { Context } context - Indicates the context of application or capability. 210 * @param { string } name - Indicates the preferences file name. 211 * @param { AsyncCallback<Preferences> } callback - The {@link Preferences} instance matching the specified 212 * preferences file name. 213 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 214 * 2. Incorrect parameter types; 215 * 3. Parameter verification failed. 216 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 217 * @crossplatform 218 * @since 10 219 */ 220 /** 221 * Obtains a {@link Preferences} instance matching a specified preferences file name. 222 * <p>The {@link references} instance loads all data of the preferences file and 223 * resides in the memory. You can use removePreferencesFromCache to remove the instance from the memory. 224 * 225 * @param { Context } context - Indicates the context of application or capability. 226 * @param { string } name - Indicates the preferences file name. 227 * @param { AsyncCallback<Preferences> } callback - The {@link Preferences} instance matching the specified 228 * preferences file name. 229 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 230 * 2. Incorrect parameter types; 231 * 3. Parameter verification failed. 232 * @throws { BusinessError } 15500000 - Inner error. 233 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 234 * @crossplatform 235 * @atomicservice 236 * @since 11 237 */ 238 function getPreferences(context: Context, name: string, callback: AsyncCallback<Preferences>): void; 239 240 /** 241 * Obtains a {@link Preferences} instance matching a specified preferences file name. 242 * <p>The {@link references} instance loads all data of the preferences file and 243 * resides in the memory. You can use removePreferencesFromCache to remove the instance from the memory. 244 * 245 * @param { Context } context - Indicates the context of application or capability. 246 * @param { Options } options - Indicates the {@link Options} option of preferences file position. 247 * @param { AsyncCallback<Preferences> } callback - The {@link Preferences} instance matching the specified 248 * preferences file name. 249 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 250 * 2. Incorrect parameter types; 251 * 3. Parameter verification failed. 252 * @throws { BusinessError } 801 - Capability not supported. 253 * @throws { BusinessError } 15501001 - Only supported in stage mode. 254 * @throws { BusinessError } 15501002 - The data group id is not valid. 255 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 256 * @crossplatform 257 * @since 10 258 */ 259 /** 260 * Obtains a {@link Preferences} instance matching a specified preferences file name. 261 * <p>The {@link references} instance loads all data of the preferences file and 262 * resides in the memory. You can use removePreferencesFromCache to remove the instance from the memory. 263 * 264 * @param { Context } context - Indicates the context of application or capability. 265 * @param { Options } options - Indicates the {@link Options} option of preferences file position. 266 * @param { AsyncCallback<Preferences> } callback - The {@link Preferences} instance matching the specified 267 * preferences file name. 268 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 269 * 2. Incorrect parameter types; 270 * 3. Parameter verification failed. 271 * @throws { BusinessError } 801 - Capability not supported. 272 * @throws { BusinessError } 15500000 - Inner error. 273 * @throws { BusinessError } 15501001 - Only supported in stage mode. 274 * @throws { BusinessError } 15501002 - The data group id is not valid. 275 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 276 * @crossplatform 277 * @atomicservice 278 * @since 11 279 */ 280 function getPreferences(context: Context, options: Options, callback: AsyncCallback<Preferences>): void; 281 282 /** 283 * Obtains a {@link Preferences} instance matching a specified preferences file name. 284 * <p>The {@link references} instance loads all data of the preferences file and 285 * resides in the memory. You can use removePreferencesFromCache to remove the instance from the memory. 286 * 287 * @param { Context } context - Indicates the context of application or capability. 288 * @param { string } name - Indicates the preferences file name. 289 * @returns { Promise<Preferences> } The {@link Preferences} instance matching the specified preferences file name. 290 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 291 * 2. Incorrect parameter types; 292 * 3. Parameter verification failed. 293 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 294 * @since 9 295 */ 296 /** 297 * Obtains a {@link Preferences} instance matching a specified preferences file name. 298 * <p>The {@link references} instance loads all data of the preferences file and 299 * resides in the memory. You can use removePreferencesFromCache to remove the instance from the memory. 300 * 301 * @param { Context } context - Indicates the context of application or capability. 302 * @param { string } name - Indicates the preferences file name. 303 * @returns { Promise<Preferences> } The {@link Preferences} instance matching the specified preferences file name. 304 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 305 * 2. Incorrect parameter types; 306 * 3. Parameter verification failed. 307 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 308 * @crossplatform 309 * @since 10 310 */ 311 /** 312 * Obtains a {@link Preferences} instance matching a specified preferences file name. 313 * <p>The {@link references} instance loads all data of the preferences file and 314 * resides in the memory. You can use removePreferencesFromCache to remove the instance from the memory. 315 * 316 * @param { Context } context - Indicates the context of application or capability. 317 * @param { string } name - Indicates the preferences file name. 318 * @returns { Promise<Preferences> } The {@link Preferences} instance matching the specified preferences file name. 319 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 320 * 2. Incorrect parameter types; 321 * 3. Parameter verification failed. 322 * @throws { BusinessError } 15500000 - Inner error. 323 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 324 * @crossplatform 325 * @atomicservice 326 * @since 11 327 */ 328 function getPreferences(context: Context, name: string): Promise<Preferences>; 329 330 /** 331 * Obtains a {@link Preferences} instance matching a specified preferences file name. 332 * <p>The {@link references} instance loads all data of the preferences file and 333 * resides in the memory. You can use removePreferencesFromCache to remove the instance from the memory. 334 * 335 * @param { Context } context - Indicates the context of application or capability. 336 * @param { Options } options - Indicates the {@link Options} option of preferences file position. 337 * @returns { Promise<Preferences> } The {@link Preferences} instance matching the specified preferences file name. 338 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 339 * 2. Incorrect parameter types; 340 * 3. Parameter verification failed. 341 * @throws { BusinessError } 801 - Capability not supported. 342 * @throws { BusinessError } 15501001 - Only supported in stage mode. 343 * @throws { BusinessError } 15501002 - The data group id is not valid. 344 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 345 * @crossplatform 346 * @since 10 347 */ 348 /** 349 * Obtains a {@link Preferences} instance matching a specified preferences file name. 350 * <p>The {@link references} instance loads all data of the preferences file and 351 * resides in the memory. You can use removePreferencesFromCache to remove the instance from the memory. 352 * 353 * @param { Context } context - Indicates the context of application or capability. 354 * @param { Options } options - Indicates the {@link Options} option of preferences file position. 355 * @returns { Promise<Preferences> } The {@link Preferences} instance matching the specified preferences file name. 356 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 357 * 2. Incorrect parameter types; 358 * 3. Parameter verification failed. 359 * @throws { BusinessError } 801 - Capability not supported. 360 * @throws { BusinessError } 15500000 - Inner error. 361 * @throws { BusinessError } 15501001 - Only supported in stage mode. 362 * @throws { BusinessError } 15501002 - The data group id is not valid. 363 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 364 * @crossplatform 365 * @atomicservice 366 * @since 11 367 */ 368 function getPreferences(context: Context, options: Options): Promise<Preferences>; 369 370 /** 371 * Obtains a {@link Preferences} instance matching a specified preferences file name. 372 * This interface is executed synchronously. 373 * <p>The {@link references} instance loads all data of the preferences file and 374 * resides in the memory. You can use removePreferencesFromCache to remove the instance from the memory. 375 * 376 * @param { Context } context - Indicates the context of application or capability. 377 * @param { Options } options - Indicates the {@link Options} option of preferences file position. 378 * @returns { Preferences } The {@link Preferences} instance matching the specified preferences file name. 379 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 380 * 2. Incorrect parameter types; 381 * 3. Parameter verification failed. 382 * @throws { BusinessError } 801 - Capability not supported. 383 * @throws { BusinessError } 15501001 - Only supported in stage mode. 384 * @throws { BusinessError } 15501002 - The data group id is not valid. 385 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 386 * @crossplatform 387 * @since 10 388 */ 389 /** 390 * Obtains a {@link Preferences} instance matching a specified preferences file name. 391 * This interface is executed synchronously. 392 * <p>The {@link references} instance loads all data of the preferences file and 393 * resides in the memory. You can use removePreferencesFromCache to remove the instance from the memory. 394 * 395 * @param { Context } context - Indicates the context of application or capability. 396 * @param { Options } options - Indicates the {@link Options} option of preferences file position. 397 * @returns { Preferences } The {@link Preferences} instance matching the specified preferences file name. 398 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 399 * 2. Incorrect parameter types; 400 * 3. Parameter verification failed. 401 * @throws { BusinessError } 801 - Capability not supported. 402 * @throws { BusinessError } 15500000 - Inner error. 403 * @throws { BusinessError } 15501001 - Only supported in stage mode. 404 * @throws { BusinessError } 15501002 - The data group id is not valid. 405 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 406 * @crossplatform 407 * @atomicservice 408 * @since 11 409 */ 410 function getPreferencesSync(context: Context, options: Options): Preferences; 411 412 /** 413 * Deletes a {@link Preferences} instance matching a specified preferences file name 414 * from the cache which is performed by removePreferencesFromCache and deletes the 415 * preferences file. 416 * <p>When deleting the {@link Preferences} instance, you must release all references 417 * of the instance. In addition, do not use the instance to perform data operations. Otherwise, data inconsistency 418 * will occur. 419 * 420 * @param { Context } context - Indicates the context of application or capability. 421 * @param { string } name - Indicates the preferences file name. 422 * @param { AsyncCallback<void> } callback - Indicates the callback function. 423 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 424 * 2. Incorrect parameter types; 425 * 3. Parameter verification failed. 426 * @throws { BusinessError } 15500010 - Failed to delete preferences file. 427 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 428 * @since 9 429 */ 430 /** 431 * Deletes a {@link Preferences} instance matching a specified preferences file name 432 * from the cache which is performed by removePreferencesFromCache and deletes the 433 * preferences file. 434 * <p>When deleting the {@link Preferences} instance, you must release all references 435 * of the instance. In addition, do not use the instance to perform data operations. Otherwise, data inconsistency 436 * will occur. 437 * 438 * @param { Context } context - Indicates the context of application or capability. 439 * @param { string } name - Indicates the preferences file name. 440 * @param { AsyncCallback<void> } callback - Indicates the callback function. 441 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 442 * 2. Incorrect parameter types; 443 * 3. Parameter verification failed. 444 * @throws { BusinessError } 15500010 - Failed to delete preferences file. 445 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 446 * @crossplatform 447 * @since 10 448 */ 449 /** 450 * Deletes a {@link Preferences} instance matching a specified preferences file name 451 * from the cache which is performed by removePreferencesFromCache and deletes the 452 * preferences file. 453 * <p>When deleting the {@link Preferences} instance, you must release all references 454 * of the instance. In addition, do not use the instance to perform data operations. Otherwise, data inconsistency 455 * will occur. 456 * 457 * @param { Context } context - Indicates the context of application or capability. 458 * @param { string } name - Indicates the preferences file name. 459 * @param { AsyncCallback<void> } callback - Indicates the callback function. 460 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 461 * 2. Incorrect parameter types; 462 * 3. Parameter verification failed. 463 * @throws { BusinessError } 15500000 - Inner error. 464 * @throws { BusinessError } 15500010 - Failed to delete preferences file. 465 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 466 * @crossplatform 467 * @atomicservice 468 * @since 11 469 */ 470 function deletePreferences(context: Context, name: string, callback: AsyncCallback<void>): void; 471 472 /** 473 * Deletes a {@link Preferences} instance matching a specified preferences file name 474 * from the cache which is performed by removePreferencesFromCache and deletes the 475 * preferences file. 476 * <p>When deleting the {@link Preferences} instance, you must release all references 477 * of the instance. In addition, do not use the instance to perform data operations. Otherwise, data inconsistency 478 * will occur. 479 * 480 * @param { Context } context - Indicates the context of application or capability. 481 * @param { Options } options - Indicates the {@link Options} option of preferences file position. 482 * @param { AsyncCallback<void> } callback - Indicates the callback function. 483 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 484 * 2. Incorrect parameter types; 485 * 3. Parameter verification failed. 486 * @throws { BusinessError } 801 - Capability not supported. 487 * @throws { BusinessError } 15500010 - Failed to delete preferences file. 488 * @throws { BusinessError } 15501001 - Only supported in stage mode. 489 * @throws { BusinessError } 15501002 - The data group id is not valid. 490 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 491 * @crossplatform 492 * @since 10 493 */ 494 /** 495 * Deletes a {@link Preferences} instance matching a specified preferences file name 496 * from the cache which is performed by removePreferencesFromCache and deletes the 497 * preferences file. 498 * <p>When deleting the {@link Preferences} instance, you must release all references 499 * of the instance. In addition, do not use the instance to perform data operations. Otherwise, data inconsistency 500 * will occur. 501 * 502 * @param { Context } context - Indicates the context of application or capability. 503 * @param { Options } options - Indicates the {@link Options} option of preferences file position. 504 * @param { AsyncCallback<void> } callback - Indicates the callback function. 505 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 506 * 2. Incorrect parameter types; 507 * 3. Parameter verification failed. 508 * @throws { BusinessError } 801 - Capability not supported. 509 * @throws { BusinessError } 15500000 - Inner error. 510 * @throws { BusinessError } 15500010 - Failed to delete preferences file. 511 * @throws { BusinessError } 15501001 - Only supported in stage mode. 512 * @throws { BusinessError } 15501002 - The data group id is not valid. 513 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 514 * @crossplatform 515 * @atomicservice 516 * @since 11 517 */ 518 function deletePreferences(context: Context, options: Options, callback: AsyncCallback<void>): void; 519 520 /** 521 * Deletes a {@link Preferences} instance matching a specified preferences file name 522 * from the cache which is performed by removePreferencesFromCache and deletes the 523 * preferences file. 524 * <p>When deleting the {@link Preferences} instance, you must release all references 525 * of the instance. In addition, do not use the instance to perform data operations. Otherwise, data inconsistency 526 * will occur. 527 * 528 * @param { Context } context - Indicates the context of application or capability. 529 * @param { string } name - Indicates the preferences file name. 530 * @returns { Promise<void> } A promise object. 531 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 532 * 2. Incorrect parameter types; 533 * 3. Parameter verification failed. 534 * @throws { BusinessError } 15500010 - Failed to delete preferences file. 535 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 536 * @since 9 537 */ 538 /** 539 * Deletes a {@link Preferences} instance matching a specified preferences file name 540 * from the cache which is performed by removePreferencesFromCache and deletes the 541 * preferences file. 542 * <p>When deleting the {@link Preferences} instance, you must release all references 543 * of the instance. In addition, do not use the instance to perform data operations. Otherwise, data inconsistency 544 * will occur. 545 * 546 * @param { Context } context - Indicates the context of application or capability. 547 * @param { string } name - Indicates the preferences file name. 548 * @returns { Promise<void> } A promise object. 549 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 550 * 2. Incorrect parameter types; 551 * 3. Parameter verification failed. 552 * @throws { BusinessError } 15500010 - Failed to delete preferences file. 553 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 554 * @crossplatform 555 * @since 10 556 */ 557 /** 558 * Deletes a {@link Preferences} instance matching a specified preferences file name 559 * from the cache which is performed by removePreferencesFromCache and deletes the 560 * preferences file. 561 * <p>When deleting the {@link Preferences} instance, you must release all references 562 * of the instance. In addition, do not use the instance to perform data operations. Otherwise, data inconsistency 563 * will occur. 564 * 565 * @param { Context } context - Indicates the context of application or capability. 566 * @param { string } name - Indicates the preferences file name. 567 * @returns { Promise<void> } A promise object. 568 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 569 * 2. Incorrect parameter types; 570 * 3. Parameter verification failed. 571 * @throws { BusinessError } 15500000 - Inner error. 572 * @throws { BusinessError } 15500010 - Failed to delete preferences file. 573 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 574 * @crossplatform 575 * @atomicservice 576 * @since 11 577 */ 578 function deletePreferences(context: Context, name: string): Promise<void>; 579 580 /** 581 * Deletes a {@link Preferences} instance matching a specified preferences file name 582 * from the cache which is performed by removePreferencesFromCache and deletes the 583 * preferences file. 584 * <p>When deleting the {@link Preferences} instance, you must release all references 585 * of the instance. In addition, do not use the instance to perform data operations. Otherwise, data inconsistency 586 * will occur. 587 * 588 * @param { Context } context - Indicates the context of application or capability. 589 * @param { Options } options - Indicates the {@link Options} option of preferences file position. 590 * @returns { Promise<void> } A promise object. 591 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 592 * 2. Incorrect parameter types; 593 * 3. Parameter verification failed. 594 * @throws { BusinessError } 801 - Capability not supported. 595 * @throws { BusinessError } 15500010 - Failed to delete preferences file. 596 * @throws { BusinessError } 15501001 - Only supported in stage mode. 597 * @throws { BusinessError } 15501002 - The data group id is not valid. 598 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 599 * @crossplatform 600 * @since 10 601 */ 602 /** 603 * Deletes a {@link Preferences} instance matching a specified preferences file name 604 * from the cache which is performed by removePreferencesFromCache and deletes the 605 * preferences file. 606 * <p>When deleting the {@link Preferences} instance, you must release all references 607 * of the instance. In addition, do not use the instance to perform data operations. Otherwise, data inconsistency 608 * will occur. 609 * 610 * @param { Context } context - Indicates the context of application or capability. 611 * @param { Options } options - Indicates the {@link Options} option of preferences file position. 612 * @returns { Promise<void> } A promise object. 613 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 614 * 2. Incorrect parameter types; 615 * 3. Parameter verification failed. 616 * @throws { BusinessError } 801 - Capability not supported. 617 * @throws { BusinessError } 15500000 - Inner error. 618 * @throws { BusinessError } 15500010 - Failed to delete preferences file. 619 * @throws { BusinessError } 15501001 - Only supported in stage mode. 620 * @throws { BusinessError } 15501002 - The data group id is not valid. 621 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 622 * @crossplatform 623 * @atomicservice 624 * @since 11 625 */ 626 function deletePreferences(context: Context, options: Options): Promise<void>; 627 628 /** 629 * Deletes a {@link Preferences} instance matching a specified preferences file name 630 * from the cache. 631 * <p>When deleting the {@link Preferences} instance, you must release all references 632 * of the instance. In addition, do not use the instance to perform data operations. Otherwise, data inconsistency 633 * will occur. 634 * 635 * @param { Context } context - Indicates the context of application or capability. 636 * @param { string } name - Indicates the preferences file name. 637 * @param { AsyncCallback<void> } callback - Indicates the callback function. 638 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 639 * 2. Incorrect parameter types; 640 * 3. Parameter verification failed. 641 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 642 * @since 9 643 */ 644 /** 645 * Deletes a {@link Preferences} instance matching a specified preferences file name 646 * from the cache. 647 * <p>When deleting the {@link Preferences} instance, you must release all references 648 * of the instance. In addition, do not use the instance to perform data operations. Otherwise, data inconsistency 649 * will occur. 650 * 651 * @param { Context } context - Indicates the context of application or capability. 652 * @param { string } name - Indicates the preferences file name. 653 * @param { AsyncCallback<void> } callback - Indicates the callback function. 654 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 655 * 2. Incorrect parameter types; 656 * 3. Parameter verification failed. 657 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 658 * @crossplatform 659 * @since 10 660 */ 661 /** 662 * Deletes a {@link Preferences} instance matching a specified preferences file name 663 * from the cache. 664 * <p>When deleting the {@link Preferences} instance, you must release all references 665 * of the instance. In addition, do not use the instance to perform data operations. Otherwise, data inconsistency 666 * will occur. 667 * 668 * @param { Context } context - Indicates the context of application or capability. 669 * @param { string } name - Indicates the preferences file name. 670 * @param { AsyncCallback<void> } callback - Indicates the callback function. 671 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 672 * 2. Incorrect parameter types; 673 * 3. Parameter verification failed. 674 * @throws { BusinessError } 15500000 - Inner error. 675 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 676 * @crossplatform 677 * @atomicservice 678 * @since 11 679 */ 680 function removePreferencesFromCache(context: Context, name: string, callback: AsyncCallback<void>): void; 681 682 /** 683 * Deletes a {@link Preferences} instance matching a specified preferences file name 684 * from the cache. 685 * <p>When deleting the {@link Preferences} instance, you must release all references 686 * of the instance. In addition, do not use the instance to perform data operations. Otherwise, data inconsistency 687 * will occur. 688 * 689 * @param { Context } context - Indicates the context of application or capability. 690 * @param { Options } options - Indicates the {@link Options} option of preferences file position. 691 * @param { AsyncCallback<void> } callback - Indicates the callback function. 692 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 693 * 2. Incorrect parameter types; 694 * 3. Parameter verification failed. 695 * @throws { BusinessError } 801 - Capability not supported. 696 * @throws { BusinessError } 15501001 - Only supported in stage mode. 697 * @throws { BusinessError } 15501002 - The data group id is not valid. 698 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 699 * @crossplatform 700 * @since 10 701 */ 702 /** 703 * Deletes a {@link Preferences} instance matching a specified preferences file name 704 * from the cache. 705 * <p>When deleting the {@link Preferences} instance, you must release all references 706 * of the instance. In addition, do not use the instance to perform data operations. Otherwise, data inconsistency 707 * will occur. 708 * 709 * @param { Context } context - Indicates the context of application or capability. 710 * @param { Options } options - Indicates the {@link Options} option of preferences file position. 711 * @param { AsyncCallback<void> } callback - Indicates the callback function. 712 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 713 * 2. Incorrect parameter types; 714 * 3. Parameter verification failed. 715 * @throws { BusinessError } 801 - Capability not supported. 716 * @throws { BusinessError } 15500000 - Inner error. 717 * @throws { BusinessError } 15501001 - Only supported in stage mode. 718 * @throws { BusinessError } 15501002 - The data group id is not valid. 719 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 720 * @crossplatform 721 * @atomicservice 722 * @since 11 723 */ 724 function removePreferencesFromCache(context: Context, options: Options, callback: AsyncCallback<void>): void; 725 726 /** 727 * Deletes a {@link Preferences} instance matching a specified preferences file name 728 * from the cache. 729 * <p>When deleting the {@link Preferences} instance, you must release all references 730 * of the instance. In addition, do not use the instance to perform data operations. Otherwise, data inconsistency 731 * will occur. 732 * 733 * @param { Context } context - Indicates the context of application or capability. 734 * @param { string } name - Indicates the preferences file name. 735 * @returns { Promise<void> } A promise object. 736 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 737 * 2. Incorrect parameter types; 738 * 3. Parameter verification failed. 739 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 740 * @since 9 741 */ 742 /** 743 * Deletes a {@link Preferences} instance matching a specified preferences file name 744 * from the cache. 745 * <p>When deleting the {@link Preferences} instance, you must release all references 746 * of the instance. In addition, do not use the instance to perform data operations. Otherwise, data inconsistency 747 * will occur. 748 * 749 * @param { Context } context - Indicates the context of application or capability. 750 * @param { string } name - Indicates the preferences file name. 751 * @returns { Promise<void> } A promise object. 752 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 753 * 2. Incorrect parameter types; 754 * 3. Parameter verification failed. 755 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 756 * @crossplatform 757 * @since 10 758 */ 759 /** 760 * Deletes a {@link Preferences} instance matching a specified preferences file name 761 * from the cache. 762 * <p>When deleting the {@link Preferences} instance, you must release all references 763 * of the instance. In addition, do not use the instance to perform data operations. Otherwise, data inconsistency 764 * will occur. 765 * 766 * @param { Context } context - Indicates the context of application or capability. 767 * @param { string } name - Indicates the preferences file name. 768 * @returns { Promise<void> } A promise object. 769 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 770 * 2. Incorrect parameter types; 771 * 3. Parameter verification failed. 772 * @throws { BusinessError } 15500000 - Inner error. 773 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 774 * @crossplatform 775 * @atomicservice 776 * @since 11 777 */ 778 function removePreferencesFromCache(context: Context, name: string): Promise<void>; 779 780 /** 781 * Deletes a {@link Preferences} instance matching a specified preferences file name 782 * from the cache. 783 * <p>When deleting the {@link Preferences} instance, you must release all references 784 * of the instance. In addition, do not use the instance to perform data operations. Otherwise, data inconsistency 785 * will occur. 786 * 787 * @param { Context } context - Indicates the context of application or capability. 788 * @param { Options } options - Indicates the {@link Options} option of preferences file position. 789 * @returns { Promise<void> } A promise object. 790 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 791 * 2. Incorrect parameter types; 792 * 3. Parameter verification failed. 793 * @throws { BusinessError } 801 - Capability not supported. 794 * @throws { BusinessError } 15501001 - Only supported in stage mode. 795 * @throws { BusinessError } 15501002 - The data group id is not valid. 796 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 797 * @crossplatform 798 * @since 10 799 */ 800 /** 801 * Deletes a {@link Preferences} instance matching a specified preferences file name 802 * from the cache. 803 * <p>When deleting the {@link Preferences} instance, you must release all references 804 * of the instance. In addition, do not use the instance to perform data operations. Otherwise, data inconsistency 805 * will occur. 806 * 807 * @param { Context } context - Indicates the context of application or capability. 808 * @param { Options } options - Indicates the {@link Options} option of preferences file position. 809 * @returns { Promise<void> } A promise object. 810 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 811 * 2. Incorrect parameter types; 812 * 3. Parameter verification failed. 813 * @throws { BusinessError } 801 - Capability not supported. 814 * @throws { BusinessError } 15500000 - Inner error. 815 * @throws { BusinessError } 15501001 - Only supported in stage mode. 816 * @throws { BusinessError } 15501002 - The data group id is not valid. 817 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 818 * @crossplatform 819 * @atomicservice 820 * @since 11 821 */ 822 function removePreferencesFromCache(context: Context, options: Options): Promise<void>; 823 824 /** 825 * Deletes a {@link Preferences} instance matching a specified preferences file name 826 * from the cache. This interface is executed synchronously. 827 * <p>When deleting the {@link Preferences} instance, you must release all references 828 * of the instance. In addition, do not use the instance to perform data operations. Otherwise, data inconsistency 829 * will occur. 830 * 831 * @param { Context } context - Indicates the context of application or capability. 832 * @param { string } name - Indicates the preferences file name. 833 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 834 * 2. Incorrect parameter types; 835 * 3. Parameter verification failed. 836 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 837 * @crossplatform 838 * @since 10 839 */ 840 /** 841 * Deletes a {@link Preferences} instance matching a specified preferences file name 842 * from the cache. This interface is executed synchronously. 843 * <p>When deleting the {@link Preferences} instance, you must release all references 844 * of the instance. In addition, do not use the instance to perform data operations. Otherwise, data inconsistency 845 * will occur. 846 * 847 * @param { Context } context - Indicates the context of application or capability. 848 * @param { string } name - Indicates the preferences file name. 849 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 850 * 2. Incorrect parameter types; 851 * 3. Parameter verification failed. 852 * @throws { BusinessError } 15500000 - Inner error. 853 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 854 * @crossplatform 855 * @atomicservice 856 * @since 11 857 */ 858 function removePreferencesFromCacheSync(context: Context, name: string): void; 859 860 /** 861 * Deletes a {@link Preferences} instance matching a specified preferences file name 862 * from the cache. This interface is executed synchronously. 863 * <p>When deleting the {@link Preferences} instance, you must release all references 864 * of the instance. In addition, do not use the instance to perform data operations. Otherwise, data inconsistency 865 * will occur. 866 * 867 * @param { Context } context - Indicates the context of application or capability. 868 * @param { Options } options - Indicates the {@link Options} option of preferences file position. 869 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 870 * 2. Incorrect parameter types; 871 * 3. Parameter verification failed. 872 * @throws { BusinessError } 801 - Capability not supported. 873 * @throws { BusinessError } 15501001 - Only supported in stage mode. 874 * @throws { BusinessError } 15501002 - The data group id is not valid. 875 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 876 * @crossplatform 877 * @since 10 878 */ 879 /** 880 * Deletes a {@link Preferences} instance matching a specified preferences file name 881 * from the cache. This interface is executed synchronously. 882 * <p>When deleting the {@link Preferences} instance, you must release all references 883 * of the instance. In addition, do not use the instance to perform data operations. Otherwise, data inconsistency 884 * will occur. 885 * 886 * @param { Context } context - Indicates the context of application or capability. 887 * @param { Options } options - Indicates the {@link Options} option of preferences file position. 888 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 889 * 2. Incorrect parameter types; 890 * 3. Parameter verification failed. 891 * @throws { BusinessError } 801 - Capability not supported. 892 * @throws { BusinessError } 15500000 - Inner error. 893 * @throws { BusinessError } 15501001 - Only supported in stage mode. 894 * @throws { BusinessError } 15501002 - The data group id is not valid. 895 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 896 * @crossplatform 897 * @atomicservice 898 * @since 11 899 */ 900 function removePreferencesFromCacheSync(context: Context, options: Options): void; 901 902 /** 903 * Provides interfaces to obtain and modify preferences data. 904 * <p>The preferences data is stored in a file, which matches only one {@link Preferences} instance in the memory. 905 * You can use getPreferences to obtain the {@link Preferences} instance matching 906 * the file that stores preferences data, and use movePreferencesFromCache 907 * to remove the {@link Preferences} instance from the memory. 908 * 909 * @interface Preferences 910 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 911 * @since 9 912 */ 913 /** 914 * Provides interfaces to obtain and modify preferences data. 915 * <p>The preferences data is stored in a file, which matches only one {@link Preferences} instance in the memory. 916 * You can use getPreferences to obtain the {@link Preferences} instance matching 917 * the file that stores preferences data, and use movePreferencesFromCache 918 * to remove the {@link Preferences} instance from the memory. 919 * 920 * @interface Preferences 921 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 922 * @crossplatform 923 * @since 10 924 */ 925 /** 926 * Provides interfaces to obtain and modify preferences data. 927 * <p>The preferences data is stored in a file, which matches only one {@link Preferences} instance in the memory. 928 * You can use getPreferences to obtain the {@link Preferences} instance matching 929 * the file that stores preferences data, and use movePreferencesFromCache 930 * to remove the {@link Preferences} instance from the memory. 931 * 932 * @interface Preferences 933 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 934 * @crossplatform 935 * @atomicservice 936 * @since 11 937 */ 938 interface Preferences { 939 /** 940 * Obtains the value of a preferences in the ValueType format. 941 * <p>If the value is {@code null} or not in the ValueType format, the default value is returned. 942 * 943 * @param { string } key - Indicates the key of the preferences. It cannot be {@code null} or empty. 944 * <tt>MAX_KEY_LENGTH</tt>. 945 * @param { ValueType } defValue - Indicates the default value to return. 946 * @param { AsyncCallback<ValueType> } callback - The value matching the specified key if it is found; 947 * returns the default value otherwise. 948 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 949 * 2. Incorrect parameter types; 950 * 3. Parameter verification failed. 951 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 952 * @since 9 953 */ 954 /** 955 * Obtains the value of a preferences in the ValueType format. 956 * <p>If the value is {@code null} or not in the ValueType format, the default value is returned. 957 * 958 * @param { string } key - Indicates the key of the preferences. It cannot be {@code null} or empty. 959 * <tt>MAX_KEY_LENGTH</tt>. 960 * @param { ValueType } defValue - Indicates the default value to return. 961 * @param { AsyncCallback<ValueType> } callback - The value matching the specified key if it is found; 962 * returns the default value otherwise. 963 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 964 * 2. Incorrect parameter types; 965 * 3. Parameter verification failed. 966 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 967 * @crossplatform 968 * @since 10 969 */ 970 /** 971 * Obtains the value of a preferences in the ValueType format. 972 * <p>If the value is {@code null} or not in the ValueType format, the default value is returned. 973 * 974 * @param { string } key - Indicates the key of the preferences. It cannot be {@code null} or empty. 975 * <tt>MAX_KEY_LENGTH</tt>. 976 * @param { ValueType } defValue - Indicates the default value to return. 977 * @param { AsyncCallback<ValueType> } callback - The value matching the specified key if it is found; 978 * returns the default value otherwise. 979 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 980 * 2. Incorrect parameter types; 981 * 3. Parameter verification failed. 982 * @throws { BusinessError } 15500000 - Inner error. 983 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 984 * @crossplatform 985 * @atomicservice 986 * @since 11 987 */ 988 get(key: string, defValue: ValueType, callback: AsyncCallback<ValueType>): void; 989 990 /** 991 * Obtains the value of a preferences in the ValueType format. 992 * <p>If the value is {@code null} or not in the ValueType format, the default value is returned. 993 * 994 * @param { string } key - Indicates the key of the preferences. It cannot be {@code null} or empty. 995 * <tt>MAX_KEY_LENGTH</tt>. 996 * @param { ValueType } defValue - Indicates the default value to return. 997 * @returns { Promise<ValueType> } The value matching the specified key if it is found; 998 * returns the default value otherwise. 999 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1000 * 2. Incorrect parameter types; 1001 * 3. Parameter verification failed. 1002 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1003 * @since 9 1004 */ 1005 /** 1006 * Obtains the value of a preferences in the ValueType format. 1007 * <p>If the value is {@code null} or not in the ValueType format, the default value is returned. 1008 * 1009 * @param { string } key - Indicates the key of the preferences. It cannot be {@code null} or empty. 1010 * <tt>MAX_KEY_LENGTH</tt>. 1011 * @param { ValueType } defValue - Indicates the default value to return. 1012 * @returns { Promise<ValueType> } The value matching the specified key if it is found; 1013 * returns the default value otherwise. 1014 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1015 * 2. Incorrect parameter types; 1016 * 3. Parameter verification failed. 1017 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1018 * @crossplatform 1019 * @since 10 1020 */ 1021 /** 1022 * Obtains the value of a preferences in the ValueType format. 1023 * <p>If the value is {@code null} or not in the ValueType format, the default value is returned. 1024 * 1025 * @param { string } key - Indicates the key of the preferences. It cannot be {@code null} or empty. 1026 * <tt>MAX_KEY_LENGTH</tt>. 1027 * @param { ValueType } defValue - Indicates the default value to return. 1028 * @returns { Promise<ValueType> } The value matching the specified key if it is found; 1029 * returns the default value otherwise. 1030 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1031 * 2. Incorrect parameter types; 1032 * 3. Parameter verification failed. 1033 * @throws { BusinessError } 15500000 - Inner error. 1034 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1035 * @crossplatform 1036 * @atomicservice 1037 * @since 11 1038 */ 1039 get(key: string, defValue: ValueType): Promise<ValueType>; 1040 1041 /** 1042 * Obtains the value of a preferences in the ValueType format. This interface is executed synchronously. 1043 * <p>If the value is {@code null} or not in the ValueType format, the default value is returned. 1044 * 1045 * @param { string } key - Indicates the key of the preferences. It cannot be {@code null} or empty. 1046 * <tt>MAX_KEY_LENGTH</tt>. 1047 * @param { ValueType } defValue - Indicates the default value to return. 1048 * @returns { ValueType } The value matching the specified key if it is found; 1049 * returns the default value otherwise. 1050 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1051 * 2. Incorrect parameter types; 1052 * 3. Parameter verification failed. 1053 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1054 * @crossplatform 1055 * @since 10 1056 */ 1057 /** 1058 * Obtains the value of a preferences in the ValueType format. This interface is executed synchronously. 1059 * <p>If the value is {@code null} or not in the ValueType format, the default value is returned. 1060 * 1061 * @param { string } key - Indicates the key of the preferences. It cannot be {@code null} or empty. 1062 * <tt>MAX_KEY_LENGTH</tt>. 1063 * @param { ValueType } defValue - Indicates the default value to return. 1064 * @returns { ValueType } The value matching the specified key if it is found; 1065 * returns the default value otherwise. 1066 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1067 * 2. Incorrect parameter types; 1068 * 3. Parameter verification failed. 1069 * @throws { BusinessError } 15500000 - Inner error. 1070 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1071 * @crossplatform 1072 * @atomicservice 1073 * @since 11 1074 */ 1075 getSync(key: string, defValue: ValueType): ValueType; 1076 1077 /** 1078 * Obtains all the keys and values of a preferences in an object. 1079 * 1080 * @param { AsyncCallback<Object> } callback - The values and keys in an object. 1081 * @throws { BusinessError } 401 - Parameter error. Mandatory parameters are left unspecified. 1082 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1083 * @since 9 1084 */ 1085 /** 1086 * Obtains all the keys and values of a preferences in an object. 1087 * 1088 * @param { AsyncCallback<Object> } callback - The values and keys in an object. 1089 * @throws { BusinessError } 401 - Parameter error. Mandatory parameters are left unspecified. 1090 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1091 * @crossplatform 1092 * @since 10 1093 */ 1094 /** 1095 * Obtains all the keys and values of a preferences in an object. 1096 * 1097 * @param { AsyncCallback<Object> } callback - The values and keys in an object. 1098 * @throws { BusinessError } 401 - Parameter error. Mandatory parameters are left unspecified. 1099 * @throws { BusinessError } 15500000 - Inner error. 1100 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1101 * @crossplatform 1102 * @atomicservice 1103 * @since 11 1104 */ 1105 getAll(callback: AsyncCallback<Object>): void; 1106 1107 /** 1108 * Obtains all the keys and values of a preferences in an object. 1109 * 1110 * @returns { Promise<Object> } The values and keys in an object. 1111 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1112 * @since 9 1113 */ 1114 /** 1115 * Obtains all the keys and values of a preferences in an object. 1116 * 1117 * @returns { Promise<Object> } The values and keys in an object. 1118 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1119 * @crossplatform 1120 * @since 10 1121 */ 1122 /** 1123 * Obtains all the keys and values of a preferences in an object. 1124 * 1125 * @returns { Promise<Object> } The values and keys in an object. 1126 * @throws { BusinessError } 15500000 - Inner error. 1127 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1128 * @crossplatform 1129 * @atomicservice 1130 * @since 11 1131 */ 1132 getAll(): Promise<Object>; 1133 1134 /** 1135 * Obtains all the keys and values of a preferences in an object. This interface 1136 * is executed synchronously. 1137 * 1138 * @returns { Object } The values and keys in an object. 1139 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1140 * @crossplatform 1141 * @since 10 1142 */ 1143 /** 1144 * Obtains all the keys and values of a preferences in an object. This interface 1145 * is executed synchronously. 1146 * 1147 * @returns { Object } The values and keys in an object. 1148 * @throws { BusinessError } 15500000 - Inner error. 1149 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1150 * @crossplatform 1151 * @atomicservice 1152 * @since 11 1153 */ 1154 getAllSync(): Object; 1155 1156 /** 1157 * Checks whether the {@link Preferences} object contains a preferences matching a specified key. 1158 * 1159 * @param { string } key - Indicates the key of the preferences to modify. It cannot be {@code null} or empty. 1160 * <tt>MAX_KEY_LENGTH</tt>. 1161 * @param { AsyncCallback<boolean> } callback - {@code true} if the {@link Preferences} object contains a preferences 1162 * with the specified key;returns {@code false} otherwise. 1163 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1164 * 2. Incorrect parameter types; 1165 * 3. Parameter verification failed. 1166 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1167 * @since 9 1168 */ 1169 /** 1170 * Checks whether the {@link Preferences} object contains a preferences matching a specified key. 1171 * 1172 * @param { string } key - Indicates the key of the preferences to modify. It cannot be {@code null} or empty. 1173 * <tt>MAX_KEY_LENGTH</tt>. 1174 * @param { AsyncCallback<boolean> } callback - {@code true} if the {@link Preferences} object contains a preferences 1175 * with the specified key;returns {@code false} otherwise. 1176 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1177 * 2. Incorrect parameter types; 1178 * 3. Parameter verification failed. 1179 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1180 * @crossplatform 1181 * @since 10 1182 */ 1183 /** 1184 * Checks whether the {@link Preferences} object contains a preferences matching a specified key. 1185 * 1186 * @param { string } key - Indicates the key of the preferences to modify. It cannot be {@code null} or empty. 1187 * <tt>MAX_KEY_LENGTH</tt>. 1188 * @param { AsyncCallback<boolean> } callback - {@code true} if the {@link Preferences} object contains a preferences 1189 * with the specified key;returns {@code false} otherwise. 1190 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1191 * 2. Incorrect parameter types; 1192 * 3. Parameter verification failed. 1193 * @throws { BusinessError } 15500000 - Inner error. 1194 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1195 * @crossplatform 1196 * @atomicservice 1197 * @since 11 1198 */ 1199 has(key: string, callback: AsyncCallback<boolean>): void; 1200 1201 /** 1202 * Checks whether the {@link Preferences} object contains a preferences matching a specified key. 1203 * 1204 * @param { string } key - Indicates the key of the preferences to modify. It cannot be {@code null} or empty. 1205 * <tt>MAX_KEY_LENGTH</tt>. 1206 * @returns { Promise<boolean> } {@code true} if the {@link Preferences} object contains 1207 * a preferences with the specified key; returns {@code false} otherwise. 1208 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1209 * 2. Incorrect parameter types; 1210 * 3. Parameter verification failed. 1211 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1212 * @since 9 1213 */ 1214 /** 1215 * Checks whether the {@link Preferences} object contains a preferences matching a specified key. 1216 * 1217 * @param { string } key - Indicates the key of the preferences to modify. It cannot be {@code null} or empty. 1218 * <tt>MAX_KEY_LENGTH</tt>. 1219 * @returns { Promise<boolean> } {@code true} if the {@link Preferences} object contains 1220 * a preferences with the specified key; returns {@code false} otherwise. 1221 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1222 * 2. Incorrect parameter types; 1223 * 3. Parameter verification failed. 1224 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1225 * @crossplatform 1226 * @since 10 1227 */ 1228 /** 1229 * Checks whether the {@link Preferences} object contains a preferences matching a specified key. 1230 * 1231 * @param { string } key - Indicates the key of the preferences to modify. It cannot be {@code null} or empty. 1232 * <tt>MAX_KEY_LENGTH</tt>. 1233 * @returns { Promise<boolean> } {@code true} if the {@link Preferences} object contains 1234 * a preferences with the specified key; returns {@code false} otherwise. 1235 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1236 * 2. Incorrect parameter types; 1237 * 3. Parameter verification failed. 1238 * @throws { BusinessError } 15500000 - Inner error. 1239 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1240 * @crossplatform 1241 * @atomicservice 1242 * @since 11 1243 */ 1244 has(key: string): Promise<boolean>; 1245 1246 /** 1247 * Checks whether the {@link Preferences} object contains a preferences matching a specified key. This interface 1248 * is executed synchronously. 1249 * 1250 * @param { string } key - Indicates the key of the preferences to modify. It cannot be {@code null} or empty. 1251 * <tt>MAX_KEY_LENGTH</tt>. 1252 * @returns { boolean } {@code true} if the {@link Preferences} object contains 1253 * a preferences with the specified key; returns {@code false} otherwise. 1254 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1255 * 2. Incorrect parameter types; 1256 * 3. Parameter verification failed. 1257 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1258 * @crossplatform 1259 * @since 10 1260 */ 1261 /** 1262 * Checks whether the {@link Preferences} object contains a preferences matching a specified key. This interface 1263 * is executed synchronously. 1264 * 1265 * @param { string } key - Indicates the key of the preferences to modify. It cannot be {@code null} or empty. 1266 * <tt>MAX_KEY_LENGTH</tt>. 1267 * @returns { boolean } {@code true} if the {@link Preferences} object contains 1268 * a preferences with the specified key; returns {@code false} otherwise. 1269 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1270 * 2. Incorrect parameter types; 1271 * 3. Parameter verification failed. 1272 * @throws { BusinessError } 15500000 - Inner error. 1273 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1274 * @crossplatform 1275 * @atomicservice 1276 * @since 11 1277 */ 1278 hasSync(key: string): boolean; 1279 1280 /** 1281 * Sets an int value for the key in the {@link Preferences} object. 1282 * <p>You can call the {@link #flush} method to save the {@link Preferences} object to the 1283 * file. 1284 * 1285 * @param { string } key - Indicates the key of the preferences to modify. It cannot be {@code null} or empty. 1286 * <tt>MAX_KEY_LENGTH</tt>. 1287 * @param { ValueType } value - Indicates the value of the preferences. 1288 * <tt>MAX_VALUE_LENGTH</tt>. 1289 * @param { AsyncCallback<void> } callback - Indicates the callback function. 1290 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1291 * 2. Incorrect parameter types; 1292 * 3. Parameter verification failed. 1293 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1294 * @since 9 1295 */ 1296 /** 1297 * Sets an int value for the key in the {@link Preferences} object. 1298 * <p>You can call the {@link #flush} method to save the {@link Preferences} object to the 1299 * file. 1300 * 1301 * @param { string } key - Indicates the key of the preferences to modify. It cannot be {@code null} or empty. 1302 * <tt>MAX_KEY_LENGTH</tt>. 1303 * @param { ValueType } value - Indicates the value of the preferences. 1304 * <tt>MAX_VALUE_LENGTH</tt>. 1305 * @param { AsyncCallback<void> } callback - Indicates the callback function. 1306 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1307 * 2. Incorrect parameter types; 1308 * 3. Parameter verification failed. 1309 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1310 * @crossplatform 1311 * @since 10 1312 */ 1313 /** 1314 * Sets an int value for the key in the {@link Preferences} object. 1315 * <p>You can call the {@link #flush} method to save the {@link Preferences} object to the 1316 * file. 1317 * 1318 * @param { string } key - Indicates the key of the preferences to modify. It cannot be {@code null} or empty. 1319 * <tt>MAX_KEY_LENGTH</tt>. 1320 * @param { ValueType } value - Indicates the value of the preferences. 1321 * <tt>MAX_VALUE_LENGTH</tt>. 1322 * @param { AsyncCallback<void> } callback - Indicates the callback function. 1323 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1324 * 2. Incorrect parameter types; 1325 * 3. Parameter verification failed. 1326 * @throws { BusinessError } 15500000 - Inner error. 1327 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1328 * @crossplatform 1329 * @atomicservice 1330 * @since 11 1331 */ 1332 put(key: string, value: ValueType, callback: AsyncCallback<void>): void; 1333 1334 /** 1335 * Sets an int value for the key in the {@link Preferences} object. 1336 * <p>You can call the {@link #flush} method to save the {@link Preferences} object to the 1337 * file. 1338 * 1339 * @param { string } key - Indicates the key of the preferences to modify. It cannot be {@code null} or empty. 1340 * <tt>MAX_KEY_LENGTH</tt>. 1341 * @param { ValueType } value - Indicates the value of the preferences. 1342 * <tt>MAX_VALUE_LENGTH</tt>. 1343 * @returns { Promise<void> } A promise object. 1344 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1345 * 2. Incorrect parameter types; 1346 * 3. Parameter verification failed. 1347 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1348 * @since 9 1349 */ 1350 /** 1351 * Sets an int value for the key in the {@link Preferences} object. 1352 * <p>You can call the {@link #flush} method to save the {@link Preferences} object to the 1353 * file. 1354 * 1355 * @param { string } key - Indicates the key of the preferences to modify. It cannot be {@code null} or empty. 1356 * <tt>MAX_KEY_LENGTH</tt>. 1357 * @param { ValueType } value - Indicates the value of the preferences. 1358 * <tt>MAX_VALUE_LENGTH</tt>. 1359 * @returns { Promise<void> } A promise object. 1360 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1361 * 2. Incorrect parameter types; 1362 * 3. Parameter verification failed. 1363 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1364 * @crossplatform 1365 * @since 10 1366 */ 1367 /** 1368 * Sets an int value for the key in the {@link Preferences} object. 1369 * <p>You can call the {@link #flush} method to save the {@link Preferences} object to the 1370 * file. 1371 * 1372 * @param { string } key - Indicates the key of the preferences to modify. It cannot be {@code null} or empty. 1373 * <tt>MAX_KEY_LENGTH</tt>. 1374 * @param { ValueType } value - Indicates the value of the preferences. 1375 * <tt>MAX_VALUE_LENGTH</tt>. 1376 * @returns { Promise<void> } A promise object. 1377 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1378 * 2. Incorrect parameter types; 1379 * 3. Parameter verification failed. 1380 * @throws { BusinessError } 15500000 - Inner error. 1381 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1382 * @crossplatform 1383 * @atomicservice 1384 * @since 11 1385 */ 1386 put(key: string, value: ValueType): Promise<void>; 1387 1388 /** 1389 * Sets an int value for the key in the {@link Preferences} object. This interface is executed synchronously. 1390 * <p>You can call the {@link #flush} method to save the {@link Preferences} object to the 1391 * file. 1392 * 1393 * @param { string } key - Indicates the key of the preferences to modify. It cannot be {@code null} or empty. 1394 * <tt>MAX_KEY_LENGTH</tt>. 1395 * @param { ValueType } value - Indicates the value of the preferences. 1396 * <tt>MAX_VALUE_LENGTH</tt>. 1397 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1398 * 2. Incorrect parameter types; 1399 * 3. Parameter verification failed. 1400 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1401 * @crossplatform 1402 * @since 10 1403 */ 1404 /** 1405 * Sets an int value for the key in the {@link Preferences} object. This interface is executed synchronously. 1406 * <p>You can call the {@link #flush} method to save the {@link Preferences} object to the 1407 * file. 1408 * 1409 * @param { string } key - Indicates the key of the preferences to modify. It cannot be {@code null} or empty. 1410 * <tt>MAX_KEY_LENGTH</tt>. 1411 * @param { ValueType } value - Indicates the value of the preferences. 1412 * <tt>MAX_VALUE_LENGTH</tt>. 1413 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1414 * 2. Incorrect parameter types; 1415 * 3. Parameter verification failed. 1416 * @throws { BusinessError } 15500000 - Inner error. 1417 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1418 * @crossplatform 1419 * @atomicservice 1420 * @since 11 1421 */ 1422 putSync(key: string, value: ValueType): void; 1423 1424 /** 1425 * Deletes the preferences with a specified key from the {@link Preferences} object. 1426 * <p>You can call the {@link #flush} method to save the {@link Preferences} object to the 1427 * file. 1428 * 1429 * @param { string } key - Indicates the key of the preferences to delete. It cannot be {@code null} or empty. 1430 * <tt>MAX_KEY_LENGTH</tt>. 1431 * @param { AsyncCallback<void> } callback - Indicates the callback function. 1432 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1433 * 2. Incorrect parameter types; 1434 * 3. Parameter verification failed. 1435 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1436 * @since 9 1437 */ 1438 /** 1439 * Deletes the preferences with a specified key from the {@link Preferences} object. 1440 * <p>You can call the {@link #flush} method to save the {@link Preferences} object to the 1441 * file. 1442 * 1443 * @param { string } key - Indicates the key of the preferences to delete. It cannot be {@code null} or empty. 1444 * <tt>MAX_KEY_LENGTH</tt>. 1445 * @param { AsyncCallback<void> } callback - Indicates the callback function. 1446 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1447 * 2. Incorrect parameter types; 1448 * 3. Parameter verification failed. 1449 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1450 * @crossplatform 1451 * @since 10 1452 */ 1453 /** 1454 * Deletes the preferences with a specified key from the {@link Preferences} object. 1455 * <p>You can call the {@link #flush} method to save the {@link Preferences} object to the 1456 * file. 1457 * 1458 * @param { string } key - Indicates the key of the preferences to delete. It cannot be {@code null} or empty. 1459 * <tt>MAX_KEY_LENGTH</tt>. 1460 * @param { AsyncCallback<void> } callback - Indicates the callback function. 1461 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1462 * 2. Incorrect parameter types; 1463 * 3. Parameter verification failed. 1464 * @throws { BusinessError } 15500000 - Inner error. 1465 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1466 * @crossplatform 1467 * @atomicservice 1468 * @since 11 1469 */ 1470 delete(key: string, callback: AsyncCallback<void>): void; 1471 1472 /** 1473 * Deletes the preferences with a specified key from the {@link Preferences} object. 1474 * <p>You can call the {@link #flush} method to save the {@link Preferences} object to the 1475 * file. 1476 * 1477 * @param { string } key - Indicates the key of the preferences to delete. It cannot be {@code null} or empty. 1478 * <tt>MAX_KEY_LENGTH</tt>. 1479 * @returns { Promise<void> } A promise object. 1480 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1481 * 2. Incorrect parameter types; 1482 * 3. Parameter verification failed. 1483 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1484 * @since 9 1485 */ 1486 /** 1487 * Deletes the preferences with a specified key from the {@link Preferences} object. 1488 * <p>You can call the {@link #flush} method to save the {@link Preferences} object to the 1489 * file. 1490 * 1491 * @param { string } key - Indicates the key of the preferences to delete. It cannot be {@code null} or empty. 1492 * <tt>MAX_KEY_LENGTH</tt>. 1493 * @returns { Promise<void> } A promise object. 1494 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1495 * 2. Incorrect parameter types; 1496 * 3. Parameter verification failed. 1497 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1498 * @crossplatform 1499 * @since 10 1500 */ 1501 /** 1502 * Deletes the preferences with a specified key from the {@link Preferences} object. 1503 * <p>You can call the {@link #flush} method to save the {@link Preferences} object to the 1504 * file. 1505 * 1506 * @param { string } key - Indicates the key of the preferences to delete. It cannot be {@code null} or empty. 1507 * <tt>MAX_KEY_LENGTH</tt>. 1508 * @returns { Promise<void> } A promise object. 1509 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1510 * 2. Incorrect parameter types; 1511 * 3. Parameter verification failed. 1512 * @throws { BusinessError } 15500000 - Inner error. 1513 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1514 * @crossplatform 1515 * @atomicservice 1516 * @since 11 1517 */ 1518 delete(key: string): Promise<void>; 1519 1520 /** 1521 * Deletes the preferences with a specified key from the {@link Preferences} object. This interface is 1522 * executed synchronously. <p>You can call the {@link #flush} method to save the {@link Preferences} 1523 * object to the file. 1524 * 1525 * @param { string } key - Indicates the key of the preferences to delete. It cannot be {@code null} or empty. 1526 * <tt>MAX_KEY_LENGTH</tt>. 1527 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1528 * 2. Incorrect parameter types; 1529 * 3. Parameter verification failed. 1530 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1531 * @crossplatform 1532 * @since 10 1533 */ 1534 /** 1535 * Deletes the preferences with a specified key from the {@link Preferences} object. This interface is 1536 * executed synchronously. <p>You can call the {@link #flush} method to save the {@link Preferences} 1537 * object to the file. 1538 * 1539 * @param { string } key - Indicates the key of the preferences to delete. It cannot be {@code null} or empty. 1540 * <tt>MAX_KEY_LENGTH</tt>. 1541 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1542 * 2. Incorrect parameter types; 1543 * 3. Parameter verification failed. 1544 * @throws { BusinessError } 15500000 - Inner error. 1545 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1546 * @crossplatform 1547 * @atomicservice 1548 * @since 11 1549 */ 1550 deleteSync(key: string): void; 1551 1552 /** 1553 * Clears all preferences from the {@link Preferences} object. 1554 * <p>You can call the {@link #flush} method to save the {@link Preferences} object to the file. 1555 * 1556 * @param { AsyncCallback<void> } callback - Indicates the callback function. 1557 * @throws { BusinessError } 401 - Parameter error. Mandatory parameters are left unspecified. 1558 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1559 * @since 9 1560 */ 1561 /** 1562 * Clears all preferences from the {@link Preferences} object. 1563 * <p>You can call the {@link #flush} method to save the {@link Preferences} object to the file. 1564 * 1565 * @param { AsyncCallback<void> } callback - Indicates the callback function. 1566 * @throws { BusinessError } 401 - Parameter error. Mandatory parameters are left unspecified. 1567 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1568 * @crossplatform 1569 * @since 10 1570 */ 1571 /** 1572 * Clears all preferences from the {@link Preferences} object. 1573 * <p>You can call the {@link #flush} method to save the {@link Preferences} object to the file. 1574 * 1575 * @param { AsyncCallback<void> } callback - Indicates the callback function. 1576 * @throws { BusinessError } 401 - Parameter error. Mandatory parameters are left unspecified. 1577 * @throws { BusinessError } 15500000 - Inner error. 1578 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1579 * @crossplatform 1580 * @atomicservice 1581 * @since 11 1582 */ 1583 clear(callback: AsyncCallback<void>): void; 1584 1585 /** 1586 * Clears all preferences from the {@link Preferences} object. 1587 * <p>You can call the {@link #flush} method to save the {@link Preferences} object to the file. 1588 * 1589 * @returns { Promise<void> } A promise object. 1590 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1591 * @since 9 1592 */ 1593 /** 1594 * Clears all preferences from the {@link Preferences} object. 1595 * <p>You can call the {@link #flush} method to save the {@link Preferences} object to the file. 1596 * 1597 * @returns { Promise<void> } A promise object. 1598 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1599 * @crossplatform 1600 * @since 10 1601 */ 1602 /** 1603 * Clears all preferences from the {@link Preferences} object. 1604 * <p>You can call the {@link #flush} method to save the {@link Preferences} object to the file. 1605 * 1606 * @returns { Promise<void> } A promise object. 1607 * @throws { BusinessError } 15500000 - Inner error. 1608 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1609 * @crossplatform 1610 * @atomicservice 1611 * @since 11 1612 */ 1613 clear(): Promise<void>; 1614 1615 /** 1616 * Clears all preferences from the {@link Preferences} object. This interface is executed synchronously. 1617 * <p>You can call the {@link #flush} method to save the {@link Preferences} object to the file. 1618 * 1619 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1620 * @crossplatform 1621 * @since 10 1622 */ 1623 /** 1624 * Clears all preferences from the {@link Preferences} object. This interface is executed synchronously. 1625 * <p>You can call the {@link #flush} method to save the {@link Preferences} object to the file. 1626 * 1627 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1628 * @crossplatform 1629 * @atomicservice 1630 * @since 11 1631 */ 1632 clearSync(): void; 1633 1634 /** 1635 * Asynchronously saves the {@link Preferences} object to the file. 1636 * 1637 * @param { AsyncCallback<void> } callback - Indicates the callback function. 1638 * @throws { BusinessError } 401 - Parameter error. Mandatory parameters are left unspecified; 1639 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1640 * @since 9 1641 */ 1642 /** 1643 * Asynchronously saves the {@link Preferences} object to the file. 1644 * 1645 * @param { AsyncCallback<void> } callback - Indicates the callback function. 1646 * @throws { BusinessError } 401 - Parameter error. Mandatory parameters are left unspecified; 1647 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1648 * @crossplatform 1649 * @since 10 1650 */ 1651 /** 1652 * Asynchronously saves the {@link Preferences} object to the file. 1653 * 1654 * @param { AsyncCallback<void> } callback - Indicates the callback function. 1655 * @throws { BusinessError } 401 - Parameter error. Mandatory parameters are left unspecified; 1656 * @throws { BusinessError } 15500000 - Inner error. 1657 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1658 * @crossplatform 1659 * @atomicservice 1660 * @since 11 1661 */ 1662 flush(callback: AsyncCallback<void>): void; 1663 1664 /** 1665 * Asynchronously saves the {@link Preferences} object to the file. 1666 * 1667 * @returns { Promise<void> } A promise object. 1668 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1669 * @since 9 1670 */ 1671 /** 1672 * Asynchronously saves the {@link Preferences} object to the file. 1673 * 1674 * @returns { Promise<void> } A promise object. 1675 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1676 * @crossplatform 1677 * @since 10 1678 */ 1679 /** 1680 * Asynchronously saves the {@link Preferences} object to the file. 1681 * 1682 * @returns { Promise<void> } A promise object. 1683 * @throws { BusinessError } 15500000 - Inner error. 1684 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1685 * @crossplatform 1686 * @atomicservice 1687 * @since 11 1688 */ 1689 flush(): Promise<void>; 1690 1691 /** 1692 * Registers an observer to listen for the change of a {@link Preferences} object. 1693 * 1694 * @param { 'change' } type - Indicates the callback when preferences changes. 1695 * @param { Callback<{ key: string }> } callback - Indicates the callback function. 1696 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1697 * 2. Incorrect parameter types; 1698 * 3. Parameter verification failed. 1699 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1700 * @since 9 1701 */ 1702 /** 1703 * Registers an observer to listen for the change of a {@link Preferences} object. 1704 * 1705 * @param { 'change' } type - Indicates the callback when preferences changes. 1706 * @param { Function } callback - Indicates the callback function. 1707 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1708 * 2. Incorrect parameter types; 1709 * 3. Parameter verification failed. 1710 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1711 * @crossplatform 1712 * @since 10 1713 */ 1714 /** 1715 * Registers an observer to listen for the change of a {@link Preferences} object. 1716 * 1717 * @param { 'change' } type - Indicates the callback when preferences changes. 1718 * @param { Callback<string> } callback - Indicates the callback function. 1719 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1720 * 2. Incorrect parameter types; 1721 * 3. Parameter verification failed. 1722 * @throws { BusinessError } 15500000 - Inner error. 1723 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1724 * @crossplatform 1725 * @atomicservice 1726 * @since 11 1727 */ 1728 on(type: 'change', callback: Callback<string>): void; 1729 1730 /** 1731 * Registers an observer to listen for the change of a {@link Preferences} object. 1732 * 1733 * @param { 'multiProcessChange' } type - Indicates the callback when preferences changed in multiple processes. 1734 * @param { Function } callback - Indicates the callback function. 1735 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1736 * 2. Incorrect parameter types; 1737 * 3. Parameter verification failed. 1738 * @throws { BusinessError } 15500019 - Failed to obtain subscription service. 1739 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1740 * @since 10 1741 */ 1742 /** 1743 * Registers an observer to listen for the change of a {@link Preferences} object. 1744 * 1745 * @param { 'multiProcessChange' } type - Indicates the callback when preferences changed in multiple processes. 1746 * @param { Callback<string> } callback - Indicates the callback function. 1747 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1748 * 2. Incorrect parameter types; 1749 * 3. Parameter verification failed. 1750 * @throws { BusinessError } 15500000 - Inner error. 1751 * @throws { BusinessError } 15500019 - Failed to obtain subscription service. 1752 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1753 * @atomicservice 1754 * @since 11 1755 */ 1756 on(type: 'multiProcessChange', callback: Callback<string>): void; 1757 1758 /** 1759 * Registers an observer to listen for changes to the {@ link Preferences} object. 1760 * 1761 * @param { 'dataChange' } type - Indicates the type of the event to observe. 1762 * @param { Array<string> } keys - Indicates one or more keys to listen for. 1763 * @param { Callback<Record<string, ValueType>> } callback - Indicates the callback used to return the data change. 1764 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1765 * 2. Incorrect parameter types; 1766 * 3. Parameter verification failed. 1767 * The callback must be function. 1768 * @throws { BusinessError } 15500000 - Inner error. 1769 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1770 * @atomicservice 1771 * @since 12 1772 */ 1773 on(type: 'dataChange', keys: Array<string>, callback: Callback<Record<string, ValueType>>): void; 1774 1775 /** 1776 * Unregisters an existing observer. 1777 * 1778 * @param { 'change' } type - Indicates the callback when preferences changes. 1779 * @param { Callback<{ key: string }> } callback - Indicates the callback function. 1780 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1781 * 2. Incorrect parameter types; 1782 * 3. Parameter verification failed. 1783 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1784 * @since 9 1785 */ 1786 /** 1787 * Unregisters an existing observer. 1788 * 1789 * @param { 'change' } type - Indicates the callback when preferences changes. 1790 * @param { Function } callback - Indicates the callback function. 1791 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1792 * 2. Incorrect parameter types; 1793 * 3. Parameter verification failed. 1794 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1795 * @crossplatform 1796 * @since 10 1797 */ 1798 /** 1799 * Unregisters an existing observer. 1800 * 1801 * @param { 'change' } type - Indicates the callback when preferences changes. 1802 * @param { Callback<string> } callback - Indicates the callback function. 1803 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1804 * 2. Incorrect parameter types; 1805 * 3. Parameter verification failed. 1806 * @throws { BusinessError } 15500000 - Inner error. 1807 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1808 * @crossplatform 1809 * @atomicservice 1810 * @since 11 1811 */ 1812 off(type: 'change', callback?: Callback<string>): void; 1813 1814 /** 1815 * Unregisters an existing observer. 1816 * 1817 * @param { 'multiProcessChange' } type - Indicates the callback when preferences changed in multiple processes. 1818 * @param { Function } callback - Indicates the callback function. 1819 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1820 * 2. Incorrect parameter types; 1821 * 3. Parameter verification failed. 1822 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1823 * @since 10 1824 */ 1825 /** 1826 * Unregisters an existing observer. 1827 * 1828 * @param { 'multiProcessChange' } type - Indicates the callback when preferences changed in multiple processes. 1829 * @param { Callback<string> } callback - Indicates the callback function. 1830 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1831 * 2. Incorrect parameter types; 1832 * 3. Parameter verification failed. 1833 * @throws { BusinessError } 15500000 - Inner error. 1834 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1835 * @atomicservice 1836 * @since 11 1837 */ 1838 off(type: 'multiProcessChange', callback?: Callback<string>): void; 1839 1840 /** 1841 * Unregisters an observer for changes to the {@ link Preferences} object. 1842 * 1843 * @param { 'dataChange' } type - Indicates the event type. 1844 * @param { Array<string> } keys - Indicates the data whose changes are not observed. 1845 * @param { Callback<Record<string, ValueType>> } callback - Indicates the callback to unregister. 1846 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1847 * 2. Incorrect parameter types; 1848 * 3. Parameter verification failed. 1849 * @throws { BusinessError } 15500000 - Inner error. 1850 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 1851 * @atomicservice 1852 * @since 12 1853 */ 1854 off(type: 'dataChange', keys: Array<string>, callback?: Callback<Record<string, ValueType>>): void; 1855 } 1856} 1857 1858export default preferences; 1859