diff options
author | android-build-prod (mdb) <android-build-team-robot@google.com> | 2019-03-25 16:06:24 +0000 |
---|---|---|
committer | android-build-prod (mdb) <android-build-team-robot@google.com> | 2019-03-25 16:06:24 +0000 |
commit | a0966410a19d0b1d975da716042ab54fa45a2c9a (patch) | |
tree | cacbb0fbffebb5f5b08837b8bc7e57bf2839174d | |
parent | a4c83184dbbb8f684c2b58a0150b21f7659765f8 (diff) | |
parent | 212cbc9f5d42268b68d091442d3625d9f4ea74d1 (diff) | |
download | platform_cts-a0966410a19d0b1d975da716042ab54fa45a2c9a.tar.gz platform_cts-a0966410a19d0b1d975da716042ab54fa45a2c9a.tar.bz2 platform_cts-a0966410a19d0b1d975da716042ab54fa45a2c9a.zip |
Snap for 5402968 from 212cbc9f5d42268b68d091442d3625d9f4ea74d1 to oreo-mr1-vts-release
Change-Id: I699bfb401d482c5cf4d57b9757291694d61cf32a
8 files changed, 286 insertions, 11 deletions
diff --git a/hostsidetests/services/activityandwindowmanager/activitymanager/app/src/android/server/cts/BroadcastReceiverActivity.java b/hostsidetests/services/activityandwindowmanager/activitymanager/app/src/android/server/cts/BroadcastReceiverActivity.java index 24be43a3be6..264f69b5c2c 100644 --- a/hostsidetests/services/activityandwindowmanager/activitymanager/app/src/android/server/cts/BroadcastReceiverActivity.java +++ b/hostsidetests/services/activityandwindowmanager/activitymanager/app/src/android/server/cts/BroadcastReceiverActivity.java @@ -16,6 +16,7 @@ package android.server.cts; +import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD; import android.app.Activity; @@ -27,6 +28,13 @@ import android.content.IntentFilter; import android.os.Bundle; import android.server.cts.tools.ActivityLauncher; import android.util.Log; +import android.view.View; +import android.view.ViewGroup; +import android.view.Window; +import android.view.WindowInsets; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; /** * Activity that registers broadcast receiver . @@ -45,6 +53,34 @@ public class BroadcastReceiverActivity extends Activity { IntentFilter broadcastFilter = new IntentFilter(ACTION_TRIGGER_BROADCAST); registerReceiver(mBroadcastReceiver, broadcastFilter); + + // Determine if a display cutout is present + final View view = new View(this); + getWindow().requestFeature(Window.FEATURE_NO_TITLE); + try { + Field field = getWindow().getAttributes().getClass().getField( + "layoutInDisplayCutoutMode"); + field.setAccessible(true); + field.setInt(getWindow().getAttributes(), + 1 /* LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES */); + } catch (Exception e) { + e.printStackTrace(); + return; + } + view.setLayoutParams(new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT)); + view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN + | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION); + view.setOnApplyWindowInsetsListener((v, insets) -> { + try { + Method method = WindowInsets.class.getDeclaredMethod("getDisplayCutout"); + Object displayCutoutInstance = method.invoke(insets); + Log.i(getClass().getSimpleName(), "cutout=" + (displayCutoutInstance != null)); + } catch (Exception e) { + e.printStackTrace(); + } + return insets; + }); + setContentView(view); } @Override diff --git a/hostsidetests/services/activityandwindowmanager/activitymanager/src/android/server/cts/ActivityManagerConfigChangeTests.java b/hostsidetests/services/activityandwindowmanager/activitymanager/src/android/server/cts/ActivityManagerConfigChangeTests.java index 7e2e53e9366..7b6dfd8d899 100644 --- a/hostsidetests/services/activityandwindowmanager/activitymanager/src/android/server/cts/ActivityManagerConfigChangeTests.java +++ b/hostsidetests/services/activityandwindowmanager/activitymanager/src/android/server/cts/ActivityManagerConfigChangeTests.java @@ -52,11 +52,21 @@ public class ActivityManagerConfigChangeTests extends ActivityManagerTestBase { } public void testRotation180Relaunch() throws Exception { + if (hasDisplayCutout()) { + // Skip case in CTS 8.1 + // Skipping test: display cutout present, can't predict exact lifecycle" + return; + } // Should receive nothing testRotation(TEST_ACTIVITY_NAME, 2, 0, 0); } public void testRotation180NoRelaunch() throws Exception { + if (hasDisplayCutout()) { + // Skip case in CTS 8.1 + // Skipping test: display cutout present, can't predict exact lifecycle" + return; + } // Should receive nothing testRotation(NO_RELAUNCH_ACTIVITY_NAME, 2, 0, 0); } diff --git a/hostsidetests/services/activityandwindowmanager/util/src/android/server/cts/ActivityManagerTestBase.java b/hostsidetests/services/activityandwindowmanager/util/src/android/server/cts/ActivityManagerTestBase.java index ca672e423ee..30b0af91f26 100755 --- a/hostsidetests/services/activityandwindowmanager/util/src/android/server/cts/ActivityManagerTestBase.java +++ b/hostsidetests/services/activityandwindowmanager/util/src/android/server/cts/ActivityManagerTestBase.java @@ -1150,6 +1150,8 @@ public abstract class ActivityManagerTestBase extends DeviceTestCase { "(.+): config size=\\((\\d+),(\\d+)\\) displaySize=\\((\\d+),(\\d+)\\)" + " metricsSize=\\((\\d+),(\\d+)\\) smallestScreenWidth=(\\d+) densityDpi=(\\d+)" + " orientation=(\\d+)"); + private static final Pattern sDisplayCutoutPattern = Pattern.compile( + "(.+): cutout=(true|false)"); private static final Pattern sDisplayStatePattern = Pattern.compile("Display Power: state=(.+)"); private static final Pattern sCurrentUiModePattern = Pattern.compile("mCurUiMode=0x(\\d+)"); @@ -1237,6 +1239,58 @@ public abstract class ActivityManagerTestBase extends DeviceTestCase { return null; } + /** Check if a device has display cutout. */ + boolean hasDisplayCutout() throws Exception { + // Launch an activity to report cutout state + final String logSeparator = clearLogcat(); + launchActivity(BROADCAST_RECEIVER_ACTIVITY); + + // Read the logs to check if cutout is present + final boolean displayCutoutPresent = getCutoutStateForActivity( + BROADCAST_RECEIVER_ACTIVITY, logSeparator); + + // Finish activity + executeShellCommand(FINISH_ACTIVITY_BROADCAST); + mAmWmState.waitForWithAmState(mDevice, (state) -> !state.containsActivity( + BROADCAST_RECEIVER_ACTIVITY), "Waiting for activity to be removed"); + + return displayCutoutPresent; + } + + /** + * Wait for activity to report cutout state in logs and return it. Will return {@code null} + * after timeout. + */ + private boolean getCutoutStateForActivity(String activityName, String logSeparator) + throws DeviceNotAvailableException { + final String logTag = activityName; + for (int retry = 1; retry <= 5; retry++) { + final boolean result = readLastReportedCutoutState(logSeparator, logTag); + if (result) { + return result; + } + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + } + } + return false; + } + + /** Read display cutout state from device logs. */ + private boolean readLastReportedCutoutState(String logSeparator, String logTag) + throws DeviceNotAvailableException { + final String[] lines = getDeviceLogsForComponents(new String[]{logTag}, logSeparator); + for (int i = lines.length - 1; i >= 0; i--) { + final String line = lines[i].trim(); + final Matcher matcher = sDisplayCutoutPattern.matcher(line); + if (matcher.matches()) { + return "true".equals(matcher.group(2)); + } + } + return false; + } + /** Waits for at least one onMultiWindowModeChanged event. */ ActivityLifecycleCounts waitForOnMultiWindowModeChanged( String activityName, String logSeparator) throws Exception { diff --git a/tests/tests/database/src/android/database/sqlite/cts/SQLiteSecurityTest.java b/tests/tests/database/src/android/database/sqlite/cts/SQLiteSecurityTest.java new file mode 100644 index 00000000000..c34a5f53ae9 --- /dev/null +++ b/tests/tests/database/src/android/database/sqlite/cts/SQLiteSecurityTest.java @@ -0,0 +1,152 @@ +/* + * Copyright (C) 2018 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.database.sqlite.cts; + + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteDatabaseCorruptException; +import android.test.AndroidTestCase; + +/** + * This CTS test verifies Magellan SQLite Security Vulnerability. + * Without the fix, the last statement in each test case triggers a segmentation fault and the test + * fails. + * With the fix, the last statement in each test case triggers SQLiteDatabaseCorruptException with + * message "database disk image is malformed (code 267 SQLITE_CORRUPT_VTAB)", this is expected + * behavior that we are crashing and we are not leaking data. + */ +public class SQLiteSecurityTest extends AndroidTestCase { + private static final String DATABASE_NAME = "database_test.db"; + + private SQLiteDatabase mDatabase; + + @Override + protected void setUp() throws Exception { + super.setUp(); + + getContext().deleteDatabase(DATABASE_NAME); + mDatabase = getContext().openOrCreateDatabase(DATABASE_NAME, Context.MODE_PRIVATE, + null); + assertNotNull(mDatabase); + } + + @Override + protected void tearDown() throws Exception { + mDatabase.close(); + getContext().deleteDatabase(DATABASE_NAME); + + super.tearDown(); + } + + public void testScript1() { + mDatabase.beginTransaction(); + mDatabase.execSQL("CREATE VIRTUAL TABLE ft USING fts3;"); + mDatabase.execSQL("INSERT INTO ft_content VALUES(1,'aback');"); + mDatabase.execSQL("INSERT INTO ft_content VALUES(2,'abaft');"); + mDatabase.execSQL("INSERT INTO ft_content VALUES(3,'abandon');"); + mDatabase.execSQL("INSERT INTO ft_segdir VALUES(0,0,0,0,'0 29',X" + + "'0005616261636b03010200ffffffff070266740302020003046e646f6e03030200');"); + mDatabase.setTransactionSuccessful(); + mDatabase.endTransaction(); + try { + mDatabase.execSQL("SELECT * FROM ft WHERE ft MATCH 'abandon';"); + } catch (SQLiteDatabaseCorruptException e) { + return; + } + fail("Expecting a SQLiteDatabaseCorruptException"); + } + + public void testScript2() { + mDatabase.beginTransaction(); + mDatabase.execSQL("CREATE VIRTUAL TABLE ft USING fts3;"); + mDatabase.execSQL("INSERT INTO ft_segments VALUES(1," + + "X'0004616263300301020003013103020200040130030b0200040131030c0200');"); + mDatabase.execSQL("INSERT INTO ft_segments VALUES(2," + + "X'00056162633132030d0200040133030e0200040134030f020004013503100200');"); + mDatabase.execSQL("INSERT INTO ft_segments VALUES(3," + + "X'0005616263313603110200040137031202000401380313020004013903140200');"); + mDatabase.execSQL("INSERT INTO ft_segments VALUES(4," + + "X'00046162633203030200030133030402000301340305020003013503060200');"); + mDatabase.execSQL("INSERT INTO ft_segments VALUES(5," + + "X'000461626336030702000301370308020003013803090200030139030a0200');"); + mDatabase.execSQL("INSERT INTO ft_segdir " + + "VALUES(0,0,1,5,'5 157',X'0101056162633132ffffffff070236030132030136');"); + mDatabase.setTransactionSuccessful(); + mDatabase.endTransaction(); + try { + mDatabase.execSQL("SELECT * FROM ft WHERE ft MATCH 'abc20';"); + } catch (SQLiteDatabaseCorruptException e) { + return; + } + fail("Expecting a SQLiteDatabaseCorruptException"); + } + + public void testScript3() { + mDatabase.beginTransaction(); + mDatabase.execSQL("CREATE VIRTUAL TABLE ft USING fts4;"); + mDatabase.execSQL("INSERT INTO ft_segments VALUES" + + "(1,X'00046162633003010200040178030202000501780303020003013103040200');"); + mDatabase.execSQL("INSERT INTO ft_segments VALUES" + + "(2,X'00056162633130031f0200ffffffff07ff5566740302020003046e646f6e03030200');"); + mDatabase.execSQL("INSERT INTO ft_segments VALUES(384,NULL);"); + mDatabase.execSQL("INSERT INTO ft_segdir VALUES" + + "(0,0,0,0,'0 24',X'000561626331780305020005017803060200');"); + mDatabase.execSQL("INSERT INTO ft_segdir VALUES" + + " (0,1,0,0,'0 24',X'000461626332030702000401780308020005017803090200');"); + mDatabase.execSQL("INSERT INTO ft_segdir VALUES" + + "(0,2,0,0,'0 24',X'000461626333030a0200040178030b0200050178030c0200');"); + mDatabase.execSQL("INSERT INTO ft_segdir VALUES" + + "(0,3,0,0,'0 24',X'000461626334030d0200040178030e0200050178030f0200');"); + mDatabase.execSQL("INSERT INTO ft_segdir VALUES" + + "(0,4,0,0,'0 24',X'000461626335031002000401780311020005017803120200');"); + mDatabase.execSQL("INSERT INTO ft_segdir VALUES" + + "(0,5,0,0,'0 24',X'000461626336031302000401780314020005017803150200');"); + mDatabase.execSQL("INSERT INTO ft_segdir VALUES" + + "(0,6,0,0,'0 24',X'000461626337031602000401780317020005017803180200');"); + mDatabase.execSQL("INSERT INTO ft_segdir VALUES" + + "(0,7,0,0,'0 24',X'00046162633803190200040178031a0200050178031b0200');"); + mDatabase.execSQL("INSERT INTO ft_segdir VALUES" + + "(0,8,0,0,'0 24',X'000461626339031c0200040178031d0200050178031e0200');"); + mDatabase.execSQL("INSERT INTO ft_segdir VALUES" + + "(0,9,0,0,'0 25',X'00066162633130780320020006017803210200');"); + mDatabase.execSQL("INSERT INTO ft_segdir VALUES" + + "(0,10,0,0,'0 25',X'00056162633131032202000501780323020006017803240200');"); + mDatabase.execSQL("INSERT INTO ft_segdir VALUES(1,0,1,2,'384 -42',X'0101056162633130');"); + mDatabase.execSQL("INSERT INTO ft_stat VALUES(1,X'000b');"); + mDatabase.execSQL("PRAGMA writable_schema=OFF;"); + mDatabase.setTransactionSuccessful(); + mDatabase.endTransaction(); + try { + mDatabase.execSQL("INSERT INTO ft(ft) VALUES('merge=1,4');"); + } catch (SQLiteDatabaseCorruptException e) { + return; + } + fail("Expecting a SQLiteDatabaseCorruptException"); + } +} + + + + + + + + + + + diff --git a/tests/tests/text/src/android/text/util/cts/LinkifyTest.java b/tests/tests/text/src/android/text/util/cts/LinkifyTest.java index 69956da8b99..e1c4742de0a 100644 --- a/tests/tests/text/src/android/text/util/cts/LinkifyTest.java +++ b/tests/tests/text/src/android/text/util/cts/LinkifyTest.java @@ -934,6 +934,17 @@ public class LinkifyTest { domain.length(), email); } + @Test + public void testAddLinks_unsupportedCharacters() { + String url = "moc.diordna.com"; + verifyAddLinksWithWebUrlSucceeds(url + " should be linkified", url); + + verifyAddLinksWithWebUrlFails("u202C character should not be linkified", "\u202C" + url); + verifyAddLinksWithWebUrlFails("u202D character should not be linkified", url + "\u202D"); + verifyAddLinksWithWebUrlFails( + "u202E character should not be linkified", url + "moc\u202E.diordna.com"); + } + // Utility functions private static void verifyAddLinksWithWebUrlSucceeds(String msg, String url) { verifyAddLinksSucceeds(msg, url, Linkify.WEB_URLS); diff --git a/tests/tests/view/res/layout/view_layout.xml b/tests/tests/view/res/layout/view_layout.xml index c3b97c5ee7c..6f886bbf9fd 100644 --- a/tests/tests/view/res/layout/view_layout.xml +++ b/tests/tests/view/res/layout/view_layout.xml @@ -26,8 +26,8 @@ <android.view.cts.MockView android:id="@+id/mock_view" - android:layout_width="100px" - android:layout_height="200px"/> + android:layout_width="100dp" + android:layout_height="75dp"/> <android.view.cts.MockView android:id="@+id/scroll_view" diff --git a/tests/tests/view/src/android/view/cts/ViewTest.java b/tests/tests/view/src/android/view/cts/ViewTest.java index 831aa1579fe..6625e0aef1b 100644 --- a/tests/tests/view/src/android/view/cts/ViewTest.java +++ b/tests/tests/view/src/android/view/cts/ViewTest.java @@ -1820,24 +1820,29 @@ public class ViewTest { @Test public void testMeasure() throws Throwable { final MockView view = (MockView) mActivity.findViewById(R.id.mock_view); + + float density = view.getContext().getResources().getDisplayMetrics().density; + int size1 = (int) (100 * density + 0.5); + int size2 = (int) (75 * density + 0.5); + assertTrue(view.hasCalledOnMeasure()); - assertEquals(100, view.getMeasuredWidth()); - assertEquals(200, view.getMeasuredHeight()); + assertEquals(size1, view.getMeasuredWidth()); + assertEquals(size2, view.getMeasuredHeight()); view.reset(); mActivityRule.runOnUiThread(view::requestLayout); mInstrumentation.waitForIdleSync(); assertTrue(view.hasCalledOnMeasure()); - assertEquals(100, view.getMeasuredWidth()); - assertEquals(200, view.getMeasuredHeight()); + assertEquals(size1, view.getMeasuredWidth()); + assertEquals(size2, view.getMeasuredHeight()); view.reset(); - final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(200, 100); + final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(size2, size1); mActivityRule.runOnUiThread(() -> view.setLayoutParams(layoutParams)); mInstrumentation.waitForIdleSync(); assertTrue(view.hasCalledOnMeasure()); - assertEquals(200, view.getMeasuredWidth()); - assertEquals(100, view.getMeasuredHeight()); + assertEquals(size2, view.getMeasuredWidth()); + assertEquals(size1, view.getMeasuredHeight()); } @Test(expected=NullPointerException.class) @@ -2416,11 +2421,15 @@ public class ViewTest { final View view = mActivity.findViewById(R.id.mock_view); Rect rect = new Rect(); + float density = view.getContext().getResources().getDisplayMetrics().density; + int size1 = (int) (100 * density + 0.5); + int size2 = (int) (75 * density + 0.5); + assertTrue(view.getLocalVisibleRect(rect)); assertEquals(0, rect.left); assertEquals(0, rect.top); - assertEquals(100, rect.right); - assertEquals(200, rect.bottom); + assertEquals(size1, rect.right); + assertEquals(size2, rect.bottom); final LinearLayout.LayoutParams layoutParams1 = new LinearLayout.LayoutParams(0, 300); mActivityRule.runOnUiThread(() -> view.setLayoutParams(layoutParams1)); diff --git a/tools/cts-tradefed/res/config/cts-known-failures.xml b/tools/cts-tradefed/res/config/cts-known-failures.xml index 5d43956e7de..b68ed938ecc 100644 --- a/tools/cts-tradefed/res/config/cts-known-failures.xml +++ b/tools/cts-tradefed/res/config/cts-known-failures.xml @@ -207,4 +207,7 @@ <!-- test fails if usb charging is disabled which is not mandatory --> <option name="compatibility:exclude-filter" value="CtsDumpsysHostTestCases android.dumpsys.cts.StoragedDumpsysTest#testStoragedOutput" /> + <!-- b/126515980 --> + <!-- fails on some devices because the IME blocks the screen, causing UIAutomator queries to fail --> + <option name="compatibility:exclude-filter" value="CtsAutoFillServiceTestCases android.autofillservice.cts.SimpleSaveActivityTest#testTapLink_changeOrientationThenTapBack" /> </configuration> |