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

Commit 13c2bc73 authored by Hyunyoung Song's avatar Hyunyoung Song
Browse files

LAUNCHER_APP_LAUNCH_TAP should log correctly for icons inside folder

Bug: 137777105

Change-Id: I5c1552481fc1b788ba41c57bfe97f126f55e5b16
parent 662796d1
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ message ContainerInfo {
    ShortcutsContainer shortcuts_container = 8;
    SettingsContainer settings_container = 9;
    PredictedHotseatContainer predicted_hotseat_container = 10;
    TaskSwitcherContainer task_switcher_container = 11;
  }
}

@@ -82,6 +83,9 @@ message ShortcutsContainer {
message SettingsContainer {
}

message TaskSwitcherContainer {
}

enum Attribute {
  UNKNOWN = 0;
  DEFAULT_LAYOUT = 1;       // icon automatically placed in workspace, folder, hotseat
+9 −35
Original line number Diff line number Diff line
@@ -26,23 +26,18 @@ import static com.android.launcher3.userevent.nano.LauncherLogProto.Action.Touch

import android.app.Activity;
import android.app.ActivityOptions;
import android.content.ComponentName;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Rect;
import android.os.Handler;
import android.os.Looper;
import android.os.UserHandle;
import android.view.View;

import com.android.launcher3.BaseDraggingActivity;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.R;
import com.android.launcher3.logger.LauncherAtom;
import com.android.launcher3.logging.StatsLogManager.LauncherEvent;
import com.android.launcher3.model.WellbeingModel;
import com.android.launcher3.model.data.WorkspaceItemInfo;
import com.android.launcher3.popup.SystemShortcut;
import com.android.launcher3.popup.SystemShortcut.AppInfo;
import com.android.launcher3.userevent.nano.LauncherLogProto;
@@ -71,28 +66,7 @@ public interface TaskShortcutFactory {

    SystemShortcut getShortcut(BaseDraggingActivity activity, TaskView view);

    static WorkspaceItemInfo dummyInfo(TaskView view) {
        Task task = view.getTask();

        WorkspaceItemInfo dummyInfo = new WorkspaceItemInfo(){
            /**
             * Helps to log events as {@link LauncherAtom.Task}
             * instead of {@link LauncherAtom.ItemInfo}.
             */
            @Override
            public LauncherAtom.ItemInfo buildProto() {
                return view.buildProto();
            }
        };
        dummyInfo.intent = new Intent();
        ComponentName component = task.getTopComponent();
        dummyInfo.getIntent().setComponent(component);
        dummyInfo.user = UserHandle.of(task.key.userId);
        dummyInfo.title = TaskUtils.getTitle(view.getContext(), task);
        return dummyInfo;
    }

    TaskShortcutFactory APP_INFO = (activity, view) -> new AppInfo(activity, dummyInfo(view));
    TaskShortcutFactory APP_INFO = (activity, view) -> new AppInfo(activity, view.getItemInfo());

    abstract class MultiWindowFactory implements TaskShortcutFactory {

@@ -136,7 +110,7 @@ public interface TaskShortcutFactory {

        public MultiWindowSystemShortcut(int iconRes, int textRes, BaseDraggingActivity activity,
                TaskView taskView, MultiWindowFactory factory, LauncherEvent launcherEvent) {
            super(iconRes, textRes, activity, dummyInfo(taskView));
            super(iconRes, textRes, activity, taskView.getItemInfo());
            mLauncherEvent = launcherEvent;
            mHandler = new Handler(Looper.getMainLooper());
            mTaskView = taskView;
@@ -222,7 +196,7 @@ public interface TaskShortcutFactory {
                WindowManagerWrapper.getInstance().overridePendingAppTransitionMultiThumbFuture(
                        future, animStartedListener, mHandler, true /* scaleUp */,
                        taskKey.displayId);
                mTarget.getStatsLogManager().log(mLauncherEvent, mTaskView.buildProto());
                mTarget.getStatsLogManager().log(mLauncherEvent, mTaskView.getItemInfo());
            }
        }
    }
@@ -306,7 +280,7 @@ public interface TaskShortcutFactory {
        private final TaskView mTaskView;

        public PinSystemShortcut(BaseDraggingActivity target, TaskView tv) {
            super(R.drawable.ic_pin, R.string.recent_task_option_pin, target, dummyInfo(tv));
            super(R.drawable.ic_pin, R.string.recent_task_option_pin, target, tv.getItemInfo());
            mTaskView = tv;
        }

@@ -323,29 +297,29 @@ public interface TaskShortcutFactory {
            mTaskView.launchTask(true, resultCallback, Executors.MAIN_EXECUTOR.getHandler());
            dismissTaskMenuView(mTarget);
            mTarget.getStatsLogManager().log(LauncherEvent.LAUNCHER_SYSTEM_SHORTCUT_PIN_TAP,
                    mTaskView.buildProto());
                    mTaskView.getItemInfo());
        }
    }

    TaskShortcutFactory INSTALL = (activity, view) ->
            InstantAppResolver.newInstance(activity).isInstantApp(activity,
                 view.getTask().getTopComponent().getPackageName())
                    ? new SystemShortcut.Install(activity, dummyInfo(view)) : null;
                    ? new SystemShortcut.Install(activity, view.getItemInfo()) : null;

    TaskShortcutFactory WELLBEING = (activity, view) ->
            WellbeingModel.SHORTCUT_FACTORY.getShortcut(activity, dummyInfo(view));
            WellbeingModel.SHORTCUT_FACTORY.getShortcut(activity, view.getItemInfo());

    TaskShortcutFactory SCREENSHOT = (activity, tv) -> {
        if (ENABLE_OVERVIEW_ACTIONS.get()) {
            return tv.getThumbnail().getTaskOverlay()
                .getScreenshotShortcut(activity, dummyInfo(tv));
                .getScreenshotShortcut(activity, tv.getItemInfo());
        }
        return null;
    };

    TaskShortcutFactory MODAL = (activity, tv) -> {
        if (ENABLE_OVERVIEW_ACTIONS.get() && ENABLE_OVERVIEW_SELECTIONS.get()) {
            return tv.getThumbnail().getTaskOverlay().getModalStateSystemShortcut(dummyInfo(tv));
            return tv.getThumbnail().getTaskOverlay().getModalStateSystemShortcut(tv.getItemInfo());
        }
        return null;
    };
+2 −2
Original line number Diff line number Diff line
@@ -1347,7 +1347,7 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
            mActivity.getUserEventDispatcher().logTaskLaunchOrDismiss(
                    endState.logAction, Direction.UP, index, compKey);
            mActivity.getStatsLogManager().log(
                    LAUNCHER_TASK_DISMISS_SWIPE_UP, taskView.buildProto());
                    LAUNCHER_TASK_DISMISS_SWIPE_UP, taskView.getItemInfo());
        }
    }

