Merge "STS test for Android Security CVE-2021-0705" into sc-dev am: 6e1a223ccb

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

Change-Id: Ib7675f5605c249666d8e28970747b8cf3f43fa2a
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/content/AndroidTest.xml b/tests/tests/content/AndroidTest.xml
index c03dd80..e39bf36 100644
--- a/tests/tests/content/AndroidTest.xml
+++ b/tests/tests/content/AndroidTest.xml
@@ -39,7 +39,6 @@
         <option name="push" value="CtsContentLongSharedUserIdTestApp.apk->/data/local/tmp/cts/content/CtsContentLongSharedUserIdTestApp.apk" />
         <option name="push" value="CtsContentMaxPackageNameTestApp.apk->/data/local/tmp/cts/content/CtsContentMaxPackageNameTestApp.apk" />
         <option name="push" value="CtsContentMaxSharedUserIdTestApp.apk->/data/local/tmp/cts/content/CtsContentMaxSharedUserIdTestApp.apk" />
-        <option name="push" value="CtsContentLongLabelNameTestApp.apk->/data/local/tmp/cts/content/CtsContentLongLabelNameTestApp.apk" />
     </target_preparer>
 
     <target_preparer class="com.android.tradefed.targetprep.PushFilePreparer">
diff --git a/tests/tests/content/emptytestapp/Android.bp b/tests/tests/content/emptytestapp/Android.bp
index f66ccdf..42f36d0 100644
--- a/tests/tests/content/emptytestapp/Android.bp
+++ b/tests/tests/content/emptytestapp/Android.bp
@@ -77,16 +77,3 @@
         "general-tests",
     ],
 }
-
-android_test_helper_app {
-    name: "CtsContentLongLabelNameTestApp",
-    defaults: ["cts_defaults"],
-    sdk_version: "current",
-    manifest: "AndroidManifestLongLabelName.xml",
-    // tag this module as a cts test artifact
-    test_suites: [
-        "cts",
-        "general-tests",
-    ],
-    min_sdk_version : "29"
-}
diff --git a/tests/tests/content/emptytestapp/AndroidManifestLongLabelName.xml b/tests/tests/content/emptytestapp/AndroidManifestLongLabelName.xml
deleted file mode 100644
index eaa69b1..0000000
--- a/tests/tests/content/emptytestapp/AndroidManifestLongLabelName.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2021 The Android Open Source Project
-
-     Licensed under the Apache License, Version 2.0 (the "License");
-     you may not use this file except in compliance with the License.
-     You may obtain a copy of the License at
-
-          http://www.apache.org/licenses/LICENSE-2.0
-
-     Unless required by applicable law or agreed to in writing, software
-     distributed under the License is distributed on an "AS IS" BASIS,
-     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-     See the License for the specific language governing permissions and
-     limitations under the License.
--->
-<!-- Test that the maximum length of the label returned from the load label api should be 1000 -->
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
-        package="android.content.cts.emptytestapp" >
-    <application android:hasCode="false" android:label="@string/long_app_name">
-        <activity android:name=".MockActivity" android:label="@string/long_app_name"
-                  android:exported="true" android:enabled="true" />
-    </application>
-</manifest>
diff --git a/tests/tests/content/emptytestapp/res/values/strings.xml b/tests/tests/content/emptytestapp/res/values/strings.xml
deleted file mode 100644
index 8c06d18..0000000
--- a/tests/tests/content/emptytestapp/res/values/strings.xml
+++ /dev/null
@@ -1,31 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2021 The Android Open Source Project
-
-     Licensed under the Apache License, Version 2.0 (the "License");
-     you may not use this file except in compliance with the License.
-     You may obtain a copy of the License at
-
-          http://www.apache.org/licenses/LICENSE-2.0
-
-     Unless required by applicable law or agreed to in writing, software
-     distributed under the License is distributed on an "AS IS" BASIS,
-     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-     See the License for the specific language governing permissions and
-     limitations under the License.
--->
-
-<resources>
-    <string name="long_app_name">
-EmptyTestApp123456789012345678901234567890123456789012345678901234567890123456789012345678901234567
-EmptyTestApp123456789012345678901234567890123456789012345678901234567890123456789012345678901234567
-EmptyTestApp123456789012345678901234567890123456789012345678901234567890123456789012345678901234567
-EmptyTestApp123456789012345678901234567890123456789012345678901234567890123456789012345678901234567
-EmptyTestApp123456789012345678901234567890123456789012345678901234567890123456789012345678901234567
-EmptyTestApp123456789012345678901234567890123456789012345678901234567890123456789012345678901234567
-EmptyTestApp123456789012345678901234567890123456789012345678901234567890123456789012345678901234567
-EmptyTestApp123456789012345678901234567890123456789012345678901234567890123456789012345678901234567
-EmptyTestApp123456789012345678901234567890123456789012345678901234567890123456789012345678901234567
-EmptyTestApp123456789012345678901234567890123456789012345678901234567890123456789012345678901234567
-EmptyTestApp123456789012345678901234567890123456789012345678901234567890123456789012345678901234567
-    </string>
-</resources>
diff --git a/tests/tests/content/src/android/content/pm/cts/PackageManagerTest.java b/tests/tests/content/src/android/content/pm/cts/PackageManagerTest.java
index 6ca8a01..598e882 100644
--- a/tests/tests/content/src/android/content/pm/cts/PackageManagerTest.java
+++ b/tests/tests/content/src/android/content/pm/cts/PackageManagerTest.java
@@ -154,8 +154,6 @@
             + "CtsContentMaxPackageNameTestApp.apk";
     private static final String MAX_SHARED_USER_ID_APK = SAMPLE_APK_BASE
             + "CtsContentMaxSharedUserIdTestApp.apk";
