• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * Copyright (c) 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
16/**
17 * @file: Mobile Network Home page
18 */
19import publiccontent from '../common/components/publiccontent';
20import item from '../common/components/listItem/listItem';
21import call from '@ohos.telephony.call';
22import { registerSimStateChange, getMaxSimCount } from '../model/registerSimStateApi';
23import { getSimStateCardOne, getSimStateCardTwo } from '../common/model/getSimStateApi';
24import { getSimCardOnePhoneNumber, getSimCardTwoPhoneNumber } from '../common/model/getSimTelephoneNumberApi';
25import {
26  isCellularDataRoamingEnabledCardOne,
27  isCellularDataRoamingEnabledCardTwo,
28  enableCellularDataRoaming,
29  disableCellularDataRoaming,
30  getSupportNetwork
31} from '../common/model/getCellularDataRoamingEnabledApi';
32import { setPreferredNetwork } from '../common/model/setPreferredNetworkApi';
33import { getPreferredNetwork } from '../common/model/getPreferredNetworkModeApi';
34import {
35  isCellularDataEnabled,
36  enableCellularData,
37  disableCellularData,
38  getOperatorName
39} from '../model/mobileDataStatus';
40import HeadComponent from '../common/components/headComponent';
41import { SubHeader } from '../common/components/subHeader';
42import LogUtils from '../common/utils/LogUtils';
43
44const TAG = "Index";
45
46@Entry
47@Component
48struct Index {
49  scroller: Scroller = new Scroller();
50  @State byValueWLMS: any = publiccontent.strings.fourAuto;
51  @State publicheader: any = publiccontent.strings.mobileData;
52  @State isLoading: boolean = true;
53  @State simState: string = '';
54  @State moisBtn: boolean = true;
55  @State isBtn: boolean = true;
56  @State gqBtn: boolean = true;
57  @State moislastone: boolean = true;
58  @State isSupport: boolean = true;
59  @State mobileDataDisabled: boolean = false;
60  @State mobileDataDisabled2: boolean = false;
61  // Mobile data switch
62  @State isDataEnable: boolean = true;
63  // Data roaming switch
64  @State dataRoamSwitchCardOne: boolean = false;
65  @State dataRoamSwitchCardTwo: boolean = false;
66  // HD call switch
67  @State volteSwitch: boolean = false;
68  // Card I status
69  @State simStateStatusCardOne: boolean = true;
70  // Card 2 status
71  @State simStateStatusCardTwo: boolean = false;
72  @State ControlswitchWLMS: boolean = false;
73  @State slotId: number = 0;
74  @State dialogTitle: any = publiccontent.strings.preferredNetworkMode;
75  setCache_cun_name = 'DISTRIBUTEDDATA_CUN_NAME';
76  setCache_wl_name = 'SETCACHE_WL_NAME';
77  @State enable5g: boolean = false;
78  @StorageLink("imsOne")enableISM: boolean = false;
79  @State enableISM2: boolean = false;
80  @State TelephoneNumber: string = '';
81  @State TelephoneNumber2?: string = '';
82  @State ceshi: boolean = false;
83  @State cardOne: number = 0;
84  @State cardTwo: number = 1;
85
86  /**
87   * Get network mode
88   *
89   * @param {Object} slotId - call slotId
90   */
91  async getPreferredNetwork(slotId) {
92    const res = await getPreferredNetwork(this.slotId);
93    if (res == 0) {
94      this.byValueWLMS = $r('app.string.mobile_data_5g');
95    } else if (res == 5) {
96      this.byValueWLMS = $r("app.string.mobile_data_4g");
97    } else if (res == 6) {
98      this.byValueWLMS = $r("app.string.mobile_data_3g");
99    } else if (res == 1) {
100      this.byValueWLMS = $r("app.string.mobile_data_2g");
101    }
102  }
103
104  /**
105   * This interface is used to obtain sim cardOne status
106   */
107  getSimStateDataCardOne() {
108    getSimStateCardOne().then((res: any) => {
109      LogUtils.i(TAG, "getSimStateData Card1 :success " + JSON.stringify(res))
110      const simState = {
111        SIM_STATE_UNKNOWN: 0,
112        SIM_STATE_NOT_PRESENT: 1,
113        SIM_STATE_LOCKED: 2,
114        SIM_STATE_NOT_READY: 3,
115        SIM_STATE_READY: 4,
116        SIM_STATE_LOADED: 5
117      };
118      this.simState = res;
119      if (res == simState.SIM_STATE_LOADED || res == simState.SIM_STATE_READY) {
120        this.simStateStatusCardOne = true;
121      } else {
122        this.simStateStatusCardOne = false;
123      }
124    }).catch((err) => {
125      this.simStateStatusCardOne = false;
126      LogUtils.i(TAG, 'getSimStateData Card1 :console.error() ' + JSON.stringify(err.message));
127    });
128  }
129
130  /**
131   * This interface is used to obtain sim cardTwo status
132   */
133  getSimStateDataCardTwo() {
134    getSimStateCardTwo().then((res: any) => {
135      LogUtils.i(TAG, "getSimState Card2 :success then" + JSON.stringify(res));
136      const simState = {
137        SIM_STATE_UNKNOWN: 0,
138        SIM_STATE_NOT_PRESENT: 1,
139        SIM_STATE_LOCKED: 2,
140        SIM_STATE_NOT_READY: 3,
141        SIM_STATE_READY: 4,
142        SIM_STATE_LOADED: 5
143      };
144      if (res == simState.SIM_STATE_LOADED || res == simState.SIM_STATE_READY) {
145        this.simStateStatusCardTwo = true;
146      } else {
147        this.simStateStatusCardTwo = false;
148      }
149    }).catch((err) => {
150      this.simStateStatusCardTwo = false;
151      LogUtils.i(TAG, 'getSimState Card2 :console.error() ' + JSON.stringify(err.message));
152    });
153  }
154
155  getSupportNetwork(slotId) {
156    getSupportNetwork(slotId).then((res) => {
157      if (res) {
158        this.isSupport = true;
159      } else {
160        this.isSupport = false;
161      }
162    }).catch((err) => {
163    });
164  }
165
166  /**
167   * Get mobile phone number
168   */
169  getSimCardOnePhoneNumber() {
170    getSimCardOnePhoneNumber().then((res) => {
171      LogUtils.i(TAG, "getSimTelephoneNumber card1 other success" + JSON.stringify(res));
172      this.TelephoneNumber = res;
173    }).catch((err) => {
174      LogUtils.i(TAG, "getSimTelephoneNumber card1 other catch" + JSON.stringify(err));
175    });
176  }
177
178  /**
179   * Get mobile phone number
180   */
181  getSimCardTwoPhoneNumber() {
182    getSimCardTwoPhoneNumber().then((res) => {
183      LogUtils.i(TAG, "getSimTelephoneNumber card2 other success" + JSON.stringify(res));
184      this.TelephoneNumber2 = res;
185    }).catch((err) => {
186      LogUtils.i(TAG, "getSimTelephoneNumber card2 other catch" + JSON.stringify(err));
187    });
188  }
189
190  /**
191   * Get mobile data on or off
192   */
193  getCellularDataState() {
194    isCellularDataEnabled().then((data) => {
195      LogUtils.i(TAG, "isCellularDataEnabled success: isON:" + JSON.stringify(data));
196      this.isDataEnable = data;
197    }).catch((error) => {
198      LogUtils.i(TAG, "isCellularDataEnabled error catch" + JSON.stringify(error));
199    });
200  }
201
202  addRegisterSimStateChange(slotId) {
203    registerSimStateChange(slotId, async () => {
204      this.getCellularDataRoamingEnabled();
205      this.getSimStateDataCardOne();
206      this.getSimStateDataCardTwo();
207      this.getPreferredNetwork(slotId);
208      this.getSupportNetwork(slotId);
209      this.getSimCardOnePhoneNumber();
210      this.getSimCardTwoPhoneNumber();
211      this.getCellularDataState();
212      this.isImsSwitchEnabled(0);
213      if (getMaxSimCount() === 2) {
214        this.isImsSwitchEnabled(1);
215      }
216    })
217  }
218
219  isImsSwitchEnabled(slotId) {
220    call.isImsSwitchEnabled(slotId).then((res: any) => {
221      if (slotId) {
222        this.enableISM2 = res;
223        LogUtils.i(TAG, "isImsSwitchEnable enable 1:" + JSON.stringify(this.enableISM2));
224      } else {
225        this.enableISM = res;
226        LogUtils.i(TAG, "isImsSwitchEnable enable 0:" + JSON.stringify(this.enableISM));
227      }
228    });
229  }
230
231  aboutToAppear() {
232    LogUtils.i(TAG, "aboutToAppear")
233    if (getMaxSimCount() === 2) {
234      this.addRegisterSimStateChange(1);
235      this.isImsSwitchEnabled(1);
236      this.getSimStateDataCardTwo();
237    }
238    this.addRegisterSimStateChange(0);
239    //Get data roaming status
240    this.getCellularDataRoamingEnabled();
241    //Get HD call status
242    this.isImsSwitchEnabled(0);
243    this.getSimStateDataCardOne();
244    //Get network mode
245    this.getPreferredNetwork(this.slotId);
246    getOperatorName().then((res) => {
247    })
248    this.getSupportNetwork(this.slotId);
249    //card number acquire
250    this.getSimCardOnePhoneNumber();
251    this.getSimCardTwoPhoneNumber();
252    this.getCellularDataState();
253  }
254
255  onPageShow() {
256    this.isImsSwitchEnabled(0);
257  }
258
259  /**
260   * Set network mode
261   */
262  radioChange(slotId, v) {
263    const res = setPreferredNetwork(slotId, v);
264    LogUtils.i(TAG, "radioChange res:" + JSON.stringify(res));
265  }
266
267  getCellularDataRoamingEnabled() {
268    isCellularDataRoamingEnabledCardOne().then((res) => {
269      LogUtils.i(TAG,"getCellularDataRoamingEnabled card one success then:" + JSON.stringify(res));
270      this.dataRoamSwitchCardOne = res;
271    }).catch((err) => {
272      this.dataRoamSwitchCardOne = false;
273      LogUtils.i(TAG, "enableCellularDataRoaming card one catch:" + JSON.stringify(err));
274    });
275    if (getMaxSimCount() === 2) {
276      isCellularDataRoamingEnabledCardTwo().then((res) => {
277        LogUtils.i(TAG,"getCellularDataRoamingEnabled card two success then:" + JSON.stringify(res));
278        this.dataRoamSwitchCardTwo = res;
279      }).catch((err) => {
280        this.dataRoamSwitchCardTwo = false;
281        LogUtils.i(TAG, "enableCellularDataRoaming card two catch:" + JSON.stringify(err));
282      });
283    }
284  }
285
286  build() {
287    GridRow({ columns: { sm: 4, md: 8, lg: 12 }, gutter: { x: 12 } }) {
288      GridCol({ span: { sm: 4, md: 8, lg: 8 }, offset: { sm: 0, md: 1, lg: 2 } }) {
289        Column() {
290          Column() {
291
292            HeadComponent();
293
294            Stack({ alignContent: Alignment.TopStart }) {
295              Scroll(this.scroller) {
296                Column() {
297                  SubHeader({ titleContent: $r('app.string.mobile_data_general'), subTitleContent: '' });
298
299                  Flex({
300                    direction: FlexDirection.Row,
301                    justifyContent: FlexAlign.SpaceBetween,
302                    alignItems: ItemAlign.Center
303                  }) {
304                    Column() {
305                      Row() {
306                        Text($r('app.string.mobile_data'))
307                          .fontSize(16)
308                          .fontWeight(FontWeight.Medium)
309                          .fontFamily('HarmonyHeiTi')
310                          .lineHeight(22)
311                          .fontColor($r('app.color.font_color_182431'))
312                          .opacity(this.isDataEnable ? 0.9 : 0.6)
313                      }
314
315                      Row() {
316                        Text($r('app.string.mobile_data_charges'))
317                          .fontSize(14)
318                          .fontWeight(FontWeight.Regular)
319                          .fontFamily('HarmonyHeiTi')
320                          .fontColor('#555')
321                          .opacity(0.6)
322                          .lineHeight(19)
323                          .maxLines(2)
324                      }
325                      .margin({ top: 2, right: 26 })
326                    }
327                    .alignItems(HorizontalAlign.Start)
328
329                    Toggle({ type: ToggleType.Switch, isOn: this.isDataEnable })
330                      .width(36)
331                      .height(20)
332                      .enabled(this.simStateStatusCardOne || this.simStateStatusCardTwo)
333                      .onChange((isOn: boolean) => {
334                        this.isDataEnable = !this.isDataEnable;
335                        LogUtils.i(TAG, "mobile data switch changes enable:" + JSON.stringify(this.isDataEnable));
336                        if (this.isDataEnable == false) {
337                          disableCellularData().then((data) => {
338                            LogUtils.i(TAG, "disableCellularData: success then" + JSON.stringify(data));
339                          }).catch((error) => {
340                            LogUtils.i(TAG, "disableCellularData: error catch" + JSON.stringify(error));
341                          });
342                        } else {
343                          enableCellularData().then((data) => {
344                            LogUtils.i(TAG, "enableCellularData: success then" + JSON.stringify(data));
345                          }).catch((error) => {
346                            LogUtils.i(TAG, "enableCellularData: error catch" + JSON.stringify(error));
347                          });
348                        }
349                      })
350                  }
351                  .padding({
352                    left: 12,
353                    right: 12,
354                    top: 4,
355                    bottom: 4
356                  })
357                  .height(90)
358                  .width("100%")
359                  .borderRadius(24)
360                  .backgroundColor($r("sys.color.ohos_id_color_foreground_contrary"))
361                  .opacity((this.simStateStatusCardOne || this.simStateStatusCardTwo) ? 1 : 0.4)
362
363                  SubHeader({
364                    titleContent: $r('app.string.mobile_data_card1'),
365                    subTitleContent: this.TelephoneNumber
366                  });
367
368                  Column() {
369                    item({
370                      isBtn: this.moisBtn,
371                      cardType: this.cardOne,
372                      controlSwitch: $dataRoamSwitchCardOne,
373                      title: $r('app.string.mobile_data_dataRoaming'),
374                      describe: $r('app.string.mobile_data_enableDataWhileRoaming'),
375                      isDisabled: this.simStateStatusCardOne,
376                      isCard: true,
377                      isSupport: false,
378                      isCon: 0,
379                    })
380
381                    Divider()
382                      .strokeWidth(0.5)
383                      .color("#E3E3E3")
384                      .lineCap(LineCapStyle.Round)
385                      .margin({ right: '2%' })
386
387                    item({
388                      isBtn: this.gqBtn,
389                      cardType: this.cardOne,
390                      controlSwitch: $enableISM,
391                      title: $r('app.string.mobile_data_volte'),
392                      describe: $r('app.string.mobile_data_confirmation_function'),
393                      isDisabled: this.simStateStatusCardOne,
394                      isSupport: false,
395                      isCard: true,
396                      isCon: 22,
397                    })
398                  }
399                  .padding({
400                    left: 12,
401                    right: 12,
402                    top: 4,
403                    bottom: 4
404                  })
405                  .width("100%")
406                  .borderRadius(24)
407                  .backgroundColor($r("sys.color.ohos_id_color_foreground_contrary"))
408                  .opacity(this.simStateStatusCardOne ? 1 : 0.4)
409
410                  SubHeader({
411                    titleContent: $r('app.string.mobile_data_card2'),
412                    subTitleContent: this.TelephoneNumber2
413                  })
414                  .visibility(getMaxSimCount() === 2 ? Visibility.Visible : Visibility.Hidden)
415
416                  Column() {
417                    item({
418                      isBtn: this.moisBtn,
419                      cardType: this.cardTwo,
420                      controlSwitch: $mobileDataDisabled2,
421                      title: $r('app.string.mobile_data_dataRoaming'),
422                      describe: $r('app.string.mobile_data_enableDataWhileRoaming'),
423                      isDisabled: this.simStateStatusCardTwo,
424                      isSupport: false,
425                      isCard: true,
426                      isCon: 0,
427                    })
428                    Divider()
429                      .strokeWidth(0.5)
430                      .color("#E3E3E3")
431                      .lineCap(LineCapStyle.Round)
432                      .margin({ right: '2%' })
433                    item({
434                      isBtn: this.gqBtn,
435                      cardType: this.cardTwo,
436                      controlSwitch: $enableISM2,
437                      title: $r('app.string.mobile_data_volte'),
438                      describe: $r('app.string.mobile_data_confirmation_function'),
439                      isDisabled: this.simStateStatusCardTwo,
440                      isSupport: false,
441                      isCard: true,
442                      isCon: 22,
443                    })
444                  }
445                  .padding({
446                    left: 12,
447                    right: 12,
448                    top: 4,
449                    bottom: 4
450                  })
451                  .padding({
452                    left: 12,
453                    right: 12,
454                    top: 4,
455                    bottom: 4
456                  })
457                  .width("100%")
458                  .borderRadius(24)
459                  .backgroundColor($r("sys.color.ohos_id_color_foreground_contrary"))
460                  .opacity(this.simStateStatusCardTwo ? 1 : 0.4)
461                  .visibility(getMaxSimCount() === 2 ? Visibility.Visible : Visibility.Hidden)
462                }
463                .alignItems(HorizontalAlign.Start)
464              }
465            }
466          }
467          .useSizeType({
468            sm: { span: 4, offset: 0 },
469            md: { span: 6, offset: 1 },
470            lg: { span: 8, offset: 2 }
471          })
472        }
473        .visibility(this.isLoading ? Visibility.Visible : Visibility.Hidden)
474      }
475    }
476    .padding({ left: 12, right: 12 })
477    .width('100%')
478    .height('100%')
479    .backgroundColor($r("sys.color.ohos_id_color_sub_background"))
480  }
481}