Allow starting of test incoming calls directly via adb

Bug: 16825519

Change-Id: I789bfed9fbe19c7775bb83455462cda39a22fb2f
diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml
index d8877fb..51d1ccf 100644
--- a/tests/AndroidManifest.xml
+++ b/tests/AndroidManifest.xml
@@ -58,6 +58,11 @@
                 <category android:name="android.intent.category.DEFAULT" />
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
+            <intent-filter>
+                <action android:name="android.telecomm.testapps.ACTION_START_INCOMING_CALL" />
+                <category android:name="android.intent.category.DEFAULT" />
+                <data android:scheme="tel" />
+            </intent-filter>
         </activity>
 
         <receiver android:name="com.android.telecomm.testapps.CallNotificationReceiver"
diff --git a/tests/src/com/android/telecomm/testapps/CallNotificationReceiver.java b/tests/src/com/android/telecomm/testapps/CallNotificationReceiver.java
index fb44069..5b49434 100644
--- a/tests/src/com/android/telecomm/testapps/CallNotificationReceiver.java
+++ b/tests/src/com/android/telecomm/testapps/CallNotificationReceiver.java
@@ -20,6 +20,7 @@
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
+import android.net.Uri;
 import android.os.Bundle;
 import android.telecomm.PhoneAccountHandle;
 import android.telecomm.TelecommManager;
@@ -55,19 +56,19 @@
         } else if (ACTION_SHOW_ALL_PHONE_ACCOUNTS.equals(action)) {
             CallServiceNotifier.getInstance().showAllPhoneAccounts(context);
         } else if (ACTION_VIDEO_CALL.equals(action)) {
-            sendIncomingCallIntent(context, true);
+            sendIncomingCallIntent(context, null, true);
         } else if (ACTION_AUDIO_CALL.equals(action)) {
-            sendIncomingCallIntent(context, false);
+            sendIncomingCallIntent(context, null, false);
         }
     }
 
     /**
-     * Creates the intent to add an incoming call through Telecomm.
+     * Creates and sends the intent to add an incoming call through Telecomm.
      *
      * @param context The current context.
      * @param isVideoCall {@code True} if this is a video call.
      */
-    private void sendIncomingCallIntent(Context context, boolean isVideoCall) {
+    public static void sendIncomingCallIntent(Context context, Uri handle, boolean isVideoCall) {
         PhoneAccountHandle phoneAccount = new PhoneAccountHandle(
                 new ComponentName(context, TestConnectionService.class),
                 CallServiceNotifier.SIM_SUBSCRIPTION_ID);
@@ -75,7 +76,10 @@
         // For the purposes of testing, indicate whether the incoming call is a video call by
         // stashing an indicator in the EXTRA_INCOMING_CALL_EXTRAS.
         Bundle extras = new Bundle();
-        extras.putBoolean(TestConnectionService.IS_VIDEO_CALL, isVideoCall);
+        extras.putBoolean(TestConnectionService.EXTRA_IS_VIDEO_CALL, isVideoCall);
+        if (handle != null) {
+            extras.putParcelable(TestConnectionService.EXTRA_HANDLE, handle);
+        }
 
         TelecommManager.from(context).addNewIncomingCall(phoneAccount, extras);
     }
diff --git a/tests/src/com/android/telecomm/testapps/TestCallActivity.java b/tests/src/com/android/telecomm/testapps/TestCallActivity.java
index b85888d..4caf3e8 100644
--- a/tests/src/com/android/telecomm/testapps/TestCallActivity.java
+++ b/tests/src/com/android/telecomm/testapps/TestCallActivity.java
@@ -17,21 +17,41 @@
 package com.android.telecomm.testapps;
 
 import android.app.Activity;
+import android.content.Intent;
+import android.net.Uri;
 import android.os.Bundle;
+import android.util.Log;
 
 /**
  * This activity exists in order to add an icon to the launcher. This activity has no UI of its own
  * and instead starts the notification for {@link TestConnectionService} via
  * {@link CallServiceNotifier}. After triggering a notification update, this activity immediately
  * finishes.
+ *
+ * To directly trigger a new incoming call, use the following adb command:
+ *
+ * adb shell am start -a android.telecomm.testapps.ACTION_START_INCOMING_CALL -d "tel:123456789"
  */
 public class TestCallActivity extends Activity {
 
+    public static final String ACTION_NEW_INCOMING_CALL =
+            "android.telecomm.testapps.ACTION_START_INCOMING_CALL";
+
     @Override
     protected void onCreate(Bundle icicle) {
         super.onCreate(icicle);
-
+        final Intent intent = getIntent();
+        if (intent != null && intent.getData() != null) {
+            startIncomingCallBroadcast(intent.getData());
+        }
         CallServiceNotifier.getInstance().updateNotification(this);
         finish();
     }
+
+    /**
+     * Bypass the notification and start the test incoming call directly.
+     */
+    private void startIncomingCallBroadcast(Uri handle) {
+        CallNotificationReceiver.sendIncomingCallIntent(this, handle, false);
+    }
 }
diff --git a/tests/src/com/android/telecomm/testapps/TestConnectionService.java b/tests/src/com/android/telecomm/testapps/TestConnectionService.java
index c50e7ab..e5d54e9 100644
--- a/tests/src/com/android/telecomm/testapps/TestConnectionService.java
+++ b/tests/src/com/android/telecomm/testapps/TestConnectionService.java
Binary files differ