Modify ActivityInstrumentationTestCase2 to not require hardcoded package name.

Deprecate old constructor.

Bug 2440167
diff --git a/api/current.xml b/api/current.xml
index 7f63a78..08de474 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -140893,7 +140893,7 @@
  type="android.test.ActivityInstrumentationTestCase2"
  static="false"
  final="false"
- deprecated="not deprecated"
+ deprecated="deprecated"
  visibility="public"
 >
 <parameter name="pkg" type="java.lang.String">
@@ -140901,6 +140901,16 @@
 <parameter name="activityClass" type="java.lang.Class&lt;T&gt;">
 </parameter>
 </constructor>
+<constructor name="ActivityInstrumentationTestCase2"
+ type="android.test.ActivityInstrumentationTestCase2"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="activityClass" type="java.lang.Class&lt;T&gt;">
+</parameter>
+</constructor>
 <method name="getActivity"
  return="T"
  abstract="false"
diff --git a/test-runner/android/test/ActivityInstrumentationTestCase.java b/test-runner/android/test/ActivityInstrumentationTestCase.java
index f6b31ad..d12ff6f 100644
--- a/test-runner/android/test/ActivityInstrumentationTestCase.java
+++ b/test-runner/android/test/ActivityInstrumentationTestCase.java
@@ -40,29 +40,26 @@
     boolean mInitialTouchMode = false;
 
     /**
-     * <b>NOTE:</b> The parameter <i>pkg</i> must refer to the package identifier of the
-     * package hosting the activity to be launched, which is specified in the AndroidManifest.xml
-     * file.  This is not necessarily the same as the java package name.
+     * Creates an {@link ActivityInstrumentationTestCase} in non-touch mode.
      * 
-     * @param pkg The package hosting the activity to be launched.
-     * @param activityClass The activity to test.
+     * @param pkg ignored - no longer in use.
+     * @param activityClass The activity to test. This must be a class in the instrumentation
+     * targetPackage specified in the AndroidManifest.xml
      */
     public ActivityInstrumentationTestCase(String pkg, Class<T> activityClass) {
         this(pkg, activityClass, false);
     }
 
     /**
-     * <b>NOTE:</b> The parameter <i>pkg</i> must refer to the package identifier of the
-     * package hosting the activity to be launched, which is specified in the AndroidManifest.xml
-     * file.  This is not necessarily the same as the java package name.
-     * 
-     * @param pkg The package hosting the activity to be launched.
-     * @param activityClass The activity to test.
+     * Creates an {@link ActivityInstrumentationTestCase}.
+     *
+     * @param pkg ignored - no longer in use.
+     * @param activityClass The activity to test. This must be a class in the instrumentation
+     * targetPackage specified in the AndroidManifest.xml
      * @param initialTouchMode true = in touch mode
      */
     public ActivityInstrumentationTestCase(String pkg, Class<T> activityClass, 
             boolean initialTouchMode) {
-        mPackage = pkg;
         mActivityClass = activityClass;
         mInitialTouchMode = initialTouchMode;
     }
@@ -77,7 +74,8 @@
         super.setUp();
         // set initial touch mode
         getInstrumentation().setInTouchMode(mInitialTouchMode);
-        setActivity(launchActivity(mPackage, mActivityClass, null));
+        final String targetPackageName = getInstrumentation().getTargetContext().getPackageName();
+        setActivity(launchActivity(targetPackageName, mActivityClass, null));
     }
 
     @Override
diff --git a/test-runner/android/test/ActivityInstrumentationTestCase2.java b/test-runner/android/test/ActivityInstrumentationTestCase2.java
index 679f634..e8570bd 100644
--- a/test-runner/android/test/ActivityInstrumentationTestCase2.java
+++ b/test-runner/android/test/ActivityInstrumentationTestCase2.java
@@ -40,21 +40,31 @@
  */
 public abstract class ActivityInstrumentationTestCase2<T extends Activity> 
         extends ActivityTestCase {
-    String mPackage;
     Class<T> mActivityClass;
     boolean mInitialTouchMode = false;
     Intent mActivityIntent = null;
 
     /**
-     * <b>NOTE:</b> The parameter <i>pkg</i> must refer to the package identifier of the
-     * package hosting the activity to be launched, which is specified in the AndroidManifest.xml
-     * file.  This is not necessarily the same as the java package name.
-     * 
-     * @param pkg The package hosting the activity to be launched.
-     * @param activityClass The activity to test.
+     * Creates an {@link ActivityInstrumentationTestCase2}.
+     *
+     * @param pkg ignored - no longer in use.
+     * @param activityClass The activity to test. This must be a class in the instrumentation
+     * targetPackage specified in the AndroidManifest.xml
+     *
+     * @deprecated use {@link #ActivityInstrumentationTestCase2(Class)} instead
      */
+    @Deprecated
     public ActivityInstrumentationTestCase2(String pkg, Class<T> activityClass) {
-        mPackage = pkg;
+        this(activityClass);
+    }
+
+    /**
+     * Creates an {@link ActivityInstrumentationTestCase2}.
+     *
+     * @param activityClass The activity to test. This must be a class in the instrumentation
+     * targetPackage specified in the AndroidManifest.xml
+     */
+    public ActivityInstrumentationTestCase2(Class<T> activityClass) {
         mActivityClass = activityClass;
     }
 
@@ -82,11 +92,12 @@
         if (a == null) {
             // set initial touch mode
             getInstrumentation().setInTouchMode(mInitialTouchMode);
+            final String targetPackage = getInstrumentation().getTargetContext().getPackageName();
             // inject custom intent, if provided
             if (mActivityIntent == null) {
-                a = launchActivity(mPackage, mActivityClass, null);
+                a = launchActivity(targetPackage, mActivityClass, null);
             } else {
-                a = launchActivityWithIntent(mPackage, mActivityClass, mActivityIntent);
+                a = launchActivityWithIntent(targetPackage, mActivityClass, mActivityIntent);
             }
             setActivity(a);
         }