Merge "port more global actions legacy logs to new pipeline" into rvc-dev am: 1886acb2c4

Change-Id: Iac3cd6d75d20771e80c360149db20531c7385059
This commit is contained in:
Chris Wren
2020-04-10 18:58:00 +00:00
committed by Automerger Merge Worker
2 changed files with 103 additions and 9 deletions

View File

@@ -222,11 +222,27 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
private ControlsController mControlsController; private ControlsController mControlsController;
private SharedPreferences mControlsPreferences; private SharedPreferences mControlsPreferences;
private final RingerModeTracker mRingerModeTracker; private final RingerModeTracker mRingerModeTracker;
private int mDialogPressDelay = DIALOG_PRESS_DELAY; // ms
@VisibleForTesting @VisibleForTesting
public enum GlobalActionsEvent implements UiEventLogger.UiEventEnum { public enum GlobalActionsEvent implements UiEventLogger.UiEventEnum {
@UiEvent(doc = "The global actions / power menu surface became visible on the screen.") @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; 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() { private EmergencyDialerAction() {
super(com.android.systemui.R.drawable.ic_emergency_star, super(com.android.systemui.R.drawable.ic_emergency_star,
R.string.global_action_emergency); R.string.global_action_emergency);
@@ -688,6 +705,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
@Override @Override
public void onPress() { public void onPress() {
mMetricsLogger.action(MetricsEvent.ACTION_EMERGENCY_DIALER_FROM_POWER_MENU); mMetricsLogger.action(MetricsEvent.ACTION_EMERGENCY_DIALER_FROM_POWER_MENU);
mUiEventLogger.log(GlobalActionsEvent.GA_EMERGENCY_DIALER_PRESS);
if (mTelecomManager != null) { if (mTelecomManager != null) {
Intent intent = mTelecomManager.createLaunchEmergencyDialerIntent( Intent intent = mTelecomManager.createLaunchEmergencyDialerIntent(
null /* number */); 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 final class RestartAction extends SinglePressAction implements LongPressAction {
private RestartAction() { private RestartAction() {
super(R.drawable.ic_restart, R.string.global_action_restart); 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() { public ScreenshotAction() {
super(R.drawable.ic_screenshot, R.string.global_action_screenshot); super(R.drawable.ic_screenshot, R.string.global_action_screenshot);
} }
@@ -747,8 +771,9 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
public void run() { public void run() {
mScreenshotHelper.takeScreenshot(1, true, true, mHandler, null); mScreenshotHelper.takeScreenshot(1, true, true, mHandler, null);
mMetricsLogger.action(MetricsEvent.ACTION_SCREENSHOT_POWER_MENU); mMetricsLogger.action(MetricsEvent.ACTION_SCREENSHOT_POWER_MENU);
mUiEventLogger.log(GlobalActionsEvent.GA_SCREENSHOT_PRESS);
} }
}, 500); }, mDialogPressDelay);
} }
@Override @Override
@@ -764,6 +789,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
@Override @Override
public boolean onLongPress() { public boolean onLongPress() {
if (FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SCREENRECORD_LONG_PRESS)) { if (FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SCREENRECORD_LONG_PRESS)) {
mUiEventLogger.log(GlobalActionsEvent.GA_SCREENSHOT_LONG_PRESS);
mScreenRecordHelper.launchRecordPrompt(); mScreenRecordHelper.launchRecordPrompt();
} else { } else {
onPress(); 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() { public BugReportAction() {
super(R.drawable.ic_lock_bugreport, R.string.bugreport_title); super(R.drawable.ic_lock_bugreport, R.string.bugreport_title);
@@ -795,6 +827,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
// Take an "interactive" bugreport. // Take an "interactive" bugreport.
mMetricsLogger.action( mMetricsLogger.action(
MetricsEvent.ACTION_BUGREPORT_FROM_POWER_MENU_INTERACTIVE); MetricsEvent.ACTION_BUGREPORT_FROM_POWER_MENU_INTERACTIVE);
mUiEventLogger.log(GlobalActionsEvent.GA_BUGREPORT_PRESS);
if (!mIActivityManager.launchBugReportHandlerApp()) { if (!mIActivityManager.launchBugReportHandlerApp()) {
Log.w(TAG, "Bugreport handler could not be launched"); Log.w(TAG, "Bugreport handler could not be launched");
mIActivityManager.requestInteractiveBugReport(); mIActivityManager.requestInteractiveBugReport();
@@ -802,7 +835,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
} catch (RemoteException e) { } catch (RemoteException e) {
} }
} }
}, 500); }, mDialogPressDelay);
} }
@Override @Override
@@ -815,6 +848,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
try { try {
// Take a "full" bugreport. // Take a "full" bugreport.
mMetricsLogger.action(MetricsEvent.ACTION_BUGREPORT_FROM_POWER_MENU_FULL); mMetricsLogger.action(MetricsEvent.ACTION_BUGREPORT_FROM_POWER_MENU_FULL);
mUiEventLogger.log(GlobalActionsEvent.GA_BUGREPORT_LONG_PRESS);
mIActivityManager.requestFullBugReport(); mIActivityManager.requestFullBugReport();
} catch (RemoteException e) { } 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 final class LogoutAction extends SinglePressAction {
private LogoutAction() { private LogoutAction() {
super(R.drawable.ic_logout, R.string.global_action_logout); super(R.drawable.ic_logout, R.string.global_action_logout);
@@ -858,7 +897,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
} catch (RemoteException re) { } catch (RemoteException re) {
Log.e(TAG, "Couldn't logout user " + 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_REFRESH = 1;
private static final int MESSAGE_SHOW = 2; private static final int MESSAGE_SHOW = 2;
private static final int DIALOG_DISMISS_DELAY = 300; // ms 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() { private Handler mHandler = new Handler() {
public void handleMessage(Message msg) { public void handleMessage(Message msg) {

View File

@@ -32,6 +32,7 @@ import android.service.dreams.IDreamManager;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import android.testing.AndroidTestingRunner; import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper; import android.testing.TestableLooper;
import android.util.FeatureFlagUtils;
import android.view.IWindowManager; import android.view.IWindowManager;
import androidx.test.filters.SmallTest; import androidx.test.filters.SmallTest;
@@ -66,7 +67,7 @@ import java.util.concurrent.Executor;
@SmallTest @SmallTest
@RunWith(AndroidTestingRunner.class) @RunWith(AndroidTestingRunner.class)
@TestableLooper.RunWithLooper @TestableLooper.RunWithLooper()
public class GlobalActionsDialogTest extends SysuiTestCase { public class GlobalActionsDialogTest extends SysuiTestCase {
private GlobalActionsDialog mGlobalActionsDialog; private GlobalActionsDialog mGlobalActionsDialog;
@@ -143,11 +144,60 @@ public class GlobalActionsDialogTest extends SysuiTestCase {
mUiEventLogger, mUiEventLogger,
mRingerModeTracker mRingerModeTracker
); );
mGlobalActionsDialog.setZeroDialogPressDelayForTesting();
} }
@Test @Test
public void testShouldLogVisibility() { public void testShouldLogVisibility() {
mGlobalActionsDialog.onShow(null); 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)) verify(mUiEventLogger, times(1))
.log(GlobalActionsDialog.GlobalActionsEvent.GA_POWER_MENU_OPEN); .log(event);
} }
} }