Merge cherrypicks of ['googleplex-android-review.googlesource.com/21224930', 'googleplex-android-review.googlesource.com/20659351'] into tm-qpr2-release.

Change-Id: Ibd249f3f4d97ee143a885b89e040a4ae8cfbde1d
diff --git a/src/com/android/server/telecom/CallScreeningServiceHelper.java b/src/com/android/server/telecom/CallScreeningServiceHelper.java
index c1aff3d..0168590 100644
--- a/src/com/android/server/telecom/CallScreeningServiceHelper.java
+++ b/src/com/android/server/telecom/CallScreeningServiceHelper.java
@@ -137,6 +137,23 @@
                                 "Cancelling outgoing call screen due to service disconnect.");
                     }
                     mFuture.complete(null);
+                    mContext.unbindService(this);
+                } finally {
+                    Log.endSession();
+                }
+            }
+
+            @Override
+            public void onNullBinding(ComponentName name) {
+                // No locking needed -- CompletableFuture only lets one thread call complete.
+                Log.continueSession(mLoggingSession, "CSSH.oNB");
+                try {
+                    if (!mFuture.isDone()) {
+                        Log.w(CallScreeningServiceHelper.this,
+                                "Cancelling outgoing call screen due to null binding.");
+                    }
+                    mFuture.complete(null);
+                    mContext.unbindService(this);
                 } finally {
                     Log.endSession();
                 }
diff --git a/src/com/android/server/telecom/NewOutgoingCallIntentBroadcaster.java b/src/com/android/server/telecom/NewOutgoingCallIntentBroadcaster.java
index 86fedd5..4569950 100644
--- a/src/com/android/server/telecom/NewOutgoingCallIntentBroadcaster.java
+++ b/src/com/android/server/telecom/NewOutgoingCallIntentBroadcaster.java
@@ -314,8 +314,18 @@
     }
 
     private String getNumberFromCallIntent(Intent intent) {
-        String number;
-        number = mPhoneNumberUtilsAdapter.getNumberFromIntent(intent, mContext);
+        String number = null;
+
+        Uri uri = intent.getData();
+        if (uri != null) {
+            String scheme = uri.getScheme();
+            if (scheme != null) {
+                if (scheme.equals("tel") || scheme.equals("sip")) {
+                    number = uri.getSchemeSpecificPart();
+                }
+            }
+        }
+
         if (TextUtils.isEmpty(number)) {
             Log.w(this, "Empty number obtained from the call intent.");
             return null;
diff --git a/src/com/android/server/telecom/callfiltering/CallScreeningServiceFilter.java b/src/com/android/server/telecom/callfiltering/CallScreeningServiceFilter.java
index 51b1bc6..5f4c40b 100644
--- a/src/com/android/server/telecom/callfiltering/CallScreeningServiceFilter.java
+++ b/src/com/android/server/telecom/callfiltering/CallScreeningServiceFilter.java
@@ -235,12 +235,14 @@
         public void onServiceDisconnected(ComponentName componentName) {
             mResultFuture.complete(mPriorStageResult);
             Log.i(this, "Service disconnected.");
+            unbindCallScreeningService();
         }
 
         @Override
         public void onBindingDied(ComponentName name) {
             mResultFuture.complete(mPriorStageResult);
             Log.i(this, "Binding died.");
+            unbindCallScreeningService();
         }
 
         @Override
diff --git a/tests/src/com/android/server/telecom/tests/NewOutgoingCallIntentBroadcasterTest.java b/tests/src/com/android/server/telecom/tests/NewOutgoingCallIntentBroadcasterTest.java
index e6c6bac..2614abf 100644
--- a/tests/src/com/android/server/telecom/tests/NewOutgoingCallIntentBroadcasterTest.java
+++ b/tests/src/com/android/server/telecom/tests/NewOutgoingCallIntentBroadcasterTest.java
@@ -214,6 +214,19 @@
         verifyNoCallPlaced();
     }
 
+    @Test
+    public void testNoCallsPlacedWithContentUri() {
+        Uri handle = Uri.parse("content://com.android.contacts/data/1");
+        Intent intent = new Intent(Intent.ACTION_CALL, handle);
+
+        int result = processIntent(intent, true).disconnectCause;
+
+        assertEquals(DisconnectCause.NO_PHONE_NUMBER_SUPPLIED, result);
+        verify(mContext, never()).getContentResolver();
+        verifyNoBroadcastSent();
+        verifyNoCallPlaced();
+    }
+
     @SmallTest
     @Test
     public void testEmergencyCallWithNonDefaultDialer() {