am 62267e0f: Merge "don\'t report missing launch intent as failure" into mnc-dev

* commit '62267e0f9e11935ff264e4b5c7dda80e35073d69':
  don't report missing launch intent as failure
diff --git a/tests/Compatibility/src/com/android/compatibilitytest/AppCompatibility.java b/tests/Compatibility/src/com/android/compatibilitytest/AppCompatibility.java
index f703903..eaff6c7 100644
--- a/tests/Compatibility/src/com/android/compatibilitytest/AppCompatibility.java
+++ b/tests/Compatibility/src/com/android/compatibilitytest/AppCompatibility.java
@@ -17,6 +17,7 @@
 package com.android.compatibilitytest;
 
 import android.app.ActivityManager;
+import android.app.UiModeManager;
 import android.app.ActivityManager.ProcessErrorStateInfo;
 import android.app.ActivityManager.RunningTaskInfo;
 import android.content.Context;
@@ -24,6 +25,7 @@
 import android.content.pm.PackageInfo;
 import android.content.pm.PackageManager;
 import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.res.Configuration;
 import android.os.Bundle;
 import android.test.InstrumentationTestCase;
 import android.util.Log;
@@ -97,7 +99,12 @@
         String packageName = mArgs.getString(PACKAGE_TO_LAUNCH);
         if (packageName != null) {
             Log.d(TAG, "Launching app " + packageName);
-            ProcessErrorStateInfo err = launchActivity(packageName);
+            Intent intent = getLaunchIntentForPackage(packageName);
+            if (intent == null) {
+                Log.w(TAG, String.format("Skipping %s; no launch intent", packageName));
+                return;
+            }
+            ProcessErrorStateInfo err = launchActivity(packageName, intent);
             // Make sure there are no errors when launching the application,
             // otherwise raise an
             // exception with the first error encountered.
@@ -155,6 +162,19 @@
         }
     }
 
+    private Intent getLaunchIntentForPackage(String packageName) {
+        UiModeManager umm = (UiModeManager)
+                getInstrumentation().getContext().getSystemService(Context.UI_MODE_SERVICE);
+        boolean isLeanback = umm.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION;
+        Intent intent = null;
+        if (isLeanback) {
+            intent = mPackageManager.getLeanbackLaunchIntentForPackage(packageName);
+        } else {
+            intent = mPackageManager.getLaunchIntentForPackage(packageName);
+        }
+        return intent;
+    }
+
     /**
      * Launches and activity and queries for errors.
      *
@@ -163,18 +183,9 @@
      * @return {@link Collection} of {@link ProcessErrorStateInfo} detected
      *         during the app launch.
      */
-    private ProcessErrorStateInfo launchActivity(String packageName) {
-        // the recommended way to see if this is a tv or not.
-        boolean isleanback = !mPackageManager.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN)
-            && !mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
-        Intent intent;
-        if (isleanback) {
-            Log.d(TAG, "Leanback and relax! " + packageName);
-            intent = mPackageManager.getLeanbackLaunchIntentForPackage(packageName);
-        } else {
-            intent = mPackageManager.getLaunchIntentForPackage(packageName);
-        }
-        assertNotNull("Skipping " + packageName + "; missing launch intent", intent);
+    private ProcessErrorStateInfo launchActivity(String packageName, Intent intent) {
+        Log.d(TAG, String.format("launching package \"%s\" with intent: %s",
+                packageName, intent.toString()));
 
         String processName = getProcessName(packageName);