Merge "Preventing dead lock in layout inflation" into ub-launcher3-master
diff --git a/quickstep/recents_ui_overrides/src/com/android/launcher3/uioverrides/states/BackgroundAppState.java b/quickstep/recents_ui_overrides/src/com/android/launcher3/uioverrides/states/BackgroundAppState.java
index f3cbc08..bb66ae1 100644
--- a/quickstep/recents_ui_overrides/src/com/android/launcher3/uioverrides/states/BackgroundAppState.java
+++ b/quickstep/recents_ui_overrides/src/com/android/launcher3/uioverrides/states/BackgroundAppState.java
@@ -69,7 +69,7 @@
             return super.getOverviewScaleAndTranslation(launcher);
         }
         TaskView dummyTask;
-        if (recentsView.getCurrentPage() >= 0) {
+        if (recentsView.getCurrentPage() >= recentsView.getTaskViewStartIndex()) {
             if (recentsView.getCurrentPage() <= taskCount - 1) {
                 dummyTask = recentsView.getCurrentPageTaskView();
             } else {
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/LauncherRecentsView.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/LauncherRecentsView.java
index ca33605..82fbbc6 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/LauncherRecentsView.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/LauncherRecentsView.java
@@ -326,8 +326,8 @@
     @Override
     protected void onAttachedToWindow() {
         super.onAttachedToWindow();
-        PluginManagerWrapper.INSTANCE.get(getContext())
-                .addPluginListener(mRecentsExtraCardPluginListener, RecentsExtraCard.class);
+        PluginManagerWrapper.INSTANCE.get(getContext()).addPluginListener(
+                mRecentsExtraCardPluginListener, RecentsExtraCard.class);
     }
 
     @Override
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java
index cf616fe..c055db1 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java
@@ -1855,8 +1855,8 @@
     private void updateEnabledOverlays() {
         int overlayEnabledPage = mOverlayEnabled ? getNextPage() : -1;
         int taskCount = getTaskViewCount();
-        for (int i = 0; i < taskCount; i++) {
-            getTaskViewAt(i).setOverlayEnabled(i == overlayEnabledPage);
+        for (int i = mTaskViewStartIndex; i < mTaskViewStartIndex + taskCount; i++) {
+            getTaskViewAtByAbsoluteIndex(i).setOverlayEnabled(i == overlayEnabledPage);
         }
     }
 
diff --git a/src/com/android/launcher3/notification/NotificationListener.java b/src/com/android/launcher3/notification/NotificationListener.java
index 0e73829..059ad18 100644
--- a/src/com/android/launcher3/notification/NotificationListener.java
+++ b/src/com/android/launcher3/notification/NotificationListener.java
@@ -115,8 +115,8 @@
         switch (message.what) {
             case MSG_NOTIFICATION_POSTED: {
                 StatusBarNotification sbn = (StatusBarNotification) message.obj;
-                mUiHandler.obtainMessage(shouldBeFilteredOut(sbn)
-                                ? MSG_NOTIFICATION_REMOVED : MSG_NOTIFICATION_POSTED,
+                mUiHandler.obtainMessage(notificationIsValidForUI(sbn)
+                                ? MSG_NOTIFICATION_POSTED : MSG_NOTIFICATION_REMOVED,
                         toKeyPair(sbn)).sendToTarget();
                 return true;
             }
@@ -148,7 +148,7 @@
                 if (sIsConnected) {
                     try {
                         activeNotifications = Arrays.stream(getActiveNotifications())
-                                .filter(this::shouldBeFilteredOut)
+                                .filter(this::notificationIsValidForUI)
                                 .collect(Collectors.toList());
                     } catch (SecurityException ex) {
                         Log.e(TAG, "SecurityException: failed to fetch notifications");
@@ -305,22 +305,22 @@
     }
 
     /**
-     * Returns true for notifications that don't have an intent
-     * or are headers for grouped notifications and should be filtered out.
+     * Returns true for notifications that have an intent and are not headers for grouped
+     * notifications and should be shown in the notification popup.
      */
     @WorkerThread
-    private boolean shouldBeFilteredOut(StatusBarNotification sbn) {
+    private boolean notificationIsValidForUI(StatusBarNotification sbn) {
         Notification notification = sbn.getNotification();
         updateGroupKeyIfNecessary(sbn);
 
         getCurrentRanking().getRanking(sbn.getKey(), mTempRanking);
         if (!mTempRanking.canShowBadge()) {
-            return true;
+            return false;
         }
         if (mTempRanking.getChannel().getId().equals(NotificationChannel.DEFAULT_CHANNEL_ID)) {
             // Special filtering for the default, legacy "Miscellaneous" channel.
             if ((notification.flags & Notification.FLAG_ONGOING_EVENT) != 0) {
-                return true;
+                return false;
             }
         }
 
@@ -328,7 +328,7 @@
         CharSequence text = notification.extras.getCharSequence(Notification.EXTRA_TEXT);
         boolean missingTitleAndText = TextUtils.isEmpty(title) && TextUtils.isEmpty(text);
         boolean isGroupHeader = (notification.flags & Notification.FLAG_GROUP_SUMMARY) != 0;
-        return (isGroupHeader || missingTitleAndText);
+        return !isGroupHeader && !missingTitleAndText;
     }
 
     private static Pair<PackageUserKey, NotificationKeyData> toKeyPair(StatusBarNotification sbn) {
diff --git a/src_plugins/com/android/systemui/plugins/RecentsExtraCard.java b/src_plugins/com/android/systemui/plugins/RecentsExtraCard.java
index 0ebea3d..cd9f33d 100644
--- a/src_plugins/com/android/systemui/plugins/RecentsExtraCard.java
+++ b/src_plugins/com/android/systemui/plugins/RecentsExtraCard.java
@@ -34,9 +34,9 @@
     /**
      * Sets up the recents overview extra card and fills in data.
      *
-     * @param context Plugin context
+     * @param context     Plugin context
      * @param frameLayout PlaceholderView
-     * @param activity Recents activity to hold extra view
+     * @param activity    Recents activity to hold extra view
      */
     void setupView(Context context, FrameLayout frameLayout, Activity activity);
 }
diff --git a/tests/tapl/com/android/launcher3/tapl/AllApps.java b/tests/tapl/com/android/launcher3/tapl/AllApps.java
index cc92327..1ecfff7 100644
--- a/tests/tapl/com/android/launcher3/tapl/AllApps.java
+++ b/tests/tapl/com/android/launcher3/tapl/AllApps.java
@@ -29,6 +29,8 @@
 import com.android.launcher3.ResourceUtils;
 import com.android.launcher3.testing.TestProtocol;
 
+import java.util.stream.Collectors;
+
 /**
  * Operations on AllApps opened from Home. Also a parent for All Apps opened from Overview.
  */
@@ -67,7 +69,7 @@
             return false;
         }
         if (iconBounds.bottom > displayBottom) {
-            LauncherInstrumentation.log("hasClickableIcon: icon center bellow bottom offset");
+            LauncherInstrumentation.log("hasClickableIcon: icon bottom below bottom offset");
             return false;
         }
         LauncherInstrumentation.log("hasClickableIcon: icon is clickable");
@@ -116,7 +118,12 @@
                             displayBottom)) {
                         mLauncher.scrollToLastVisibleRow(
                                 allAppsContainer,
-                                mLauncher.getObjectsInContainer(allAppsContainer, "icon"),
+                                mLauncher.getObjectsInContainer(allAppsContainer, "icon")
+                                        .stream()
+                                        .filter(object ->
+                                                object.getVisibleBounds().bottom
+                                                        <= displayBottom)
+                                        .collect(Collectors.toList()),
                                 searchBox.getVisibleBounds().bottom
                                         - allAppsContainer.getVisibleBounds().top);
                         final int newScroll = getAllAppsScroll();
diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
index 1c851f4..0d3938f 100644
--- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
+++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
@@ -797,14 +797,15 @@
 
         // TODO: Make the gesture steps dependent on the distance so that it can run for various
         //       screen sizes
+        final int totalMargin = Math.max(bottomMargin, getBottomGestureMargin(container));
         scroll(
                 container,
                 Direction.DOWN,
                 new Rect(
                         0,
+                        totalMargin / 2,
                         0,
-                        0,
-                        Math.max(bottomMargin, getBottomGestureMargin(container))),
+                        totalMargin / 2),
                 80);
     }