Merge "Exclude automotive from Condition Provider Test." into pie-cts-dev am: b76c2db94d am: c8c108745c am: ee0ffb830f
am: f339b75293

Change-Id: Ic227e5324ca82fb5ce2e6f041c25e8f6159cedb6
diff --git a/apps/CtsVerifier/res/values/strings.xml b/apps/CtsVerifier/res/values/strings.xml
index d688ce9..22109e7 100755
--- a/apps/CtsVerifier/res/values/strings.xml
+++ b/apps/CtsVerifier/res/values/strings.xml
@@ -5103,11 +5103,7 @@
     <string name="bubbles_notification_test_verify_9">Click the button below and verify that a bubble
         appears on screen, auto-expanded.</string>
     <string name="bubbles_notification_test_button_9">Send auto-expanded bubble notification</string>
-    <string name="bubbles_notification_test_title_10">No bubbles on low memory device</string>
-    <string name="bubbles_notification_test_verify_10">Click the button below and verify that a
-        bubble does NOT appear on screen. Verify that there is a notification in the notification
-        shade.</string>
-    <string name="bubbles_notification_test_button_10">Add bubble</string>
+    <string name="bubbles_notification_no_bubbles_low_mem">No bubbles on low memory device; no tests to run</string>
     <string name="bubbles_test_summary_title">Test Complete</string>
     <string name="bubbles_test_summary">%1$d out of %2$d tests passed</string>
     <string name="bubble_activity_title">Bubble Activity</string>
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/notifications/BubblesVerifierActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/notifications/BubblesVerifierActivity.java
index 0c4addf..3dc41e6 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/notifications/BubblesVerifierActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/notifications/BubblesVerifierActivity.java
@@ -103,14 +103,9 @@
             runNextTestOrShowSummary();
         });
 
-        // Make sure they're enabled
-        mTests.add(new EnableBubbleTest());
-
         ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
-        if (am.isLowRamDevice()) {
-            // Bubbles don't occur on low ram, instead they just show as notifs so test that
-            mTests.add(new LowRamBubbleTest());
-        } else {
+        if (!am.isLowRamDevice()) {
+            mTests.add(new EnableBubbleTest());
             mTests.add(new SendBubbleTest());
             mTests.add(new SuppressNotifTest());
             mTests.add(new AddNotifTest());
@@ -120,6 +115,10 @@
             mTests.add(new DismissBubbleTest());
             mTests.add(new DismissNotificationTest());
             mTests.add(new AutoExpandBubbleTest());
+        } else {
+            Toast.makeText(getApplicationContext(),
+                    getResources().getString(R.string.bubbles_notification_no_bubbles_low_mem),
+                    Toast.LENGTH_LONG).show();
         }
 
         setPassFailButtonClickListeners();
@@ -463,32 +462,6 @@
         }
     }
 
-    private class LowRamBubbleTest extends BubblesTestStep {
-        @Override
-        public int getButtonText() {
-            return R.string.bubbles_notification_test_button_10;
-        }
-
-        @Override
-        public int getTestTitle() {
-            return R.string.bubbles_notification_test_title_10;
-        }
-
-        @Override
-        public int getTestDescription() {
-            return R.string.bubbles_notification_test_verify_10;
-        }
-
-        @Override
-        public void performTestAction() {
-            Notification.Builder builder =
-                    getBasicNotifBuilder("Bubble notification", "Low ram test");
-            builder.setBubbleMetadata(getBasicBubbleBuilder().build());
-
-            mNotificationManager.notify(NOTIFICATION_ID, builder.build());
-        }
-    }
-
     /** Creates a minimally filled out {@link android.app.Notification.BubbleMetadata.Builder} */
     private Notification.BubbleMetadata.Builder getBasicBubbleBuilder() {
         Context context = getApplicationContext();
diff --git a/tests/apppredictionservice/src/android/apppredictionservice/cts/AppPredictionServiceTest.java b/tests/apppredictionservice/src/android/apppredictionservice/cts/AppPredictionServiceTest.java
index dbc5f38..8e92d9a 100644
--- a/tests/apppredictionservice/src/android/apppredictionservice/cts/AppPredictionServiceTest.java
+++ b/tests/apppredictionservice/src/android/apppredictionservice/cts/AppPredictionServiceTest.java
@@ -39,6 +39,7 @@
 import androidx.test.InstrumentationRegistry;
 import androidx.test.runner.AndroidJUnit4;
 
+import com.android.compatibility.common.util.RequiredServiceRule;
 import com.android.compatibility.common.util.SystemUtil;
 
 import org.junit.After;
@@ -47,6 +48,7 @@
 import org.junit.runner.RunWith;
 
 import java.util.ArrayList;
+import org.junit.ClassRule;
 import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.Executors;
@@ -66,6 +68,10 @@
     private static final String TEST_LAUNCH_LOCATION = "testCollapsedLocation";
     private static final int TEST_ACTION = 2;
 
+    @ClassRule
+    public static final RequiredServiceRule mRequiredServiceRule =
+            new RequiredServiceRule(APP_PREDICTION_SERVICE);
+
     private ServiceReporter mReporter;
     private Bundle mPredictionContextExtras;
 
diff --git a/tests/contentsuggestions/src/android/contentsuggestions/cts/ContentSuggestionsManagerTest.java b/tests/contentsuggestions/src/android/contentsuggestions/cts/ContentSuggestionsManagerTest.java
index c9f7fbb..20c6a5f 100644
--- a/tests/contentsuggestions/src/android/contentsuggestions/cts/ContentSuggestionsManagerTest.java
+++ b/tests/contentsuggestions/src/android/contentsuggestions/cts/ContentSuggestionsManagerTest.java
@@ -37,10 +37,13 @@
 import androidx.annotation.NonNull;
 import androidx.test.runner.AndroidJUnit4;
 
+import com.android.compatibility.common.util.RequiredServiceRule;
+
 import com.google.common.collect.Lists;
 
 import org.junit.After;
 import org.junit.Before;
+import org.junit.ClassRule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
@@ -58,6 +61,10 @@
     private static final long VERIFY_TIMEOUT_MS = 5_000;
     private static final long SERVICE_LIFECYCLE_TIMEOUT_MS = 10_000;
 
+    @ClassRule
+    public static final RequiredServiceRule mRequiredServiceRule =
+            new RequiredServiceRule(Context.CONTENT_SUGGESTIONS_SERVICE);
+
     private ContentSuggestionsManager mManager;
     private CtsContentSuggestionsService.Watcher mWatcher;
 
diff --git a/tests/tests/view/src/android/view/cts/SystemGestureExclusionRectsTest.java b/tests/tests/view/src/android/view/cts/SystemGestureExclusionRectsTest.java
index 423f3b7..25312e7 100644
--- a/tests/tests/view/src/android/view/cts/SystemGestureExclusionRectsTest.java
+++ b/tests/tests/view/src/android/view/cts/SystemGestureExclusionRectsTest.java
@@ -201,9 +201,62 @@
         assertTrue("set rects timeout", setter[0].await(3, SECONDS));
     }
 