@@ -1930,7 +1930,7 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
                            endState.logAction, Direction.DOWN, indexOfChild(tv),
                            TaskUtils.getLaunchComponentKeyForTask(task.key));
                    mActivity.getStatsLogManager().log(
                            LAUNCHER_TASK_LAUNCH_SWIPE_DOWN, tv.buildProto());
                            LAUNCHER_TASK_LAUNCH_SWIPE_DOWN, tv.getItemInfo());
                }
            } else {
                onTaskLaunched(false);
+14 −11
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import android.animation.TimeInterpolator;
import android.animation.ValueAnimator;
import android.app.ActivityOptions;
import android.content.Context;
import android.content.Intent;
import android.graphics.Outline;
import android.graphics.Rect;
import android.graphics.RectF;
@@ -48,7 +49,6 @@ import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.InsetDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Process;
import android.util.AttributeSet;
import android.util.FloatProperty;
import android.util.Log;
@@ -61,13 +61,14 @@ import android.widget.Toast;

import com.android.launcher3.BaseDraggingActivity;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.anim.AnimatorPlaybackController;
import com.android.launcher3.anim.Interpolators;
import com.android.launcher3.anim.PendingAnimation;
import com.android.launcher3.logger.LauncherAtom;
import com.android.launcher3.logging.UserEventDispatcher;
import com.android.launcher3.model.data.WorkspaceItemInfo;
import com.android.launcher3.popup.SystemShortcut;
import com.android.launcher3.testing.TestLogging;
import com.android.launcher3.testing.TestProtocol;
@@ -213,7 +214,7 @@ public class TaskView extends FrameLayout implements PageCallbacks, Reusable {
            mActivity.getUserEventDispatcher().logTaskLaunchOrDismiss(
                    Touch.TAP, Direction.NONE, getRecentsView().indexOfChild(this),
                    TaskUtils.getLaunchComponentKeyForTask(getTask().key));
            mActivity.getStatsLogManager().log(LAUNCHER_TASK_LAUNCH_TAP, buildProto());
            mActivity.getStatsLogManager().log(LAUNCHER_TASK_LAUNCH_TAP, getItemInfo());
        });

        mCurrentFullscreenParams = new FullscreenDrawParams(context);
