From d024b26257010656d2a009f7e35918733b766a5a Mon Sep 17 00:00:00 2001 From: li_juntao Date: Wed, 14 Sep 2022 10:44:49 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0preferences=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E7=A0=81=20Signed-off-by:=20li=5Fjuntao=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/@ohos.data.preferences.d.ts | 161 +++++++++++++++++++++++++++++++- 1 file changed, 160 insertions(+), 1 deletion(-) diff --git a/api/@ohos.data.preferences.d.ts b/api/@ohos.data.preferences.d.ts index 7355e75a0d..55ad50944e 100644 --- a/api/@ohos.data.preferences.d.ts +++ b/api/@ohos.data.preferences.d.ts @@ -34,10 +34,28 @@ declare namespace preferences { * @param name Indicates the preferences file name. * @return Returns the {@link Preferences} instance matching the specified preferences file name. * @throws BusinessError if invoked failed - * @since 9 + * @since 9 */ function getPreferences(context: Context, name: string, callback: AsyncCallback): void; function getPreferences(context: Context, name: string): Promise; + + /** + * Obtains a {@link Preferences} instance matching a specified preferences file name. + * + *

The {@link references} instance loads all data of the preferences file and + * resides in the memory. You can use removePreferencesFromCache to remove the instance from the memory. + * + * @param context Indicates the context of application or capability. + * @param name Indicates the preferences file name. + * @return Returns the {@link Preferences} instance matching the specified preferences file name. + * @throws {BusinessError} if invoked failed + * @since 9 + * @errorcode 15500001 + * @errorcode 15500012 + * @errorcode 15500013 + */ + function getPreferencesV9(context: Context, name: string, callback: AsyncCallback): void; + function getPreferencesV9(context: Context, name: string): Promise; /** * Deletes a {@link Preferences} instance matching a specified preferences file name @@ -55,6 +73,26 @@ declare namespace preferences { */ function deletePreferences(context: Context, name: string, callback: AsyncCallback): void; function deletePreferences(context: Context, name: string): Promise; + + /** + * Deletes a {@link Preferences} instance matching a specified preferences file name + * from the cache which is performed by removePreferencesFromCache and deletes the + * preferences file. + * + *

When deleting the {@link Preferences} instance, you must release all references + * of the instance. In addition, do not use the instance to perform data operations. Otherwise, data inconsistency + * will occur. + * + * @param context Indicates the context of application or capability. + * @param name Indicates the preferences file name. + * @throws {BusinessError} if invoked failed + * @since 9 + * @errorcode 15500001 + * @errorcode 15500012 + * @errorcode 15500013 + */ + function deletePreferencesV9(context: Context, name: string, callback: AsyncCallback): void; + function deletePreferencesV9(context: Context, name: string): Promise; /** * Deletes a {@link Preferences} instance matching a specified preferences file name @@ -71,6 +109,25 @@ declare namespace preferences { */ function removePreferencesFromCache(context: Context, name: string, callback: AsyncCallback): void; function removePreferencesFromCache(context: Context, name: string): Promise; + + /** + * Deletes a {@link Preferences} instance matching a specified preferences file name + * from the cache. + * + *

When deleting the {@link Preferences} instance, you must release all references + * of the instance. In addition, do not use the instance to perform data operations. Otherwise, data inconsistency + * will occur. + * + * @param context Indicates the context of application or capability. + * @param name Indicates the preferences file name. + * @throws {BusinessError} if invoked failed + * @since 9 + * @errorcode 15500001 + * @errorcode 15500012 + * @errorcode 15500013 + */ + function removePreferencesFromCacheV9(context: Context, name: string, callback: AsyncCallback): void; + function removePreferencesFromCacheV9(context: Context, name: string): Promise; /** * Provides interfaces to obtain and modify preferences data. @@ -98,6 +155,23 @@ declare namespace preferences { */ get(key: string, defValue: ValueType, callback: AsyncCallback): void; get(key: string, defValue: ValueType): Promise; + + /** + * Obtains the value of a preferences in the int format. + * + *

If the value is {@code null} or not in the int format, the default value is returned. + * + * @param key Indicates the key of the preferences. It cannot be {@code null} or empty. + * @param defValue Indicates the default value to return. + * @return Returns the value matching the specified key if it is found; returns the default value otherwise. + * @throws {BusinessError} if invoked failed + * @since 9 + * @errorcode 15500001 + * @errorcode 15500006 + * @errorcode 15500007 + */ + getV9(key: string, defValue: ValueType, callback: AsyncCallback): void; + getV9(key: string, defValue: ValueType): Promise; /** * Obtains all the keys and values of a preferences in an object. @@ -108,6 +182,17 @@ declare namespace preferences { */ getAll(callback: AsyncCallback): void; getAll(): Promise; + + /** + * Obtains all the keys and values of a preferences in an object. + * + * @return Returns the values and keys in an object. + * @throws {BusinessError} if invoked failed + * @since 9 + * @errorcode 15500001 + */ + getAllV9(callback: AsyncCallback): void; + getAllV9(): Promise; /** * Checks whether the {@link Preferences} object contains a preferences matching a specified key. @@ -120,6 +205,21 @@ declare namespace preferences { */ has(key: string, callback: AsyncCallback): void; has(key: string): Promise; + + /** + * Checks whether the {@link Preferences} object contains a preferences matching a specified key. + * + * @param key Indicates the key of the preferences to check for. + * @return Returns {@code true} if the {@link Preferences} object contains a preferences with the specified key; + * returns {@code false} otherwise. + * @throws BusinessError if invoked failed + * @since 9 + * @errorcode 15500001 + * @errorcode 15500006 + * @errorcode 15500007 + */ + hasV9(key: string, callback: AsyncCallback): void; + hasV9(key: string): Promise; /** * Sets an int value for the key in the {@link Preferences} object. @@ -135,6 +235,25 @@ declare namespace preferences { */ put(key: string, value: ValueType, callback: AsyncCallback): void; put(key: string, value: ValueType): Promise; + + /** + * Sets an int value for the key in the {@link Preferences} object. + * + *

You can call the {@link #flush} method to save the {@link Preferences} object to the + * file. + * + * @param key Indicates the key of the preferences to modify. It cannot be {@code null} or empty. + * @param value Indicates the value of the preferences. + * MAX_KEY_LENGTH. + * @throws BusinessError if invoked failed + * @since 9 + * @errorcode 15500001 + * @errorcode 15500006 + * @errorcode 15500007 + * @errorcode 15500015 + */ + putV9(key: string, value: ValueType, callback: AsyncCallback): void; + putV9(key: string, value: ValueType): Promise; /** * Deletes the preferences with a specified key from the {@link Preferences} object. @@ -149,6 +268,23 @@ declare namespace preferences { */ delete(key: string, callback: AsyncCallback): void; delete(key: string): Promise; + + /** + * Deletes the preferences with a specified key from the {@link Preferences} object. + * + *

You can call the {@link #flush} method to save the {@link Preferences} object to the + * file. + * + * @param key Indicates the key of the preferences to delete. It cannot be {@code null} or empty. + * MAX_KEY_LENGTH. + * @throws BusinessError if invoked failed + * @since 9 + * @errorcode 15500001 + * @errorcode 15500006 + * @errorcode 15500007 + */ + deleteV9(key: string, callback: AsyncCallback): void; + deleteV9(key: string): Promise; /** * Clears all preferences from the {@link Preferences} object. @@ -161,6 +297,19 @@ declare namespace preferences { */ clear(callback: AsyncCallback): void; clear(): Promise; + + /** + * Clears all preferences from the {@link Preferences} object. + * + *

You can call the {@link #flush} method to save the {@link Preferences} object to the + * file. + * + * @throws BusinessError if invoked failed + * @since 9 + * @errorcode 15500001 + */ + clearV9(callback: AsyncCallback): void; + clearV9(): Promise; /** * Asynchronously saves the {@link Preferences} object to the file. @@ -170,6 +319,16 @@ declare namespace preferences { */ flush(callback: AsyncCallback): void; flush(): Promise; + + /** + * Asynchronously saves the {@link Preferences} object to the file. + * + * @throws BusinessError if invoked failed + * @since 9 + * @errorcode 15500001 + */ + flushV9(callback: AsyncCallback): void; + flushV9(): Promise; /** * Registers an observer to listen for the change of a {@link Preferences} object. -- Gitee From f6290b58309cabdf53a20e286bbfbeb5a1345132 Mon Sep 17 00:00:00 2001 From: li_juntao Date: Fri, 16 Sep 2022 10:30:45 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0preference=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li_juntao --- api/@ohos.data.preferences.d.ts | 108 +++++++++++++++++++------------- 1 file changed, 64 insertions(+), 44 deletions(-) diff --git a/api/@ohos.data.preferences.d.ts b/api/@ohos.data.preferences.d.ts index 55ad50944e..7167c6429f 100644 --- a/api/@ohos.data.preferences.d.ts +++ b/api/@ohos.data.preferences.d.ts @@ -38,7 +38,7 @@ declare namespace preferences { */ function getPreferences(context: Context, name: string, callback: AsyncCallback): void; function getPreferences(context: Context, name: string): Promise; - + /** * Obtains a {@link Preferences} instance matching a specified preferences file name. * @@ -50,9 +50,9 @@ declare namespace preferences { * @return Returns the {@link Preferences} instance matching the specified preferences file name. * @throws {BusinessError} if invoked failed * @since 9 - * @errorcode 15500001 - * @errorcode 15500012 - * @errorcode 15500013 + * @errorcode 15500001 + * @errorcode 15500012 + * @errorcode 15500013 */ function getPreferencesV9(context: Context, name: string, callback: AsyncCallback): void; function getPreferencesV9(context: Context, name: string): Promise; @@ -73,8 +73,8 @@ declare namespace preferences { */ function deletePreferences(context: Context, name: string, callback: AsyncCallback): void; function deletePreferences(context: Context, name: string): Promise; - - /** + + /** * Deletes a {@link Preferences} instance matching a specified preferences file name * from the cache which is performed by removePreferencesFromCache and deletes the * preferences file. @@ -87,9 +87,9 @@ declare namespace preferences { * @param name Indicates the preferences file name. * @throws {BusinessError} if invoked failed * @since 9 - * @errorcode 15500001 - * @errorcode 15500012 - * @errorcode 15500013 + * @errorcode 15500001 + * @errorcode 15500012 + * @errorcode 15500013 */ function deletePreferencesV9(context: Context, name: string, callback: AsyncCallback): void; function deletePreferencesV9(context: Context, name: string): Promise; @@ -109,8 +109,8 @@ declare namespace preferences { */ function removePreferencesFromCache(context: Context, name: string, callback: AsyncCallback): void; function removePreferencesFromCache(context: Context, name: string): Promise; - - /** + + /** * Deletes a {@link Preferences} instance matching a specified preferences file name * from the cache. * @@ -122,9 +122,9 @@ declare namespace preferences { * @param name Indicates the preferences file name. * @throws {BusinessError} if invoked failed * @since 9 - * @errorcode 15500001 - * @errorcode 15500012 - * @errorcode 15500013 + * @errorcode 15500001 + * @errorcode 15500012 + * @errorcode 15500013 */ function removePreferencesFromCacheV9(context: Context, name: string, callback: AsyncCallback): void; function removePreferencesFromCacheV9(context: Context, name: string): Promise; @@ -155,8 +155,8 @@ declare namespace preferences { */ get(key: string, defValue: ValueType, callback: AsyncCallback): void; get(key: string, defValue: ValueType): Promise; - - /** + + /** * Obtains the value of a preferences in the int format. * *

If the value is {@code null} or not in the int format, the default value is returned. @@ -166,9 +166,9 @@ declare namespace preferences { * @return Returns the value matching the specified key if it is found; returns the default value otherwise. * @throws {BusinessError} if invoked failed * @since 9 - * @errorcode 15500001 - * @errorcode 15500006 - * @errorcode 15500007 + * @errorcode 15500001 + * @errorcode 15500006 + * @errorcode 15500007 */ getV9(key: string, defValue: ValueType, callback: AsyncCallback): void; getV9(key: string, defValue: ValueType): Promise; @@ -182,14 +182,14 @@ declare namespace preferences { */ getAll(callback: AsyncCallback): void; getAll(): Promise; - - /** + + /** * Obtains all the keys and values of a preferences in an object. * * @return Returns the values and keys in an object. * @throws {BusinessError} if invoked failed * @since 9 - * @errorcode 15500001 + * @errorcode 15500001 */ getAllV9(callback: AsyncCallback): void; getAllV9(): Promise; @@ -205,8 +205,8 @@ declare namespace preferences { */ has(key: string, callback: AsyncCallback): void; has(key: string): Promise; - - /** + + /** * Checks whether the {@link Preferences} object contains a preferences matching a specified key. * * @param key Indicates the key of the preferences to check for. @@ -214,9 +214,9 @@ declare namespace preferences { * returns {@code false} otherwise. * @throws BusinessError if invoked failed * @since 9 - * @errorcode 15500001 - * @errorcode 15500006 - * @errorcode 15500007 + * @errorcode 15500001 + * @errorcode 15500006 + * @errorcode 15500007 */ hasV9(key: string, callback: AsyncCallback): void; hasV9(key: string): Promise; @@ -235,8 +235,8 @@ declare namespace preferences { */ put(key: string, value: ValueType, callback: AsyncCallback): void; put(key: string, value: ValueType): Promise; - - /** + + /** * Sets an int value for the key in the {@link Preferences} object. * *

You can call the {@link #flush} method to save the {@link Preferences} object to the @@ -247,10 +247,10 @@ declare namespace preferences { * MAX_KEY_LENGTH. * @throws BusinessError if invoked failed * @since 9 - * @errorcode 15500001 - * @errorcode 15500006 - * @errorcode 15500007 - * @errorcode 15500015 + * @errorcode 15500001 + * @errorcode 15500006 + * @errorcode 15500007 + * @errorcode 15500015 */ putV9(key: string, value: ValueType, callback: AsyncCallback): void; putV9(key: string, value: ValueType): Promise; @@ -268,8 +268,8 @@ declare namespace preferences { */ delete(key: string, callback: AsyncCallback): void; delete(key: string): Promise; - - /** + + /** * Deletes the preferences with a specified key from the {@link Preferences} object. * *

You can call the {@link #flush} method to save the {@link Preferences} object to the @@ -279,9 +279,9 @@ declare namespace preferences { * MAX_KEY_LENGTH. * @throws BusinessError if invoked failed * @since 9 - * @errorcode 15500001 - * @errorcode 15500006 - * @errorcode 15500007 + * @errorcode 15500001 + * @errorcode 15500006 + * @errorcode 15500007 */ deleteV9(key: string, callback: AsyncCallback): void; deleteV9(key: string): Promise; @@ -297,8 +297,8 @@ declare namespace preferences { */ clear(callback: AsyncCallback): void; clear(): Promise; - - /** + + /** * Clears all preferences from the {@link Preferences} object. * *

You can call the {@link #flush} method to save the {@link Preferences} object to the @@ -306,7 +306,7 @@ declare namespace preferences { * * @throws BusinessError if invoked failed * @since 9 - * @errorcode 15500001 + * @errorcode 15500001 */ clearV9(callback: AsyncCallback): void; clearV9(): Promise; @@ -319,13 +319,13 @@ declare namespace preferences { */ flush(callback: AsyncCallback): void; flush(): Promise; - - /** + + /** * Asynchronously saves the {@link Preferences} object to the file. * * @throws BusinessError if invoked failed * @since 9 - * @errorcode 15500001 + * @errorcode 15500001 */ flushV9(callback: AsyncCallback): void; flushV9(): Promise; @@ -338,6 +338,16 @@ declare namespace preferences { * @since 9 */ on(type: 'change', callback: Callback<{ key: string }>): void; + + /** + * Registers an observer to listen for the change of a {@link Preferences} object. + * + * @param callback Indicates the callback when preferences changes. + * @throws {BusinessError} if invoked failed + * @since 9 + * @errorcode 15500001 + */ + onV9(type: 'change', callback: Callback<{ key: string }>): void; /** * Unregisters an existing observer. @@ -347,6 +357,16 @@ declare namespace preferences { * @since 9 */ off(type: 'change', callback?: Callback<{ key: string }>): void; + + /** + * Unregisters an existing observer. + * + * @param callback Indicates the registered callback. + * @throws BusinessError if invoked failed + * @since 9 + * @errorcode 15500001 + */ + offV9(type: 'change', callback?: Callback<{ key: string }>): void; } /** -- Gitee