List of usage examples for android.telephony ServiceState getOperatorAlphaLong
public String getOperatorAlphaLong()
From source file:org.restcomm.app.qoslib.Services.LibPhoneStateListener.java
@Override public void onServiceStateChanged(ServiceState serviceState) { super.onServiceStateChanged(serviceState); if (serviceState == null) return;/*from ww w . j ava 2 s .c om*/ boolean isRoaming = serviceState.getRoaming(); String operator = serviceState.getOperatorAlphaLong(); String mccmnc = serviceState.getOperatorNumeric(); //owner.getConnectionHistory().updateConnectionHistory(cellnettype, state, activity, networkInfo) try { String activity = owner.getConnectionHistory().updateConnectionHistory( telephonyManager.getNetworkType(), telephonyManager.getDataState(), telephonyManager.getDataActivity(), serviceState, owner.getConnectivityManager().getActiveNetworkInfo()); if (activity != null) owner.getIntentDispatcher().updateConnection(activity, false); } catch (Exception e) { LoggerUtil.logToFile(LoggerUtil.Level.ERROR, TAG, "onServiceStateChanged", "exception with updateConnectionHistory:", e); } //MMCLogger.logToFile(MMCLogger.Level.DEBUG, TAG, "onServiceStateChanged", String.format("State: %s, roaming: %s, operator: %s, mccmnc: %s", // serviceState, isRoaming, operator, mccmnc)); //MMCLogger.logToFile(MMCLogger.Level.DEBUG, TAG, "onServiceStateChanged", "Reflected: " + listServiceStateFields(serviceState)); boolean wasRoaming = PreferenceManager.getDefaultSharedPreferences(owner) .getBoolean(PreferenceKeys.Miscellaneous.WAS_ROAMING, false); //If roaming, track time spend doing this if (mPhoneState.isRoaming() != wasRoaming) { int roamValue = 2; //off String status = "off"; if (mPhoneState.isRoaming()) { roamValue = 1; //on status = "on"; //For DataMonitor tracking Intent intent = new Intent(IntentHandler.ROAMING_ON); owner.sendBroadcast(intent); } else { Intent intent = new Intent(IntentHandler.ROAMING_OFF); owner.sendBroadcast(intent); } LoggerUtil.logToFile(LoggerUtil.Level.DEBUG, TAG, "onServiceStateChanged", "roaming status: " + status); owner.trackAccessPoints(roamValue); if (!EventObj.isDisabledEvent(owner, EventObj.DISABLE_ROAMUPDATE)) owner.getEventManager().triggerUpdateEvent(false, false); PreferenceManager.getDefaultSharedPreferences(owner).edit() .putBoolean(PreferenceKeys.Miscellaneous.WAS_ROAMING, mPhoneState.isRoaming()).commit(); } //If wimax, track time spend doing this if (PhoneState.ActiveConnection(owner) == 12) { Intent intent = new Intent(IntentHandler.WIMAX_STATE_CHANGE); owner.sendBroadcast(intent); } //in airplane mode if (isAirplaneModeOn(owner.getApplicationContext()) == true) { LoggerUtil.logToFile(LoggerUtil.Level.DEBUG, TAG, "onServiceStateChanged", "airplane mode on"); mPhoneState.previousServiceState = mPhoneState.SERVICE_STATE_AIRPLANE; try { SignalEx mmcSignal = new SignalEx(); processNewMMCSignal(mmcSignal); } catch (Exception e) { } return; } if (serviceState.getState() == ServiceState.STATE_IN_SERVICE) { if (mPhoneState.previousServiceState != ServiceState.STATE_IN_SERVICE) { //state changed from OUT_OF_SERVICE to IN_SERVICE LoggerUtil.logToFile(LoggerUtil.Level.DEBUG, TAG, "onServiceStateChanged", "trigger regain service"); owner.getEventManager().stopPhoneEvent(EventType.COV_VOD_NO, EventType.COV_VOD_YES); mPhoneState.mLastServiceStateChangeTimeStamp = System.currentTimeMillis(); } } else if (serviceState.getState() == ServiceState.STATE_OUT_OF_SERVICE) {// || serviceState.getState() == ServiceState.STATE_EMERGENCY_ONLY) { if (mPhoneState.previousServiceState == mPhoneState.SERVICE_STATE_AIRPLANE) return; // discard 'no-service' occurring after exiting airplane mode if (mPhoneState.previousServiceState == ServiceState.STATE_IN_SERVICE) { // && previousServiceState != SERVICE_STATE_AIRPLANE) { mPhoneState.previousServiceState = serviceState.getState(); SignalEx signal = mPhoneState.getLastMMCSignal(); processNewMMCSignal(signal); // Outage needs to last longer than 5 seconds to actually trigger int delay = 5000; if (mPhoneState.isCallConnected() || mPhoneState.disconnectTime + 12000 > System.currentTimeMillis()) delay = 1; // If phone call is connected (or recently disconnected), no delay, dont ignore short outages owner.handler.postDelayed(new Runnable() { @Override public void run() { // If longer outage after 2 seconds, do nothing if (mPhoneState.previousServiceState != ServiceState.STATE_OUT_OF_SERVICE) // && previousServiceState != ServiceState.STATE_EMERGENCY_ONLY) { LoggerUtil.logToFile(LoggerUtil.Level.DEBUG, TAG, "onServiceStateChanged", "Outage lasted < 5 sec, ignoring"); return; } // Officially an outage now // If service dropped straight from 3G to nothing, trigger a 3G outage as well // If was connected to wifi when service was lost, does not count as a 3G outage if (PhoneState.ActiveConnection(owner) <= 1 && mPhoneState.previousNetworkTier >= 3) // 10=Wifi, 11=Wimax, 12=Ethernet, 0=other { owner.getEventManager().startPhoneEvent(EventType.COV_3G_NO, EventType.COV_3G_YES); if (mPhoneState.previousNetworkTier >= 5) owner.getEventManager().startPhoneEvent(EventType.COV_4G_NO, EventType.COV_4G_YES); } mPhoneState.mLastServiceStateChangeTimeStamp = System.currentTimeMillis(); LoggerUtil.logToFile(LoggerUtil.Level.DEBUG, TAG, "onServiceStateChanged", "trigger lost service"); //state changed from IN_SERVICE to OUT_OF_SERVICE owner.getEventManager().startPhoneEvent(EventType.COV_VOD_NO, EventType.COV_VOD_YES); if (mPhoneState.previousNetworkTier >= 2) owner.getEventManager().startPhoneEvent(EventType.COV_DATA_NO, EventType.COV_DATA_YES); SignalEx signal = mPhoneState.getLastMMCSignal(); processNewMMCSignal(signal); mPhoneState.previousNetworkTier = 0; //previousNetworkState = 0; } }, delay); } } mPhoneState.previousServiceState = serviceState.getState(); mPhoneState.previousServiceStateObj = serviceState; }