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

Commit dc122e81 authored by Samuel Fufa's avatar Samuel Fufa Committed by Android (Google) Code Review
Browse files

Merge "[WW logging] Log rankings for app launches" into ub-launcher3-rvc-dev

parents eb9f60ad e9c4f401
Loading
Loading
Loading
Loading
+39 −13
Original line number Original line Diff line number Diff line
@@ -18,12 +18,12 @@ package com.android.launcher3.appprediction;


import static com.android.launcher3.LauncherState.BACKGROUND_APP;
import static com.android.launcher3.LauncherState.BACKGROUND_APP;
import static com.android.launcher3.LauncherState.OVERVIEW;
import static com.android.launcher3.LauncherState.OVERVIEW;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ALL_APPS_RANKED;


import android.app.prediction.AppPredictor;
import android.app.prediction.AppPredictor;
import android.app.prediction.AppTarget;
import android.app.prediction.AppTarget;
import android.content.ComponentName;
import android.content.ComponentName;
import android.content.Context;
import android.content.Context;
import android.os.Process;


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


@@ -36,9 +36,10 @@ import com.android.launcher3.LauncherState;
import com.android.launcher3.Utilities;
import com.android.launcher3.Utilities;
import com.android.launcher3.allapps.AllAppsContainerView;
import com.android.launcher3.allapps.AllAppsContainerView;
import com.android.launcher3.allapps.AllAppsStore.OnUpdateListener;
import com.android.launcher3.allapps.AllAppsStore.OnUpdateListener;
import com.android.launcher3.hybridhotseat.HotseatFileLog;
import com.android.launcher3.hybridhotseat.HotseatPredictionController;
import com.android.launcher3.hybridhotseat.HotseatPredictionController;
import com.android.launcher3.icons.IconCache.ItemInfoUpdateReceiver;
import com.android.launcher3.icons.IconCache.ItemInfoUpdateReceiver;
import com.android.launcher3.logger.LauncherAtom;
import com.android.launcher3.logging.InstanceId;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.model.data.ItemInfoWithIcon;
import com.android.launcher3.model.data.ItemInfoWithIcon;
import com.android.launcher3.shortcuts.ShortcutKey;
import com.android.launcher3.shortcuts.ShortcutKey;
@@ -50,6 +51,7 @@ import com.android.launcher3.util.MainThreadInitializedObject;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Collections;
import java.util.List;
import java.util.List;
import java.util.OptionalInt;
import java.util.stream.IntStream;
import java.util.stream.IntStream;


