Add an option to enable splash screen on launch tests

When apps are launched from an instrumentation test, splash screen won't show as it inherits some of the window properties from the instrumentation app. We can re-enable the splash screen by creating a new bundle and set the splash screen property.

Test: atest csuite-harness-tests
Bug: 191278526
Change-Id: I6d2728c0f1d3839ad0b42aa70c5b3575ddd4ea8b
diff --git a/harness/src/main/java/com/android/compatibility/testtype/AppLaunchTest.java b/harness/src/main/java/com/android/compatibility/testtype/AppLaunchTest.java
index c5309e4..49fa2f8 100644
--- a/harness/src/main/java/com/android/compatibility/testtype/AppLaunchTest.java
+++ b/harness/src/main/java/com/android/compatibility/testtype/AppLaunchTest.java
@@ -68,6 +68,7 @@
     @VisibleForTesting static final String COLLECT_GMS_VERSION = "collect-gms-version";
     @VisibleForTesting static final String GMS_PACKAGE_NAME = "com.google.android.gms";
     @VisibleForTesting static final String RECORD_SCREEN = "record-screen";
+    @VisibleForTesting static final String ENABLE_SPLASH_SCREEN = "enable-splash-screen";
 
     @Option(name = RECORD_SCREEN, description = "Whether to record screen during test.")
     private boolean mRecordScreen;
@@ -91,6 +92,13 @@
                             + " test log files.")
     private boolean mCollectGmsVersion;
 
+    @Option(
+            name = ENABLE_SPLASH_SCREEN,
+            description =
+                    "Whether to enable splash screen when launching an package from the"
+                            + " instrumentation test.")
+    private boolean mEnableSplashScreen;
+
     @Option(name = "package-name", description = "Package name of testing app.")
     private String mPackageName;
 
@@ -162,6 +170,8 @@
                 APP_LAUNCH_TIMEOUT_LABEL, Integer.toString(mAppLaunchTimeoutMs));
         instrumentationTest.addInstrumentationArg(
                 ARG_DISMISS_DIALOG, Boolean.toString(mDismissDialog));
+        instrumentationTest.addInstrumentationArg(
+                ENABLE_SPLASH_SCREEN, Boolean.toString(mEnableSplashScreen));
 
         int testTimeoutMs = BASE_INSTRUMENTATION_TEST_TIMEOUT_MS + mAppLaunchTimeoutMs * 2;
         instrumentationTest.setShellTimeout(testTimeoutMs);
diff --git a/instrumentation/launch/src/main/java/com/android/compatibilitytest/AppCompatibility.java b/instrumentation/launch/src/main/java/com/android/compatibilitytest/AppCompatibility.java
index 870076c..95a3bc9 100644
--- a/instrumentation/launch/src/main/java/com/android/compatibilitytest/AppCompatibility.java
+++ b/instrumentation/launch/src/main/java/com/android/compatibilitytest/AppCompatibility.java
@@ -64,6 +64,7 @@
     private static final String PACKAGE_TO_LAUNCH = "package_to_launch";
     private static final String APP_LAUNCH_TIMEOUT_MSECS = "app_launch_timeout_ms";
     private static final String ARG_DISMISS_DIALOG = "ARG_DISMISS_DIALOG";
+    private static final String ENABLE_SPLASH_SCREEN = "enable-splash-screen";
     private static final Set<String> DROPBOX_TAGS = new HashSet<>();
     private static final int MAX_CRASH_SNIPPET_LINES = 20;
     private static final int MAX_NUM_CRASH_SNIPPET = 3;
@@ -273,7 +274,13 @@
                         packageName, intent.toString()));
 
         // Launch Activity
-        mContext.startActivity(intent);
+        if (mArgs.getString(ENABLE_SPLASH_SCREEN, "false").equals("true")) {
+            Bundle bundle = new Bundle();
+            bundle.putInt("android.activity.splashScreenStyle", 1);
+            mContext.startActivity(intent, bundle);
+        } else {
+            mContext.startActivity(intent);
+        }
 
         try {
             // artificial delay: in case app crashes after doing some work during launch