Merge "Exercise voicemail permissions in Test Dialer" into mnc-dev
diff --git a/src/com/android/server/telecom/CallIntentProcessor.java b/src/com/android/server/telecom/CallIntentProcessor.java
index 525359f..b354bf5 100644
--- a/src/com/android/server/telecom/CallIntentProcessor.java
+++ b/src/com/android/server/telecom/CallIntentProcessor.java
@@ -26,7 +26,11 @@
 
     public static final String KEY_IS_UNKNOWN_CALL = "is_unknown_call";
     public static final String KEY_IS_INCOMING_CALL = "is_incoming_call";
-    public static final String KEY_IS_DEFAULT_DIALER = "is_default_dialer";
+    /*
+     *  Whether or not the dialer initiating this outgoing call is the default dialer, or system
+     *  dialer and thus allowed to make emergency calls.
+     */
+    public static final String KEY_IS_PRIVILEGED_DIALER = "is_privileged_dialer";
 
     private final Context mContext;
     private final CallsManager mCallsManager;
@@ -83,7 +87,7 @@
             clientExtras = new Bundle();
         }
 
-        final boolean isDefaultDialer = intent.getBooleanExtra(KEY_IS_DEFAULT_DIALER, false);
+        final boolean isPrivilegedDialer = intent.getBooleanExtra(KEY_IS_PRIVILEGED_DIALER, false);
 
         // Send to CallsManager to ensure the InCallUI gets kicked off before the broadcast returns
         Call call = callsManager.startOutgoingCall(handle, phoneAccountHandle, clientExtras);
@@ -95,7 +99,7 @@
             // process will be running throughout the duration of the phone call and should never
             // be killed.
             NewOutgoingCallIntentBroadcaster broadcaster = new NewOutgoingCallIntentBroadcaster(
-                    context, callsManager, call, intent, isDefaultDialer);
+                    context, callsManager, call, intent, isPrivilegedDialer);
             final int result = broadcaster.processIntent();
             final boolean success = result == DisconnectCause.NOT_DISCONNECTED;
 
diff --git a/src/com/android/server/telecom/InCallController.java b/src/com/android/server/telecom/InCallController.java
index 22ee132..9a5aa4f 100644
--- a/src/com/android/server/telecom/InCallController.java
+++ b/src/com/android/server/telecom/InCallController.java
@@ -33,6 +33,7 @@
 import android.telecom.AudioState;
 import android.telecom.CallProperties;
 import android.telecom.Connection;
+import android.telecom.DefaultDialerManager;
 import android.telecom.InCallService;
 import android.telecom.ParcelableCall;
 import android.telecom.TelecomManager;
@@ -298,10 +299,11 @@
                         continue;
                     }
 
-                    if (!hasControlInCallPermission) {
-                        Log.w(this,
-                                "InCall UI does not have CONTROL_INCALL_EXPERIENCE permission: " +
-                                        serviceInfo.packageName);
+                    if (!hasControlInCallPermission
+                            && !DefaultDialerManager.isDefaultOrSystemDialer(mContext,
+                                    serviceInfo.packageName)) {
+                        Log.w(this, "Service does not have CONTROL_INCALL_EXPERIENCE permission: %s"
+                                + " and is not system or default dialer.", serviceInfo.packageName);
                         continue;
                     }
 
diff --git a/src/com/android/server/telecom/TelecomServiceImpl.java b/src/com/android/server/telecom/TelecomServiceImpl.java
index f267efc..a012e5f 100644
--- a/src/com/android/server/telecom/TelecomServiceImpl.java
+++ b/src/com/android/server/telecom/TelecomServiceImpl.java
@@ -1046,7 +1046,7 @@
                         Binder.getCallingUid(), defaultDialerComponent.getPackageName());
                 return true;
             } catch (SecurityException e) {
-                Log.e(this, e, "Could not get default dialer.");
+                Log.i(this, "Calling uid %d is not the default dialer.", Binder.getCallingUid());
             }
         }
         return false;
diff --git a/src/com/android/server/telecom/components/UserCallIntentProcessor.java b/src/com/android/server/telecom/components/UserCallIntentProcessor.java
index a3e9b1b..d50073d 100644
--- a/src/com/android/server/telecom/components/UserCallIntentProcessor.java
+++ b/src/com/android/server/telecom/components/UserCallIntentProcessor.java
@@ -48,11 +48,11 @@
  * calls via ACTION_CALL_PRIVILEGED.
  *
  * In addition, the default dialer (identified via
- * {@link android.telecom.TelecomManager#getDefaultPhoneApp()} will also be granted the ability to
- * make emergency outgoing calls using the CALL action. In order to do this, it must call
- * startActivityForResult on the CALL intent to allow its package name to be passed to
- * {@link UserCallIntentProcessor}. Calling startActivity will continue to work on all
- * non-emergency numbers just like it did pre-L.
+ * {@link android.telecom.TelecomManager#getDefaultDialerPackage()} will also be granted the
+ * ability to make emergency outgoing calls using the CALL action. In order to do this, it must
+ * use the {@link TelecomManager#placeCall(Uri, android.os.Bundle)} method to allow its package
+ * name to be passed to {@link UserCallIntentProcessor}. Calling startActivity will continue to
+ * work on all non-emergency numbers just like it did pre-L.
  */
 public class UserCallIntentProcessor {
 
@@ -126,7 +126,8 @@
             return;
         }
 
-        intent.putExtra(CallIntentProcessor.KEY_IS_DEFAULT_DIALER, isDefaultDialer(callingPackageName));
+        intent.putExtra(CallIntentProcessor.KEY_IS_PRIVILEGED_DIALER,
+                isDefaultOrSystemDialer(callingPackageName));
         sendBroadcastToReceiver(intent);
     }
 
@@ -137,16 +138,18 @@
                 TelecomManager.TTY_MODE_OFF) != TelecomManager.TTY_MODE_OFF);
     }
 
-    private boolean isDefaultDialer(String callingPackageName) {
+    private boolean isDefaultOrSystemDialer(String callingPackageName) {
         if (TextUtils.isEmpty(callingPackageName)) {
             return false;
         }
 
         final TelecomManager telecomManager =
                 (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
-        final ComponentName defaultPhoneApp = telecomManager.getDefaultPhoneApp();
-        return (defaultPhoneApp != null
-                && TextUtils.equals(defaultPhoneApp.getPackageName(), callingPackageName));
+        if (TextUtils.equals(telecomManager.getDefaultDialerPackage(), callingPackageName)) {
+            return true;
+        }
+
+        return TextUtils.equals(telecomManager.getSystemDialerPackage(), callingPackageName);
     }
 
     /**
diff --git a/testapps/AndroidManifest.xml b/testapps/AndroidManifest.xml
index 130cf48..aafcecc 100644
--- a/testapps/AndroidManifest.xml
+++ b/testapps/AndroidManifest.xml
@@ -56,6 +56,7 @@
         </service>
 
         <activity android:name="com.android.server.telecom.testapps.TestCallActivity"
+                  android:theme="@android:style/Theme.NoDisplay"
                   android:label="@string/testCallActivityLabel"
                   android:process="com.android.server.telecom.testapps.TestInCallService">
             <intent-filter>