Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5a695b5b authored by Thiru Ramasamy's avatar Thiru Ramasamy Committed by Automerger Merge Worker
Browse files

Merge "Fixes NPE with system shortcuts." into rvc-dev am: 6f5d4bb8

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/12035575

Change-Id: I75738a78334c20f7e1bc167ed269ca1ee121f7d9
parents 9fd2aa3b 6f5d4bb8
Loading
Loading
Loading
Loading
+16 −11
Original line number Diff line number Diff line
@@ -52,7 +52,6 @@ import com.android.launcher3.util.MainThreadInitializedObject;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.OptionalInt;
import java.util.stream.IntStream;

@@ -315,16 +314,22 @@ public class PredictionUiStateManager implements StateListener<LauncherState>,
     * {@link LauncherSettings.Favorites#ITEM_TYPE_DEEP_SHORTCUT}
     */
    public OptionalInt getAllAppsRank(@Nullable ItemInfo itemInfo) {
        Optional<ComponentKey> componentKey = Optional.ofNullable(itemInfo)
                .filter(item -> item.itemType == ITEM_TYPE_APPLICATION
                        || item.itemType == ITEM_TYPE_SHORTCUT
                        || item.itemType == ITEM_TYPE_DEEP_SHORTCUT)
                .map(ItemInfo::getTargetComponent)
                .map(componentName -> new ComponentKey(componentName, itemInfo.user));

        return componentKey.map(key -> IntStream.range(0, getCurrentState().apps.size())
                .filter(index -> key.equals(getCurrentState().apps.get(index).getComponentKey()))
                .findFirst()).orElseGet(OptionalInt::empty);
        if (itemInfo == null || itemInfo.getTargetComponent() == null || itemInfo.user == null) {
            return OptionalInt.empty();
        }

        if (itemInfo.itemType == ITEM_TYPE_APPLICATION
                || itemInfo.itemType == ITEM_TYPE_SHORTCUT
                || itemInfo.itemType == ITEM_TYPE_DEEP_SHORTCUT) {
            ComponentKey key = new ComponentKey(itemInfo.getTargetComponent(),
                    itemInfo.user);
            final List<ComponentKeyMapper> apps = getCurrentState().apps;
            return IntStream.range(0, apps.size())
                    .filter(index -> key.equals(apps.get(index).getComponentKey()))
                    .findFirst();
        }

        return OptionalInt.empty();
    }

    /**
+6 −2
Original line number Diff line number Diff line
@@ -655,11 +655,15 @@ public class HotseatPredictionController implements DragController.DragListener,
                            + ",launchLocation:" + itemInfo.container);
        }

        final ComponentKey k = new ComponentKey(itemInfo.getTargetComponent(), itemInfo.user);
        if (itemInfo.getTargetComponent() == null || itemInfo.user == null) {
            return;
        }

        final ComponentKey key = new ComponentKey(itemInfo.getTargetComponent(), itemInfo.user);

        final List<ComponentKeyMapper> predictedApps = new ArrayList<>(mComponentKeyMappers);
        OptionalInt rank = IntStream.range(0, predictedApps.size())
                .filter((i) -> k.equals(predictedApps.get(i).getComponentKey()))
                .filter(index -> key.equals(predictedApps.get(index).getComponentKey()))
                .findFirst();
        if (!rank.isPresent()) {
            return;