Add Phone.getPhoneType() operation.

This routine returns integer values defined in the Phone interface,
derived from RILConstants values.  Direct references to the
RILConstants are replaced by references to these new ones for
consistency.

API CHANGE:
  unhide TelephonyManager.PHONE_TYPE_CDMA

Addresses issue:
http://buganizer/issue?id=1905415

Change-Id: Icfec6d457231b098c031677a66770b5e57be4a44
diff --git a/api/current.xml b/api/current.xml
index d764d16..36a82a8 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -125112,6 +125112,17 @@
  visibility="public"
 >
 </field>
+<field name="PHONE_TYPE_CDMA"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="2"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="PHONE_TYPE_GSM"
  type="int"
  transient="false"
diff --git a/telephony/java/android/telephony/CellLocation.java b/telephony/java/android/telephony/CellLocation.java
index 7d600f0..f763d3f 100644
--- a/telephony/java/android/telephony/CellLocation.java
+++ b/telephony/java/android/telephony/CellLocation.java
@@ -26,11 +26,10 @@
 import android.telephony.cdma.CdmaCellLocation;
 import android.telephony.gsm.GsmCellLocation;
 import com.android.internal.telephony.ITelephony;
-import com.android.internal.telephony.RILConstants;
+import com.android.internal.telephony.Phone;
 
 /**
- * Abstract class that represents the location of the device.  Currently the only
- * subclass is {@link android.telephony.gsm.GsmCellLocation}.  {@more}
+ * Abstract class that represents the location of the device.  {@more}
  */
 public abstract class CellLocation {
 
@@ -64,11 +63,13 @@
     public static CellLocation newFromBundle(Bundle bundle) {
         // TelephonyManager.getDefault().getPhoneType() handles the case when
         // ITelephony interface is not up yet.
-        int type = TelephonyManager.getDefault().getPhoneType();
-        if (type == RILConstants.CDMA_PHONE) {
+        switch(TelephonyManager.getDefault().getPhoneType()) {
+        case Phone.PHONE_TYPE_CDMA:
             return new CdmaCellLocation(bundle);
-        } else {
+        case Phone.PHONE_TYPE_GSM:
             return new GsmCellLocation(bundle);
+        default:
+            return null;
         }
     }
 
@@ -78,17 +79,20 @@
     public abstract void fillInNotifierBundle(Bundle bundle);
 
     /**
-     * Return a new CellLocation object representing an unknown location.
+     * Return a new CellLocation object representing an unknown
+     * location, or null for unknown/none phone radio types.
      *
      */
     public static CellLocation getEmpty() {
         // TelephonyManager.getDefault().getPhoneType() handles the case when
         // ITelephony interface is not up yet.
-        int type = TelephonyManager.getDefault().getPhoneType();
-        if (type == RILConstants.CDMA_PHONE) {
+        switch(TelephonyManager.getDefault().getPhoneType()) {
+        case Phone.PHONE_TYPE_CDMA:
             return new CdmaCellLocation();
-        } else {
+        case Phone.PHONE_TYPE_GSM:
             return new GsmCellLocation();
+        default:
+            return null;
         }
     }
 }
diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java
index 8914aceac..6664b08 100644
--- a/telephony/java/android/telephony/TelephonyManager.java
+++ b/telephony/java/android/telephony/TelephonyManager.java
@@ -263,22 +263,12 @@
        }
     }
 
