• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * Copyright (c) 2021 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
16import ConfigData from './ConfigData';
17import LogUtil from './LogUtil'
18//import Storage from '@ohos.data.storage';
19
20//let preference = Storage.getStorageSync(ConfigData.PREFERENCES_PATH);
21this.storage = await dataStorage.getPreferences(globalThis.settingsAbilityContext, ConfigData.PREFERENCES_PATH)
22
23export class PreferenceUtil {
24  /**
25   * Set up storage data
26   *
27   * @param key - key
28   * @param value - value
29   */
30  setStorageValue(key,value): void {
31    LogUtil.info(`Set preference, key: ${key}, value: ${value}")`);
32    preference.putSync(key, value);
33    preference.flushSync();
34  }
35
36  /**
37   * Get stored data
38   *
39   * @param key - key
40   * @param defaultValue - defaultValue
41   */
42  getStorageValue(key: string, defaultValue) {
43    let value = preference.getSync(key, defaultValue);
44    LogUtil.info(`Get storage value, key: ${key}, value: ${value}`);
45    return value;
46  }
47}
48
49let preferenceUtil = new PreferenceUtil();
50export default preferenceUtil as PreferenceUtil