mirror of
https://github.com/openharmony/applications_systemui.git
synced 2026-07-15 07:29:05 -04:00
@@ -14,13 +14,24 @@
|
||||
*/
|
||||
|
||||
export default class Constants {
|
||||
static readonly NETWORK_TYPE_UNKNOWN = 0;
|
||||
static readonly NETWORK_TYPE_GSM = 1;
|
||||
static readonly NETWORK_TYPE_CDMA = 2;
|
||||
static readonly NETWORK_TYPE_W_CDMA = 3;
|
||||
static readonly NETWORK_TYPE_TDS_CDMA = 4;
|
||||
static readonly NETWORK_TYPE_LTE = 5;
|
||||
static readonly NETWORK_TYPE_NR = 6;
|
||||
static readonly RADIO_TECHNOLOGY_UNKNOWN = 0;
|
||||
static readonly RADIO_TECHNOLOGY_GSM = 1;
|
||||
static readonly RADIO_TECHNOLOGY_1XRTT = 2;
|
||||
static readonly RADIO_TECHNOLOGY_WCDMA = 3;
|
||||
static readonly RADIO_TECHNOLOGY_HSPA = 4;
|
||||
static readonly RADIO_TECHNOLOGY_HSPAP = 5;
|
||||
static readonly RADIO_TECHNOLOGY_TD_SCDMA = 6;
|
||||
static readonly RADIO_TECHNOLOGY_EVDO = 7;
|
||||
static readonly RADIO_TECHNOLOGY_EHRPD = 8;
|
||||
static readonly RADIO_TECHNOLOGY_LTE = 9;
|
||||
static readonly RADIO_TECHNOLOGY_LTE_CA = 10;
|
||||
static readonly RADIO_TECHNOLOGY_IWLAN = 11;
|
||||
static readonly RADIO_TECHNOLOGY_NR = 12;
|
||||
|
||||
static readonly REG_STATE_NO_SERVICE = 0;
|
||||
static readonly REG_STATE_IN_SERVICE = 1;
|
||||
static readonly REG_STATE_EMERGENCY_CALL_ONLY = 2;
|
||||
static readonly REG_STATE_POWER_OFF = 3;
|
||||
|
||||
static readonly CELLULAR_SIGNAL_NO = 0;
|
||||
static readonly CELLULAR_SIGNAL_MIN = 1;
|
||||
@@ -31,4 +42,7 @@ export default class Constants {
|
||||
static readonly CELLULAR_NO_SIM_CARD = -1;
|
||||
|
||||
static readonly NET_NULL = 'NULL';
|
||||
|
||||
// Events for Subscribing to Notifications
|
||||
static readonly COMMON_EVENT_SPN_INFO_CHANGED = "usual.event.SPN_INFO_CHANGED";
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ const TAG = 'SignalComponent-SignalIcon'
|
||||
@Component
|
||||
export default struct SignalIcon {
|
||||
@StorageLink('cellularLevel') cellularLevel: number = Constants.CELLULAR_NO_SIM_CARD
|
||||
@StorageLink('cellularType') cellularType: number = Constants.NETWORK_TYPE_UNKNOWN
|
||||
@StorageLink('cellularType') cellularType: number = Constants.RADIO_TECHNOLOGY_UNKNOWN
|
||||
@StorageLink('networkState') networkState: string = Constants.NET_NULL
|
||||
@StorageLink('signalObserved') signalObserved: boolean = false
|
||||
@State mTintContentInfo: TintContentInfo = ViewModel.getTintContentInfo()
|
||||
@@ -62,7 +62,7 @@ export default struct SignalIcon {
|
||||
|
||||
Stack({ alignContent: Alignment.TopStart }) {
|
||||
Text(this.updateCellularType(this.cellularType))
|
||||
.fontSize(this.cellularType == Constants.NETWORK_TYPE_UNKNOWN ? this.style.statusBarSignalUnknownFontSize : this.style.statusBarSignalTypeFontSize)
|
||||
.fontSize(this.cellularType == Constants.RADIO_TECHNOLOGY_UNKNOWN ? this.style.statusBarSignalUnknownFontSize : this.style.statusBarSignalTypeFontSize)
|
||||
.fontColor(this.mTintContentInfo.contentColor)
|
||||
.width(this.style.netSignalTextMaxWidth)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
@@ -92,24 +92,32 @@ export default struct SignalIcon {
|
||||
Log.showInfo(TAG, `updateCellularType, signalType: ${signalType}`);
|
||||
let typeString;
|
||||
switch (signalType) {
|
||||
case Constants.NETWORK_TYPE_UNKNOWN:
|
||||
case Constants.RADIO_TECHNOLOGY_UNKNOWN:
|
||||
typeString = $r('app.string.signal_null');
|
||||
break;
|
||||
case Constants.NETWORK_TYPE_GSM:
|
||||
case Constants.NETWORK_TYPE_CDMA:
|
||||
case Constants.RADIO_TECHNOLOGY_GSM:
|
||||
case Constants.RADIO_TECHNOLOGY_1XRTT:
|
||||
typeString = $r('app.string.2G');
|
||||
break;
|
||||
case Constants.NETWORK_TYPE_W_CDMA:
|
||||
case Constants.NETWORK_TYPE_TDS_CDMA:
|
||||
case Constants.RADIO_TECHNOLOGY_WCDMA:
|
||||
case Constants.RADIO_TECHNOLOGY_HSPA:
|
||||
case Constants.RADIO_TECHNOLOGY_HSPAP:
|
||||
case Constants.RADIO_TECHNOLOGY_TD_SCDMA:
|
||||
case Constants.RADIO_TECHNOLOGY_EVDO:
|
||||
case Constants.RADIO_TECHNOLOGY_EHRPD:
|
||||
typeString = $r('app.string.3G');
|
||||
break;
|
||||
case Constants.NETWORK_TYPE_LTE:
|
||||
case Constants.RADIO_TECHNOLOGY_LTE:
|
||||
case Constants.RADIO_TECHNOLOGY_LTE_CA:
|
||||
case Constants.RADIO_TECHNOLOGY_IWLAN:
|
||||
typeString = $r('app.string.4G');
|
||||
break;
|
||||
case Constants.NETWORK_TYPE_NR:
|
||||
default:
|
||||
case Constants.RADIO_TECHNOLOGY_NR:
|
||||
typeString = $r('app.string.5G');
|
||||
break;
|
||||
default:
|
||||
typeString = $r('app.string.signal_null');
|
||||
break;
|
||||
}
|
||||
return typeString;
|
||||
}
|
||||
|
||||
@@ -13,37 +13,64 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import commonEvent from "@ohos.commonEvent";
|
||||
import Radio from '@ohos.telephony.radio';
|
||||
import Sim from '@ohos.telephony.sim'
|
||||
import Sim from '@ohos.telephony.sim';
|
||||
import Observer from '@ohos.telephony.observer';
|
||||
import Log from "../../../../../../common/src/main/ets/default/Log";
|
||||
import CheckEmpty from '../../../../../../common/src/main/ets/default/CheckEmptyUtils';
|
||||
import Constants from './common/constants'
|
||||
import Constants from './common/constants';
|
||||
|
||||
const TAG = 'SignalStatus-SignalModel';
|
||||
const EMPTY_LEVEL = 0;
|
||||
|
||||
let mSignalCallback;
|
||||
let signalValue = {
|
||||
cellularLevel: '',
|
||||
cellularType: '',
|
||||
networkState: ''
|
||||
};
|
||||
let isInitObserver = false
|
||||
let isInitObserver = false;
|
||||
let commonEventData = null;
|
||||
|
||||
var mLevelLink;
|
||||
var mTypeLink;
|
||||
var mStateLink;
|
||||
|
||||
export class SignalModel {
|
||||
constructor() {
|
||||
mLevelLink = AppStorage.SetAndLink("cellularLevel", Constants.CELLULAR_NO_SIM_CARD);
|
||||
mTypeLink = AppStorage.SetAndLink("cellularType", Constants.RADIO_TECHNOLOGY_UNKNOWN);
|
||||
mStateLink = AppStorage.SetAndLink("networkState", Constants.NET_NULL);
|
||||
this.addSubscriberListener();
|
||||
}
|
||||
|
||||
initSignalModel() {
|
||||
Log.showInfo(TAG, 'initSignalModel');
|
||||
mLevelLink = AppStorage.SetAndLink("cellularLevel", Constants.CELLULAR_NO_SIM_CARD);
|
||||
mTypeLink = AppStorage.SetAndLink("cellularType", Constants.NETWORK_TYPE_UNKNOWN);
|
||||
mStateLink = AppStorage.SetAndLink("networkState", Constants.NET_NULL);
|
||||
this.checkCellularStatus();
|
||||
}
|
||||
|
||||
/**
|
||||
* add mms app subscriber
|
||||
*/
|
||||
async addSubscriberListener() {
|
||||
let events = [Constants.COMMON_EVENT_SPN_INFO_CHANGED];
|
||||
let commonEventSubscribeInfo = {
|
||||
events: events
|
||||
};
|
||||
commonEvent.createSubscriber(commonEventSubscribeInfo, this.createSubscriberCallBack.bind(this));
|
||||
}
|
||||
|
||||
createSubscriberCallBack(err, data) {
|
||||
commonEventData = data;
|
||||
commonEvent.subscribe(commonEventData, this.subscriberCallBack.bind(this));
|
||||
}
|
||||
|
||||
subscriberCallBack(err, data) {
|
||||
Log.showInfo(TAG, `subscriberCallBack, err: ${JSON.stringify(err.message)}, event: ${data.event}`);
|
||||
if (data.event === Constants.COMMON_EVENT_SPN_INFO_CHANGED) {
|
||||
Log.showInfo(TAG, `receive stateLink: ${data?.parameters?.CUR_PLMN}`);
|
||||
if (data?.parameters?.CUR_PLMN) {
|
||||
mStateLink.set(data.parameters.CUR_PLMN);
|
||||
} else {
|
||||
Log.showError(TAG, `get stateLink failed.`);
|
||||
mStateLink.set(Constants.NET_NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uninitSignalModel() {
|
||||
Log.showInfo(TAG, 'uninitSignalModel');
|
||||
this.unInitObserver();
|
||||
@@ -53,66 +80,42 @@ export class SignalModel {
|
||||
* Check the connection type and signal level of cellular network
|
||||
*/
|
||||
checkCellularStatus() {
|
||||
let cellularStatus;
|
||||
let slotId = 0;
|
||||
|
||||
Sim.hasSimCard(slotId, (err, value) => {
|
||||
if (value === true) {
|
||||
//The interface of getting the cellular signal status is unavailable temporarily
|
||||
Radio.getSignalInformation(slotId, (err, value) => {
|
||||
if (err) {
|
||||
// Failed to call the interface,error is not null
|
||||
Log.showError(TAG, `failed to getSimState because ${err.message}`);
|
||||
// When failed to call the interface, set the result as no signal
|
||||
Radio.getNetworkState((err, value) => {
|
||||
if (err || !value) {
|
||||
Log.showError(TAG, `failed to getnetworkState because ${err.message}`);
|
||||
mTypeLink.set(Constants.RADIO_TECHNOLOGY_UNKNOWN);
|
||||
mLevelLink.set(Constants.CELLULAR_NO_SIM_CARD);
|
||||
mTypeLink.set(Constants.NETWORK_TYPE_UNKNOWN);
|
||||
} else {
|
||||
// Call interface succeed,error is null
|
||||
Log.showInfo(TAG, `success to getSignalInformation: ${JSON.stringify(value)}`);
|
||||
// Since the value might be empty, set it as no signal by hand
|
||||
if (!value || !value.length) {
|
||||
Log.showError(TAG, 'value from api is empty, set 0');
|
||||
Log.showInfo(TAG, `success to getnetworkState: ${JSON.stringify(value)}`);
|
||||
// If there is no service, no signal is displayed.
|
||||
if (value.regState != Constants.REG_STATE_IN_SERVICE) {
|
||||
mTypeLink.set(Constants.RADIO_TECHNOLOGY_UNKNOWN);
|
||||
mLevelLink.set(Constants.CELLULAR_NO_SIM_CARD);
|
||||
mTypeLink.set(Constants.NETWORK_TYPE_UNKNOWN);
|
||||
} else {
|
||||
Log.showInfo(TAG, 'get signal level by value.');
|
||||
mLevelLink.set(value[0].signalLevel);
|
||||
mTypeLink.set(value[0].signalType);
|
||||
mTypeLink.set(value.cfgTech);
|
||||
Radio.getSignalInformation(slotId, (err, value) => {
|
||||
if (err || !value || !value.length) {
|
||||
Log.showError(TAG, `failed to getSimState because ${err.message}`);
|
||||
mLevelLink.set(Constants.CELLULAR_NO_SIM_CARD);
|
||||
} else {
|
||||
Log.showInfo(TAG, `success to getSignalInfo: ${JSON.stringify(value)}`);
|
||||
mLevelLink.set(value[0].signalLevel);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Log.showInfo(TAG, 'enter checknetworkState ============');
|
||||
//The interface of getting the cellular signal status is unavailable temporarily
|
||||
Radio.getNetworkState((err, value) => {
|
||||
if (err) {
|
||||
// Failed to call the interface,error is not null
|
||||
Log.showError(TAG, `failed to getnetworkState because ${err.message}`);
|
||||
// When failed to call the interface, set the result as no signal
|
||||
mStateLink.set(Constants.NET_NULL);
|
||||
} else {
|
||||
// Call interface succeed,error is null
|
||||
Log.showInfo(TAG, `success to getnetworkState: ${JSON.stringify(value)}`);
|
||||
// Since the value might be empty, set it as no signal by hand
|
||||
if (!value) {
|
||||
Log.showError(TAG, 'value from api is empty, set 0');
|
||||
mStateLink.set(Constants.NET_NULL);
|
||||
} else {
|
||||
mStateLink.set(value.longOperatorName);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
if (!isInitObserver) {
|
||||
this.initObserver();
|
||||
}
|
||||
} else {
|
||||
Log.showError(TAG, `hasSimCard failed to hasSimCard because`);
|
||||
mLevelLink.set(Constants.CELLULAR_NO_SIM_CARD);
|
||||
mTypeLink.set(Constants.NETWORK_TYPE_UNKNOWN);
|
||||
mTypeLink.set(Constants.RADIO_TECHNOLOGY_UNKNOWN);
|
||||
mStateLink.set(Constants.NET_NULL);
|
||||
if (!isInitObserver) {
|
||||
this.initObserver();
|
||||
}
|
||||
}
|
||||
if (!isInitObserver) {
|
||||
this.initObserver();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user