-    /**
-     * No phone module
-     *
-     */
-    public static final int PHONE_TYPE_NONE = RILConstants.NO_PHONE;
-
-    /**
-     * GSM phone
-     */
-    public static final int PHONE_TYPE_GSM = RILConstants.GSM_PHONE;
-
-    /**
-     * CDMA phone
-     * @hide
-     */
-    public static final int PHONE_TYPE_CDMA = RILConstants.CDMA_PHONE;
+    /** No phone radio. */
+    public static final int PHONE_TYPE_NONE = Phone.PHONE_TYPE_NONE;
+    /** Phone radio is GSM. */
+    public static final int PHONE_TYPE_GSM = Phone.PHONE_TYPE_GSM;
+    /** Phone radio is CDMA. */
+    public static final int PHONE_TYPE_CDMA = Phone.PHONE_TYPE_CDMA;
 
     /**
      * Returns a constant indicating the device phone type.
@@ -291,11 +281,7 @@
         try{
             ITelephony telephony = getITelephony();
             if (telephony != null) {
-                if(telephony.getActivePhoneType() == RILConstants.CDMA_PHONE) {
-                    return PHONE_TYPE_CDMA;
-                } else {
-                    return PHONE_TYPE_GSM;
-                }
+                return telephony.getActivePhoneType();
             } else {
                 // This can happen when the ITelephony interface is not up yet.
                 return getPhoneTypeFromProperty();
diff --git a/telephony/java/com/android/internal/telephony/BaseCommands.java b/telephony/java/com/android/internal/telephony/BaseCommands.java
index 52f25f6..7586ba2 100644
--- a/telephony/java/com/android/internal/telephony/BaseCommands.java
+++ b/telephony/java/com/android/internal/telephony/BaseCommands.java
@@ -676,7 +676,7 @@
                 mRadioTechnologyChangedRegistrants.notifyRegistrants();
             }
 
-            if (mState.isGsm() && !oldState.isOn() && (mPhoneType == RILConstants.CDMA_PHONE)) {
+            if (mState.isGsm() && !oldState.isOn() && (mPhoneType == Phone.PHONE_TYPE_CDMA)) {
                 Log.d(LOG_TAG,"Notifying: radio technology change CDMA OFF to GSM");
                 mRadioTechnologyChangedRegistrants.notifyRegistrants();
             }
@@ -686,7 +686,7 @@
                 mRadioTechnologyChangedRegistrants.notifyRegistrants();
             }
 
-            if (mState.isCdma() && !oldState.isOn() && (mPhoneType == RILConstants.GSM_PHONE)) {
+            if (mState.isCdma() && !oldState.isOn() && (mPhoneType == Phone.PHONE_TYPE_GSM)) {
                 Log.d(LOG_TAG,"Notifying: radio technology change GSM OFF to CDMA");
                 mRadioTechnologyChangedRegistrants.notifyRegistrants();
             }
diff --git a/telephony/java/com/android/internal/telephony/CommandsInterface.java b/telephony/java/com/android/internal/telephony/CommandsInterface.java
index 9d83556..5777cad 100644
--- a/telephony/java/com/android/internal/telephony/CommandsInterface.java
+++ b/telephony/java/com/android/internal/telephony/CommandsInterface.java
@@ -1256,6 +1256,7 @@
 
     /** Set the Phone type created */
     void setPhoneType(int phoneType);
