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

Commit d6b9d5a6 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "add uievent logs for nav assistant longpress" into rvc-dev

parents dee3bbc8 119913a4
Loading
Loading
Loading
Loading
+25 −1
Original line number Diff line number Diff line
@@ -96,6 +96,8 @@ import androidx.annotation.VisibleForTesting;

import com.android.internal.accessibility.dialog.AccessibilityButtonChooserActivity;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.UiEvent;
import com.android.internal.logging.UiEventLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.util.LatencyTracker;
import com.android.internal.view.AppearanceRegion;
@@ -225,6 +227,25 @@ public class NavigationBarFragment extends LifecycleFragment implements Callback
    private int mCurrentRotation;
    private boolean mFixedRotationEnabled;
    private ViewTreeObserver.OnGlobalLayoutListener mOrientationHandleGlobalLayoutListener;
    private UiEventLogger mUiEventLogger;

    @com.android.internal.annotations.VisibleForTesting
    public enum NavBarActionEvent implements UiEventLogger.UiEventEnum {

        @UiEvent(doc = "Assistant invoked via home button long press.")
        NAVBAR_ASSIST_LONGPRESS(550);

        private final int mId;

        NavBarActionEvent(int id) {
            mId = id;
        }

        @Override
        public int getId() {
            return mId;
        }
    }

    /** Only for default display */
    @Nullable
@@ -367,7 +388,8 @@ public class NavigationBarFragment extends LifecycleFragment implements Callback
            ShadeController shadeController,
            NotificationRemoteInputManager notificationRemoteInputManager,
            SystemActions systemActions,
            @Main Handler mainHandler) {
            @Main Handler mainHandler,
            UiEventLogger uiEventLogger) {
        mAccessibilityManagerWrapper = accessibilityManagerWrapper;
        mDeviceProvisionedController = deviceProvisionedController;
        mStatusBarStateController = statusBarStateController;
@@ -387,6 +409,7 @@ public class NavigationBarFragment extends LifecycleFragment implements Callback
        mRecentsOptional = recentsOptional;
        mSystemActions = systemActions;
        mHandler = mainHandler;
        mUiEventLogger = uiEventLogger;
    }

    // ----- Fragment Lifecycle Callbacks -----
@@ -1008,6 +1031,7 @@ public class NavigationBarFragment extends LifecycleFragment implements Callback
            return false;
        }
        mMetricsLogger.action(MetricsEvent.ACTION_ASSIST_LONG_PRESS);
        mUiEventLogger.log(NavBarActionEvent.NAVBAR_ASSIST_LONGPRESS);
        Bundle args  = new Bundle();
        args.putInt(
                AssistManager.INVOCATION_TYPE_KEY, AssistManager.INVOCATION_HOME_BUTTON_LONG_PRESS);
