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

Commit 5012640a authored by helencheuk's avatar helencheuk
Browse files

[Contextual Edu] Update Edu stats when going to overview and all apps from home

Update education stats when
- go overview and all apps by swiping up at homepage (AbstractStateChangeTouchController)
- go home from all apps by swiping down the all apps panel (AbstractStateChangeTouchController)
- go home from all apps or overview by swiping up from the bottom nav bar (NavBarToHomeTouchController)
- in 3 button navgiation mode (TaskbarNavButtonController)

NavBarToHomeTouchController does not inherit from AbstractStateChangeTouchController so logic are added separately.

Bug: 363480554
Test: TaskbarNavButtonControllerTest
Flag: com.android.systemui.keyboard_touchpad_contextual_education
Change-Id: I0662704a9093b9f5a4d2f086a8297429fbc49881
parent 6138138d
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ import com.android.launcher3.DeviceProfile;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.anim.AnimatorPlaybackController;
import com.android.launcher3.contextualeducation.ContextualEduStatsManager;
import com.android.launcher3.statehandlers.DesktopVisibilityController;
import com.android.launcher3.statemanager.StatefulActivity;
import com.android.launcher3.taskbar.TaskbarNavButtonController.TaskbarNavButtonCallbacks;
@@ -247,6 +248,7 @@ public class TaskbarManager {
                context,
                navCallbacks,
                SystemUiProxy.INSTANCE.get(mContext),
                ContextualEduStatsManager.INSTANCE.get(mContext),
                new Handler(),
                AssistUtils.newInstance(mContext));
        mComponentCallbacks = new ComponentCallbacks() {
+11 −0
Original line number Diff line number Diff line
@@ -45,12 +45,14 @@ import androidx.annotation.Nullable;
import androidx.annotation.StringRes;

import com.android.launcher3.R;
import com.android.launcher3.contextualeducation.ContextualEduStatsManager;
import com.android.launcher3.logging.StatsLogManager;
import com.android.launcher3.testing.TestLogging;
import com.android.launcher3.testing.shared.TestProtocol;
import com.android.quickstep.SystemUiProxy;
import com.android.quickstep.TaskUtils;
import com.android.quickstep.util.AssistUtils;
import com.android.systemui.contextualeducation.GestureType;
import com.android.systemui.shared.system.QuickStepContract.SystemUiStateFlags;

import java.io.PrintWriter;
@@ -109,6 +111,7 @@ public class TaskbarNavButtonController implements TaskbarControllers.LoggableTa
    private final Context mContext;
    private final TaskbarNavButtonCallbacks mCallbacks;
    private final SystemUiProxy mSystemUiProxy;
    private final ContextualEduStatsManager mContextualEduStatsManager;
    private final Handler mHandler;
    private final AssistUtils mAssistUtils;
    @Nullable private StatsLogManager mStatsLogManager;
@@ -119,11 +122,13 @@ public class TaskbarNavButtonController implements TaskbarControllers.LoggableTa
            Context context,
            TaskbarNavButtonCallbacks callbacks,
            SystemUiProxy systemUiProxy,
            ContextualEduStatsManager contextualEduStatsManager,
            Handler handler,
            AssistUtils assistUtils) {
        mContext = context;
        mCallbacks = callbacks;
        mSystemUiProxy = systemUiProxy;
        mContextualEduStatsManager = contextualEduStatsManager;
        mHandler = handler;
        mAssistUtils = assistUtils;
    }
