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

Commit af4ce846 authored by Chris Wren's avatar Chris Wren
Browse files

port more global actions legacy logs to new pipeline

Bug: 147508238
Test: atest GlobalActionsDialogTest
Change-Id: I57d9d43b6076eb4a10d74fd007becd585ff01d68
parent 6c6d81a1
Loading
Loading
Loading
Loading
+51 −7
Original line number Diff line number Diff line
@@ -222,11 +222,27 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
    private ControlsController mControlsController;
    private SharedPreferences mControlsPreferences;
    private final RingerModeTracker mRingerModeTracker;
    private int mDialogPressDelay = DIALOG_PRESS_DELAY; // ms

    @VisibleForTesting
    public enum GlobalActionsEvent implements UiEventLogger.UiEventEnum {
        @UiEvent(doc = "The global actions / power menu surface became visible on the screen.")
        GA_POWER_MENU_OPEN(337);
        GA_POWER_MENU_OPEN(337),

        @UiEvent(doc = "The global actions bugreport button was pressed.")
        GA_BUGREPORT_PRESS(344),

        @UiEvent(doc = "The global actions bugreport button was long pressed.")
        GA_BUGREPORT_LONG_PRESS(345),

        @UiEvent(doc = "The global actions emergency button was pressed.")
        GA_EMERGENCY_DIALER_PRESS(346),

        @UiEvent(doc = "The global actions screenshot button was pressed.")
        GA_SCREENSHOT_PRESS(347),

        @UiEvent(doc = "The global actions screenshot button was long pressed.")
        GA_SCREENSHOT_LONG_PRESS(348);

        private final int mId;

@@ -679,7 +695,8 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
        }
    }

    private class EmergencyDialerAction extends EmergencyAction {
    @VisibleForTesting
    class EmergencyDialerAction extends EmergencyAction {
        private EmergencyDialerAction() {
            super(com.android.systemui.R.drawable.ic_emergency_star,
                    R.string.global_action_emergency);
@@ -688,6 +705,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
        @Override
        public void onPress() {
            mMetricsLogger.action(MetricsEvent.ACTION_EMERGENCY_DIALER_FROM_POWER_MENU);
            mUiEventLogger.log(GlobalActionsEvent.GA_EMERGENCY_DIALER_PRESS);
            if (mTelecomManager != null) {
                Intent intent = mTelecomManager.createLaunchEmergencyDialerIntent(
                        null /* number */);
@@ -701,6 +719,11 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
        }
    }

    @VisibleForTesting
    EmergencyDialerAction makeEmergencyDialerActionForTesting() {
        return new EmergencyDialerAction();
    }

    private final class RestartAction extends SinglePressAction implements LongPressAction {
        private RestartAction() {
            super(R.drawable.ic_restart, R.string.global_action_restart);
@@ -731,7 +754,8 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
        }
    }

    private class ScreenshotAction extends SinglePressAction implements LongPressAction {
    @VisibleForTesting
    class ScreenshotAction extends SinglePressAction implements LongPressAction {
        public ScreenshotAction() {
            super(R.drawable.ic_screenshot, R.string.global_action_screenshot);
        }
@@ -747,8 +771,9 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
                public void run() {
                    mScreenshotHelper.takeScreenshot(1, true, true, mHandler, null);
                    mMetricsLogger.action(MetricsEvent.ACTION_SCREENSHOT_POWER_MENU);
                    mUiEventLogger.log(GlobalActionsEvent.GA_SCREENSHOT_PRESS);
                }
            }, 500);
            }, mDialogPressDelay);
        }

        @Override
@@ -764,6 +789,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
        @Override
        public boolean onLongPress() {
            if (FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SCREENRECORD_LONG_PRESS)) {
                mUiEventLogger.log(GlobalActionsEvent.GA_SCREENSHOT_LONG_PRESS);
                mScreenRecordHelper.launchRecordPrompt();
            } else {
                onPress();
@@ -772,7 +798,13 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
        }
    }

    private class BugReportAction extends SinglePressAction implements LongPressAction {
    @VisibleForTesting
    ScreenshotAction makeScreenshotActionForTesting() {
        return new ScreenshotAction();
    }

    @VisibleForTesting
    class BugReportAction extends SinglePressAction implements LongPressAction {

        public BugReportAction() {
            super(R.drawable.ic_lock_bugreport, R.string.bugreport_title);
@@ -795,6 +827,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
                        // Take an "interactive" bugreport.
                        mMetricsLogger.action(
                                MetricsEvent.ACTION_BUGREPORT_FROM_POWER_MENU_INTERACTIVE);
                        mUiEventLogger.log(GlobalActionsEvent.GA_BUGREPORT_PRESS);
                        if (!mIActivityManager.launchBugReportHandlerApp()) {
                            Log.w(TAG, "Bugreport handler could not be launched");
                            mIActivityManager.requestInteractiveBugReport();
@@ -802,7 +835,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
                    } catch (RemoteException e) {
                    }
                }
            }, 500);
            }, mDialogPressDelay);
        }

        @Override
