Revert "Get rid of RIL version."

This reverts commit 81ea341d2deb767cbd1de2f356296ad92e951c52.

Bug: 36018228
Change-Id: Iee0410f197c2869e2bdefcaaae51e7ef215cdff1
(cherry picked from commit a56f405d3006b1d8378b5f7757a5613b75fa8fb4)
diff --git a/src/java/com/android/internal/telephony/BaseCommands.java b/src/java/com/android/internal/telephony/BaseCommands.java
index bc26bb9..8865901 100644
--- a/src/java/com/android/internal/telephony/BaseCommands.java
+++ b/src/java/com/android/internal/telephony/BaseCommands.java
@@ -102,8 +102,8 @@
     protected int mCdmaSubscription;
     // Type of Phone, GSM or CDMA. Set by GsmCdmaPhone.
     protected int mPhoneType;
-    // RIL connected
-    protected boolean mRilConnected = false;
+    // RIL Version
+    protected int mRilVersion = -1;
 
     public BaseCommands(Context context) {
         mContext = context;  // May be null (if so we won't log statistics)
@@ -736,8 +736,8 @@
     public void registerForRilConnected(Handler h, int what, Object obj) {
         Registrant r = new Registrant (h, what, obj);
         mRilConnectedRegistrants.add(r);
-        if (mRilConnected) {
-            r.notifyRegistrant(new AsyncResult(null, null, null));
+        if (mRilVersion != -1) {
+            r.notifyRegistrant(new AsyncResult(null, new Integer(mRilVersion), null));
         }
     }
 
@@ -836,6 +836,11 @@
     @Override
     public void testingEmergencyCall() {}
 
+    @Override
+    public int getRilVersion() {
+        return mRilVersion;
+    }
+
     public void setUiccSubscription(int slotId, int appIndex, int subId, int subStatus,
             Message response) {
     }
diff --git a/src/java/com/android/internal/telephony/CommandsInterface.java b/src/java/com/android/internal/telephony/CommandsInterface.java
index 9667553..78625ad 100644
--- a/src/java/com/android/internal/telephony/CommandsInterface.java
+++ b/src/java/com/android/internal/telephony/CommandsInterface.java
@@ -1886,6 +1886,11 @@
      */
     void getHardwareConfig (Message result);
 
+    /**
+     * @return version of the ril.
+     */
+    int getRilVersion();
+
    /**
      * Sets user selected subscription at Modem.
      *
diff --git a/src/java/com/android/internal/telephony/GsmCdmaPhone.java b/src/java/com/android/internal/telephony/GsmCdmaPhone.java
index 4cf2d87..92056fb 100644
--- a/src/java/com/android/internal/telephony/GsmCdmaPhone.java
+++ b/src/java/com/android/internal/telephony/GsmCdmaPhone.java
@@ -186,6 +186,7 @@
 
     private boolean mResetModemOnRadioTechnologyChange = false;
 
+    private int mRilVersion;
     private boolean mBroadcastEmergencyCallStateChanges = false;
 
     // Constructors
@@ -260,6 +261,7 @@
         mResetModemOnRadioTechnologyChange = SystemProperties.getBoolean(
                 TelephonyProperties.PROPERTY_RESET_ON_RADIO_TECH_CHANGE, false);
 
+        mCi.registerForRilConnected(this, EVENT_RIL_CONNECTED, null);
         mCi.registerForVoiceRadioTechChanged(this, EVENT_VOICE_RADIO_TECH_CHANGED, null);
         mContext.registerReceiver(mBroadcastReceiver, new IntentFilter(
                 CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED));
@@ -2132,6 +2134,16 @@
                 handleRadioOn();
                 break;
 
+            case EVENT_RIL_CONNECTED:
+                ar = (AsyncResult) msg.obj;
+                if (ar.exception == null && ar.result != null) {
+                    mRilVersion = (Integer) ar.result;
+                } else {
+                    logd("Unexpected exception on EVENT_RIL_CONNECTED");
+                    mRilVersion = -1;
+                }
+                break;
+
             case EVENT_VOICE_RADIO_TECH_CHANGED:
             case EVENT_REQUEST_VOICE_RADIO_TECH_DONE:
                 String what = (msg.what == EVENT_VOICE_RADIO_TECH_CHANGED) ?
@@ -3116,27 +3128,46 @@
             }
         }
 
-        // If the device is shutting down, then there is no need to switch to the new phone
-        // which might send unnecessary attach request to the modem.
-        if (isShuttingDown()) {
-            logd("Device is shutting down. No need to switch phone now.");
-            return;
-        }
+        if(mRilVersion == 6 && getLteOnCdmaMode() == PhoneConstants.LTE_ON_CDMA_TRUE) {
+            /*
+             * On v6 RIL, when LTE_ON_CDMA is TRUE, always create CDMALTEPhone
+             * irrespective of the voice radio tech reported.
+             */
+            if (getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
+                logd("phoneObjectUpdater: LTE ON CDMA property is set. Use CDMA Phone" +
+                        " newVoiceRadioTech=" + newVoiceRadioTech +
+                        " mActivePhone=" + getPhoneName());
+                return;
+            } else {
+                logd("phoneObjectUpdater: LTE ON CDMA property is set. Switch to CDMALTEPhone" +
+                        " newVoiceRadioTech=" + newVoiceRadioTech +
+                        " mActivePhone=" + getPhoneName());
+                newVoiceRadioTech = ServiceState.RIL_RADIO_TECHNOLOGY_1xRTT;
+            }
+        } else {
 
-        boolean matchCdma = ServiceState.isCdma(newVoiceRadioTech);
-        boolean matchGsm = ServiceState.isGsm(newVoiceRadioTech);
-        if ((matchCdma && getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) ||
-                (matchGsm && getPhoneType() == PhoneConstants.PHONE_TYPE_GSM)) {
-            // Nothing changed. Keep phone as it is.
-            logd("phoneObjectUpdater: No change ignore," +
-                    " newVoiceRadioTech=" + newVoiceRadioTech +
-                    " mActivePhone=" + getPhoneName());
-            return;
-        }
-        if (!matchCdma && !matchGsm) {
-            loge("phoneObjectUpdater: newVoiceRadioTech=" + newVoiceRadioTech +
-                    " doesn't match either CDMA or GSM - error! No phone change");
-            return;
+            // If the device is shutting down, then there is no need to switch to the new phone
+            // which might send unnecessary attach request to the modem.
+            if (isShuttingDown()) {
+                logd("Device is shutting down. No need to switch phone now.");
+                return;
+            }
+
+            boolean matchCdma = ServiceState.isCdma(newVoiceRadioTech);
+            boolean matchGsm = ServiceState.isGsm(newVoiceRadioTech);
+            if ((matchCdma && getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) ||
+                    (matchGsm && getPhoneType() == PhoneConstants.PHONE_TYPE_GSM)) {
+                // Nothing changed. Keep phone as it is.
+                logd("phoneObjectUpdater: No change ignore," +
+                        " newVoiceRadioTech=" + newVoiceRadioTech +
+                        " mActivePhone=" + getPhoneName());
+                return;
+            }
+            if (!matchCdma && !matchGsm) {
+                loge("phoneObjectUpdater: newVoiceRadioTech=" + newVoiceRadioTech +
+                        " doesn't match either CDMA or GSM - error! No phone change");
+                return;
+            }
         }
 
         if (newVoiceRadioTech == ServiceState.RIL_RADIO_TECHNOLOGY_UNKNOWN) {
diff --git a/src/java/com/android/internal/telephony/Phone.java b/src/java/com/android/internal/telephony/Phone.java
index 52114a8..f653265 100644
--- a/src/java/com/android/internal/telephony/Phone.java
+++ b/src/java/com/android/internal/telephony/Phone.java
@@ -187,6 +187,7 @@
     private static final int EVENT_CHECK_FOR_NETWORK_AUTOMATIC      = 38;
     protected static final int EVENT_VOICE_RADIO_TECH_CHANGED       = 39;
     protected static final int EVENT_REQUEST_VOICE_RADIO_TECH_DONE  = 40;
+    protected static final int EVENT_RIL_CONNECTED                  = 41;
     protected static final int EVENT_UPDATE_PHONE_OBJECT            = 42;
     protected static final int EVENT_CARRIER_CONFIG_CHANGED         = 43;
     // Carrier's CDMA prefer mode setting
diff --git a/src/java/com/android/internal/telephony/RIL.java b/src/java/com/android/internal/telephony/RIL.java
index 7ef5829..482055e 100644
--- a/src/java/com/android/internal/telephony/RIL.java
+++ b/src/java/com/android/internal/telephony/RIL.java
@@ -629,6 +629,9 @@
             }} catch (Throwable tr) {
                 Rlog.e(RILJ_LOG_TAG,"Uncaught exception", tr);
             }
+
+            /* We're disconnected so we don't know the ril version */
+            notifyRegistrantsRilConnectionChanged(-1);
         }
     }
 
