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

Commit a591bf17 authored by Samuel Fufa's avatar Samuel Fufa
Browse files

Add logging for hybrid hotseat

Bug: 142753423
Test: Manual
Change-Id: I5abacd64c43130af54314d3c2fd07407e39d6af9
parent 56c9c86f
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.util.Log;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.android.launcher3.allapps.AllAppsStore;
@@ -45,11 +46,13 @@ import com.android.launcher3.popup.SystemShortcut;
import com.android.launcher3.shortcuts.ShortcutKey;
import com.android.launcher3.uioverrides.PredictedAppIcon;
import com.android.launcher3.uioverrides.QuickstepLauncher;
import com.android.launcher3.userevent.nano.LauncherLogProto;
import com.android.launcher3.util.ComponentKey;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.IntStream;

/**
 * Provides prediction ability for the hotseat. Fills gaps in hotseat with predicted items, allows
@@ -73,6 +76,7 @@ public class HotseatPredictionController implements DragController.DragListener,

    private DropTarget.DragObject mDragObject;
    private int mHotSeatItemsCount;
    private int mPredictedSpotsCount = 0;

    private Launcher mLauncher;
    private Hotseat mHotseat;
@@ -86,6 +90,8 @@ public class HotseatPredictionController implements DragController.DragListener,

    private List<PredictedAppIcon.PredictedIconOutlineDrawing> mOutlineDrawings = new ArrayList<>();

    private static HotseatPredictionController sInstance;

    public HotseatPredictionController(Launcher launcher) {
        mLauncher = launcher;
        mHotseat = launcher.getHotseat();
@@ -95,6 +101,7 @@ public class HotseatPredictionController implements DragController.DragListener,
        mHotSeatItemsCount = mLauncher.getDeviceProfile().inv.numHotseatIcons;
        launcher.getDeviceProfile().inv.addOnChangeListener(this);
        mHotseat.addOnAttachStateChangeListener(this);
        sInstance = this;
    }

    @Override
@@ -144,6 +151,7 @@ public class HotseatPredictionController implements DragController.DragListener,
            }
            preparePredictionInfo(predictedItem, rank);
        }
        mPredictedSpotsCount = predictionIndex;
        bindItems(newItems, animate, callback);
    }

@@ -421,6 +429,26 @@ public class HotseatPredictionController implements DragController.DragListener,
        }
    }

    /**
     * Fill in predicted_rank field based on app prediction.
     * Only applicable when {@link ItemInfo#itemType} is PREDICTED_HOTSEAT
     */
    public static void fillInHybridHotseatRank(
            @NonNull ItemInfo itemInfo, @NonNull LauncherLogProto.Target target) {
        if (sInstance == null || itemInfo.getTargetComponent() == null
                || itemInfo.container != LauncherSettings.Favorites.CONTAINER_HOTSEAT_PREDICTION) {
            return;
        }
        final ComponentKey k = new ComponentKey(itemInfo.getTargetComponent(), itemInfo.user);

        final List<ComponentKeyMapper> predictedApps = sInstance.mComponentKeyMappers;
        IntStream.range(0, predictedApps.size())
                .filter((i) -> k.equals(predictedApps.get(i).getComponentKey()))
                .findFirst()
                .ifPresent((rank) -> target.predictedRank =
                        Integer.parseInt(sInstance.mPredictedSpotsCount + "0" + rank));
    }

    private static boolean isPredictedIcon(View view) {
        return view instanceof PredictedAppIcon && view.getTag() instanceof WorkspaceItemInfo
                && ((WorkspaceItemInfo) view.getTag()).container
+6 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.content.Context;

import androidx.annotation.NonNull;

import com.android.launcher3.HotseatPredictionController;
import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.InvariantDeviceProfile.OnIDPChangeListener;
import com.android.launcher3.ItemInfo;
@@ -316,6 +317,11 @@ public class PredictionUiStateManager implements StateListener, ItemInfoUpdateRe
                && itemInfo.itemType != LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT)) {
            return;
        }
        if (itemInfo.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT_PREDICTION) {
            HotseatPredictionController.fillInHybridHotseatRank(itemInfo, target);
            return;
        }

        final ComponentKey k = new ComponentKey(itemInfo.getTargetComponent(), itemInfo.user);
        final List<ComponentKeyMapper> predictedApps = manager.getCurrentState().apps;
        IntStream.range(0, predictedApps.size())