+    @Test
+    public void ignoreHiddenViewRects() throws Throwable {
+        final Activity activity = mActivityRule.getActivity();
+        final View contentView = activity.findViewById(R.id.abslistview_root);
+        final List<Rect> dummyLocalExclusionRects = Lists.newArrayList(new Rect(0, 0, 5, 5));
+        final List<Rect> dummyWindowExclusionRects = new ArrayList<>();
+
+        mActivityRule.runOnUiThread(() -> {
+            final View v = activity.findViewById(R.id.animating_view);
+            int[] point = new int[2];
+            v.getLocationInWindow(point);
+            for (Rect r : dummyLocalExclusionRects) {
+                Rect offsetR = new Rect(r);
+                offsetR.offsetTo(point[0], point[1]);
+                dummyWindowExclusionRects.add(offsetR);
+            }
+        });
+
+        // Set an exclusion rect on the animating view, ensure it's reported
+        final GestureExclusionLatcher[] setLatch = new GestureExclusionLatcher[1];
+        mActivityRule.runOnUiThread(() -> {
+            final View v = activity.findViewById(R.id.animating_view);
+            setLatch[0] = GestureExclusionLatcher.watching(v.getViewTreeObserver());
+            v.setSystemGestureExclusionRects(dummyLocalExclusionRects);
+        });
+        assertTrue("set rects timeout", setLatch[0].await(3, SECONDS));
+        assertEquals("returned rects as expected", dummyWindowExclusionRects,
+                setLatch[0].getLastReportedRects());
+
+        // Hide the content view, ensure that the reported rects are null for the child view
+        final GestureExclusionLatcher[] updateHideLatch = new GestureExclusionLatcher[1];
+        mActivityRule.runOnUiThread(() -> {
+            final View v = activity.findViewById(R.id.animating_view);
+            updateHideLatch[0] = GestureExclusionLatcher.watching(v.getViewTreeObserver());
+            contentView.setVisibility(View.INVISIBLE);
+        });
+        assertTrue("set rects timeout", updateHideLatch[0].await(3, SECONDS));
+        assertEquals("returned rects as expected", Collections.EMPTY_LIST,
+                updateHideLatch[0].getLastReportedRects());
+
+        // Show the content view again, ensure that the reported rects are valid for the child view
+        final GestureExclusionLatcher[] updateShowLatch = new GestureExclusionLatcher[1];
+        mActivityRule.runOnUiThread(() -> {
+            final View v = activity.findViewById(R.id.animating_view);
+            updateShowLatch[0] = GestureExclusionLatcher.watching(v.getViewTreeObserver());
+            contentView.setVisibility(View.VISIBLE);
+        });
+        assertTrue("set rects timeout", updateShowLatch[0].await(3, SECONDS));
+        assertEquals("returned rects as expected", dummyWindowExclusionRects,
+                updateShowLatch[0].getLastReportedRects());
+    }
+
     private static class GestureExclusionLatcher implements Consumer<List<Rect>> {
         private final CountDownLatch mLatch = new CountDownLatch(1);
         private final ViewTreeObserver mVto;
+        private List<Rect> mLastReportedRects = Collections.EMPTY_LIST;
 
         public static GestureExclusionLatcher watching(ViewTreeObserver vto) {
             final GestureExclusionLatcher latcher = new GestureExclusionLatcher(vto);
@@ -219,8 +272,13 @@
             return mLatch.await(time, unit);
         }
 
+        public List<Rect> getLastReportedRects() {
+            return mLastReportedRects;
+        }
+
         @Override
         public void accept(List<Rect> rects) {
+            mLastReportedRects = rects;
             mLatch.countDown();
             mVto.removeOnSystemGestureExclusionRectsChangedListener(this);
         }