@@ -4357,11 +4360,14 @@
 
     /**
      * Notify all registrants that the ril has connected or disconnected.
+     *
+     * @param rilVer is the version of the ril or -1 if disconnected.
      */
-    void notifyRegistrantsRilConnected() {
+    void notifyRegistrantsRilConnectionChanged(int rilVer) {
+        mRilVersion = rilVer;
         if (mRilConnectedRegistrants != null) {
             mRilConnectedRegistrants.notifyRegistrants(
-                    new AsyncResult(null, null, null));
+                    new AsyncResult(null, new Integer(rilVer), null));
         }
     }
 
diff --git a/src/java/com/android/internal/telephony/RadioIndication.java b/src/java/com/android/internal/telephony/RadioIndication.java
index 11e8b32..649948a 100644
--- a/src/java/com/android/internal/telephony/RadioIndication.java
+++ b/src/java/com/android/internal/telephony/RadioIndication.java
@@ -602,7 +602,9 @@
         mRil.setRadioPower(false, null);
         mRil.setCdmaSubscriptionSource(mRil.mCdmaSubscription, null);
         mRil.setCellInfoListRate();
-        mRil.notifyRegistrantsRilConnected();
+        // todo: this should not require a version number now. Setting it to latest RIL version for
+        // now.
+        mRil.notifyRegistrantsRilConnectionChanged(15);
     }
 
     public void voiceRadioTechChanged(int indicationType, int rat) {
diff --git a/src/java/com/android/internal/telephony/ServiceStateTracker.java b/src/java/com/android/internal/telephony/ServiceStateTracker.java
index a42f9e8..03eed9b 100644
--- a/src/java/com/android/internal/telephony/ServiceStateTracker.java
+++ b/src/java/com/android/internal/telephony/ServiceStateTracker.java
@@ -4137,26 +4137,32 @@
     public List<CellInfo> getAllCellInfo(WorkSource workSource) {
         CellInfoResult result = new CellInfoResult();
         if (VDBG) log("SST.getAllCellInfo(): E");
-        if (isCallerOnDifferentThread()) {
-            if ((SystemClock.elapsedRealtime() - mLastCellInfoListTime)
-                    > LAST_CELL_INFO_LIST_MAX_AGE_MS) {
-                Message msg = obtainMessage(EVENT_GET_CELL_INFO_LIST, result);
-                synchronized(result.lockObj) {
-                    result.list = null;
-                    mCi.getCellInfoList(msg, workSource);
-                    try {
-                        result.lockObj.wait(5000);
-                    } catch (InterruptedException e) {
-                        e.printStackTrace();
+        int ver = mCi.getRilVersion();
+        if (ver >= 8) {
+            if (isCallerOnDifferentThread()) {
+                if ((SystemClock.elapsedRealtime() - mLastCellInfoListTime)
+                        > LAST_CELL_INFO_LIST_MAX_AGE_MS) {
+                    Message msg = obtainMessage(EVENT_GET_CELL_INFO_LIST, result);
+                    synchronized(result.lockObj) {
+                        result.list = null;
+                        mCi.getCellInfoList(msg, workSource);
+                        try {
+                            result.lockObj.wait(5000);
+                        } catch (InterruptedException e) {
+                            e.printStackTrace();
+                        }
                     }
+                } else {
+                    if (DBG) log("SST.getAllCellInfo(): return last, back to back calls");
+                    result.list = mLastCellInfoList;
                 }
             } else {
-                if (DBG) log("SST.getAllCellInfo(): return last, back to back calls");
+                if (DBG) log("SST.getAllCellInfo(): return last, same thread can't block");
                 result.list = mLastCellInfoList;
             }
         } else {
-            if (DBG) log("SST.getAllCellInfo(): return last, same thread can't block");
-            result.list = mLastCellInfoList;
+            if (DBG) log("SST.getAllCellInfo(): not implemented");
+            result.list = null;
         }
         synchronized(result.lockObj) {
             if (result.list != null) {
diff --git a/src/java/com/android/internal/telephony/dataconnection/DataConnection.java b/src/java/com/android/internal/telephony/dataconnection/DataConnection.java
index 41185660..c1995b1 100644
--- a/src/java/com/android/internal/telephony/dataconnection/DataConnection.java
+++ b/src/java/com/android/internal/telephony/dataconnection/DataConnection.java
@@ -177,6 +177,7 @@
     static final int EVENT_GET_LAST_FAIL_DONE = BASE + 2;
     static final int EVENT_DEACTIVATE_DONE = BASE + 3;
     static final int EVENT_DISCONNECT = BASE + 4;
+    static final int EVENT_RIL_CONNECTED = BASE + 5;
     static final int EVENT_DISCONNECT_ALL = BASE + 6;
     static final int EVENT_DATA_STATE_CHANGED = BASE + 7;
     static final int EVENT_TEAR_DOWN_NOW = BASE + 8;
@@ -199,6 +200,7 @@
         sCmdToString[EVENT_GET_LAST_FAIL_DONE - BASE] = "EVENT_GET_LAST_FAIL_DONE";
         sCmdToString[EVENT_DEACTIVATE_DONE - BASE] = "EVENT_DEACTIVATE_DONE";
         sCmdToString[EVENT_DISCONNECT - BASE] = "EVENT_DISCONNECT";
+        sCmdToString[EVENT_RIL_CONNECTED - BASE] = "EVENT_RIL_CONNECTED";
         sCmdToString[EVENT_DISCONNECT_ALL - BASE] = "EVENT_DISCONNECT_ALL";
         sCmdToString[EVENT_DATA_STATE_CHANGED - BASE] = "EVENT_DATA_STATE_CHANGED";
         sCmdToString[EVENT_TEAR_DOWN_NOW - BASE] = "EVENT_TEAR_DOWN_NOW";
diff --git a/src/java/com/android/internal/telephony/dataconnection/DcController.java b/src/java/com/android/internal/telephony/dataconnection/DcController.java
index 354b765..291d6f5 100644
--- a/src/java/com/android/internal/telephony/dataconnection/DcController.java
+++ b/src/java/com/android/internal/telephony/dataconnection/DcController.java
@@ -157,6 +157,8 @@
     private class DccDefaultState extends State {
         @Override
         public void enter() {
+            mPhone.mCi.registerForRilConnected(getHandler(),
+                    DataConnection.EVENT_RIL_CONNECTED, null);
             mPhone.mCi.registerForDataCallListChanged(getHandler(),
                     DataConnection.EVENT_DATA_STATE_CHANGED, null);
             if (Build.IS_DEBUGGABLE) {
@@ -168,6 +170,7 @@
         @Override
         public void exit() {
             if (mPhone != null) {
+                mPhone.mCi.unregisterForRilConnected(getHandler());
                 mPhone.mCi.unregisterForDataCallListChanged(getHandler());
             }
             if (mDcTesterDeactivateAll != null) {
@@ -180,6 +183,18 @@
             AsyncResult ar;
 
             switch (msg.what) {
+                case DataConnection.EVENT_RIL_CONNECTED:
+                    ar = (AsyncResult)msg.obj;
+                    if (ar.exception == null) {
+                        if (DBG) {
+                            log("DccDefaultState: msg.what=EVENT_RIL_CONNECTED mRilVersion=" +
+                                ar.result);
+                        }
+                    } else {
+                        log("DccDefaultState: Unexpected exception on EVENT_RIL_CONNECTED");
+                    }
+                    break;
+
                 case DataConnection.EVENT_DATA_STATE_CHANGED:
                     ar = (AsyncResult)msg.obj;
                     if (ar.exception == null) {
diff --git a/src/java/com/android/internal/telephony/test/SimulatedCommands.java b/src/java/com/android/internal/telephony/test/SimulatedCommands.java
index 3731b32..334b629 100644
--- a/src/java/com/android/internal/telephony/test/SimulatedCommands.java
+++ b/src/java/com/android/internal/telephony/test/SimulatedCommands.java
@@ -1818,6 +1818,11 @@
     }
 
     @Override
+    public int getRilVersion() {
+        return 11;
+    }
+
+    @Override
     public void setCellInfoListRate(int rateInMillis, Message response, WorkSource workSource) {
         unimplemented(response);
     }
diff --git a/src/java/com/android/internal/telephony/test/SimulatedCommandsVerifier.java b/src/java/com/android/internal/telephony/test/SimulatedCommandsVerifier.java
index 229112a..f03c4ca 100644
--- a/src/java/com/android/internal/telephony/test/SimulatedCommandsVerifier.java
+++ b/src/java/com/android/internal/telephony/test/SimulatedCommandsVerifier.java
@@ -1267,6 +1267,11 @@
     }
 
     @Override
+    public int getRilVersion() {
+        return 0;
+    }
+
+    @Override
     public void setUiccSubscription(int slotId, int appIndex, int subId, int subStatus,
                                     Message result) {