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 return deviceInfo; 73 } 74 75 /** 76 * Read local file 77 */ 78 @Log 79 public getAboutDeviceInfoListener(): any[] { 80 LogUtil.info('settings getAboutDeviceInfoListener come in'); 81 return this.deviceInfo; 82 } 83 84 /** 85 * Get system name from SettingsData 86 */ 87 @Log 88 @CatchError(ConfigData.DEVICE_NAME) 89 getSystemName() { 90 let context = GlobalContext.getContext().getObject(GlobalContext.globalKeySettingsAbilityContext) as common.Context; 91 let deviceName = settings.getValueSync(context, ConfigData.SETTINGSDATA_DEVICE_NAME, ConfigData.DEVICE_NAME); 92 return deviceName; 93 } 94 95 /** 96 * Set system name to SettingsData 97 */ 98 @Log 99 @CatchError(undefined) 100 setSystemName(name: string) { 101 let context = GlobalContext.getContext().getObject(GlobalContext.globalKeySettingsAbilityContext) as common.Context; 102 try { 103 settings.setValueSync(context, ConfigData.SETTINGSDATA_DEVICE_NAME, name); 104 } catch(err) { 105 LogUtil.error(`setValueSync err, ${err.message}`); 106 }; 107 return; 108 } 109} 110 111let aboutDeviceModel = new AboutDeviceModel(); 112 113export default aboutDeviceModel as AboutDeviceModel 114;