/**
/**
@@ -304,26 +306,50 @@ public class PredictionUiStateManager implements StateListener<LauncherState>,
    }
    }


    /**
    /**
     * Fill in predicted_rank field based on app prediction.
     * Logs ranking info for launched app within all apps prediction.
     * Only applicable when {@link ItemInfo#itemType} is one of the followings:
     * Only applicable when {@link ItemInfo#itemType} is one of the followings:
     * {@link LauncherSettings.Favorites#ITEM_TYPE_APPLICATION},
     * {@link LauncherSettings.Favorites#ITEM_TYPE_APPLICATION},
     * {@link LauncherSettings.Favorites#ITEM_TYPE_SHORTCUT},
     * {@link LauncherSettings.Favorites#ITEM_TYPE_SHORTCUT},
     * {@link LauncherSettings.Favorites#ITEM_TYPE_DEEP_SHORTCUT}
     * {@link LauncherSettings.Favorites#ITEM_TYPE_DEEP_SHORTCUT}
     */
     */
    public static void fillInPredictedRank(
    public void logLaunchedAppRankingInfo(@NonNull ItemInfo itemInfo, InstanceId instanceId) {
            @NonNull ItemInfo itemInfo, @NonNull LauncherLogProto.Target target) {
        if (itemInfo.getTargetComponent() == null || itemInfo.user == null
                || (itemInfo.itemType != LauncherSettings.Favorites.ITEM_TYPE_APPLICATION
                && itemInfo.itemType != LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT
                && itemInfo.itemType != LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT)) {
            return;
        }


        HotseatFileLog hotseatFileLog = HotseatFileLog.INSTANCE.getNoCreate();
        Launcher launcher = Launcher.getLauncher(mAppsView.getContext());
        final ComponentKey k = new ComponentKey(itemInfo.getTargetComponent(), itemInfo.user);
        final List<ComponentKeyMapper> predictedApps = getCurrentState().apps;
        OptionalInt rank = IntStream.range(0, predictedApps.size())
                .filter((i) -> k.equals(predictedApps.get(i).getComponentKey()))
                .findFirst();
        if (!rank.isPresent()) {
            return;
        }


        if (hotseatFileLog != null && itemInfo != null && Utilities.IS_DEBUG_DEVICE) {
        LauncherAtom.ItemInfo.Builder atomBuilder = LauncherAtom.ItemInfo.newBuilder();
            final String pkg = itemInfo.getTargetComponent() != null
        atomBuilder.setRank(rank.getAsInt());
                    ? itemInfo.getTargetComponent().getPackageName() : "unknown";
        atomBuilder.setContainerInfo(
            hotseatFileLog.log("UserEvent",
                LauncherAtom.ContainerInfo.newBuilder().setPredictionContainer(
                    "appLaunch: packageName:" + pkg + ",isWorkApp:" + (itemInfo.user != null
                        LauncherAtom.PredictionContainer.newBuilder().build()).build());
                            && !Process.myUserHandle().equals(itemInfo.user))
        launcher.getStatsLogManager().log(LAUNCHER_ALL_APPS_RANKED, instanceId,
                            + ",launchLocation:" + itemInfo.container);
                atomBuilder.build());
    }
    }



    /**
     * Fill in predicted_rank field based on app prediction.
     * Only applicable when {@link ItemInfo#itemType} is one of the followings:
     * {@link LauncherSettings.Favorites#ITEM_TYPE_APPLICATION},
     * {@link LauncherSettings.Favorites#ITEM_TYPE_SHORTCUT},
     * {@link LauncherSettings.Favorites#ITEM_TYPE_DEEP_SHORTCUT}
     */
    public static void fillInPredictedRank(
            @NonNull ItemInfo itemInfo, @NonNull LauncherLogProto.Target target) {

        final PredictionUiStateManager manager = PredictionUiStateManager.INSTANCE.getNoCreate();
        final PredictionUiStateManager manager = PredictionUiStateManager.INSTANCE.getNoCreate();
        if (manager == null || itemInfo.getTargetComponent() == null || itemInfo.user == null
        if (manager == null || itemInfo.getTargetComponent() == null || itemInfo.user == null
                || (itemInfo.itemType != LauncherSettings.Favorites.ITEM_TYPE_APPLICATION
                || (itemInfo.itemType != LauncherSettings.Favorites.ITEM_TYPE_APPLICATION
+47 −1
Original line number Original line Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.launcher3.hybridhotseat;
import static com.android.launcher3.InvariantDeviceProfile.CHANGE_FLAG_GRID;
import static com.android.launcher3.InvariantDeviceProfile.CHANGE_FLAG_GRID;
import static com.android.launcher3.LauncherAnimUtils.SCALE_PROPERTY;
import static com.android.launcher3.LauncherAnimUtils.SCALE_PROPERTY;
import static com.android.launcher3.hybridhotseat.HotseatEduController.SETTINGS_ACTION;
import static com.android.launcher3.hybridhotseat.HotseatEduController.SETTINGS_ACTION;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_HOTSEAT_RANKED;


import android.animation.Animator;
import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.AnimatorSet;
@@ -29,6 +30,7 @@ import android.app.prediction.AppTarget;
import android.app.prediction.AppTargetEvent;
import android.app.prediction.AppTargetEvent;
import android.content.ComponentName;
import android.content.ComponentName;
import android.content.Intent;
import android.content.Intent;
import android.os.Process;
import android.util.Log;
import android.util.Log;
import android.view.View;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup;
@@ -52,6 +54,8 @@ import com.android.launcher3.appprediction.DynamicItemCache;
import com.android.launcher3.dragndrop.DragController;
import com.android.launcher3.dragndrop.DragController;
import com.android.launcher3.dragndrop.DragOptions;
import com.android.launcher3.dragndrop.DragOptions;
import com.android.launcher3.icons.IconCache;
import com.android.launcher3.icons.IconCache;
import com.android.launcher3.logger.LauncherAtom;
import com.android.launcher3.logging.InstanceId;
import com.android.launcher3.model.data.AppInfo;
import com.android.launcher3.model.data.AppInfo;
import com.android.launcher3.model.data.FolderInfo;
import com.android.launcher3.model.data.FolderInfo;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.model.data.ItemInfo;
@@ -185,7 +189,6 @@ public class HotseatPredictionController implements DragController.DragListener,


    /**
    /**
     * Returns if hotseat client has predictions
     * Returns if hotseat client has predictions
     * @return
     */
     */
    public boolean hasPredictions() {
    public boolean hasPredictions() {
        return !mComponentKeyMappers.isEmpty();
        return !mComponentKeyMappers.isEmpty();
@@ -358,6 +361,7 @@ public class HotseatPredictionController implements DragController.DragListener,
        updateDependencies();
        updateDependencies();
        bindItems(items, false, null);
        bindItems(items, false, null);
    }
    }

    private void setPredictedApps(List<AppTarget> appTargets) {
    private void setPredictedApps(List<AppTarget> appTargets) {
        mComponentKeyMappers.clear();
        mComponentKeyMappers.clear();
        if (appTargets.isEmpty()) {
        if (appTargets.isEmpty()) {
@@ -635,6 +639,48 @@ public class HotseatPredictionController implements DragController.DragListener,
        mHotseat.fillInLogContainerData(childInfo, child, parents);
        mHotseat.fillInLogContainerData(childInfo, child, parents);
    }
    }


    /**
     * Logs rank info based on current list of predicted items
     */
    public void logLaunchedAppRankingInfo(@NonNull ItemInfo itemInfo, InstanceId instanceId) {
        if (Utilities.IS_DEBUG_DEVICE) {
            final String pkg = itemInfo.getTargetComponent() != null
                    ? itemInfo.getTargetComponent().getPackageName() : "unknown";
            HotseatFileLog.INSTANCE.get(mLauncher).log("UserEvent",
                    "appLaunch: packageName:" + pkg + ",isWorkApp:" + (itemInfo.user != null
                            && !Process.myUserHandle().equals(itemInfo.user))
                            + ",launchLocation:" + itemInfo.container);
        }

        final ComponentKey k = 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()))
                .findFirst();
        if (!rank.isPresent()) {
            return;
        }
        LauncherAtom.PredictedHotseatContainer.Builder containerBuilder =
                LauncherAtom.PredictedHotseatContainer.newBuilder();
        LauncherAtom.ItemInfo.Builder atomBuilder = LauncherAtom.ItemInfo.newBuilder();
        int cardinality = 0;
        for (PredictedAppIcon icon : getPredictedIcons()) {
            ItemInfo info = (ItemInfo) icon.getTag();
            cardinality |= 1 << info.screenId;
        }
        containerBuilder.setCardinality(cardinality);
        atomBuilder.setRank(rank.getAsInt());
        if (itemInfo.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT_PREDICTION) {
            containerBuilder.setIndex(rank.getAsInt());
        }
        atomBuilder.setContainerInfo(
                LauncherAtom.ContainerInfo.newBuilder().setPredictedHotseatContainer(
                        containerBuilder).build());
        mLauncher.getStatsLogManager().log(LAUNCHER_HOTSEAT_RANKED, instanceId,
                atomBuilder.build());
    }

    private class PinPrediction extends SystemShortcut<QuickstepLauncher> {
    private class PinPrediction extends SystemShortcut<QuickstepLauncher> {


        private PinPrediction(QuickstepLauncher target, ItemInfo itemInfo) {
        private PinPrediction(QuickstepLauncher target, ItemInfo itemInfo) {
+11 −0
Original line number Original line Diff line number Diff line
@@ -41,10 +41,12 @@ import com.android.launcher3.LauncherState;
import com.android.launcher3.Workspace;
import com.android.launcher3.Workspace;
import com.android.launcher3.allapps.DiscoveryBounce;
import com.android.launcher3.allapps.DiscoveryBounce;
import com.android.launcher3.anim.AnimatorPlaybackController;
import com.android.launcher3.anim.AnimatorPlaybackController;
import com.android.launcher3.appprediction.PredictionUiStateManager;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.folder.Folder;
import com.android.launcher3.folder.Folder;
import com.android.launcher3.hybridhotseat.HotseatEduController;
import com.android.launcher3.hybridhotseat.HotseatEduController;
import com.android.launcher3.hybridhotseat.HotseatPredictionController;
import com.android.launcher3.hybridhotseat.HotseatPredictionController;
import com.android.launcher3.logging.InstanceId;
import com.android.launcher3.model.data.AppInfo;
import com.android.launcher3.model.data.AppInfo;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.model.data.WorkspaceItemInfo;
import com.android.launcher3.model.data.WorkspaceItemInfo;
@@ -111,6 +113,15 @@ public class QuickstepLauncher extends BaseQuickstepLauncher {
        }
        }
    }
    }


    @Override
    protected void logAppLaunch(ItemInfo info, InstanceId instanceId) {
        super.logAppLaunch(info, instanceId);
        if (mHotseatPredictionController != null) {
            mHotseatPredictionController.logLaunchedAppRankingInfo(info, instanceId);
        }
        PredictionUiStateManager.INSTANCE.get(this).logLaunchedAppRankingInfo(info, instanceId);
    }

    @Override
    @Override
    public void onConfigurationChanged(Configuration newConfig) {
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        super.onConfigurationChanged(newConfig);
+21 −2
Original line number Original line Diff line number Diff line
@@ -78,7 +78,7 @@ public class StatsLogCompatManager extends StatsLogManager {
     */
     */
    @Override
    @Override
    public void log(EventEnum event) {
    public void log(EventEnum event) {
        log(event, DEFAULT_INSTANCE_ID, null);
        log(event, DEFAULT_INSTANCE_ID, (ItemInfo) null);
    }
    }


    /**
    /**
@@ -86,7 +86,7 @@ public class StatsLogCompatManager extends StatsLogManager {
     */
     */
    @Override
    @Override
    public void log(EventEnum event, InstanceId instanceId) {
    public void log(EventEnum event, InstanceId instanceId) {
        log(event, instanceId, null);
        log(event, instanceId, (ItemInfo) null);
    }
    }


    /**
    /**
@@ -97,6 +97,25 @@ public class StatsLogCompatManager extends StatsLogManager {
        log(event, DEFAULT_INSTANCE_ID, info);
        log(event, DEFAULT_INSTANCE_ID, info);
    }
    }


    /**
     * Logs an event.
     *
     * @param event an enum implementing EventEnum interface.
     * @param atomInfo item typically containing app or task launch related information.
     */
    public void log(EventEnum event, InstanceId instanceId, LauncherAtom.ItemInfo atomInfo) {
        LauncherAppState.getInstance(sContext).getModel().enqueueModelUpdateTask(
                new BaseModelUpdateTask() {
                    @Override
                    public void execute(LauncherAppState app, BgDataModel dataModel,
                            AllAppsList apps) {
                        write(event, instanceId, atomInfo, null,
                                LAUNCHER_UICHANGED__DST_STATE__HOME,
                                LAUNCHER_UICHANGED__DST_STATE__BACKGROUND);
                    }
                });
    }

    /**
    /**
     * Logs an event.
     * Logs an event.
     *
     *
+8 −1
Original line number Original line Diff line number Diff line
@@ -43,6 +43,8 @@ import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.annotation.Nullable;


import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.logging.InstanceId;
import com.android.launcher3.logging.InstanceIdSequence;
import com.android.launcher3.model.AppLaunchTracker;
import com.android.launcher3.model.AppLaunchTracker;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.model.data.WorkspaceItemInfo;
import com.android.launcher3.model.data.WorkspaceItemInfo;
@@ -188,7 +190,8 @@ public abstract class BaseDraggingActivity extends BaseActivity
            }
            }
            getUserEventDispatcher().logAppLaunch(v, intent, user);
            getUserEventDispatcher().logAppLaunch(v, intent, user);
            if (item != null) {
            if (item != null) {
                getStatsLogManager().log(LAUNCHER_APP_LAUNCH_TAP, item);
                InstanceId instanceId = new InstanceIdSequence().newInstanceId();
                logAppLaunch(item, instanceId);
            }
            }
            return true;
            return true;
        } catch (NullPointerException|ActivityNotFoundException|SecurityException e) {
        } catch (NullPointerException|ActivityNotFoundException|SecurityException e) {
@@ -198,6 +201,10 @@ public abstract class BaseDraggingActivity extends BaseActivity
        return false;
        return false;
    }
    }


    protected void logAppLaunch(ItemInfo info, InstanceId instanceId) {
        getStatsLogManager().log(LAUNCHER_APP_LAUNCH_TAP, instanceId, info);
    }

    private void startShortcutIntentSafely(Intent intent, Bundle optsBundle, ItemInfo info,
    private void startShortcutIntentSafely(Intent intent, Bundle optsBundle, ItemInfo info,
            @Nullable String sourceContainer) {
            @Nullable String sourceContainer) {
        try {
        try {
Loading