@@ -815,6 +848,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
            try {
                // Take a "full" bugreport.
                mMetricsLogger.action(MetricsEvent.ACTION_BUGREPORT_FROM_POWER_MENU_FULL);
                mUiEventLogger.log(GlobalActionsEvent.GA_BUGREPORT_LONG_PRESS);
                mIActivityManager.requestFullBugReport();
            } catch (RemoteException e) {
            }
@@ -831,6 +865,11 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
        }
    }

    @VisibleForTesting
    BugReportAction makeBugReportActionForTesting() {
        return new BugReportAction();
    }

    private final class LogoutAction extends SinglePressAction {
        private LogoutAction() {
            super(R.drawable.ic_logout, R.string.global_action_logout);
@@ -858,7 +897,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
                } catch (RemoteException re) {
                    Log.e(TAG, "Couldn't logout user " + re);
                }
            }, 500);
            }, mDialogPressDelay);
        }
    }

@@ -1599,6 +1638,11 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
    private static final int MESSAGE_REFRESH = 1;
    private static final int MESSAGE_SHOW = 2;
    private static final int DIALOG_DISMISS_DELAY = 300; // ms
    private static final int DIALOG_PRESS_DELAY = 500; // ms

    @VisibleForTesting void setZeroDialogPressDelayForTesting() {
        mDialogPressDelay = 0; // ms
    }

    private Handler mHandler = new Handler() {
        public void handleMessage(Message msg) {
+52 −2
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.service.dreams.IDreamManager;
import android.telephony.TelephonyManager;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.util.FeatureFlagUtils;
import android.view.IWindowManager;

import androidx.test.filters.SmallTest;
@@ -66,7 +67,7 @@ import java.util.concurrent.Executor;

@SmallTest
@RunWith(AndroidTestingRunner.class)
@TestableLooper.RunWithLooper
@TestableLooper.RunWithLooper()
public class GlobalActionsDialogTest extends SysuiTestCase {
    private GlobalActionsDialog mGlobalActionsDialog;

@@ -143,11 +144,60 @@ public class GlobalActionsDialogTest extends SysuiTestCase {
                mUiEventLogger,
                mRingerModeTracker
        );
        mGlobalActionsDialog.setZeroDialogPressDelayForTesting();
    }

    @Test
    public void testShouldLogVisibility() {
        mGlobalActionsDialog.onShow(null);
        mTestableLooper.processAllMessages();
        verifyLogPosted(GlobalActionsDialog.GlobalActionsEvent.GA_POWER_MENU_OPEN);
    }

    @Test
    public void testShouldLogBugreportPress() throws InterruptedException {
        GlobalActionsDialog.BugReportAction bugReportAction =
                mGlobalActionsDialog.makeBugReportActionForTesting();
        bugReportAction.onPress();
        verifyLogPosted(GlobalActionsDialog.GlobalActionsEvent.GA_BUGREPORT_PRESS);
    }

    @Test
    public void testShouldLogBugreportLongPress() {
        GlobalActionsDialog.BugReportAction bugReportAction =
                mGlobalActionsDialog.makeBugReportActionForTesting();
        bugReportAction.onLongPress();
        verifyLogPosted(GlobalActionsDialog.GlobalActionsEvent.GA_BUGREPORT_LONG_PRESS);
    }

    @Test
    public void testShouldLogEmergencyDialerPress() {
        GlobalActionsDialog.EmergencyDialerAction emergencyDialerAction =
                mGlobalActionsDialog.makeEmergencyDialerActionForTesting();
        emergencyDialerAction.onPress();
        verifyLogPosted(GlobalActionsDialog.GlobalActionsEvent.GA_EMERGENCY_DIALER_PRESS);
    }

    @Test
    public void testShouldLogScreenshotPress() {
        GlobalActionsDialog.ScreenshotAction screenshotAction =
                mGlobalActionsDialog.makeScreenshotActionForTesting();
        screenshotAction.onPress();
        verifyLogPosted(GlobalActionsDialog.GlobalActionsEvent.GA_SCREENSHOT_PRESS);
    }

    @Test
    public void testShouldLogScreenshotLongPress() {
        FeatureFlagUtils.setEnabled(mContext, FeatureFlagUtils.SCREENRECORD_LONG_PRESS, true);
        GlobalActionsDialog.ScreenshotAction screenshotAction =
                mGlobalActionsDialog.makeScreenshotActionForTesting();
        screenshotAction.onLongPress();
        verifyLogPosted(GlobalActionsDialog.GlobalActionsEvent.GA_SCREENSHOT_LONG_PRESS);
    }

    private void verifyLogPosted(GlobalActionsDialog.GlobalActionsEvent event) {
        mTestableLooper.processAllMessages();
        verify(mUiEventLogger, times(1))
                .log(GlobalActionsDialog.GlobalActionsEvent.GA_POWER_MENU_OPEN);
                .log(event);
    }
}