161847f8eSopenharmony_ci/* 261847f8eSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 361847f8eSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 461847f8eSopenharmony_ci * you may not use this file except in compliance with the License. 561847f8eSopenharmony_ci * You may obtain a copy of the License at 661847f8eSopenharmony_ci * 761847f8eSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 861847f8eSopenharmony_ci * 961847f8eSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1061847f8eSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1161847f8eSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1261847f8eSopenharmony_ci * See the License for the specific language governing permissions and 1361847f8eSopenharmony_ci * limitations under the License. 1461847f8eSopenharmony_ci */ 1561847f8eSopenharmony_ci 1661847f8eSopenharmony_ci/** 1761847f8eSopenharmony_ci * @file 1861847f8eSopenharmony_ci * @kit ArkData 1961847f8eSopenharmony_ci */ 2061847f8eSopenharmony_ci 2161847f8eSopenharmony_ciimport { Callback } from './@ohos.base'; 2261847f8eSopenharmony_ciimport Context from './application/BaseContext'; 2361847f8eSopenharmony_ciimport collections from '../arkts/@arkts.collections'; 2461847f8eSopenharmony_ciimport lang from '../arkts/@arkts.lang'; 2561847f8eSopenharmony_ci 2661847f8eSopenharmony_ci/** 2761847f8eSopenharmony_ci * Provides interfaces to obtain and modify preferences data. 2861847f8eSopenharmony_ci * 2961847f8eSopenharmony_ci * @namespace sendablePreferences 3061847f8eSopenharmony_ci * @syscap SystemCapability.DistributedDataManager.Preferences.Core 3161847f8eSopenharmony_ci * @atomicservice 3261847f8eSopenharmony_ci * @since 12 3361847f8eSopenharmony_ci * @name sendablePreferences 3461847f8eSopenharmony_ci */ 3561847f8eSopenharmony_cideclare namespace sendablePreferences { 3661847f8eSopenharmony_ci /** 3761847f8eSopenharmony_ci * Maximum length of a key. 3861847f8eSopenharmony_ci * 3961847f8eSopenharmony_ci * @syscap SystemCapability.DistributedDataManager.Preferences.Core 4061847f8eSopenharmony_ci * @atomicservice 4161847f8eSopenharmony_ci * @since 12 4261847f8eSopenharmony_ci */ 4361847f8eSopenharmony_ci const MAX_KEY_LENGTH: number; 4461847f8eSopenharmony_ci 4561847f8eSopenharmony_ci /** 4661847f8eSopenharmony_ci * Maximum length of a value. 4761847f8eSopenharmony_ci * 4861847f8eSopenharmony_ci * @syscap SystemCapability.DistributedDataManager.Preferences.Core 4961847f8eSopenharmony_ci * @atomicservice 5061847f8eSopenharmony_ci * @since 12 5161847f8eSopenharmony_ci */ 5261847f8eSopenharmony_ci const MAX_VALUE_LENGTH: number; 5361847f8eSopenharmony_ci 5461847f8eSopenharmony_ci /** 5561847f8eSopenharmony_ci * Defines the configuration of a preferences file. 5661847f8eSopenharmony_ci * 5761847f8eSopenharmony_ci * @interface Options 5861847f8eSopenharmony_ci * @syscap SystemCapability.DistributedDataManager.Preferences.Core 5961847f8eSopenharmony_ci * @atomicservice 6061847f8eSopenharmony_ci * @since 12 6161847f8eSopenharmony_ci */ 6261847f8eSopenharmony_ci interface Options { 6361847f8eSopenharmony_ci /** 6461847f8eSopenharmony_ci * Name of the preferences file. 6561847f8eSopenharmony_ci * 6661847f8eSopenharmony_ci * @type { string } 6761847f8eSopenharmony_ci * @syscap SystemCapability.DistributedDataManager.Preferences.Core 6861847f8eSopenharmony_ci * @atomicservice 6961847f8eSopenharmony_ci * @since 12 7061847f8eSopenharmony_ci */ 7161847f8eSopenharmony_ci name: string; 7261847f8eSopenharmony_ci 7361847f8eSopenharmony_ci /** 7461847f8eSopenharmony_ci * Application group ID. 7561847f8eSopenharmony_ci * 7661847f8eSopenharmony_ci * @type { ?(string | null) } 7761847f8eSopenharmony_ci * @syscap SystemCapability.DistributedDataManager.Preferences.Core 7861847f8eSopenharmony_ci * @StageModelOnly 7961847f8eSopenharmony_ci * @atomicservice 8061847f8eSopenharmony_ci * @since 12 8161847f8eSopenharmony_ci */ 8261847f8eSopenharmony_ci dataGroupId?: string | null; 8361847f8eSopenharmony_ci } 8461847f8eSopenharmony_ci 8561847f8eSopenharmony_ci /** 8661847f8eSopenharmony_ci * Obtains a {@link Preferences} instance matching the specified preferences file name. 8761847f8eSopenharmony_ci * <p>The {@link references} instance loads all data of the preferences file and 8861847f8eSopenharmony_ci * resides in the cache. You can use removePreferencesFromCache to remove the instance from the cache. 8961847f8eSopenharmony_ci * 9061847f8eSopenharmony_ci * @param { Context } context - Indicates the context of application or capability. 9161847f8eSopenharmony_ci * @param { Options } options - Indicates information about the preferences file. For details, see {@link Options}. 9261847f8eSopenharmony_ci * @returns { Promise<Preferences> } Promise used to return the {@link Preferences}. 9361847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 9461847f8eSopenharmony_ci * 2. Incorrect parameter types; 9561847f8eSopenharmony_ci * 3. Parameter verification failed. 9661847f8eSopenharmony_ci * @throws { BusinessError } 801 - Capability not supported. 9761847f8eSopenharmony_ci * @throws { BusinessError } 15500000 - Inner error. 9861847f8eSopenharmony_ci * @throws { BusinessError } 15501001 - Only supported in stage mode. 9961847f8eSopenharmony_ci * @throws { BusinessError } 15501002 - The data group id is not valid. 10061847f8eSopenharmony_ci * @syscap SystemCapability.DistributedDataManager.Preferences.Core 10161847f8eSopenharmony_ci * @atomicservice 10261847f8eSopenharmony_ci * @since 12 10361847f8eSopenharmony_ci */ 10461847f8eSopenharmony_ci function getPreferences(context: Context, options: Options): Promise<Preferences>; 10561847f8eSopenharmony_ci 10661847f8eSopenharmony_ci /** 10761847f8eSopenharmony_ci * Obtains a {@link Preferences} instance matching a specified preferences file name. 10861847f8eSopenharmony_ci * This API returns the result synchronously. 10961847f8eSopenharmony_ci * <p>The {@link references} instance loads all data of the preferences file and 11061847f8eSopenharmony_ci * resides in the cache. You can use removePreferencesFromCache to remove the instance from the cache. 11161847f8eSopenharmony_ci * 11261847f8eSopenharmony_ci * @param { Context } context - Indicates the context of application or capability. 11361847f8eSopenharmony_ci * @param { Options } options - Indicates information about the preferences file. For details, see {@link Options}. 11461847f8eSopenharmony_ci * @returns { Preferences } return the {@link Preferences}. 11561847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 11661847f8eSopenharmony_ci * 2. Incorrect parameter types; 11761847f8eSopenharmony_ci * 3. Parameter verification failed. 11861847f8eSopenharmony_ci * @throws { BusinessError } 801 - Capability not supported. 11961847f8eSopenharmony_ci * @throws { BusinessError } 15500000 - Inner error. 12061847f8eSopenharmony_ci * @throws { BusinessError } 15501001 - Only supported in stage mode. 12161847f8eSopenharmony_ci * @throws { BusinessError } 15501002 - The data group id is not valid. 12261847f8eSopenharmony_ci * @syscap SystemCapability.DistributedDataManager.Preferences.Core 12361847f8eSopenharmony_ci * @atomicservice 12461847f8eSopenharmony_ci * @since 12 12561847f8eSopenharmony_ci */ 12661847f8eSopenharmony_ci function getPreferencesSync(context: Context, options: Options): Preferences; 12761847f8eSopenharmony_ci 12861847f8eSopenharmony_ci /** 12961847f8eSopenharmony_ci * Deletes a {@link Preferences} instance matching the specified preferences file name 13061847f8eSopenharmony_ci * from the cache (which is equivalent to calling removePreferencesFromCache) and deletes 13161847f8eSopenharmony_ci * the preferences file. 13261847f8eSopenharmony_ci * <p>When deleting a {@link Preferences} instance, you must release all references 13361847f8eSopenharmony_ci * of the instance. In addition, do not use the instance to perform data operations. Otherwise, data inconsistency 13461847f8eSopenharmony_ci * will occur. 13561847f8eSopenharmony_ci * 13661847f8eSopenharmony_ci * @param { Context } context - Indicates the context of application or capability. 13761847f8eSopenharmony_ci * @param { Options } options - Indicates information about the preferences file. For details, see {@link Options}. 13861847f8eSopenharmony_ci * @returns { Promise<void> } Promise that returns no value. 13961847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 14061847f8eSopenharmony_ci * 2. Incorrect parameter types; 14161847f8eSopenharmony_ci * 3. Parameter verification failed. 14261847f8eSopenharmony_ci * @throws { BusinessError } 801 - Capability not supported. 14361847f8eSopenharmony_ci * @throws { BusinessError } 15500000 - Inner error. 14461847f8eSopenharmony_ci * @throws { BusinessError } 15500010 - Failed to delete preferences file. 14561847f8eSopenharmony_ci * @throws { BusinessError } 15501001 - Only supported in stage mode. 14661847f8eSopenharmony_ci * @throws { BusinessError } 15501002 - The data group id is not valid. 14761847f8eSopenharmony_ci * @syscap SystemCapability.DistributedDataManager.Preferences.Core 14861847f8eSopenharmony_ci * @atomicservice 14961847f8eSopenharmony_ci * @since 12 15061847f8eSopenharmony_ci */ 15161847f8eSopenharmony_ci function deletePreferences(context: Context, options: Options): Promise<void>; 15261847f8eSopenharmony_ci 15361847f8eSopenharmony_ci /** 15461847f8eSopenharmony_ci * Removes a {@link Preferences} instance matching the specified preferences file name 15561847f8eSopenharmony_ci * from the cache. 15661847f8eSopenharmony_ci * <p>When removing a {@link Preferences} instance, you must release all references 15761847f8eSopenharmony_ci * of the instance. In addition, do not use the instance to perform data operations. Otherwise, data inconsistency 15861847f8eSopenharmony_ci * will occur. 15961847f8eSopenharmony_ci * 16061847f8eSopenharmony_ci * @param { Context } context - Indicates the context of application or capability. 16161847f8eSopenharmony_ci * @param { Options } options - Indicates information about the preferences file. For details, see {@link Options}. 16261847f8eSopenharmony_ci * @returns { Promise<void> } Promise that returns no value. 16361847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 16461847f8eSopenharmony_ci * 2. Incorrect parameter types; 16561847f8eSopenharmony_ci * 3. Parameter verification failed. 16661847f8eSopenharmony_ci * @throws { BusinessError } 801 - Capability not supported. 16761847f8eSopenharmony_ci * @throws { BusinessError } 15500000 - Inner error. 16861847f8eSopenharmony_ci * @throws { BusinessError } 15501001 - Only supported in stage mode. 16961847f8eSopenharmony_ci * @throws { BusinessError } 15501002 - The data group id is not valid. 17061847f8eSopenharmony_ci * @syscap SystemCapability.DistributedDataManager.Preferences.Core 17161847f8eSopenharmony_ci * @atomicservice 17261847f8eSopenharmony_ci * @since 12 17361847f8eSopenharmony_ci */ 17461847f8eSopenharmony_ci function removePreferencesFromCache(context: Context, options: Options): Promise<void>; 17561847f8eSopenharmony_ci 17661847f8eSopenharmony_ci /** 17761847f8eSopenharmony_ci * Removes a {@link Preferences} instance matching the specified preferences file name 17861847f8eSopenharmony_ci * from the cache. This API returns the result synchronously. 17961847f8eSopenharmony_ci * <p>When removing a {@link Preferences} instance, you must release all references 18061847f8eSopenharmony_ci * of the instance. In addition, do not use the instance to perform data operations. Otherwise, data inconsistency 18161847f8eSopenharmony_ci * will occur. 18261847f8eSopenharmony_ci * 18361847f8eSopenharmony_ci * @param { Context } context - Indicates the context of application or capability. 18461847f8eSopenharmony_ci * @param { Options } options - Indicates information about the preferences file. For details, see {@link Options}. 18561847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 18661847f8eSopenharmony_ci * 2. Incorrect parameter types; 18761847f8eSopenharmony_ci * 3. Parameter verification failed. 18861847f8eSopenharmony_ci * @throws { BusinessError } 801 - Capability not supported. 18961847f8eSopenharmony_ci * @throws { BusinessError } 15500000 - Inner error. 19061847f8eSopenharmony_ci * @throws { BusinessError } 15501001 - Only supported in stage mode. 19161847f8eSopenharmony_ci * @throws { BusinessError } 15501002 - The data group id is not valid. 19261847f8eSopenharmony_ci * @syscap SystemCapability.DistributedDataManager.Preferences.Core 19361847f8eSopenharmony_ci * @atomicservice 19461847f8eSopenharmony_ci * @since 12 19561847f8eSopenharmony_ci */ 19661847f8eSopenharmony_ci function removePreferencesFromCacheSync(context: Context, options: Options): void; 19761847f8eSopenharmony_ci 19861847f8eSopenharmony_ci /** 19961847f8eSopenharmony_ci * Provides interfaces to obtain and modify preferences data. 20061847f8eSopenharmony_ci * <p>The preferences data is stored in a file, which matches only one {@link Preferences} instance in the cache. 20161847f8eSopenharmony_ci * You can use getPreferences to obtain the {@link Preferences} instance matching 20261847f8eSopenharmony_ci * the file that stores preferences data, and use removePreferencesFromCache 20361847f8eSopenharmony_ci * to remove the {@link Preferences} instance from the cache. 20461847f8eSopenharmony_ci * 20561847f8eSopenharmony_ci * @interface Preferences 20661847f8eSopenharmony_ci * @syscap SystemCapability.DistributedDataManager.Preferences.Core 20761847f8eSopenharmony_ci * @atomicservice 20861847f8eSopenharmony_ci * @since 12 20961847f8eSopenharmony_ci */ 21061847f8eSopenharmony_ci interface Preferences extends lang.ISendable { 21161847f8eSopenharmony_ci /** 21261847f8eSopenharmony_ci * Obtains the value of a preferences instance. 21361847f8eSopenharmony_ci * <p>If the value is {@code null} or not in the lang.ISendable format, the default value is returned. 21461847f8eSopenharmony_ci * 21561847f8eSopenharmony_ci * @param { string } key - Indicates the key of the preferences. It cannot be {@code null} or empty. 21661847f8eSopenharmony_ci * <tt>MAX_KEY_LENGTH</tt>. 21761847f8eSopenharmony_ci * @param { lang.ISendable } defValue - Indicates the default value to return. 21861847f8eSopenharmony_ci * @returns { Promise<lang.ISendable> } Promise used to return the result. If a value matching the specified key 21961847f8eSopenharmony_ci * is found, the value is returned. Otherwise, the default value is returned. 22061847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 22161847f8eSopenharmony_ci * 2. Incorrect parameter types; 22261847f8eSopenharmony_ci * 3. Parameter verification failed. 22361847f8eSopenharmony_ci * @throws { BusinessError } 15500000 - Inner error. 22461847f8eSopenharmony_ci * @syscap SystemCapability.DistributedDataManager.Preferences.Core 22561847f8eSopenharmony_ci * @atomicservice 22661847f8eSopenharmony_ci * @since 12 22761847f8eSopenharmony_ci */ 22861847f8eSopenharmony_ci get(key: string, defValue: lang.ISendable): Promise<lang.ISendable>; 22961847f8eSopenharmony_ci 23061847f8eSopenharmony_ci /** 23161847f8eSopenharmony_ci * Obtains the value of a preferences instance. This API returns the result synchronously. 23261847f8eSopenharmony_ci * <p>If the value is {@code null} or not in the lang.ISendable format, the default value is returned. 23361847f8eSopenharmony_ci * 23461847f8eSopenharmony_ci * @param { string } key - Indicates the key of the preferences. It cannot be {@code null} or empty. 23561847f8eSopenharmony_ci * <tt>MAX_KEY_LENGTH</tt>. 23661847f8eSopenharmony_ci * @param { lang.ISendable } defValue - Indicates the default value to return. 23761847f8eSopenharmony_ci * @returns { lang.ISendable } If a value matching the specified key is found, the value is returned. Otherwise, 23861847f8eSopenharmony_ci * the default value is returned. 23961847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 24061847f8eSopenharmony_ci * 2. Incorrect parameter types; 24161847f8eSopenharmony_ci * 3. Parameter verification failed. 24261847f8eSopenharmony_ci * @throws { BusinessError } 15500000 - Inner error. 24361847f8eSopenharmony_ci * @syscap SystemCapability.DistributedDataManager.Preferences.Core 24461847f8eSopenharmony_ci * @atomicservice 24561847f8eSopenharmony_ci * @since 12 24661847f8eSopenharmony_ci */ 24761847f8eSopenharmony_ci getSync(key: string, defValue: lang.ISendable): lang.ISendable; 24861847f8eSopenharmony_ci 24961847f8eSopenharmony_ci /** 25061847f8eSopenharmony_ci * Obtains all the keys and values of a preferences instance in an object. 25161847f8eSopenharmony_ci * 25261847f8eSopenharmony_ci * @returns { Promise<lang.ISendable> } Promise used to return the values and keys obtained in an object. 25361847f8eSopenharmony_ci * @throws { BusinessError } 15500000 - Inner error. 25461847f8eSopenharmony_ci * @syscap SystemCapability.DistributedDataManager.Preferences.Core 25561847f8eSopenharmony_ci * @atomicservice 25661847f8eSopenharmony_ci * @since 12 25761847f8eSopenharmony_ci */ 25861847f8eSopenharmony_ci getAll(): Promise<lang.ISendable>; 25961847f8eSopenharmony_ci 26061847f8eSopenharmony_ci /** 26161847f8eSopenharmony_ci * Obtains all the keys and values of a preferences instance. This API returns the result synchronously. 26261847f8eSopenharmony_ci * 26361847f8eSopenharmony_ci * @returns { lang.ISendable } Returns the values and keys obtained in an object. 26461847f8eSopenharmony_ci * @throws { BusinessError } 15500000 - Inner error. 26561847f8eSopenharmony_ci * @syscap SystemCapability.DistributedDataManager.Preferences.Core 26661847f8eSopenharmony_ci * @atomicservice 26761847f8eSopenharmony_ci * @since 12 26861847f8eSopenharmony_ci */ 26961847f8eSopenharmony_ci getAllSync(): lang.ISendable; 27061847f8eSopenharmony_ci 27161847f8eSopenharmony_ci /** 27261847f8eSopenharmony_ci * Checks whether the {@link Preferences} instance contains a value matching the specified key. 27361847f8eSopenharmony_ci * 27461847f8eSopenharmony_ci * @param { string } key - Indicates the key of the value to check. It cannot be {@code null} or empty. 27561847f8eSopenharmony_ci * <tt>MAX_KEY_LENGTH</tt>. 27661847f8eSopenharmony_ci * @returns { Promise<boolean> } Promise used to return the result. {@code true} is returned if the 27761847f8eSopenharmony_ci * {@link Preferences} object contains a value matching the specified key; {@code false} is returned otherwise. 27861847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 27961847f8eSopenharmony_ci * 2. Incorrect parameter types; 28061847f8eSopenharmony_ci * 3. Parameter verification failed. 28161847f8eSopenharmony_ci * @throws { BusinessError } 15500000 - Inner error. 28261847f8eSopenharmony_ci * @syscap SystemCapability.DistributedDataManager.Preferences.Core 28361847f8eSopenharmony_ci * @atomicservice 28461847f8eSopenharmony_ci * @since 12 28561847f8eSopenharmony_ci */ 28661847f8eSopenharmony_ci has(key: string): Promise<boolean>; 28761847f8eSopenharmony_ci 28861847f8eSopenharmony_ci /** 28961847f8eSopenharmony_ci * Checks whether the {@link Preferences} instance contains a value matching the specified key. 29061847f8eSopenharmony_ci * This API returns the result synchronously. 29161847f8eSopenharmony_ci * 29261847f8eSopenharmony_ci * @param { string } key - Indicates the key of the value to check. It cannot be {@code null} or empty. 29361847f8eSopenharmony_ci * <tt>MAX_KEY_LENGTH</tt>. 29461847f8eSopenharmony_ci * @returns { boolean } {@code true} is returned if the {@link Preferences} object contains a value matching 29561847f8eSopenharmony_ci * the specified key; {@code false} is returned otherwise. 29661847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 29761847f8eSopenharmony_ci * 2. Incorrect parameter types; 29861847f8eSopenharmony_ci * 3. Parameter verification failed. 29961847f8eSopenharmony_ci * @throws { BusinessError } 15500000 - Inner error. 30061847f8eSopenharmony_ci * @syscap SystemCapability.DistributedDataManager.Preferences.Core 30161847f8eSopenharmony_ci * @atomicservice 30261847f8eSopenharmony_ci * @since 12 30361847f8eSopenharmony_ci */ 30461847f8eSopenharmony_ci hasSync(key: string): boolean; 30561847f8eSopenharmony_ci 30661847f8eSopenharmony_ci /** 30761847f8eSopenharmony_ci * Sets an lang.ISendable value for the key in the {@link Preferences} object. 30861847f8eSopenharmony_ci * <p>You can call the {@link #flush} method to save the {@link Preferences} object to the file. 30961847f8eSopenharmony_ci * 31061847f8eSopenharmony_ci * @param { string } key - Indicates the key of the preferences to set. It cannot be {@code null} or empty. 31161847f8eSopenharmony_ci * <tt>MAX_KEY_LENGTH</tt>. 31261847f8eSopenharmony_ci * @param { lang.ISendable } value - Indicates the value of the preferences. 31361847f8eSopenharmony_ci * <tt>MAX_VALUE_LENGTH</tt>. 31461847f8eSopenharmony_ci * @returns { Promise<void> } Promise that returns no value. 31561847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 31661847f8eSopenharmony_ci * 2. Incorrect parameter types; 31761847f8eSopenharmony_ci * 3. Parameter verification failed. 31861847f8eSopenharmony_ci * @throws { BusinessError } 15500000 - Inner error. 31961847f8eSopenharmony_ci * @syscap SystemCapability.DistributedDataManager.Preferences.Core 32061847f8eSopenharmony_ci * @atomicservice 32161847f8eSopenharmony_ci * @since 12 32261847f8eSopenharmony_ci */ 32361847f8eSopenharmony_ci put(key: string, value: lang.ISendable): Promise<void>; 32461847f8eSopenharmony_ci 32561847f8eSopenharmony_ci /** 32661847f8eSopenharmony_ci * Sets an lang.ISendable value for the key in the {@link Preferences} object. 32761847f8eSopenharmony_ci * This API returns the result synchronously. 32861847f8eSopenharmony_ci * <p>You can call the {@link #flush} method to save the {@link Preferences} object to the file. 32961847f8eSopenharmony_ci * 33061847f8eSopenharmony_ci * @param { string } key - Indicates the key of the preferences to set. It cannot be {@code null} or empty. 33161847f8eSopenharmony_ci * <tt>MAX_KEY_LENGTH</tt>. 33261847f8eSopenharmony_ci * @param { lang.ISendable } value - Indicates the value of the preferences. 33361847f8eSopenharmony_ci * <tt>MAX_VALUE_LENGTH</tt>. 33461847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 33561847f8eSopenharmony_ci * 2. Incorrect parameter types; 33661847f8eSopenharmony_ci * 3. Parameter verification failed. 33761847f8eSopenharmony_ci * @throws { BusinessError } 15500000 - Inner error. 33861847f8eSopenharmony_ci * @syscap SystemCapability.DistributedDataManager.Preferences.Core 33961847f8eSopenharmony_ci * @atomicservice 34061847f8eSopenharmony_ci * @since 12 34161847f8eSopenharmony_ci */ 34261847f8eSopenharmony_ci putSync(key: string, value: lang.ISendable): void; 34361847f8eSopenharmony_ci 34461847f8eSopenharmony_ci /** 34561847f8eSopenharmony_ci * Deletes the preferences with a specified key from the {@link Preferences} object. 34661847f8eSopenharmony_ci * <p>You can call the {@link #flush} method to save the {@link Preferences} object to the file. 34761847f8eSopenharmony_ci * 34861847f8eSopenharmony_ci * @param { string } key - Indicates the key of the preferences to delete. It cannot be {@code null} or empty. 34961847f8eSopenharmony_ci * <tt>MAX_KEY_LENGTH</tt>. 35061847f8eSopenharmony_ci * @returns { Promise<void> } Promise that returns no value. 35161847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 35261847f8eSopenharmony_ci * 2. Incorrect parameter types; 35361847f8eSopenharmony_ci * 3. Parameter verification failed. 35461847f8eSopenharmony_ci * @throws { BusinessError } 15500000 - Inner error. 35561847f8eSopenharmony_ci * @syscap SystemCapability.DistributedDataManager.Preferences.Core 35661847f8eSopenharmony_ci * @atomicservice 35761847f8eSopenharmony_ci * @since 12 35861847f8eSopenharmony_ci */ 35961847f8eSopenharmony_ci delete(key: string): Promise<void>; 36061847f8eSopenharmony_ci 36161847f8eSopenharmony_ci /** 36261847f8eSopenharmony_ci * Deletes the preferences with a specified key from the {@link Preferences} object. This API returns the result 36361847f8eSopenharmony_ci * synchronously. 36461847f8eSopenharmony_ci * <p>You can call the {@link #flush} method to save the {@link Preferences} object to the file. 36561847f8eSopenharmony_ci * 36661847f8eSopenharmony_ci * @param { string } key - Indicates the key of the preferences to delete. It cannot be {@code null} or empty. 36761847f8eSopenharmony_ci * <tt>MAX_KEY_LENGTH</tt>. 36861847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 36961847f8eSopenharmony_ci * 2. Incorrect parameter types; 37061847f8eSopenharmony_ci * 3. Parameter verification failed. 37161847f8eSopenharmony_ci * @throws { BusinessError } 15500000 - Inner error. 37261847f8eSopenharmony_ci * @syscap SystemCapability.DistributedDataManager.Preferences.Core 37361847f8eSopenharmony_ci * @atomicservice 37461847f8eSopenharmony_ci * @since 12 37561847f8eSopenharmony_ci */ 37661847f8eSopenharmony_ci deleteSync(key: string): void; 37761847f8eSopenharmony_ci 37861847f8eSopenharmony_ci /** 37961847f8eSopenharmony_ci * Clears all preferences from the {@link Preferences} object. 38061847f8eSopenharmony_ci * <p>You can call the {@link #flush} method to save the {@link Preferences} object to the file. 38161847f8eSopenharmony_ci * 38261847f8eSopenharmony_ci * @returns { Promise<void> } Promise that returns no value. 38361847f8eSopenharmony_ci * @throws { BusinessError } 15500000 - Inner error. 38461847f8eSopenharmony_ci * @syscap SystemCapability.DistributedDataManager.Preferences.Core 38561847f8eSopenharmony_ci * @atomicservice 38661847f8eSopenharmony_ci * @since 12 38761847f8eSopenharmony_ci */ 38861847f8eSopenharmony_ci clear(): Promise<void>; 38961847f8eSopenharmony_ci 39061847f8eSopenharmony_ci /** 39161847f8eSopenharmony_ci * Clears all preferences from the {@link Preferences} object. This API returns the result synchronously. 39261847f8eSopenharmony_ci * <p>You can call the {@link #flush} method to save the {@link Preferences} object to the file. 39361847f8eSopenharmony_ci * 39461847f8eSopenharmony_ci * @throws { BusinessError } 15500000 - Inner error. 39561847f8eSopenharmony_ci * @syscap SystemCapability.DistributedDataManager.Preferences.Core 39661847f8eSopenharmony_ci * @atomicservice 39761847f8eSopenharmony_ci * @since 12 39861847f8eSopenharmony_ci */ 39961847f8eSopenharmony_ci clearSync(): void; 40061847f8eSopenharmony_ci 40161847f8eSopenharmony_ci /** 40261847f8eSopenharmony_ci * Flushes the {@link Preferences} object to the file. 40361847f8eSopenharmony_ci * 40461847f8eSopenharmony_ci * @returns { Promise<void> } Promise that returns no value. 40561847f8eSopenharmony_ci * @throws { BusinessError } 15500000 - Inner error. 40661847f8eSopenharmony_ci * @syscap SystemCapability.DistributedDataManager.Preferences.Core 40761847f8eSopenharmony_ci * @atomicservice 40861847f8eSopenharmony_ci * @since 12 40961847f8eSopenharmony_ci */ 41061847f8eSopenharmony_ci flush(): Promise<void>; 41161847f8eSopenharmony_ci 41261847f8eSopenharmony_ci /** 41361847f8eSopenharmony_ci * Registers an observer to listen for the change of a {@link Preferences} object. 41461847f8eSopenharmony_ci * 41561847f8eSopenharmony_ci * @param { 'change' } type - Indicates the type of the event to observe. 41661847f8eSopenharmony_ci * @param { Callback<string> } callback - Indicates the callback used to return the preferences changes. 41761847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 41861847f8eSopenharmony_ci * 2. Incorrect parameter types; 41961847f8eSopenharmony_ci * 3. Parameter verification failed. 42061847f8eSopenharmony_ci * @throws { BusinessError } 15500000 - Inner error. 42161847f8eSopenharmony_ci * @syscap SystemCapability.DistributedDataManager.Preferences.Core 42261847f8eSopenharmony_ci * @atomicservice 42361847f8eSopenharmony_ci * @since 12 42461847f8eSopenharmony_ci */ 42561847f8eSopenharmony_ci on(type: 'change', callback: Callback<string>): void; 42661847f8eSopenharmony_ci 42761847f8eSopenharmony_ci /** 42861847f8eSopenharmony_ci * Registers an observer to listen for the change of a {@link Preferences} object in multiple processes. 42961847f8eSopenharmony_ci * 43061847f8eSopenharmony_ci * @param { 'multiProcessChange' } type - Indicates the type of the event to observe. 43161847f8eSopenharmony_ci * @param { Callback<string> } callback - Indicates the callback used to return the preferences changed 43261847f8eSopenharmony_ci * in multiple processes. 43361847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 43461847f8eSopenharmony_ci * 2. Incorrect parameter types; 43561847f8eSopenharmony_ci * 3. Parameter verification failed. 43661847f8eSopenharmony_ci * @throws { BusinessError } 15500000 - Inner error. 43761847f8eSopenharmony_ci * @throws { BusinessError } 15500019 - Failed to obtain subscription service. 43861847f8eSopenharmony_ci * @syscap SystemCapability.DistributedDataManager.Preferences.Core 43961847f8eSopenharmony_ci * @atomicservice 44061847f8eSopenharmony_ci * @since 12 44161847f8eSopenharmony_ci */ 44261847f8eSopenharmony_ci on(type: 'multiProcessChange', callback: Callback<string>): void; 44361847f8eSopenharmony_ci 44461847f8eSopenharmony_ci /** 44561847f8eSopenharmony_ci * Registers an observer to listen for changes to the {@link Preferences} object. 44661847f8eSopenharmony_ci * 44761847f8eSopenharmony_ci * @param { 'dataChange' } type - Indicates the type of the event to observe. 44861847f8eSopenharmony_ci * @param { Array<string> } keys - Indicates one or more keys to listen for. 44961847f8eSopenharmony_ci * @param { Callback<lang.ISendable> } callback - Indicates the callback used to return the data change. 45061847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 45161847f8eSopenharmony_ci * 2. Incorrect parameter types; 45261847f8eSopenharmony_ci * 3. Parameter verification failed. 45361847f8eSopenharmony_ci * @throws { BusinessError } 15500000 - Inner error. 45461847f8eSopenharmony_ci * @syscap SystemCapability.DistributedDataManager.Preferences.Core 45561847f8eSopenharmony_ci * @atomicservice 45661847f8eSopenharmony_ci * @since 12 45761847f8eSopenharmony_ci */ 45861847f8eSopenharmony_ci on(type: 'dataChange', keys: Array<string>, callback: Callback<lang.ISendable>): void; 45961847f8eSopenharmony_ci 46061847f8eSopenharmony_ci /** 46161847f8eSopenharmony_ci * Unregisters an observer used to listen for changes to the {@link Preferences} object. 46261847f8eSopenharmony_ci * 46361847f8eSopenharmony_ci * @param { 'change' } type - Indicates the event type. 46461847f8eSopenharmony_ci * @param { Callback<string> } callback - Indicates the callback to unregister. 46561847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 46661847f8eSopenharmony_ci * 2. Incorrect parameter types; 46761847f8eSopenharmony_ci * 3. Parameter verification failed. 46861847f8eSopenharmony_ci * @throws { BusinessError } 15500000 - Inner error. 46961847f8eSopenharmony_ci * @syscap SystemCapability.DistributedDataManager.Preferences.Core 47061847f8eSopenharmony_ci * @atomicservice 47161847f8eSopenharmony_ci * @since 12 47261847f8eSopenharmony_ci */ 47361847f8eSopenharmony_ci off(type: 'change', callback?: Callback<string>): void; 47461847f8eSopenharmony_ci 47561847f8eSopenharmony_ci /** 47661847f8eSopenharmony_ci * Unregisters an observer used to listen for the preferences changed in multiple processes. 47761847f8eSopenharmony_ci * 47861847f8eSopenharmony_ci * @param { 'multiProcessChange' } type - Indicates the event type. 47961847f8eSopenharmony_ci * @param { Callback<string> } callback - Indicates the callback to unregister. 48061847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 48161847f8eSopenharmony_ci * 2. Incorrect parameter types; 48261847f8eSopenharmony_ci * 3. Parameter verification failed. 48361847f8eSopenharmony_ci * @throws { BusinessError } 15500000 - Inner error. 48461847f8eSopenharmony_ci * @syscap SystemCapability.DistributedDataManager.Preferences.Core 48561847f8eSopenharmony_ci * @atomicservice 48661847f8eSopenharmony_ci * @since 12 48761847f8eSopenharmony_ci */ 48861847f8eSopenharmony_ci off(type: 'multiProcessChange', callback?: Callback<string>): void; 48961847f8eSopenharmony_ci 49061847f8eSopenharmony_ci /** 49161847f8eSopenharmony_ci * Unregisters an observer for changes to the {@ link Preferences} object. 49261847f8eSopenharmony_ci * 49361847f8eSopenharmony_ci * @param { 'dataChange' } type - Indicates the event type. 49461847f8eSopenharmony_ci * @param { Array<string> } keys - Indicates the data whose changes are not observed. 49561847f8eSopenharmony_ci * @param { Callback<lang.ISendable> } callback - Indicates the callback to unregister. 49661847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 49761847f8eSopenharmony_ci * 2. Incorrect parameter types; 49861847f8eSopenharmony_ci * 3. Parameter verification failed. 49961847f8eSopenharmony_ci * @throws { BusinessError } 15500000 - Inner error. 50061847f8eSopenharmony_ci * @syscap SystemCapability.DistributedDataManager.Preferences.Core 50161847f8eSopenharmony_ci * @atomicservice 50261847f8eSopenharmony_ci * @since 12 50361847f8eSopenharmony_ci */ 50461847f8eSopenharmony_ci off(type: 'dataChange', keys: Array<string>, callback?: Callback<lang.ISendable>): void; 50561847f8eSopenharmony_ci } 50661847f8eSopenharmony_ci} 50761847f8eSopenharmony_ci 50861847f8eSopenharmony_ciexport default sendablePreferences; 509