• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022-2023 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 Logger from '../model/Logger'
17import sim from '@ohos.telephony.sim'
18import radio from '@ohos.telephony.radio'
19
20const TAG = '[RadioStatus]'
21
22export class RadioStatus {
23    constructor() {
24    }
25
26    async getSimSpn(slotId: number) {
27        const simSpn = await sim.getSimSpn(slotId)
28        Logger.info(`${TAG}, getSimSpn radioTech = ${simSpn}`)
29        return simSpn
30    }
31
32    async getRadioTech(slotId: number) {
33        const radioTech = await radio.getRadioTech(slotId)
34        Logger.info(`${TAG}, getRadioTech radioTech = ${JSON.stringify(radioTech)}`)
35        return radioTech
36    }
37
38    async getSignalInformation(slotId: number) {
39        const signalInformation = await radio.getSignalInformation(slotId)
40        Logger.info(`${TAG}, getSignalInformation signalInformation = ${JSON.stringify(signalInformation)}`)
41        if (signalInformation.length === 0) {
42            return 'not available'
43        } else {
44            return signalInformation
45        }
46    }
47
48    async getNetworkSelectionMode(slotId: number) {
49        Logger.info(`${TAG}, getNetworkSelectionMode networkSelectionMode start`)
50        const networkSelectionMode = await radio.getNetworkSelectionMode(slotId)
51        Logger.info(`${TAG}, getNetworkSelectionMode networkSelectionMode = ${networkSelectionMode}`)
52        return networkSelectionMode
53    }
54
55    async getISOCountryCodeForNetwork(slotId: number) {
56        const iSOCountryCode = await radio.getISOCountryCodeForNetwork(slotId)
57        Logger.info(`${TAG}, getISOCountryCodeForNetwork iSOCountryCode = ${iSOCountryCode}`)
58        if (typeof (iSOCountryCode) === `undefined`) {
59            return 'not available'
60        } else {
61            return iSOCountryCode
62        }
63    }
64
65    async getNetworkState() {
66        const data = await radio.getNetworkState()
67        Logger.info(`${TAG}, getNetworkState data = ${JSON.stringify(data)}`)
68        if (typeof (JSON.stringify(data)) === `undefined`) {
69            return 'not available'
70        } else {
71            const networkState: string = `longOperatorName:${JSON.stringify(data.longOperatorName)}\n` +
72            `shortOperatorName:${JSON.stringify(data.shortOperatorName)}\n` +
73            `plmnNumeric:${JSON.stringify(data.plmnNumeric)}\n` +
74            `isRoaming:${JSON.stringify(data.isRoaming)}\n` +
75            `regState:${JSON.stringify(data.regState)}\n` +
76            `nsaState:${JSON.stringify(data.nsaState)}\n` +
77            `isCaActive:${JSON.stringify(data.isCaActive)}\n` +
78            `isEmergency:${JSON.stringify(data.isEmergency)}\n`
79            Logger.info(`${TAG}, getNetworkState networkState = ${JSON.stringify(networkState)}`)
80            return networkState
81        }
82    }
83
84    async getRadioOn() {
85        Logger.info(`${TAG}, getRadioOn radioOn start`)
86        const radioOn = await radio.isRadioOn()
87        Logger.info(`${TAG}, getRadioOn radioOn = ${radioOn}`)
88        return JSON.stringify(radioOn)
89    }
90}