+10 −10
Original line number Diff line number Diff line
@@ -87,7 +87,7 @@ public class KeyButtonView extends ImageView implements ButtonInterface {
    private boolean mHasOvalBg = false;

    @VisibleForTesting
    public enum NavBarActionsEvent implements UiEventLogger.UiEventEnum {
    public enum NavBarButtonEvent implements UiEventLogger.UiEventEnum {

        @UiEvent(doc = "The home button was pressed in the navigation bar.")
        NAVBAR_HOME_BUTTON_TAP(533),
@@ -111,7 +111,7 @@ public class KeyButtonView extends ImageView implements ButtonInterface {

        private final int mId;

        NavBarActionsEvent(int id) {
        NavBarButtonEvent(int id) {
            mId = id;
        }

@@ -368,7 +368,7 @@ public class KeyButtonView extends ImageView implements ButtonInterface {

    private void logSomePresses(int action, int flags) {
        boolean longPressSet = (flags & KeyEvent.FLAG_LONG_PRESS) != 0;
        NavBarActionsEvent uiEvent = NavBarActionsEvent.NONE;
        NavBarButtonEvent uiEvent = NavBarButtonEvent.NONE;
        if (action == MotionEvent.ACTION_UP && mLongClicked) {
            return;  // don't log the up after a long press
        }
@@ -382,21 +382,21 @@ public class KeyButtonView extends ImageView implements ButtonInterface {
        switch(mCode) {
            case KeyEvent.KEYCODE_BACK:
                uiEvent = longPressSet
                        ? NavBarActionsEvent.NAVBAR_BACK_BUTTON_LONGPRESS
                        : NavBarActionsEvent.NAVBAR_BACK_BUTTON_TAP;
                        ? NavBarButtonEvent.NAVBAR_BACK_BUTTON_LONGPRESS
                        : NavBarButtonEvent.NAVBAR_BACK_BUTTON_TAP;
                break;
            case KeyEvent.KEYCODE_HOME:
                uiEvent = longPressSet
                        ? NavBarActionsEvent.NAVBAR_HOME_BUTTON_LONGPRESS
                        : NavBarActionsEvent.NAVBAR_HOME_BUTTON_TAP;
                        ? NavBarButtonEvent.NAVBAR_HOME_BUTTON_LONGPRESS
                        : NavBarButtonEvent.NAVBAR_HOME_BUTTON_TAP;
                break;
            case KeyEvent.KEYCODE_APP_SWITCH:
                uiEvent = longPressSet
                        ? NavBarActionsEvent.NAVBAR_OVERVIEW_BUTTON_LONGPRESS
                        : NavBarActionsEvent.NAVBAR_OVERVIEW_BUTTON_TAP;
                        ? NavBarButtonEvent.NAVBAR_OVERVIEW_BUTTON_LONGPRESS
                        : NavBarButtonEvent.NAVBAR_OVERVIEW_BUTTON_TAP;
                break;
        }
        if (uiEvent != NavBarActionsEvent.NONE) {
        if (uiEvent != NavBarButtonEvent.NONE) {
            mUiEventLogger.log(uiEvent);
        }
    }
+12 −1
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@ import static android.inputmethodservice.InputMethodService.IME_VISIBLE;
import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.DisplayAdjustments.DEFAULT_DISPLAY_ADJUSTMENTS;

import static com.android.systemui.statusbar.phone.NavigationBarFragment.NavBarActionEvent.NAVBAR_ASSIST_LONGPRESS;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -28,6 +30,7 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@@ -59,6 +62,7 @@ import android.view.accessibility.AccessibilityManager.AccessibilityServicesStat
import androidx.test.filters.SmallTest;

import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.UiEventLogger;
import com.android.systemui.Dependency;
import com.android.systemui.SysuiBaseFragmentTest;
import com.android.systemui.SysuiTestableContext;
@@ -105,6 +109,8 @@ public class NavigationBarFragmentTest extends SysuiBaseFragmentTest {
    private Recents mRecents;
    @Mock
    private SystemActions mSystemActions;
    @Mock
    private UiEventLogger mUiEventLogger;

    private AccessibilityManagerWrapper mAccessibilityWrapper =
            new AccessibilityManagerWrapper(mContext) {
@@ -187,6 +193,8 @@ public class NavigationBarFragmentTest extends SysuiBaseFragmentTest {
        mFragments.dispatchResume();
        processAllMessages();
        navigationBarFragment.onHomeLongClick(navigationBarFragment.getView());

        verify(mUiEventLogger, times(1)).log(NAVBAR_ASSIST_LONGPRESS);
    }

    @Test
@@ -242,6 +250,7 @@ public class NavigationBarFragmentTest extends SysuiBaseFragmentTest {
    protected Fragment instantiate(Context context, String className, Bundle arguments) {
        DeviceProvisionedController deviceProvisionedController =
                mock(DeviceProvisionedController.class);
        when(deviceProvisionedController.isDeviceProvisioned()).thenReturn(true);
        assertNotNull(mAccessibilityWrapper);
        return new NavigationBarFragment(
                context.getDisplayId() == DEFAULT_DISPLAY ? mAccessibilityWrapper
@@ -261,7 +270,8 @@ public class NavigationBarFragmentTest extends SysuiBaseFragmentTest {
                mock(ShadeController.class),
                mock(NotificationRemoteInputManager.class),
                mock(SystemActions.class),
                mHandler);
                mHandler,
                mUiEventLogger);
    }

    private class HostCallbacksForExternalDisplay extends
@@ -319,6 +329,7 @@ public class NavigationBarFragmentTest extends SysuiBaseFragmentTest {
                    mock(LightBarTransitionsController.class));
            when(view.getRotationButtonController()).thenReturn(
                    mock(RotationButtonController.class));
            when(view.isRecentsButtonVisible()).thenReturn(true);
            return view;
        }
    }
+8 −8
Original line number Diff line number Diff line
@@ -23,12 +23,12 @@ import static android.view.KeyEvent.KEYCODE_APP_SWITCH;
import static android.view.KeyEvent.KEYCODE_BACK;
import static android.view.KeyEvent.KEYCODE_HOME;

import static com.android.systemui.statusbar.policy.KeyButtonView.NavBarActionsEvent.NAVBAR_BACK_BUTTON_LONGPRESS;
import static com.android.systemui.statusbar.policy.KeyButtonView.NavBarActionsEvent.NAVBAR_BACK_BUTTON_TAP;
import static com.android.systemui.statusbar.policy.KeyButtonView.NavBarActionsEvent.NAVBAR_HOME_BUTTON_LONGPRESS;
import static com.android.systemui.statusbar.policy.KeyButtonView.NavBarActionsEvent.NAVBAR_HOME_BUTTON_TAP;
import static com.android.systemui.statusbar.policy.KeyButtonView.NavBarActionsEvent.NAVBAR_OVERVIEW_BUTTON_LONGPRESS;
import static com.android.systemui.statusbar.policy.KeyButtonView.NavBarActionsEvent.NAVBAR_OVERVIEW_BUTTON_TAP;
import static com.android.systemui.statusbar.policy.KeyButtonView.NavBarButtonEvent.NAVBAR_BACK_BUTTON_LONGPRESS;
import static com.android.systemui.statusbar.policy.KeyButtonView.NavBarButtonEvent.NAVBAR_BACK_BUTTON_TAP;
import static com.android.systemui.statusbar.policy.KeyButtonView.NavBarButtonEvent.NAVBAR_HOME_BUTTON_LONGPRESS;
import static com.android.systemui.statusbar.policy.KeyButtonView.NavBarButtonEvent.NAVBAR_HOME_BUTTON_TAP;
import static com.android.systemui.statusbar.policy.KeyButtonView.NavBarButtonEvent.NAVBAR_OVERVIEW_BUTTON_LONGPRESS;
import static com.android.systemui.statusbar.policy.KeyButtonView.NavBarButtonEvent.NAVBAR_OVERVIEW_BUTTON_TAP;

import static junit.framework.Assert.assertEquals;

@@ -140,11 +140,11 @@ public class KeyButtonViewTest extends SysuiTestCase {
    }

    private void checkmetrics(int code, int action, int flag,
            KeyButtonView.NavBarActionsEvent expected) {
            KeyButtonView.NavBarButtonEvent expected) {
        mKeyButtonView.setCode(code);
        mKeyButtonView.sendEvent(action, flag);
        if (expected == null) {
            verify(mUiEventLogger, never()).log(any(KeyButtonView.NavBarActionsEvent.class));
            verify(mUiEventLogger, never()).log(any(KeyButtonView.NavBarButtonEvent.class));
        } else {
            verify(mUiEventLogger, times(1)).log(expected);
        }