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