From 0dde2c20a07770bc2f1b21e49222c968f3d8b39a Mon Sep 17 00:00:00 2001 From: Wink Saville Date: Fri, 16 Nov 2012 08:12:11 -0800 Subject: [PATCH] Separate voice and data radio technology/network type & registration state. Change-Id: Ic9622e3fd637751b427c1627bbdf4d142acbc66e --- .../java/android/telephony/ServiceState.java | 195 +++++++++++++++--- .../android/telephony/TelephonyManager.java | 36 +++- .../internal/telephony/ITelephony.aidl | 12 +- 3 files changed, 207 insertions(+), 36 deletions(-) diff --git a/telephony/java/android/telephony/ServiceState.java b/telephony/java/android/telephony/ServiceState.java index a9a5e905fb8c9..2c171b1f865fc 100644 --- a/telephony/java/android/telephony/ServiceState.java +++ b/telephony/java/android/telephony/ServiceState.java @@ -36,6 +36,7 @@ import android.util.Log; public class ServiceState implements Parcelable { static final String LOG_TAG = "PHONE"; + static final boolean DBG = true; /** * Normal operation condition, the phone is registered @@ -61,6 +62,46 @@ public class ServiceState implements Parcelable { */ public static final int STATE_POWER_OFF = 3; + /** + * RIL level registration state values from ril.h + * ((const char **)response)[0] is registration state 0-6, + * 0 - Not registered, MT is not currently searching + * a new operator to register + * 1 - Registered, home network + * 2 - Not registered, but MT is currently searching + * a new operator to register + * 3 - Registration denied + * 4 - Unknown + * 5 - Registered, roaming + * 10 - Same as 0, but indicates that emergency calls + * are enabled. + * 12 - Same as 2, but indicates that emergency calls + * are enabled. + * 13 - Same as 3, but indicates that emergency calls + * are enabled. + * 14 - Same as 4, but indicates that emergency calls + * are enabled. + * @hide + */ + public static final int RIL_REG_STATE_NOT_REG = 0; + /** @hide */ + public static final int RIL_REG_STATE_HOME = 1; + /** @hide */ + public static final int RIL_REG_STATE_SEARCHING = 2; + /** @hide */ + public static final int RIL_REG_STATE_DENIED = 3; + /** @hide */ + public static final int RIL_REG_STATE_UNKNOWN = 4; + /** @hide */ + public static final int RIL_REG_STATE_ROAMING = 5; + /** @hide */ + public static final int RIL_REG_STATE_NOT_REG_EMERGENCY_CALL_ENABLED = 10; + /** @hide */ + public static final int RIL_REG_STATE_SEARCHING_EMERGENCY_CALL_ENABLED = 12; + /** @hide */ + public static final int RIL_REG_STATE_DENIED_EMERGENCY_CALL_ENABLED = 13; + /** @hide */ + public static final int RIL_REG_STATE_UNKNOWN_EMERGENCY_CALL_ENABLED = 14; /** * Available radio technologies for GSM, UMTS and CDMA. @@ -122,7 +163,8 @@ public class ServiceState implements Parcelable { /** @hide */ public static final int REGISTRATION_STATE_ROAMING = 5; - private int mState = STATE_OUT_OF_SERVICE; + private int mVoiceRegState = STATE_OUT_OF_SERVICE; + private int mDataRegState = STATE_OUT_OF_SERVICE; private boolean mRoaming; private String mOperatorAlphaLong; private String mOperatorAlphaShort; @@ -131,8 +173,9 @@ public class ServiceState implements Parcelable { private boolean mIsEmergencyOnly; - //***** CDMA - private int mRadioTechnology; + private int mRilVoiceRadioTechnology; + private int mRilDataRadioTechnology; + private boolean mCssIndicator; private int mNetworkId; private int mSystemId; @@ -174,13 +217,15 @@ public class ServiceState implements Parcelable { } protected void copyFrom(ServiceState s) { - mState = s.mState; + mVoiceRegState = s.mVoiceRegState; + mDataRegState = s.mDataRegState; mRoaming = s.mRoaming; mOperatorAlphaLong = s.mOperatorAlphaLong; mOperatorAlphaShort = s.mOperatorAlphaShort; mOperatorNumeric = s.mOperatorNumeric; mIsManualNetworkSelection = s.mIsManualNetworkSelection; - mRadioTechnology = s.mRadioTechnology; + mRilVoiceRadioTechnology = s.mRilVoiceRadioTechnology; + mRilDataRadioTechnology = s.mRilDataRadioTechnology; mCssIndicator = s.mCssIndicator; mNetworkId = s.mNetworkId; mSystemId = s.mSystemId; @@ -195,13 +240,15 @@ public class ServiceState implements Parcelable { * Construct a ServiceState object from the given parcel. */ public ServiceState(Parcel in) { - mState = in.readInt(); + mVoiceRegState = in.readInt(); + mDataRegState = in.readInt(); mRoaming = in.readInt() != 0; mOperatorAlphaLong = in.readString(); mOperatorAlphaShort = in.readString(); mOperatorNumeric = in.readString(); mIsManualNetworkSelection = in.readInt() != 0; - mRadioTechnology = in.readInt(); + mRilVoiceRadioTechnology = in.readInt(); + mRilDataRadioTechnology = in.readInt(); mCssIndicator = (in.readInt() != 0); mNetworkId = in.readInt(); mSystemId = in.readInt(); @@ -213,13 +260,15 @@ public class ServiceState implements Parcelable { } public void writeToParcel(Parcel out, int flags) { - out.writeInt(mState); + out.writeInt(mVoiceRegState); + out.writeInt(mDataRegState); out.writeInt(mRoaming ? 1 : 0); out.writeString(mOperatorAlphaLong); out.writeString(mOperatorAlphaShort); out.writeString(mOperatorNumeric); out.writeInt(mIsManualNetworkSelection ? 1 : 0); - out.writeInt(mRadioTechnology); + out.writeInt(mRilVoiceRadioTechnology); + out.writeInt(mRilDataRadioTechnology); out.writeInt(mCssIndicator ? 1 : 0); out.writeInt(mNetworkId); out.writeInt(mSystemId); @@ -246,15 +295,38 @@ public class ServiceState implements Parcelable { }; /** - * Get current service state of phone + * Get current voice service state + */ + public int getState() { + return getVoiceRegState(); + } + + /** + * Get current voice service state * * @see #STATE_IN_SERVICE * @see #STATE_OUT_OF_SERVICE * @see #STATE_EMERGENCY_ONLY * @see #STATE_POWER_OFF + * + * @hide */ - public int getState() { - return mState; + public int getVoiceRegState() { + return mVoiceRegState; + } + + /** + * Get current data service state + * + * @see #STATE_IN_SERVICE + * @see #STATE_OUT_OF_SERVICE + * @see #STATE_EMERGENCY_ONLY + * @see #STATE_POWER_OFF + * + * @hide + */ + public int getDataRegState() { + return mDataRegState; } /** @@ -354,7 +426,8 @@ public class ServiceState implements Parcelable { @Override public int hashCode() { - return ((mState * 0x1234) + return ((mVoiceRegState * 31) + + (mDataRegState * 37) + (mRoaming ? 1 : 0) + (mIsManualNetworkSelection ? 1 : 0) + ((null == mOperatorAlphaLong) ? 0 : mOperatorAlphaLong.hashCode()) @@ -379,13 +452,15 @@ public class ServiceState implements Parcelable { return false; } - return (mState == s.mState + return (mVoiceRegState == s.mVoiceRegState + && mDataRegState == s.mDataRegState && mRoaming == s.mRoaming && mIsManualNetworkSelection == s.mIsManualNetworkSelection && equalsHandlesNulls(mOperatorAlphaLong, s.mOperatorAlphaLong) && equalsHandlesNulls(mOperatorAlphaShort, s.mOperatorAlphaShort) && equalsHandlesNulls(mOperatorNumeric, s.mOperatorNumeric) - && equalsHandlesNulls(mRadioTechnology, s.mRadioTechnology) + && equalsHandlesNulls(mRilVoiceRadioTechnology, s.mRilVoiceRadioTechnology) + && equalsHandlesNulls(mRilDataRadioTechnology, s.mRilDataRadioTechnology) && equalsHandlesNulls(mCssIndicator, s.mCssIndicator) && equalsHandlesNulls(mNetworkId, s.mNetworkId) && equalsHandlesNulls(mSystemId, s.mSystemId) @@ -468,14 +543,16 @@ public class ServiceState implements Parcelable { @Override public String toString() { - String radioTechnology = rilRadioTechnologyToString(mRadioTechnology); + String radioTechnology = rilRadioTechnologyToString(mRilVoiceRadioTechnology); + String dataRadioTechnology = rilRadioTechnologyToString(mRilDataRadioTechnology); - return (mState + " " + (mRoaming ? "roaming" : "home") + return (mVoiceRegState + " " + mDataRegState + " " + (mRoaming ? "roaming" : "home") + " " + mOperatorAlphaLong + " " + mOperatorAlphaShort + " " + mOperatorNumeric + " " + (mIsManualNetworkSelection ? "(manual)" : "") + " " + radioTechnology + + " " + dataRadioTechnology + " " + (mCssIndicator ? "CSS supported" : "CSS not supported") + " " + mNetworkId + " " + mSystemId @@ -485,13 +562,16 @@ public class ServiceState implements Parcelable { } private void setNullState(int state) { - mState = state; + if (DBG) Log.d(LOG_TAG, "[ServiceState] setNullState=" + state); + mVoiceRegState = state; + mDataRegState = state; mRoaming = false; mOperatorAlphaLong = null; mOperatorAlphaShort = null; mOperatorNumeric = null; mIsManualNetworkSelection = false; - mRadioTechnology = 0; + mRilVoiceRadioTechnology = 0; + mRilDataRadioTechnology = 0; mCssIndicator = false; mNetworkId = -1; mSystemId = -1; @@ -511,7 +591,20 @@ public class ServiceState implements Parcelable { } public void setState(int state) { - mState = state; + setVoiceRegState(state); + if (DBG) Log.e(LOG_TAG, "[ServiceState] setState deprecated use setVoiceRegState()"); + } + + /** @hide */ + public void setVoiceRegState(int state) { + mVoiceRegState = state; + if (DBG) Log.d(LOG_TAG, "[ServiceState] setVoiceRegState=" + mVoiceRegState); + } + + /** @hide */ + public void setDataRegState(int state) { + mDataRegState = state; + if (DBG) Log.d(LOG_TAG, "[ServiceState] setDataRegState=" + mDataRegState); } public void setRoaming(boolean roaming) { @@ -592,13 +685,15 @@ public class ServiceState implements Parcelable { * @hide */ private void setFromNotifierBundle(Bundle m) { - mState = m.getInt("state"); + mVoiceRegState = m.getInt("voiceRegState"); + mDataRegState = m.getInt("dataRegState"); mRoaming = m.getBoolean("roaming"); mOperatorAlphaLong = m.getString("operator-alpha-long"); mOperatorAlphaShort = m.getString("operator-alpha-short"); mOperatorNumeric = m.getString("operator-numeric"); mIsManualNetworkSelection = m.getBoolean("manual"); - mRadioTechnology = m.getInt("radioTechnology"); + mRilVoiceRadioTechnology = m.getInt("radioTechnology"); + mRilVoiceRadioTechnology = m.getInt("dataRadioTechnology"); mCssIndicator = m.getBoolean("cssIndicator"); mNetworkId = m.getInt("networkId"); mSystemId = m.getInt("systemId"); @@ -614,13 +709,15 @@ public class ServiceState implements Parcelable { * @hide */ public void fillInNotifierBundle(Bundle m) { - m.putInt("state", mState); + m.putInt("voiceRegState", mVoiceRegState); + m.putInt("dataRegState", mDataRegState); m.putBoolean("roaming", Boolean.valueOf(mRoaming)); m.putString("operator-alpha-long", mOperatorAlphaLong); m.putString("operator-alpha-short", mOperatorAlphaShort); m.putString("operator-numeric", mOperatorNumeric); m.putBoolean("manual", Boolean.valueOf(mIsManualNetworkSelection)); - m.putInt("radioTechnology", mRadioTechnology); + m.putInt("radioTechnology", mRilVoiceRadioTechnology); + m.putInt("dataRadioTechnology", mRilDataRadioTechnology); m.putBoolean("cssIndicator", mCssIndicator); m.putInt("networkId", mNetworkId); m.putInt("systemId", mSystemId); @@ -629,10 +726,15 @@ public class ServiceState implements Parcelable { m.putBoolean("emergencyOnly", Boolean.valueOf(mIsEmergencyOnly)); } - //***** CDMA /** @hide */ - public void setRadioTechnology(int state) { - this.mRadioTechnology = state; + public void setRilVoiceRadioTechnology(int rt) { + this.mRilVoiceRadioTechnology = rt; + } + + /** @hide */ + public void setRilDataRadioTechnology(int rt) { + this.mRilDataRadioTechnology = rt; + if (DBG) Log.d(LOG_TAG, "[ServiceState] setDataRadioTechnology=" + mRilDataRadioTechnology); } /** @hide */ @@ -647,17 +749,25 @@ public class ServiceState implements Parcelable { } /** @hide */ - public int getRilRadioTechnology() { - return this.mRadioTechnology; + public int getRilVoiceRadioTechnology() { + return this.mRilVoiceRadioTechnology; } /** @hide */ + public int getRilDataRadioTechnology() { + return this.mRilDataRadioTechnology; + } + /** + * @hide + * @Deprecated to be removed Q3 2013 use {@link #getRilDataRadioTechnology} or + * {@link #getRilVoiceRadioTechnology} + */ public int getRadioTechnology() { - return getRilRadioTechnology(); + Log.e(LOG_TAG, "ServiceState.getRadioTechnology() DEPRECATED will be removed *******"); + return getRilDataRadioTechnology(); } - /** @hide */ - public int getNetworkType() { - switch(mRadioTechnology) { + private int rilRadioTechnologyToNetworkType(int rt) { + switch(rt) { case ServiceState.RIL_RADIO_TECHNOLOGY_GPRS: return TelephonyManager.NETWORK_TYPE_GPRS; case ServiceState.RIL_RADIO_TECHNOLOGY_EDGE: @@ -692,6 +802,25 @@ public class ServiceState implements Parcelable { } } + /** + * @Deprecated to be removed Q3 2013 use {@link #getVoiceNetworkType} + * @hide + */ + public int getNetworkType() { + Log.e(LOG_TAG, "ServiceState.getNetworkType() DEPRECATED will be removed *******"); + return rilRadioTechnologyToNetworkType(mRilVoiceRadioTechnology); + } + + /** @hide */ + public int getDataNetworkType() { + return rilRadioTechnologyToNetworkType(mRilDataRadioTechnology); + } + + /** @hide */ + public int getVoiceNetworkType() { + return rilRadioTechnologyToNetworkType(mRilVoiceRadioTechnology); + } + /** @hide */ public int getCssIndicator() { return this.mCssIndicator ? 1 : 0; diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index 2fa41e77758ba..261174ac3937b 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -556,6 +556,13 @@ public class TelephonyManager { /** Current network is HSPA+ */ public static final int NETWORK_TYPE_HSPAP = 15; + /** + * Returns the NETWORK_TYPE_xxxx for data transmission + */ + public int getNetworkType() { + return getDataNetworkType(); + } + /** * Returns a constant indicating the radio technology (network type) * currently in use on the device for data transmission. @@ -577,12 +584,37 @@ public class TelephonyManager { * @see #NETWORK_TYPE_LTE * @see #NETWORK_TYPE_EHRPD * @see #NETWORK_TYPE_HSPAP + * + * @hide */ - public int getNetworkType() { + public int getDataNetworkType() { try{ ITelephony telephony = getITelephony(); if (telephony != null) { - return telephony.getNetworkType(); + return telephony.getDataNetworkType(); + } else { + // This can happen when the ITelephony interface is not up yet. + return NETWORK_TYPE_UNKNOWN; + } + } catch(RemoteException ex) { + // This shouldn't happen in the normal case + return NETWORK_TYPE_UNKNOWN; + } catch (NullPointerException ex) { + // This could happen before phone restarts due to crashing + return NETWORK_TYPE_UNKNOWN; + } + } + + /** + * Returns the NETWORK_TYPE_xxxx for voice + * + * @hide + */ + public int getVoiceNetworkType() { + try{ + ITelephony telephony = getITelephony(); + if (telephony != null) { + return telephony.getVoiceNetworkType(); } else { // This can happen when the ITelephony interface is not up yet. return NETWORK_TYPE_UNKNOWN; diff --git a/telephony/java/com/android/internal/telephony/ITelephony.aidl b/telephony/java/com/android/internal/telephony/ITelephony.aidl index 12a7286a9c63e..d5f0467e007dc 100644 --- a/telephony/java/com/android/internal/telephony/ITelephony.aidl +++ b/telephony/java/com/android/internal/telephony/ITelephony.aidl @@ -261,10 +261,20 @@ interface ITelephony { int getVoiceMessageCount(); /** - * Returns the network type + * Returns the network type for data transmission */ int getNetworkType(); + /** + * Returns the network type for data transmission + */ + int getDataNetworkType(); + + /** + * Returns the network type for voice + */ + int getVoiceNetworkType(); + /** * Return true if an ICC card is present */