+
     /**
      *  Query the CDMA roaming preference setting
      *
diff --git a/telephony/java/com/android/internal/telephony/Phone.java b/telephony/java/com/android/internal/telephony/Phone.java
index fffd128..c113581 100644
--- a/telephony/java/com/android/internal/telephony/Phone.java
+++ b/telephony/java/com/android/internal/telephony/Phone.java
@@ -173,6 +173,11 @@
     static final int BM_AUS2_BAND   = 5; // GSM-900 / DCS-1800 / WCDMA-850
     static final int BM_BOUNDARY    = 6; // upper band boundary
 
+    // Radio Type
+    static final int PHONE_TYPE_NONE = RILConstants.NO_PHONE;
+    static final int PHONE_TYPE_GSM = RILConstants.GSM_PHONE;
+    static final int PHONE_TYPE_CDMA = RILConstants.CDMA_PHONE;
+
     // Used for preferred network type
     // Note NT_* substitute RILConstants.NETWORK_MODE_* above the Phone
     int NT_MODE_WCDMA_PREF   = RILConstants.NETWORK_MODE_WCDMA_PREF;
@@ -288,6 +293,12 @@
     String getPhoneName();
 
     /**
+     * Return a numerical identifier for the phone radio interface.
+     * @return PHONE_TYPE_XXX as defined above.
+     */
+    int getPhoneType();
+
+    /**
      * Returns an array of string identifiers for the APN types serviced by the
      * currently active or last connected APN.
      *  @return The string array.
diff --git a/telephony/java/com/android/internal/telephony/PhoneBase.java b/telephony/java/com/android/internal/telephony/PhoneBase.java
index 1c62a82..1c03c5a 100644
--- a/telephony/java/com/android/internal/telephony/PhoneBase.java
+++ b/telephony/java/com/android/internal/telephony/PhoneBase.java
@@ -740,6 +740,8 @@
 
     public abstract String getPhoneName();
 
+    public abstract int getPhoneType();
+
     /** @hide */
     public int getVoiceMessageCount(){
         return 0;
diff --git a/telephony/java/com/android/internal/telephony/PhoneFactory.java b/telephony/java/com/android/internal/telephony/PhoneFactory.java
index a84f74e..cd72752 100644
--- a/telephony/java/com/android/internal/telephony/PhoneFactory.java
+++ b/telephony/java/com/android/internal/telephony/PhoneFactory.java
@@ -108,11 +108,11 @@
                 sCommandsInterface = new RIL(context, networkMode, cdmaSubscription);
 
                 int phoneType = getPhoneType(networkMode);
-                if (phoneType == RILConstants.GSM_PHONE) {
+                if (phoneType == Phone.PHONE_TYPE_GSM) {
                     sProxyPhone = new PhoneProxy(new GSMPhone(context,
                             sCommandsInterface, sPhoneNotifier));
                     Log.i(LOG_TAG, "Creating GSMPhone");
-                } else if (phoneType == RILConstants.CDMA_PHONE) {
+                } else if (phoneType == Phone.PHONE_TYPE_CDMA) {
                     sProxyPhone = new PhoneProxy(new CDMAPhone(context,
                             sCommandsInterface, sPhoneNotifier));
                     Log.i(LOG_TAG, "Creating CDMAPhone");
@@ -135,18 +135,18 @@
         case RILConstants.NETWORK_MODE_CDMA:
         case RILConstants.NETWORK_MODE_CDMA_NO_EVDO:
         case RILConstants.NETWORK_MODE_EVDO_NO_CDMA:
-            return RILConstants.CDMA_PHONE;
+            return Phone.PHONE_TYPE_CDMA;
 
         case RILConstants.NETWORK_MODE_WCDMA_PREF:
         case RILConstants.NETWORK_MODE_GSM_ONLY:
         case RILConstants.NETWORK_MODE_WCDMA_ONLY:
         case RILConstants.NETWORK_MODE_GSM_UMTS:
-            return RILConstants.GSM_PHONE;
+            return Phone.PHONE_TYPE_GSM;
 
         case RILConstants.NETWORK_MODE_GLOBAL:
-            return RILConstants.CDMA_PHONE;
+            return Phone.PHONE_TYPE_CDMA;
         default:
-            return RILConstants.GSM_PHONE;
+            return Phone.PHONE_TYPE_GSM;
         }
     }
 
diff --git a/telephony/java/com/android/internal/telephony/PhoneProxy.java b/telephony/java/com/android/internal/telephony/PhoneProxy.java
index c4f663a..b1eaa93 100644
--- a/telephony/java/com/android/internal/telephony/PhoneProxy.java
+++ b/telephony/java/com/android/internal/telephony/PhoneProxy.java
@@ -191,6 +191,10 @@
         return mActivePhone.getPhoneName();
     }
 
+    public int getPhoneType() {
+        return mActivePhone.getPhoneType();
+    }
+
     public String[] getActiveApnTypes() {
         return mActivePhone.getActiveApnTypes();
     }
diff --git a/telephony/java/com/android/internal/telephony/cdma/CDMAPhone.java b/telephony/java/com/android/internal/telephony/cdma/CDMAPhone.java
index dfc4889..6dcfcd9 100755
--- a/telephony/java/com/android/internal/telephony/cdma/CDMAPhone.java
+++ b/telephony/java/com/android/internal/telephony/cdma/CDMAPhone.java
@@ -60,7 +60,6 @@
 import com.android.internal.telephony.PhoneNotifier;
 import com.android.internal.telephony.PhoneProxy;
 import com.android.internal.telephony.PhoneSubInfo;