@@ -137,14 +142,20 @@ public class TaskbarNavButtonController implements TaskbarControllers.LoggableTa
        switch (buttonType) {
            case BUTTON_BACK:
                logEvent(LAUNCHER_TASKBAR_BACK_BUTTON_TAP);
                mContextualEduStatsManager.updateEduStats(/* isTrackpadGesture= */ false,
                        GestureType.BACK);
                executeBack();
                break;
            case BUTTON_HOME:
                logEvent(LAUNCHER_TASKBAR_HOME_BUTTON_TAP);
                mContextualEduStatsManager.updateEduStats(/* isTrackpadGesture= */ false,
                        GestureType.HOME);
                navigateHome();
                break;
            case BUTTON_RECENTS:
                logEvent(LAUNCHER_TASKBAR_OVERVIEW_BUTTON_TAP);
                mContextualEduStatsManager.updateEduStats(/* isTrackpadGesture= */ false,
                        GestureType.OVERVIEW);
                navigateToOverview();
                break;
            case BUTTON_IME_SWITCH:
+4 −0
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import com.android.launcher3.anim.AnimatorPlaybackController;
import com.android.launcher3.anim.PendingAnimation;
import com.android.launcher3.compat.AccessibilityManagerCompat;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.contextualeducation.ContextualEduStatsManager;
import com.android.launcher3.statemanager.StateManager;
import com.android.launcher3.touch.SingleAxisSwipeDetector;
import com.android.launcher3.util.DisplayController;
@@ -53,6 +54,7 @@ import com.android.quickstep.TaskUtils;
import com.android.quickstep.util.AnimatorControllerWithResistance;
import com.android.quickstep.util.OverviewToHomeAnim;
import com.android.quickstep.views.RecentsView;
import com.android.systemui.contextualeducation.GestureType;

import java.util.function.BiConsumer;

@@ -219,6 +221,8 @@ public class NavBarToHomeTouchController implements TouchController,
            }
            if (mStartState != mEndState) {
                logHomeGesture();
                ContextualEduStatsManager.INSTANCE.get(mLauncher).updateEduStats(
                        mSwipeDetector.isTrackpadGesture(), GestureType.HOME);
            }
            AbstractFloatingView topOpenView = AbstractFloatingView.getTopOpenView(mLauncher);
            if (topOpenView != null) {
+29 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static com.google.common.truth.Truth.assertThat;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
@@ -33,11 +34,13 @@ import android.view.inputmethod.Flags;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;

import com.android.launcher3.contextualeducation.ContextualEduStatsManager;
import com.android.launcher3.logging.StatsLogManager;
import com.android.launcher3.taskbar.TaskbarNavButtonController.TaskbarNavButtonCallbacks;
import com.android.quickstep.SystemUiProxy;
import com.android.quickstep.TouchInteractionService;
import com.android.quickstep.util.AssistUtils;
import com.android.systemui.contextualeducation.GestureType;

import org.junit.Before;
import org.junit.Test;
@@ -52,6 +55,10 @@ public class TaskbarNavButtonControllerTest {

    @Mock
    SystemUiProxy mockSystemUiProxy;

    @Mock
    ContextualEduStatsManager mockContextualEduStatsManager;

    @Mock
    TouchInteractionService mockService;
    @Mock
@@ -100,6 +107,7 @@ public class TaskbarNavButtonControllerTest {
                mockService,
                mCallbacks,
                mockSystemUiProxy,
                mockContextualEduStatsManager,
                mockHandler,
                mockAssistUtils);
    }
@@ -110,6 +118,13 @@ public class TaskbarNavButtonControllerTest {
        verify(mockSystemUiProxy, times(1)).onBackPressed();
    }

    @Test
    public void testPressBack_updateContextualEduData() {
        mNavButtonController.onButtonClick(BUTTON_BACK, mockView);
        verify(mockContextualEduStatsManager, times(1))
                .updateEduStats(/* isTrackpad= */ eq(false), eq(GestureType.BACK));
    }

    @Test
    public void testPressImeSwitcher() {
        mNavButtonController.init(mockTaskbarControllers);
@@ -194,12 +209,26 @@ public class TaskbarNavButtonControllerTest {
        assertThat(mHomePressCount).isEqualTo(1);
    }

    @Test
    public void testPressHome_updateContextualEduData() {
        mNavButtonController.onButtonClick(BUTTON_HOME, mockView);
        verify(mockContextualEduStatsManager, times(1))
                .updateEduStats(/* isTrackpad= */ eq(false), eq(GestureType.HOME));
    }

    @Test
    public void testPressRecents() {
        mNavButtonController.onButtonClick(BUTTON_RECENTS, mockView);
        assertThat(mOverviewToggleCount).isEqualTo(1);
    }

    @Test
    public void testPressRecents_updateContextualEduData() {
        mNavButtonController.onButtonClick(BUTTON_RECENTS, mockView);
        verify(mockContextualEduStatsManager, times(1))
                .updateEduStats(/* isTrackpad= */ eq(false), eq(GestureType.OVERVIEW));
    }

    @Test
    public void testPressRecentsWithScreenPinned_noNavigationToOverview() {
        mNavButtonController.updateSysuiFlags(SYSUI_STATE_SCREEN_PINNING);
+18 −0
Original line number Diff line number Diff line
@@ -40,11 +40,13 @@ import com.android.launcher3.LauncherAnimUtils;
import com.android.launcher3.LauncherState;
import com.android.launcher3.Utilities;
import com.android.launcher3.anim.AnimatorPlaybackController;
import com.android.launcher3.contextualeducation.ContextualEduStatsManager;
import com.android.launcher3.logger.LauncherAtom;
import com.android.launcher3.logging.StatsLogManager;
import com.android.launcher3.states.StateAnimationConfig;
import com.android.launcher3.util.FlingBlockCheck;
import com.android.launcher3.util.TouchController;
import com.android.systemui.contextualeducation.GestureType;

/**
 * TouchController for handling state changes
@@ -388,6 +390,7 @@ public abstract class AbstractStateChangeTouchController
        } else {
            logReachedState(mToState);
        }
        updateContextualEduStats(targetState);
    }

    protected void goToTargetState(LauncherState targetState) {
@@ -403,6 +406,21 @@ public abstract class AbstractStateChangeTouchController
                .setDuration(0).start();
    }

    private void updateContextualEduStats(LauncherState targetState) {
        if (targetState == NORMAL) {
            ContextualEduStatsManager.INSTANCE.get(
                    mLauncher).updateEduStats(mDetector.isTrackpadGesture(), GestureType.HOME);
        } else if (targetState == OVERVIEW) {
            ContextualEduStatsManager.INSTANCE.get(
                    mLauncher).updateEduStats(mDetector.isTrackpadGesture(), GestureType.OVERVIEW);
        } else if (targetState == ALL_APPS && !mDetector.isTrackpadGesture()) {
            // Only update if it is touch gesture as trackpad gesture is not relevant for all apps
            // which only provides keyboard education.
            ContextualEduStatsManager.INSTANCE.get(
                    mLauncher).updateEduStats(/* isTrackpadGesture= */ false, GestureType.ALL_APPS);
        }
    }

    private void logReachedState(LauncherState targetState) {
        if (mStartState == targetState) {
            return;
Loading