Merge "Adds a cached phone factory." into master-nova
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 93320f7..2b5c0c8 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -550,5 +550,26 @@
         <!-- service to dump telephony information -->
         <service android:name="HfaService" android:exported="false"/>
 
+        <!-- Telecomm integration -->
+        <service android:name="com.android.services.telephony.TelephonyCallServiceProvider">
+            <intent-filter>
+                <action android:name="android.telecomm.ICallServiceProvider" />
+            </intent-filter>
+        </service>
+        <service android:name="com.android.services.telephony.GsmCallService">
+            <intent-filter>
+                <action android:name="android.telecomm.ICallService" />
+            </intent-filter>
+        </service>
+        <service android:name="com.android.services.telephony.CdmaCallService">
+            <intent-filter>
+                <action android:name="android.telecomm.ICallService" />
+            </intent-filter>
+        </service>
+        <service android:name="com.android.services.telephony.SipCallService">
+            <intent-filter>
+                <action android:name="android.telecomm.ICallService" />
+            </intent-filter>
+        </service>
     </application>
 </manifest>
diff --git a/src/com/android/phone/CallModeler.java b/src/com/android/phone/CallModeler.java
index 3e37f29..edf0656 100644
--- a/src/com/android/phone/CallModeler.java
+++ b/src/com/android/phone/CallModeler.java
@@ -132,9 +132,12 @@
     public void addListener(Listener listener) {
         Preconditions.checkNotNull(listener);
         Preconditions.checkNotNull(mListeners);
+        // Disable updates to avoid interference between Telecomm and Telephony.
+        /*
         if (!mListeners.contains(listener)) {
             mListeners.add(listener);
         }
+        */
     }
 
     public List<Call> getFullList() {
diff --git a/src/com/android/services/telephony/BaseTelephonyCallService.java b/src/com/android/services/telephony/BaseTelephonyCallService.java
index 104bcde..a1b1d7c 100644
--- a/src/com/android/services/telephony/BaseTelephonyCallService.java
+++ b/src/com/android/services/telephony/BaseTelephonyCallService.java
@@ -65,10 +65,9 @@
 
     /** {@inheritDoc} */
     @Override
-    public void disconnect(String callId) {
-        // Maybe null if the connection has already disconnected.
+    public void abort(String callId) {
         if (sCallConnections.containsKey(callId)) {
-            sCallConnections.get(callId).disconnect();
+            sCallConnections.get(callId).disconnect(true);
         }
     }
 
@@ -82,6 +81,15 @@
     public void reject(String callId) {
     }
 
+    /** {@inheritDoc} */
+    @Override
+    public void disconnect(String callId) {
+        // Maybe null if the connection has already disconnected.
+        if (sCallConnections.containsKey(callId)) {
+            sCallConnections.get(callId).disconnect(false);
+        }
+    }
+
     /**
      * Initiates the call, should be called by the subclass.
      */
diff --git a/src/com/android/services/telephony/TelephonyCallConnection.java b/src/com/android/services/telephony/TelephonyCallConnection.java
index 278943b..3abeb14 100644
--- a/src/com/android/services/telephony/TelephonyCallConnection.java
+++ b/src/com/android/services/telephony/TelephonyCallConnection.java
@@ -34,10 +34,11 @@
     private static final String TAG = TelephonyCallConnection.class.getSimpleName();
     private static final int EVENT_PRECISE_CALL_STATE_CHANGED = 1;
 
-    private final ICallServiceAdapter mCallServiceAdapter;
     private final String mCallId;
     private final StateHandler mHandler = new StateHandler();
 
+    private ICallServiceAdapter mCallServiceAdapter;
+
     private Connection mConnection;
     private Call.State mOldState = Call.State.IDLE;
 
@@ -55,7 +56,10 @@
         return mCallId;
     }
 
-    void disconnect() {
+    void disconnect(boolean shouldAbort) {
+        if (shouldAbort) {
+            mCallServiceAdapter = null;
+        }
         if (mConnection != null) {
             try {
                 mConnection.hangup();
@@ -66,7 +70,7 @@
     }
 
     private void updateState() {
-        if (mConnection == null) {
+        if (mConnection == null || mCallServiceAdapter == null) {
             return;
         }