Snap for 8417597 from 8147cd62239b8aa19b2f6fce18ba80b2e607b4a1 to sc-qpr3-release

Change-Id: I837aeeb90d4e454f36fe185b2cafcb2a38f29c0b
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/widget/WidgetCtsProvider.java b/apps/CtsVerifier/src/com/android/cts/verifier/widget/WidgetCtsProvider.java
index 23477c2..bcc8ce9 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/widget/WidgetCtsProvider.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/widget/WidgetCtsProvider.java
@@ -139,7 +139,8 @@
                 && sSDKLevel < android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
             return false;
         }
-        return true;
+        // TODO: revert when b/228227212 is fixed (underlying cause of b/204831731)
+        return false;
     }
 
     @Override
diff --git a/apps/VpnApp/Android.bp b/apps/VpnApp/Android.bp
index 898f4bd..55ef022 100644
--- a/apps/VpnApp/Android.bp
+++ b/apps/VpnApp/Android.bp
@@ -49,6 +49,7 @@
     manifest: "latest/AndroidManifest.xml",
     test_suites: [
         "cts",
+        "gts",
         "general-tests",
     ],
 }
diff --git a/tests/inputmethod/mockime/Android.bp b/tests/inputmethod/mockime/Android.bp
index 5ee0505..a724602 100644
--- a/tests/inputmethod/mockime/Android.bp
+++ b/tests/inputmethod/mockime/Android.bp
@@ -44,6 +44,7 @@
     // tag this module as a cts test artifact
     test_suites: [
         "cts",
+        "gts",
         "general-tests",
         "mts",
         "sts",
diff --git a/tests/tests/security/src/android/security/cts/WallpaperManagerTest.java b/tests/tests/security/src/android/security/cts/WallpaperManagerTest.java
new file mode 100644
index 0000000..fda462b
--- /dev/null
+++ b/tests/tests/security/src/android/security/cts/WallpaperManagerTest.java
@@ -0,0 +1,94 @@
+/*
+ * 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.
+ */
+
+package android.security.cts;
+
+import static android.view.Display.DEFAULT_DISPLAY;
+import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
+
+import android.Manifest;
+import android.app.WallpaperManager;
+import android.content.Context;
+import android.graphics.Rect;
+import android.hardware.display.DisplayManager;
+import android.platform.test.annotations.AsbSecurityTest;
+import android.view.Display;
+
+import androidx.test.platform.app.InstrumentationRegistry;
+
+import com.android.compatibility.common.util.CtsAndroidTestCase;
+
+import org.junit.After;
+import org.junit.Before;
+
+public class WallpaperManagerTest extends CtsAndroidTestCase {
+
+    @Before
+    public void setUp() {
+        InstrumentationRegistry
+                .getInstrumentation()
+                .getUiAutomation()
+                .adoptShellPermissionIdentity(Manifest.permission.SET_WALLPAPER_HINTS);
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        InstrumentationRegistry.getInstrumentation().getUiAutomation()
+                .dropShellPermissionIdentity();
+    }
+
+    // b/204316511
+    @AsbSecurityTest(cveBugId = 204316511)
+    public void testSetDisplayPadding() {
+        WallpaperManager wallpaperManager = WallpaperManager.getInstance(getContext());
+
+        Rect validRect = new Rect(1, 1, 1, 1);
+        // This should work, no exception expected
+        wallpaperManager.setDisplayPadding(validRect);
+
+        Rect negativeRect = new Rect(-1, 0 , 0, 0);
+        try {
+            wallpaperManager.setDisplayPadding(negativeRect);
+            fail("setDisplayPadding should fail for a Rect with negative values");
+        } catch (IllegalArgumentException e) {
+            // Expected exception
+        }
+
+        DisplayManager dm = getContext().getSystemService(DisplayManager.class);
+        Display primaryDisplay = dm.getDisplay(DEFAULT_DISPLAY);
+        Context windowContext = getContext().createWindowContext(primaryDisplay,
+                TYPE_APPLICATION, null);
+        Display display = windowContext.getDisplay();
+
+        Rect tooWideRect = new Rect(0, 0, display.getMaximumSizeDimension() + 1, 0);
+        try {
+            wallpaperManager.setDisplayPadding(tooWideRect);
+            fail("setDisplayPadding should fail for a Rect width larger than "
+                    + display.getMaximumSizeDimension());
+        } catch (IllegalArgumentException e) {
+            // Expected exception
+        }
+
+        Rect tooHighRect = new Rect(0, 0, 0, display.getMaximumSizeDimension() + 1);
+        try {
+            wallpaperManager.setDisplayPadding(tooHighRect);
+            fail("setDisplayPadding should fail for a Rect height larger than "
+                    + display.getMaximumSizeDimension());
+        } catch (IllegalArgumentException e) {
+            // Expected exception
+        }
+    }
+}
diff --git a/tests/tests/systemui/Android.bp b/tests/tests/systemui/Android.bp
index 0d28f65..fc48c72 100644
--- a/tests/tests/systemui/Android.bp
+++ b/tests/tests/systemui/Android.bp
@@ -19,8 +19,10 @@
 android_test {
     name: "CtsSystemUiTestCases",
     defaults: ["cts_defaults"],
+    min_sdk_version: "27",
     test_suites: [
         "cts",
+        "gts",
         "general-tests",
     ],
 
diff --git a/tests/tests/systemui/AndroidManifest.xml b/tests/tests/systemui/AndroidManifest.xml
index f55ed3f..c1c0a31 100644
--- a/tests/tests/systemui/AndroidManifest.xml
+++ b/tests/tests/systemui/AndroidManifest.xml
@@ -18,6 +18,9 @@
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="android.systemui.cts"
      android:targetSandboxVersion="2">
+
+    <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="17" />
+
     <uses-permission android:name="android.permission.INJECT_EVENTS"/>
     <uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
     <uses-permission android:name="android.permission.READ_DREAM_STATE"/>
diff --git a/tests/tests/systemui/AndroidTest.xml b/tests/tests/systemui/AndroidTest.xml
index 74876ae..7a84857 100644
--- a/tests/tests/systemui/AndroidTest.xml
+++ b/tests/tests/systemui/AndroidTest.xml
@@ -15,6 +15,7 @@
 -->
 <configuration description="Config for CTS SystemUI test cases">
     <option name="test-suite-tag" value="cts" />
+    <option name="test-suite-tag" value="gts" />
     <option name="config-descriptor:metadata" key="component" value="sysui" />
     <option name="config-descriptor:metadata" key="parameter" value="instant_app" />
     <option name="config-descriptor:metadata" key="parameter" value="not_multi_abi" />
diff --git a/tests/tests/systemui/AudioRecorderTestApp_AudioRecord/Android.bp b/tests/tests/systemui/AudioRecorderTestApp_AudioRecord/Android.bp
index 3737637..41b247c 100644
--- a/tests/tests/systemui/AudioRecorderTestApp_AudioRecord/Android.bp
+++ b/tests/tests/systemui/AudioRecorderTestApp_AudioRecord/Android.bp
@@ -24,6 +24,7 @@
     // tag this module as a cts test artifact
     test_suites: [
         "cts",
+        "gts",
         "vts10",
         "general-tests",
     ],
diff --git a/tests/tests/systemui/AudioRecorderTestApp_MediaRecorder/Android.bp b/tests/tests/systemui/AudioRecorderTestApp_MediaRecorder/Android.bp
index af7f01c..76b1250 100644
--- a/tests/tests/systemui/AudioRecorderTestApp_MediaRecorder/Android.bp
+++ b/tests/tests/systemui/AudioRecorderTestApp_MediaRecorder/Android.bp
@@ -24,6 +24,7 @@
     // tag this module as a cts test artifact
     test_suites: [
         "cts",
+        "gts",
         "vts10",
         "general-tests",
     ],
diff --git a/tests/tests/systemui/PipTestApp/Android.bp b/tests/tests/systemui/PipTestApp/Android.bp
index b8219c8..5b7b4d9 100644
--- a/tests/tests/systemui/PipTestApp/Android.bp
+++ b/tests/tests/systemui/PipTestApp/Android.bp
@@ -36,6 +36,7 @@
     // Tag this module as a cts test artifact
     test_suites: [
         "cts",
+        "gts",
         "vts10",
         "general-tests",
     ],
diff --git a/tests/tests/systemui/src/android/systemui/cts/WindowInsetsBehaviorTests.java b/tests/tests/systemui/src/android/systemui/cts/WindowInsetsBehaviorTests.java
index b5e657c..1f0369a 100644
--- a/tests/tests/systemui/src/android/systemui/cts/WindowInsetsBehaviorTests.java
+++ b/tests/tests/systemui/src/android/systemui/cts/WindowInsetsBehaviorTests.java
@@ -46,6 +46,7 @@
 import android.graphics.Point;
 import android.graphics.Rect;
 import android.hardware.display.DisplayManager;
+import android.os.Build;
 import android.os.Bundle;
 import android.provider.DeviceConfig;
 import android.support.test.uiautomator.By;
@@ -64,6 +65,8 @@
 import androidx.test.rule.ActivityTestRule;
 import androidx.test.runner.AndroidJUnit4;
 
+import com.android.compatibility.common.util.ApiLevelUtil;
+import com.android.compatibility.common.util.CtsDownstreamingTest;
 import com.android.compatibility.common.util.SystemUtil;
 import com.android.compatibility.common.util.ThrowingRunnable;
 
@@ -600,9 +603,11 @@
     /**
      * @throws Throwable when setting the property goes wrong.
      */
+    @CtsDownstreamingTest
     @Test
     public void systemGesture_excludeViewRects_withoutAnyCancel()
             throws Throwable {
+        assumeTrue(ApiLevelUtil.isAtLeast(Build.VERSION_CODES.S_V2));
         assumeTrue(hasSystemGestureFeature());
 
         mainThreadRun(() -> mContentViewWindowInsets = mActivity.getDecorViewWindowInsets());
@@ -635,8 +640,10 @@
         assertEquals(swipeCount[0], mActionDownPoints.size());
     }
 
+    @CtsDownstreamingTest
     @Test
     public void systemGesture_notExcludeViewRects_withoutAnyCancel() {
+        assumeTrue(ApiLevelUtil.isAtLeast(Build.VERSION_CODES.S_V2));
         assumeTrue(hasSystemGestureFeature());
 
         mainThreadRun(() -> mActivity.setSystemGestureExclusion(null));