• 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 type common from '@ohos.app.ability.common';
17import deviceInfo from '@ohos.deviceInfo';
18import settings from '@ohos.settings';
19import BaseModel from '../../../../../../../common/utils/src/main/ets/default/model/BaseModel';
20import ConfigData from '../../../../../../../common/utils/src/main/ets/default/baseUtil/ConfigData';
21import LogUtil from '../../../../../../../common/utils/src/main/ets/default/baseUtil/LogUtil';
22import { GlobalContext } from '../../../../../../../common/utils/src/main/ets/default/baseUtil/GlobalContext';
23import Log from '../../../../../../../common/utils/src/main/ets/default/baseUtil/LogDecorator';
24import CatchError from '../../../../../../../common/utils/src/main/ets/default/baseUtil/CatchError';
25
26/**
27 * about device service class
28 */
29export class AboutDeviceModel extends BaseModel {
30  private deviceInfo: BaseModel[] = [
31    {
32      settingAlias: "model",
33      settingTitle: "",
34      settingValue: ""
35    },
36    {
37      settingAlias: "companyInfo",
38      settingTitle: "",
39      settingValue: ""
40    },
41    {
42      settingAlias: "deviceId",
43      settingTitle: "",
44      settingValue: "00000000000000"
45    },
46    {
47      settingAlias: "softwareVersion",
48      settingTitle: "",
49      settingValue: ""
50    }
51  ]
52
53  constructor() {
54    super();
55  }
56
57  /**
58   * Get Uri
59   */
60  @Log
61  @CatchError(`dataability:///com.ohos.settingsdata.DataAbility/${ConfigData.SETTINGSDATA_DEVICE_NAME}`)
62  public getUri() {
63    return settings.getUriSync(ConfigData.SETTINGSDATA_BRIGHTNESS);
64  }
65
66  /**
67   * Get phone information
68   */
69  @Log
70  setOnAboutDeviceListener(): any {
71    LogUtil.info('settings setOnAboutDeviceListener in');
72    LogUtil.info('settings setOnAboutDeviceListener deviceInfo ' + JSON.stringify(deviceInfo));
73    return deviceInfo;
74  }
75
76  /**
77   * Read local file
78   */
79  @Log
80  public getAboutDeviceInfoListener(): any[] {
81    LogUtil.info('settings getAboutDeviceInfoListener come in');
82    return this.deviceInfo;
83  }
84
85  /**
86   * Get system name from SettingsData
87   */
88  @Log
89  @CatchError(ConfigData.DEVICE_NAME)
90  getSystemName() {
91    let context = GlobalContext.getContext().getObject(GlobalContext.globalKeySettingsAbilityContext) as common.Context;
92    let deviceName = settings.getValueSync(context, ConfigData.SETTINGSDATA_DEVICE_NAME, ConfigData.DEVICE_NAME);
93    return deviceName;
94  }
95
96  /**
97   * Set system name to SettingsData
98   */
99  @Log
100  @CatchError(undefined)
101  setSystemName(name: string) {
102    let context = GlobalContext.getContext().getObject(GlobalContext.globalKeySettingsAbilityContext) as common.Context;
103    try {
104      settings.setValueSync(context, ConfigData.SETTINGSDATA_DEVICE_NAME, name);
105    } catch(err) {
106      LogUtil.error(`setValueSync err, ${err.message}`);
107    };
108    return;
109  }
110}
111
112let aboutDeviceModel = new AboutDeviceModel();
113
114export default aboutDeviceModel as AboutDeviceModel
115;