1/** 2 * Copyright (c) 2021-2022 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 ConfigData from '../../../../../../../common/utils/src/main/ets/default/baseUtil/ConfigData'; 18import LogUtil from '../../../../../../../common/utils/src/main/ets/default/baseUtil/LogUtil'; 19import { GlobalContext } from '../../../../../../../common/utils/src/main/ets/default/baseUtil/GlobalContext'; 20import Log from '../../../../../../../common/utils/src/main/ets/default/baseUtil/LogDecorator'; 21import BaseModel from '../../../../../../../common/utils/src/main/ets/default/model/BaseModel'; 22import ResourceUtil from '../../../../../../../common/search/src/main/ets/default/common/ResourceUtil'; 23 24import wifi from '@ohos.wifi'; 25import prompt from '@system.prompt'; 26import Router from '@system.router'; 27 28/** 29 * app setting homepage service class 30 */ 31export class SettingListModel extends BaseModel { 32 private TAG = `${ConfigData.TAG} SettingListModel`; 33 34 /** 35 * Get settingsList 36 */ 37 @Log 38 getSettingList() { 39 // return this.settingsList; 40 } 41 42 /** 43 * Item on click 44 */ 45 @Log 46 onSettingItemClick(targetPage): void { 47 if (targetPage === 'mobileData') { 48 let context = GlobalContext.getContext().getObject(GlobalContext.globalKeySettingsAbilityContext) as common.UIAbilityContext; 49 context.startAbility({ 50 bundleName: ConfigData.MOBILE_DATA_BUNDLE_NAME, 51 abilityName: ConfigData.MOBILE_DATA_ABILITY_NAME, 52 }) 53 .then((data) => { 54 LogUtil.info(`${this.TAG}, ${ConfigData.MOBILE_DATA_BUNDLE_NAME} start successful. Data: ${JSON.stringify(data)}`); 55 }) 56 .catch((error) => { 57 ResourceUtil.getString($r("app.string.mobileDataFailed")).then(value => { 58 prompt.showToast({ 59 message: value, 60 duration: 2000, 61 }); 62 LogUtil.error(`${this.TAG}, ${ConfigData.MOBILE_DATA_BUNDLE_NAME} start failed. Cause: ${JSON.stringify(error)}`); 63 }) 64 }) 65 } else if (targetPage === 'security') { 66 let context = GlobalContext.getContext().getObject(GlobalContext.globalKeySettingsAbilityContext) as common.UIAbilityContext; 67 context.startAbility({ 68 bundleName: ConfigData.SECURITY_BUNDLE_NAME, 69 abilityName: ConfigData.SECURITY_ABILITY_NAME, 70 }) 71 .then((data) => { 72 LogUtil.info(`${this.TAG}, ${ConfigData.SECURITY_BUNDLE_NAME} start successful. Data: ${JSON.stringify(data)}`); 73 }) 74 .catch((error) => { 75 ResourceUtil.getString($r("app.string.securityFailed")).then(value => { 76 prompt.showToast({ 77 message: value, 78 duration: 2000, 79 }); 80 LogUtil.error(`${this.TAG}, ${ConfigData.SECURITY_BUNDLE_NAME} start failed. Cause: ${JSON.stringify(error)}`); 81 }) 82 }) 83 } else { 84 Router.push({ 85 uri: targetPage, 86 }); 87 } 88 } 89 90 /** 91 * Register Observer 92 */ 93 @Log 94 registerObserver() { 95 wifi.on('wifiStateChange', (code) => { 96 AppStorage.SetOrCreate('wifiStatus', wifi.isWifiActive()); 97 }) 98 } 99} 100 101let settingListModel = new SettingListModel(); 102 103export default settingListModel as SettingListModel; 104