From 491cb86f1cf103843ab43fd415fc48050d487bc4 Mon Sep 17 00:00:00 2001 From: Santiago Etchebehere Date: Fri, 3 Dec 2021 10:51:18 -0800 Subject: Add test for displayPadding restrictions in WallpaperManager Bug: 204316511 Test: self Change-Id: If87d56df985546c3e7dc9b284ef809aeeac78dc4 Merged-In: If87d56df985546c3e7dc9b284ef809aeeac78dc4 --- .../android/security/cts/WallpaperManagerTest.java | 94 ++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 tests/tests/security/src/android/security/cts/WallpaperManagerTest.java 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 00000000000..fda462b9cd5 --- /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 + } + } +} -- cgit v1.2.3 From 2eb06a9840369a6de672333d8660fe71671b1ca7 Mon Sep 17 00:00:00 2001 From: shawnlin Date: Fri, 1 Apr 2022 11:05:18 +0800 Subject: [DO NOT MERGE] WindowInsetsBehaviorTests downstreaming Bug: 205493938 Test: 1.make gts 2.gts-tradef 3.run gts -m CtsSystemUiTestCases -t android.systemui.cts.WindowInsetsBehaviorTests Change-Id: If246221404ea1044b0683138959faf0b33c7d713 --- apps/VpnApp/Android.bp | 1 + tests/inputmethod/mockime/Android.bp | 1 + tests/tests/systemui/Android.bp | 2 ++ tests/tests/systemui/AndroidManifest.xml | 3 +++ tests/tests/systemui/AndroidTest.xml | 1 + tests/tests/systemui/AudioRecorderTestApp_AudioRecord/Android.bp | 1 + tests/tests/systemui/AudioRecorderTestApp_MediaRecorder/Android.bp | 1 + tests/tests/systemui/PipTestApp/Android.bp | 1 + .../src/android/systemui/cts/WindowInsetsBehaviorTests.java | 7 +++++++ 9 files changed, 18 insertions(+) diff --git a/apps/VpnApp/Android.bp b/apps/VpnApp/Android.bp index 898f4bdf91b..55ef022080a 100644 --- a/apps/VpnApp/Android.bp +++ b/apps/VpnApp/Android.bp @@ -49,6 +49,7 @@ android_test_helper_app { 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 5ee05054e40..a72460251a8 100644 --- a/tests/inputmethod/mockime/Android.bp +++ b/tests/inputmethod/mockime/Android.bp @@ -44,6 +44,7 @@ android_test_helper_app { // tag this module as a cts test artifact test_suites: [ "cts", + "gts", "general-tests", "mts", "sts", diff --git a/tests/tests/systemui/Android.bp b/tests/tests/systemui/Android.bp index 0d28f65c5c2..fc48c72c684 100644 --- a/tests/tests/systemui/Android.bp +++ b/tests/tests/systemui/Android.bp @@ -19,8 +19,10 @@ package { 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 f55ed3f13c5..c1c0a317b0c 100644 --- a/tests/tests/systemui/AndroidManifest.xml +++ b/tests/tests/systemui/AndroidManifest.xml @@ -18,6 +18,9 @@ + + + diff --git a/tests/tests/systemui/AndroidTest.xml b/tests/tests/systemui/AndroidTest.xml index 74876ae668e..7a848572ebc 100644 --- a/tests/tests/systemui/AndroidTest.xml +++ b/tests/tests/systemui/AndroidTest.xml @@ -15,6 +15,7 @@ -->