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