-import com.android.internal.telephony.RILConstants;
 import com.android.internal.telephony.TelephonyIntents;
 import com.android.internal.telephony.TelephonyProperties;
 
@@ -143,7 +142,7 @@
             boolean unitTestMode) {
         super(notifier, context, ci, unitTestMode);
 
-        mCM.setPhoneType(RILConstants.CDMA_PHONE);
+        mCM.setPhoneType(Phone.PHONE_TYPE_CDMA);
         mCT = new CdmaCallTracker(this);
         mSST = new CdmaServiceStateTracker (this);
         mSMS = new CdmaSMSDispatcher(this);
@@ -171,7 +170,7 @@
 
         //Change the system setting
         SystemProperties.set(TelephonyProperties.CURRENT_ACTIVE_PHONE,
-                new Integer(RILConstants.CDMA_PHONE).toString());
+                new Integer(Phone.PHONE_TYPE_CDMA).toString());
 
         // This is needed to handle phone process crashes
         String inEcm=SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE, "false");
@@ -261,23 +260,24 @@
         return mSST.ss;
     }
 
-    public Phone.State
-    getState() {
+    public Phone.State getState() {
         return mCT.state;
     }
 
-    public String
-    getPhoneName() {
+    public String getPhoneName() {
         return "CDMA";
     }
 
+    public int getPhoneType() {
+        return Phone.PHONE_TYPE_CDMA;
+    }
+
     public boolean canTransfer() {
         Log.e(LOG_TAG, "canTransfer: not possible in CDMA");
         return false;
     }
 
-    public CdmaCall
-    getRingingCall() {
+    public CdmaCall getRingingCall() {
         return mCT.ringingCall;
     }
 
diff --git a/telephony/java/com/android/internal/telephony/gsm/GSMPhone.java b/telephony/java/com/android/internal/telephony/gsm/GSMPhone.java
index 2fc2e13..5614c12 100755
--- a/telephony/java/com/android/internal/telephony/gsm/GSMPhone.java
+++ b/telephony/java/com/android/internal/telephony/gsm/GSMPhone.java
@@ -66,7 +66,6 @@
 import com.android.internal.telephony.PhoneNotifier;
 import com.android.internal.telephony.PhoneProxy;
 import com.android.internal.telephony.PhoneSubInfo;
-import com.android.internal.telephony.RILConstants;
 import com.android.internal.telephony.TelephonyProperties;
 import com.android.internal.telephony.gsm.stk.StkService;
 import com.android.internal.telephony.test.SimulatedRadioControl;
@@ -141,7 +140,7 @@
             mSimulatedRadioControl = (SimulatedRadioControl) ci;
         }
 
-        mCM.setPhoneType(RILConstants.GSM_PHONE);
+        mCM.setPhoneType(Phone.PHONE_TYPE_GSM);
         mCT = new GsmCallTracker(this);
         mSST = new GsmServiceStateTracker (this);
         mSMS = new GsmSMSDispatcher(this);
@@ -201,7 +200,7 @@
 
         //Change the system property
         SystemProperties.set(TelephonyProperties.CURRENT_ACTIVE_PHONE,
-                new Integer(RILConstants.GSM_PHONE).toString());
+                new Integer(Phone.PHONE_TYPE_GSM).toString());
     }
 
     public void dispose() {
@@ -262,27 +261,27 @@
         return mSST.cellLoc;
     }
 
-    public Phone.State
-    getState() {
+    public Phone.State getState() {
         return mCT.state;
     }
 
-    public String
-    getPhoneName() {
+    public String getPhoneName() {
         return "GSM";
     }
 
+    public int getPhoneType() {
+        return Phone.PHONE_TYPE_GSM;
+    }
+
     public SignalStrength getSignalStrength() {
         return mSST.mSignalStrength;
     }
 
-    public boolean
-    getMessageWaitingIndicator() {
+    public boolean getMessageWaitingIndicator() {
         return mSIMRecords.getVoiceMessageWaiting();
     }
 
-    public boolean
-    getCallForwardingIndicator() {
+    public boolean getCallForwardingIndicator() {
         return mSIMRecords.getVoiceCallForwardingFlag();
     }