-    private static final String LONG_LABEL_NAME_APK = SAMPLE_APK_BASE
-            + "CtsContentLongLabelNameTestApp.apk";
     private static final String EMPTY_APP_PACKAGE_NAME = "android.content.cts.emptytestapp";
     private static final String EMPTY_APP_MAX_PACKAGE_NAME = "android.content.cts.emptytestapp27j"
             + "EBRNRG3ozwBsGr1sVIM9U0bVTI2TdyIyeRkZgW4JrJefwNIBAmCg4AzqXiCvG6JjqA0uTCWSFu2YqAVxVd"
@@ -165,8 +163,6 @@
     private static final String HELLO_WORLD_PACKAGE_NAME = "com.example.helloworld";
     private static final String HELLO_WORLD_APK = SAMPLE_APK_BASE + "HelloWorld5.apk";
 
-    private static final int MAX_SAFE_LABEL_LENGTH = 1000;
-
     @Before
     public void setup() throws Exception {
         mContext = InstrumentationRegistry.getContext();
@@ -1468,33 +1464,4 @@
     private void uninstallPackage(String packageName) {
         SystemUtil.runShellCommand("pm uninstall " + packageName);
     }
-
-    @Test
-    public void loadApplicationLabel_withLongLabelName_truncated() throws Exception {
-        assertThat(installPackage(LONG_LABEL_NAME_APK)).isTrue();
-        final ApplicationInfo info = mPackageManager.getApplicationInfo(
-                EMPTY_APP_PACKAGE_NAME, 0 /* flags */);
-        final CharSequence resLabel = mPackageManager.getText(
-                EMPTY_APP_PACKAGE_NAME, info.labelRes, info);
-
-        assertThat(resLabel.length()).isGreaterThan(MAX_SAFE_LABEL_LENGTH);
-        assertThat(info.loadLabel(mPackageManager).length()).isEqualTo(MAX_SAFE_LABEL_LENGTH);
-    }
-
-    @Test
-    public void loadComponentLabel_withLongLabelName_truncated() throws Exception {
-        assertThat(installPackage(LONG_LABEL_NAME_APK)).isTrue();
-        final ComponentName componentName = ComponentName.createRelative(
-                EMPTY_APP_PACKAGE_NAME, ".MockActivity");
-        final ApplicationInfo appInfo = mPackageManager.getApplicationInfo(
-                EMPTY_APP_PACKAGE_NAME, 0 /* flags */);
-        final ActivityInfo activityInfo = mPackageManager.getActivityInfo(
-                componentName, 0 /* flags */);
-        final CharSequence resLabel = mPackageManager.getText(
-                EMPTY_APP_PACKAGE_NAME, activityInfo.labelRes, appInfo);
-
-        assertThat(resLabel.length()).isGreaterThan(MAX_SAFE_LABEL_LENGTH);
-        assertThat(activityInfo.loadLabel(mPackageManager).length())
-                .isEqualTo(MAX_SAFE_LABEL_LENGTH);
-    }
 }