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

Commit 3289e4fa authored by Andy Wickham's avatar Andy Wickham Committed by Android (Google) Code Review
Browse files

Merge "Add tests for LPH override for 3 button mode Taskbar." into udc-qpr-dev

parents a0f18503 976876ec
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -64,6 +64,7 @@ import com.android.launcher3.util.SimpleBroadcastReceiver;
import com.android.quickstep.RecentsActivity;
import com.android.quickstep.SystemUiProxy;
import com.android.quickstep.TouchInteractionService;
import com.android.quickstep.util.AssistUtils;
import com.android.systemui.shared.system.QuickStepContract;
import com.android.systemui.unfold.UnfoldTransitionProgressProvider;
import com.android.systemui.unfold.util.ScopedUnfoldTransitionProgressProvider;
@@ -176,7 +177,8 @@ public class TaskbarManager {
                service.getSystemService(DisplayManager.class).getDisplay(DEFAULT_DISPLAY);
        mContext = service.createWindowContext(display, TYPE_NAVIGATION_BAR_PANEL, null);
        mNavButtonController = new TaskbarNavButtonController(service,
                SystemUiProxy.INSTANCE.get(mContext), new Handler());
                SystemUiProxy.INSTANCE.get(mContext), new Handler(),
                AssistUtils.newInstance(mContext));
        mComponentCallbacks = new ComponentCallbacks() {
            private Configuration mOldConfig = mContext.getResources().getConfiguration();

+4 −3
Original line number Diff line number Diff line
@@ -109,15 +109,17 @@ public class TaskbarNavButtonController implements TaskbarControllers.LoggableTa
    private final TouchInteractionService mService;
    private final SystemUiProxy mSystemUiProxy;
    private final Handler mHandler;
    private final AssistUtils mAssistUtils;
    @Nullable private StatsLogManager mStatsLogManager;

    private final Runnable mResetLongPress = this::resetScreenUnpin;

    public TaskbarNavButtonController(TouchInteractionService service,
            SystemUiProxy systemUiProxy, Handler handler) {
            SystemUiProxy systemUiProxy, Handler handler, AssistUtils assistUtils) {
        mService = service;
        mSystemUiProxy = systemUiProxy;
        mHandler = handler;
        mAssistUtils = assistUtils;
    }

    public void onButtonClick(@TaskbarButton int buttonType, View view) {
@@ -313,8 +315,7 @@ public class TaskbarNavButtonController implements TaskbarControllers.LoggableTa
            return;
        }
        // Attempt to start Assist with AssistUtils, otherwise fall back to SysUi's implementation.
        if (!AssistUtils.newInstance(mService.getApplicationContext()).tryStartAssistOverride(
                INVOCATION_TYPE_HOME_BUTTON_LONG_PRESS)) {
        if (!mAssistUtils.tryStartAssistOverride(INVOCATION_TYPE_HOME_BUTTON_LONG_PRESS)) {
            Bundle args = new Bundle();
            args.putInt(INVOCATION_TYPE_KEY, INVOCATION_TYPE_HOME_BUTTON_LONG_PRESS);
            mSystemUiProxy.startAssistant(args);
+33 −3
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ import static com.android.quickstep.OverviewCommandHelper.TYPE_TOGGLE;
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_SCREEN_PINNING;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
@@ -33,6 +34,7 @@ import com.android.launcher3.logging.StatsLogManager;
import com.android.quickstep.OverviewCommandHelper;
import com.android.quickstep.SystemUiProxy;
import com.android.quickstep.TouchInteractionService;
import com.android.quickstep.util.AssistUtils;

import org.junit.Before;
import org.junit.Test;
@@ -54,6 +56,8 @@ public class TaskbarNavButtonControllerTest {
    @Mock
    Handler mockHandler;
    @Mock
    AssistUtils mockAssistUtils;
    @Mock
    StatsLogManager mockStatsLogManager;
    @Mock
    StatsLogManager.StatsLogger mockStatsLogger;
@@ -79,7 +83,7 @@ public class TaskbarNavButtonControllerTest {
                .thenReturn(mockTaskbarActivityContext);
        doReturn(mockStatsLogManager).when(mockTaskbarActivityContext).getStatsLogManager();
        mNavButtonController = new TaskbarNavButtonController(mockService,
                mockSystemUiProxy, mockHandler);
                mockSystemUiProxy, mockHandler, mockAssistUtils);
    }

    @Test
@@ -108,16 +112,42 @@ public class TaskbarNavButtonControllerTest {
    }

    @Test
    public void testLongPressHome_enabled() {
    public void testLongPressHome_enabled_withoutOverride() {
        mNavButtonController.setAssistantLongPressEnabled(true /*assistantLongPressEnabled*/);
        when(mockAssistUtils.tryStartAssistOverride(anyInt())).thenReturn(false);

        mNavButtonController.onButtonLongClick(BUTTON_HOME, mockView);
        verify(mockAssistUtils, times(1)).tryStartAssistOverride(anyInt());
        verify(mockSystemUiProxy, times(1)).startAssistant(any());
    }

    @Test
    public void testLongPressHome_disabled() {
    public void testLongPressHome_enabled_withOverride() {
        mNavButtonController.setAssistantLongPressEnabled(true /*assistantLongPressEnabled*/);
        when(mockAssistUtils.tryStartAssistOverride(anyInt())).thenReturn(true);

        mNavButtonController.onButtonLongClick(BUTTON_HOME, mockView);
        verify(mockAssistUtils, times(1)).tryStartAssistOverride(anyInt());
        verify(mockSystemUiProxy, never()).startAssistant(any());
    }

    @Test
    public void testLongPressHome_disabled_withoutOverride() {
        mNavButtonController.setAssistantLongPressEnabled(false /*assistantLongPressEnabled*/);
        when(mockAssistUtils.tryStartAssistOverride(anyInt())).thenReturn(false);

        mNavButtonController.onButtonLongClick(BUTTON_HOME, mockView);
        verify(mockAssistUtils, never()).tryStartAssistOverride(anyInt());
        verify(mockSystemUiProxy, never()).startAssistant(any());
    }

    @Test
    public void testLongPressHome_disabled_withOverride() {
        mNavButtonController.setAssistantLongPressEnabled(false /*assistantLongPressEnabled*/);
        when(mockAssistUtils.tryStartAssistOverride(anyInt())).thenReturn(true);

        mNavButtonController.onButtonLongClick(BUTTON_HOME, mockView);
        verify(mockAssistUtils, never()).tryStartAssistOverride(anyInt());
        verify(mockSystemUiProxy, never()).startAssistant(any());
    }