Code cleanup including removing direct references to IMS classes.

Also removing code in PstnIncomingCallNotifier to unregister and
re-register on phone type switch as that is not required now.

Bug: 25793157
Change-Id: Ic0c0fd5067d65b950a2a0ddb2bec528c22b694d4
diff --git a/src/com/android/phone/INetworkQueryService.aidl b/src/com/android/phone/INetworkQueryService.aidl
index 81eb8e6..b0fe992 100644
--- a/src/com/android/phone/INetworkQueryService.aidl
+++ b/src/com/android/phone/INetworkQueryService.aidl
@@ -21,8 +21,7 @@
 /**
  * Service interface to handle queries for available networks.  The
  * Phone application lets this service interface handle carrier 
- * availability queries instead of making direct calls to the 
- * GSMPhone layer.
+ * availability queries instead of making direct calls to the Phone layer.
  */
 oneway interface INetworkQueryService {
  
diff --git a/src/com/android/phone/PhoneUtils.java b/src/com/android/phone/PhoneUtils.java
index 474b9d0..983967c 100644
--- a/src/com/android/phone/PhoneUtils.java
+++ b/src/com/android/phone/PhoneUtils.java
@@ -1897,7 +1897,7 @@
      *
      * @return true if we find a connection that is disconnected, and
      * pending removal via
-     * {@link com.android.internal.telephony.gsm.GsmCall#clearDisconnected()}.
+     * {@link com.android.internal.telephony.Call#clearDisconnected()}.
      */
     private static final boolean hasDisconnectedConnections(Call call) {
         // look through all connections for non-active ones.
diff --git a/src/com/android/services/telephony/ImsConference.java b/src/com/android/services/telephony/ImsConference.java
index f676c57..dcc71a0 100644
--- a/src/com/android/services/telephony/ImsConference.java
+++ b/src/com/android/services/telephony/ImsConference.java
@@ -34,8 +34,6 @@
 import com.android.internal.telephony.CallStateException;
 import com.android.internal.telephony.Phone;
 import com.android.internal.telephony.PhoneConstants;
-import com.android.internal.telephony.imsphone.ImsPhone;
-import com.android.internal.telephony.imsphone.ImsPhoneConnection;
 import com.android.phone.PhoneUtils;
 import com.android.phone.R;
 
@@ -476,12 +474,8 @@
         }
         com.android.internal.telephony.Connection originalConnection =
                 mConferenceHost.getOriginalConnection();
-        if (!(originalConnection instanceof ImsPhoneConnection)) {
-            return false;
-        }
 
-        ImsPhoneConnection imsPhoneConnection = (ImsPhoneConnection) originalConnection;
-        return imsPhoneConnection.isMultiparty() && imsPhoneConnection.isConferenceHost();
+        return originalConnection.isMultiparty() && originalConnection.isConferenceHost();
     }
 
     /**
@@ -528,10 +522,11 @@
         // Attempt to get the conference host's address (e.g. the host's own phone number).
         // We need to look at the default phone for the ImsPhone when creating the phone account
         // for the
-        if (mConferenceHost.getPhone() != null &&  mConferenceHost.getPhone() instanceof ImsPhone) {
+        if (mConferenceHost.getPhone() != null &&
+                mConferenceHost.getPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_IMS) {
             // Look up the conference host's address; we need this later for filtering out the
             // conference host in conference event package data.
-            ImsPhone imsPhone = (ImsPhone) mConferenceHost.getPhone();
+            Phone imsPhone = mConferenceHost.getPhone();
             mConferenceHostPhoneAccountHandle =
                     PhoneUtils.makePstnPhoneAccountHandle(imsPhone.getDefaultPhone());
             mConferenceHostAddress = TelecomAccountRegistry.getInstance(mTelephonyConnectionService)
@@ -768,7 +763,7 @@
         com.android.internal.telephony.Connection originalConnection =
                 mConferenceHost.getOriginalConnection();
 
-        if (!(originalConnection instanceof ImsPhoneConnection)) {
+        if (originalConnection.getPhoneType() != PhoneConstants.PHONE_TYPE_IMS) {
             if (Log.VERBOSE) {
                 Log.v(this,
                         "Original connection for conference host is no longer an IMS connection; " +
@@ -777,8 +772,8 @@
 
             PhoneAccountHandle phoneAccountHandle = null;
             if (mConferenceHost.getPhone() != null &&
-                    mConferenceHost.getPhone() instanceof ImsPhone) {
-                ImsPhone imsPhone = (ImsPhone) mConferenceHost.getPhone();
+                    mConferenceHost.getPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_IMS) {
+                Phone imsPhone = mConferenceHost.getPhone();
                 // The phone account handle for an ImsPhone is based on the default phone (ie the
                 // base GSM or CDMA phone, not on the ImsPhone itself).
                 phoneAccountHandle =
diff --git a/src/com/android/services/telephony/ImsConferenceController.java b/src/com/android/services/telephony/ImsConferenceController.java
index a629a5d..0c25fbb 100644
--- a/src/com/android/services/telephony/ImsConferenceController.java
+++ b/src/com/android/services/telephony/ImsConferenceController.java
@@ -16,8 +16,8 @@
 
 package com.android.services.telephony;
 
-import com.android.internal.telephony.imsphone.ImsPhone;
-import com.android.internal.telephony.imsphone.ImsPhoneConnection;
+import com.android.internal.telephony.Phone;
+import com.android.internal.telephony.PhoneConstants;
 import com.android.phone.PhoneUtils;
 
 import android.telecom.Conference;
@@ -273,12 +273,8 @@
         TelephonyConnection telephonyConnection = (TelephonyConnection) connection;
         com.android.internal.telephony.Connection originalConnection =
                 telephonyConnection.getOriginalConnection();
-        if (!(originalConnection instanceof ImsPhoneConnection)) {
-            return false;
-        }
 
-        ImsPhoneConnection imsPhoneConnection = (ImsPhoneConnection) originalConnection;
-        return imsPhoneConnection.isMultiparty() && !imsPhoneConnection.isConferenceHost();
+        return originalConnection.isMultiparty() && originalConnection.isMemberOfPeerConference();
     }
 
     /**
@@ -328,8 +324,8 @@
 
         // Attempt to determine the phone account associated with the conference host connection.
         if (connection.getPhone() != null &&
-                connection.getPhone() instanceof ImsPhone) {
-            ImsPhone imsPhone = (ImsPhone) connection.getPhone();
+                connection.getPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_IMS) {
+            Phone imsPhone = connection.getPhone();
             // The phone account handle for an ImsPhone is based on the default phone (ie the
             // base GSM or CDMA phone, not on the ImsPhone itself).
             phoneAccountHandle =
diff --git a/src/com/android/services/telephony/PstnIncomingCallNotifier.java b/src/com/android/services/telephony/PstnIncomingCallNotifier.java
index 6e43e36..af59e65 100644
--- a/src/com/android/services/telephony/PstnIncomingCallNotifier.java
+++ b/src/com/android/services/telephony/PstnIncomingCallNotifier.java
@@ -16,10 +16,6 @@
 
 package com.android.services.telephony;
 
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
 import android.net.Uri;
 import android.os.AsyncResult;
 import android.os.Bundle;
@@ -32,8 +28,6 @@
 import com.android.internal.telephony.Call;
 import com.android.internal.telephony.Connection;
 import com.android.internal.telephony.Phone;
-import com.android.internal.telephony.PhoneConstants;
-import com.android.internal.telephony.TelephonyIntents;
 import com.android.internal.telephony.cdma.CdmaCallWaitingNotification;
 import com.android.phone.PhoneUtils;
 
@@ -55,15 +49,7 @@
     private final Phone mPhone;
 
     /**
-     * The base phone implementation behind phone proxy. The underlying phone implementation can
-     * change underneath when the radio technology changes. We listen for these events and update
-     * the base phone in this variable. We save it so that when the change happens, we can
-     * unregister from the events we were listening to.
-     */
-    private Phone mPhoneBase;
-
-    /**
-     * Used to listen to events from {@link #mPhoneBase}.
+     * Used to listen to events from {@link #mPhone}.
      */
     private final Handler mHandler = new Handler() {
         @Override
@@ -85,22 +71,6 @@
     };
 
     /**
-     * Receiver to listen for radio technology change events.
-     */
-    private final BroadcastReceiver mRATReceiver = new BroadcastReceiver() {
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            String action = intent.getAction();
-            if (TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED.equals(action)) {
-                String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY);
-                Log.d(this, "Radio technology switched. Now %s is active.", newPhone);
-
-                registerForNotifications();
-            }
-        }
-    };
-
-    /**
      * Persists the specified parameters and starts listening to phone events.
      *
      * @param phone The phone object for listening to incoming calls.
@@ -111,51 +81,30 @@
         mPhone = phone;
 
         registerForNotifications();
-
-        IntentFilter intentFilter =
-                new IntentFilter(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
-        mPhone.getContext().registerReceiver(mRATReceiver, intentFilter);
     }
 
     void teardown() {
         unregisterForNotifications();
-        mPhone.getContext().unregisterReceiver(mRATReceiver);
     }
 
     /**
      * Register for notifications from the base phone.
-     * TODO: We should only need to interact with the phoneproxy directly. However,
-     * since the phoneproxy only interacts directly with CallManager we either listen to callmanager
-     * or we have to poke into the proxy like this.  Neither is desirable. It would be better if
-     * this class and callManager could register generically with the phone proxy instead and get
-     * radio techonology changes directly.  Or better yet, just register for the notifications
-     * directly with phone proxy and never worry about the technology changes. This requires a
-     * change in opt/telephony code.
      */
     private void registerForNotifications() {
-        Phone newPhone = mPhone;
-        if (newPhone != mPhoneBase) {
-            unregisterForNotifications();
-
-            if (newPhone != null) {
-                Log.i(this, "Registering: %s", newPhone);
-                mPhoneBase = newPhone;
-                mPhoneBase.registerForNewRingingConnection(
-                        mHandler, EVENT_NEW_RINGING_CONNECTION, null);
-                mPhoneBase.registerForCallWaiting(
-                        mHandler, EVENT_CDMA_CALL_WAITING, null);
-                mPhoneBase.registerForUnknownConnection(mHandler, EVENT_UNKNOWN_CONNECTION,
-                        null);
-            }
+        if (mPhone != null) {
+            Log.i(this, "Registering: %s", mPhone);
+            mPhone.registerForNewRingingConnection(mHandler, EVENT_NEW_RINGING_CONNECTION, null);
+            mPhone.registerForCallWaiting(mHandler, EVENT_CDMA_CALL_WAITING, null);
+            mPhone.registerForUnknownConnection(mHandler, EVENT_UNKNOWN_CONNECTION, null);
         }
     }
 
     private void unregisterForNotifications() {
-        if (mPhoneBase != null) {
-            Log.i(this, "Unregistering: %s", mPhoneBase);
-            mPhoneBase.unregisterForNewRingingConnection(mHandler);
-            mPhoneBase.unregisterForCallWaiting(mHandler);
-            mPhoneBase.unregisterForUnknownConnection(mHandler);
+        if (mPhone != null) {
+            Log.i(this, "Unregistering: %s", mPhone);
+            mPhone.unregisterForNewRingingConnection(mHandler);
+            mPhone.unregisterForCallWaiting(mHandler);
+            mPhone.unregisterForUnknownConnection(mHandler);
         }
     }
 
@@ -180,7 +129,7 @@
     private void handleCdmaCallWaiting(AsyncResult asyncResult) {
         Log.d(this, "handleCdmaCallWaiting");
         CdmaCallWaitingNotification ccwi = (CdmaCallWaitingNotification) asyncResult.result;
-        Call call = mPhoneBase.getRingingCall();
+        Call call = mPhone.getRingingCall();
         if (call.getState() == Call.State.WAITING) {
             Connection connection = call.getLatestConnection();
             if (connection != null) {
diff --git a/src/com/android/services/telephony/TelephonyConnection.java b/src/com/android/services/telephony/TelephonyConnection.java
index e77df16..d6ef942 100644
--- a/src/com/android/services/telephony/TelephonyConnection.java
+++ b/src/com/android/services/telephony/TelephonyConnection.java
@@ -35,10 +35,10 @@
 import com.android.internal.telephony.Call;
 import com.android.internal.telephony.CallStateException;
 import com.android.internal.telephony.Connection.PostDialListener;
+import com.android.internal.telephony.PhoneConstants;
 import com.android.internal.telephony.gsm.SuppServiceNotification;
 
 import com.android.internal.telephony.Phone;
-import com.android.internal.telephony.imsphone.ImsPhoneConnection;
 import com.android.phone.R;
 
 import java.lang.Override;
@@ -1211,7 +1211,7 @@
      *     otherwise.
      */
     protected boolean isImsConnection() {
-        return getOriginalConnection() instanceof ImsPhoneConnection;
+        return getOriginalConnection().getPhoneType() == PhoneConstants.PHONE_TYPE_IMS;
     }
 
     /**