Merge "[CTS] Skip the test appropriately" into stage-aosp-sc-ts-dev am: 70c384b122 am: b2b2a0126d

Original change: https://googleplex-android-review.googlesource.com/c/platform/cts/+/15560888

Change-Id: I21a560bfca601d5d86d48127d06e4b0cc3182a41
diff --git a/tests/app/AppExitTest/src/android/app/cts/ActivityManagerAppExitInfoTest.java b/tests/app/AppExitTest/src/android/app/cts/ActivityManagerAppExitInfoTest.java
index db74563..27378c3 100644
--- a/tests/app/AppExitTest/src/android/app/cts/ActivityManagerAppExitInfoTest.java
+++ b/tests/app/AppExitTest/src/android/app/cts/ActivityManagerAppExitInfoTest.java
@@ -55,6 +55,7 @@
 import android.util.Pair;
 
 import com.android.compatibility.common.util.AmMonitor;
+import com.android.compatibility.common.util.PollingCheck;
 import com.android.compatibility.common.util.ShellIdentityUtils;
 import com.android.compatibility.common.util.SystemUtil;
 import com.android.internal.util.ArrayUtils;
@@ -103,6 +104,8 @@
     private static final int EXIT_CODE = 123;
     private static final int CRASH_SIGNAL = OsConstants.SIGSEGV;
 
+    private static final int TOMBSTONE_FETCH_TIMEOUT_MS = 10_000;
+
     private static final int WAITFOR_MSEC = 10000;
     private static final int WAITFOR_SETTLE_DOWN = 2000;
 
@@ -840,17 +843,11 @@
         verify(list.get(0), mStubPackagePid, mStubPackageUid, STUB_PACKAGE_NAME,
                 ApplicationExitInfo.REASON_CRASH_NATIVE, null, null, now, now2);
 
-        InputStream trace = ShellIdentityUtils.invokeMethodWithShellPermissions(
-                list.get(0),
-                (i) -> {
-                    try {
-                        return i.getTraceInputStream();
-                    } catch (IOException ex) {
-                        return null;
-                    }
-                },
-                android.Manifest.permission.DUMP);
+        TombstoneFetcher tombstoneFetcher = new TombstoneFetcher(list.get(0));
+        PollingCheck.check("not able to get tombstone", TOMBSTONE_FETCH_TIMEOUT_MS,
+                () -> tombstoneFetcher.fetchTrace());
 
+        InputStream trace = tombstoneFetcher.getTrace();
         assertNotNull(trace);
         Tombstone tombstone = Tombstone.parseFrom(trace);
         assertEquals(tombstone.getPid(), mStubPackagePid);
@@ -1242,4 +1239,31 @@
         assertTrue(ArrayUtils.equals(info.getProcessStateSummary(), cookie,
                 cookie == null ? 0 : cookie.length));
     }
+
+    private static class TombstoneFetcher {
+        private InputStream mTrace = null;
+        private final ApplicationExitInfo mExitInfo;
+
+        TombstoneFetcher(ApplicationExitInfo exitInfo) {
+            mExitInfo = exitInfo;
+        }
+
+        public InputStream getTrace() {
+            return mTrace;
+        }
+
+        public boolean fetchTrace() throws Exception {
+            mTrace = ShellIdentityUtils.invokeMethodWithShellPermissions(
+                    mExitInfo,
+                    (i) -> {
+                        try {
+                            return i.getTraceInputStream();
+                        } catch (IOException ex) {
+                            return null;
+                        }
+                    },
+                    android.Manifest.permission.DUMP);
+            return (mTrace != null);
+        }
+    }
 }
diff --git a/tests/framework/base/windowmanager/AndroidManifest.xml b/tests/framework/base/windowmanager/AndroidManifest.xml
index f0f40a6..287e67c 100644
--- a/tests/framework/base/windowmanager/AndroidManifest.xml
+++ b/tests/framework/base/windowmanager/AndroidManifest.xml
@@ -366,7 +366,7 @@
              android:theme="@style/no_starting_window"/>
         <activity android:name="android.server.wm.WindowFocusTests$PrimaryActivity"/>
         <activity android:name="android.server.wm.WindowFocusTests$SecondaryActivity"
-             android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout|colorMode|density"/>
+             android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout|colorMode|density|touchscreen"/>
         <activity android:name="android.server.wm.WindowFocusTests$LosingFocusActivity"/>
         <activity android:name="android.server.wm.WindowFocusTests$AutoEngagePointerCaptureActivity" />
         <activity android:name="android.server.wm.WindowMetricsActivityTests$MetricsActivity"