@@ -226,14 +227,16 @@ public class TaskView extends FrameLayout implements PageCallbacks, Reusable {
    /**
     * Builds proto for logging
     */
    public LauncherAtom.ItemInfo buildProto() {
    public WorkspaceItemInfo getItemInfo() {
        ComponentKey componentKey = TaskUtils.getLaunchComponentKeyForTask(getTask().key);
        LauncherAtom.ItemInfo.Builder itemBuilder = LauncherAtom.ItemInfo.newBuilder();
        itemBuilder.setIsWork(componentKey.user != Process.myUserHandle());
        itemBuilder.setTask(LauncherAtom.Task.newBuilder()
                .setComponentName(componentKey.componentName.flattenToShortString())
                .setIndex(getRecentsView().indexOfChild(this)));
        return itemBuilder.build();
        WorkspaceItemInfo dummyInfo = new WorkspaceItemInfo();
        dummyInfo.itemType = LauncherSettings.Favorites.ITEM_TYPE_TASK;
        dummyInfo.container = LauncherSettings.Favorites.CONTAINER_TASKSWITCHER;
        dummyInfo.user = componentKey.user;
        dummyInfo.intent = new Intent().setComponent(componentKey.componentName);
        dummyInfo.title = TaskUtils.getTitle(getContext(), getTask());
        dummyInfo.screenId = getRecentsView().indexOfChild(this);
        return dummyInfo;
    }

    @Override
@@ -429,7 +432,7 @@ public class TaskView extends FrameLayout implements PageCallbacks, Reusable {
            getRecentsView().snapToPage(getRecentsView().indexOfChild(this));
        } else {
            mMenuView = TaskMenuView.showForTask(this);
            mActivity.getStatsLogManager().log(LAUNCHER_TASK_ICON_TAP_OR_LONGPRESS, buildProto());
            mActivity.getStatsLogManager().log(LAUNCHER_TASK_ICON_TAP_OR_LONGPRESS, getItemInfo());
            UserEventDispatcher.newInstance(getContext()).logActionOnItem(action, Direction.NONE,
                    LauncherLogProto.ItemType.TASK_ICON);
            if (mMenuView != null) {
+62 −61
Original line number Diff line number Diff line
@@ -64,6 +64,9 @@ public class StatsLogCompatManager extends StatsLogManager {
    private static Context sContext;

    private static final InstanceId DEFAULT_INSTANCE_ID = InstanceId.fakeInstanceId(0);
    // LauncherAtom.ItemInfo.getDefaultInstance() should be used but until launcher proto migrates
    // from nano to lite, bake constant to prevent robo test failure.
    private static final int DEFAULT_PAGE_INDEX = -2;
    private static final int FOLDER_HIERARCHY_OFFSET = 100;

    public StatsLogCompatManager(Context context) {
@@ -75,7 +78,7 @@ public class StatsLogCompatManager extends StatsLogManager {
     */
    @Override
    public void log(EventEnum event) {
        log(event, DEFAULT_INSTANCE_ID, LauncherAtom.ItemInfo.getDefaultInstance());
        log(event, DEFAULT_INSTANCE_ID, null);
    }

    /**
@@ -83,31 +86,27 @@ public class StatsLogCompatManager extends StatsLogManager {
     */
    @Override
    public void log(EventEnum event, InstanceId instanceId) {
        log(event, instanceId, LauncherAtom.ItemInfo.getDefaultInstance());
        log(event, instanceId, null);
    }

    /**
     * Logs an event and accompanying {@link ItemInfo}.
     */
    @Override
    public void log(EventEnum event, @Nullable LauncherAtom.ItemInfo info) {
    public void log(EventEnum event, @Nullable ItemInfo info) {
        log(event, DEFAULT_INSTANCE_ID, info);
    }

    @Override
    public void log(EventEnum event, ItemInfo itemInfo) {
        logInternal(event, DEFAULT_INSTANCE_ID, itemInfo);
    }

    /**
     * Logs an event and accompanying {@link InstanceId} and {@link LauncherAtom.ItemInfo}.
     */
    @Override
    public void log(EventEnum event, InstanceId instanceId,
            @Nullable LauncherAtom.ItemInfo info) {
            @Nullable ItemInfo info) {
        logInternal(event, instanceId, info,
                LAUNCHER_UICHANGED__DST_STATE__HOME,
                LAUNCHER_UICHANGED__DST_STATE__BACKGROUND);
                LAUNCHER_UICHANGED__DST_STATE__BACKGROUND,
                DEFAULT_PAGE_INDEX);
    }

    /**
@@ -129,58 +128,60 @@ public class StatsLogCompatManager extends StatsLogManager {
     */
    @Override
    public void log(EventEnum event, int srcState, int dstState, int pageIndex) {
        LauncherAtom.ItemInfo info = LauncherAtom.ItemInfo.getDefaultInstance();
        if (srcState == LAUNCHER_UICHANGED__DST_STATE__HOME
                || dstState == LAUNCHER_UICHANGED__SRC_STATE__HOME) {
            info = LauncherAtom.ItemInfo.newBuilder().setContainerInfo(
                    LauncherAtom.ContainerInfo.newBuilder().setWorkspace(
                            LauncherAtom.WorkspaceContainer.newBuilder().setPageIndex(pageIndex)
                    )).build();
        }
        logInternal(event, DEFAULT_INSTANCE_ID, info, srcState, dstState);
        logInternal(event, DEFAULT_INSTANCE_ID, null, srcState, dstState, pageIndex);
    }

    private void logInternal(EventEnum event, InstanceId instanceId, @Nullable ItemInfo info) {
    /**
     * Logs an event and accompanying {@link InstanceId} and {@link ItemInfo}.
     */
    private void logInternal(EventEnum event, InstanceId instanceId,
            @Nullable ItemInfo info, int srcState, int dstState, int pageIndex) {

        LauncherAppState.getInstance(sContext).getModel().enqueueModelUpdateTask(
                new BaseModelUpdateTask() {
                    @Override
                    public void execute(LauncherAppState app, BgDataModel dataModel,
                            AllAppsList apps) {
                        writeEvent(event, instanceId, info, srcState, dstState, pageIndex,
                                dataModel.folders);
                    }
                });
    }

    private static void writeEvent(EventEnum event, InstanceId instanceId,
            @Nullable ItemInfo info, int srcState, int dstState, int pageIndex,
            IntSparseArrayMap<FolderInfo> folders) {

        if (!Utilities.ATLEAST_R) {
            return;
        }
        LauncherAtom.ItemInfo atomInfo = LauncherAtom.ItemInfo.getDefaultInstance();
        if (info != null) {
            if (info.container >= 0) {
                                atomInfo = info.buildProto(dataModel.folders.get(info.container));
                atomInfo = info.buildProto(folders.get(info.container));
            } else {
                atomInfo = info.buildProto();
            }
        } else {
            if (srcState == LAUNCHER_UICHANGED__DST_STATE__HOME
                    || dstState == LAUNCHER_UICHANGED__SRC_STATE__HOME) {
                atomInfo = LauncherAtom.ItemInfo.newBuilder().setContainerInfo(
                        LauncherAtom.ContainerInfo.newBuilder().setWorkspace(
                                LauncherAtom.WorkspaceContainer.newBuilder().setPageIndex(pageIndex)
                        )).build();
            }
                        logInternal(event, instanceId, atomInfo,
                                LAUNCHER_UICHANGED__DST_STATE__HOME,
                                LAUNCHER_UICHANGED__DST_STATE__BACKGROUND);
                    }
                });
        }

    /**
     * Logs an event and accompanying {@link InstanceId} and {@link LauncherAtom.ItemInfo}.
     */
    private void logInternal(EventEnum event, InstanceId instanceId,
            @Nullable LauncherAtom.ItemInfo info, int srcState, int dstState) {
        info = info == null ? LauncherAtom.ItemInfo.getDefaultInstance() : info;

        if (IS_VERBOSE) {
            String name = (event instanceof Enum) ? ((Enum) event).name() :
                    event.getId() + "";

            Log.d(TAG, instanceId == DEFAULT_INSTANCE_ID
                    ? String.format("\n%s (State:%s->%s) \n%s", name, getStateString(srcState),
                    getStateString(dstState), info)
                    : String.format("\n%s (State:%s->%s) (InstanceId:%s)\n%s", name,
                            getStateString(srcState), getStateString(dstState), instanceId, info));
        }

        if (!Utilities.ATLEAST_R) {
            return;
                    ? String.format("\n%s (State:%s->%s) \n%s\n%s", name, getStateString(srcState),
                            getStateString(dstState), info, atomInfo)
                    : String.format("\n%s (State:%s->%s) (InstanceId:%s)\n%s\n%s", name,
                            getStateString(srcState), getStateString(dstState), instanceId, info,
                            atomInfo));
        }

        SysUiStatsLog.write(
@@ -191,24 +192,24 @@ public class StatsLogCompatManager extends StatsLogManager {
                null /* launcher extensions, deprecated */,
                false /* quickstep_enabled, deprecated */,
                event.getId() /* event_id */,
                info.getItemCase().getNumber() /* target_id */,
                atomInfo.getItemCase().getNumber() /* target_id */,
                instanceId.getId() /* instance_id TODO */,
                0 /* uid TODO */,
                getPackageName(info) /* package_name */,
                getComponentName(info) /* component_name */,
                getGridX(info, false) /* grid_x */,
                getGridY(info, false) /* grid_y */,
                getPageId(info, false) /* page_id */,
                getGridX(info, true) /* grid_x_parent */,
                getGridY(info, true) /* grid_y_parent */,
                getPageId(info, true) /* page_id_parent */,
                getHierarchy(info) /* hierarchy */,
                info.getIsWork() /* is_work_profile */,
                info.getRank() /* rank */,
                info.getFolderIcon().getFromLabelState().getNumber() /* fromState */,
                info.getFolderIcon().getToLabelState().getNumber() /* toState */,
                info.getFolderIcon().getLabelInfo() /* edittext */,
                getCardinality(info) /* cardinality */);
                getPackageName(atomInfo) /* package_name */,
                getComponentName(atomInfo) /* component_name */,
                getGridX(atomInfo, false) /* grid_x */,
                getGridY(atomInfo, false) /* grid_y */,
                getPageId(atomInfo, false) /* page_id */,
                getGridX(atomInfo, true) /* grid_x_parent */,
                getGridY(atomInfo, true) /* grid_y_parent */,
                getPageId(atomInfo, true) /* page_id_parent */,
                getHierarchy(atomInfo) /* hierarchy */,
                atomInfo.getIsWork() /* is_work_profile */,
                atomInfo.getRank() /* rank */,
                atomInfo.getFolderIcon().getFromLabelState().getNumber() /* fromState */,
                atomInfo.getFolderIcon().getToLabelState().getNumber() /* toState */,
                atomInfo.getFolderIcon().getLabelInfo() /* edittext */,
                getCardinality(atomInfo) /* cardinality */);
    }

    /**
Loading