Fix NPE when user swipes back in All Apps and no matching view found
This crash will occur every time user swipes back and
there is not a view to return to
Introduced in I56cda07f3eccc11e8909f7fb28210f65cc6e0f1d
Bug: 235494234
Test: manual
Change-Id: I1261afcefec8fed4be20ab9ef439a50bc706d464
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index d26e1ab..ebed31b 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -2776,7 +2776,7 @@
View v = getFirstMatch(Collections.singletonList(activeRecyclerView),
preferredItem, packageAndUserAndApp);
- if (activeRecyclerView.getCurrentScrollY() > 0) {
+ if (v != null && activeRecyclerView.getCurrentScrollY() > 0) {
RectF locationBounds = new RectF();
FloatingIconView.getLocationBoundsForView(this, v, false, locationBounds,
new Rect());
@@ -2804,6 +2804,7 @@
* @param containers List of ViewGroups to scan, in order of preference.
* @param operators List of operators, in order starting from best matching operator.
*/
+ @Nullable
private static View getFirstMatch(Iterable<ViewGroup> containers,
final Predicate<ItemInfo>... operators) {
for (Predicate<ItemInfo> operator : operators) {
@@ -2821,6 +2822,7 @@
* Returns the first view matching the operator in the given ViewGroups, or null if none.
* Forward iteration matters.
*/
+ @Nullable
private static View mapOverViewGroup(ViewGroup container, Predicate<ItemInfo> op) {
final int itemCount = container.getChildCount();
for (int itemIdx = 0; itemIdx < itemCount; itemIdx++) {