diff --git a/tests/framework/base/windowmanager/src/android/server/wm/WindowFocusTests.java b/tests/framework/base/windowmanager/src/android/server/wm/WindowFocusTests.java
index 0b42360..024ea17 100644
--- a/tests/framework/base/windowmanager/src/android/server/wm/WindowFocusTests.java
+++ b/tests/framework/base/windowmanager/src/android/server/wm/WindowFocusTests.java
@@ -290,7 +290,6 @@
                 DEFAULT_DISPLAY);
 
         final InvisibleVirtualDisplaySession session = createManagedInvisibleDisplaySession();
-        final int secondaryDisplayId = session.getDisplayId();
         final SecondaryActivity secondaryActivity = session.startActivityAndFocus();
         // Secondary display disconnected.
         session.close();
diff --git a/tests/tests/provider/src/android/provider/cts/SettingsPanelTest.java b/tests/tests/provider/src/android/provider/cts/SettingsPanelTest.java
index 6db2d4c..55fb3d0 100644
--- a/tests/tests/provider/src/android/provider/cts/SettingsPanelTest.java
+++ b/tests/tests/provider/src/android/provider/cts/SettingsPanelTest.java
@@ -29,8 +29,6 @@
 import android.support.test.uiautomator.UiObject2;
 import android.support.test.uiautomator.Until;
 
-import com.android.compatibility.common.util.RequiredServiceRule;
-
 import androidx.test.InstrumentationRegistry;
 import androidx.test.filters.MediumTest;
 import androidx.test.runner.AndroidJUnit4;
@@ -40,8 +38,6 @@
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
-import java.util.Arrays;
-
 /**
  * Tests related SettingsPanels:
  *
@@ -56,6 +52,7 @@
     private static final String RESOURCE_DONE = "done";
     private static final String RESOURCE_SEE_MORE = "see_more";
     private static final String RESOURCE_TITLE = "panel_title";
+    private static final String SYSTEMUI_PACKAGE_NAME = "com.android.systemui";
 
     private String mSettingsPackage;
     private String mLauncherPackage;
@@ -100,12 +97,12 @@
     // Check correct package is opened
 
     @Test
-    public void internetPanel_correctPackage() {
-        launchInternetPanel();
+    public void internetDialog_correctPackage() {
+        launchInternetDialog();
 
         String currentPackage = mDevice.getCurrentPackageName();
 
-        assertThat(currentPackage).isEqualTo(mSettingsPackage);
+        assertThat(currentPackage).isEqualTo(SYSTEMUI_PACKAGE_NAME);
     }
 
     @Test
@@ -137,18 +134,23 @@
     }
 
     @Test
-    public void internetPanel_doneClosesPanel() {
+    public void internetDialog_doneClosesDialog() {
         // Launch panel
-        launchInternetPanel();
+        launchInternetDialog();
         String currentPackage = mDevice.getCurrentPackageName();
-        assertThat(currentPackage).isEqualTo(mSettingsPackage);
+        assertThat(currentPackage).isEqualTo(SYSTEMUI_PACKAGE_NAME);
 
         // Click the done button
-        pressDone();
+        if (mHasTouchScreen) {
+            mDevice.findObject(By.res(SYSTEMUI_PACKAGE_NAME, RESOURCE_DONE)).click();
+            mDevice.wait(Until.hasObject(By.pkg(mLauncherPackage).depth(0)), TIMEOUT);
+        } else {
+            mDevice.pressBack();
+        }
 
         // Assert that we have left the panel
         currentPackage = mDevice.getCurrentPackageName();
-        assertThat(currentPackage).isNotEqualTo(mSettingsPackage);
+        assertThat(currentPackage).isNotEqualTo(SYSTEMUI_PACKAGE_NAME);
     }
 
     @Test
@@ -252,8 +254,19 @@
         launchPanel(Settings.Panel.ACTION_VOLUME);
     }
 
-    private void launchInternetPanel() {
-        launchPanel(Settings.Panel.ACTION_INTERNET_CONNECTIVITY);
+    private void launchInternetDialog() {
+        // Start from the home screen
+        mDevice.pressHome();
+        mDevice.wait(Until.hasObject(By.pkg(mLauncherPackage).depth(0)), TIMEOUT);
+
+        Intent intent = new Intent(Settings.Panel.ACTION_INTERNET_CONNECTIVITY);
+        intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND)
+                .setPackage(SYSTEMUI_PACKAGE_NAME);
+
+        mContext.sendBroadcast(intent);
+
+        // Wait for the app to appear
+        mDevice.wait(Until.hasObject(By.pkg(SYSTEMUI_PACKAGE_NAME).depth(0)), TIMEOUT);
     }
 
     private void launchNfcPanel() {