From ee8e1ae2db445bb0b7ddd6de71db6e35f3d4dce1 Mon Sep 17 00:00:00 2001 From: TreeHugger Robot Date: Fri, 18 Jan 2019 19:26:40 +0000 Subject: [PATCH] Add notification information to logging for ACTION_NOTE_CONTROLS. This event occurs when the user clicks through to modify notification interruptiveness. Also add test for logging. Bug: 121380248 Test: atest SystemUITests and manual verification Change-Id: I5d1876ce79188a457f264eb71f8bd5709944483b --- .../row/NotificationGutsManager.java | 10 ++++- .../row/NotificationGutsManagerTest.java | 37 ++++++++++++++++++- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationGutsManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationGutsManager.java index bd1dfb181afe0..5e9f20795272b 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationGutsManager.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationGutsManager.java @@ -25,6 +25,7 @@ import android.app.NotificationChannel; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; +import android.metrics.LogMaker; import android.net.Uri; import android.os.ServiceManager; import android.os.UserHandle; @@ -159,7 +160,8 @@ public class NotificationGutsManager implements Dumpable, NotificationLifetimeEx return bindGuts(row, mGutsMenuItem); } - private boolean bindGuts(final ExpandableNotificationRow row, + @VisibleForTesting + protected boolean bindGuts(final ExpandableNotificationRow row, NotificationMenuRowPlugin.MenuItem item) { StatusBarNotification sbn = row.getStatusBarNotification(); @@ -389,7 +391,11 @@ public class NotificationGutsManager implements Dumpable, NotificationLifetimeEx return false; } - mMetricsLogger.action(MetricsProto.MetricsEvent.ACTION_NOTE_CONTROLS); + LogMaker logMaker = (row.getStatusBarNotification() == null) + ? new LogMaker(MetricsProto.MetricsEvent.ACTION_NOTE_CONTROLS) + : row.getStatusBarNotification().getLogMaker(); + mMetricsLogger.write(logMaker.setCategory(MetricsProto.MetricsEvent.ACTION_NOTE_CONTROLS) + .setType(MetricsProto.MetricsEvent.TYPE_ACTION)); // ensure that it's laid but not visible until actually laid out guts.setVisibility(View.INVISIBLE); diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationGutsManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationGutsManagerTest.java index 0899c73ab07b3..40d2da9a77290 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationGutsManagerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationGutsManagerTest.java @@ -45,6 +45,7 @@ import android.app.Notification; import android.app.NotificationChannel; import android.content.Intent; import android.content.pm.PackageManager; +import android.metrics.LogMaker; import android.os.Binder; import android.os.Handler; import android.provider.Settings; @@ -55,6 +56,8 @@ import android.testing.TestableLooper; import android.util.ArraySet; import android.view.View; +import com.android.internal.logging.MetricsLogger; +import com.android.internal.logging.nano.MetricsProto; import com.android.systemui.SysuiTestCase; import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin; import com.android.systemui.statusbar.NotificationPresenter; @@ -92,6 +95,7 @@ public class NotificationGutsManagerTest extends SysuiTestCase { private NotificationGutsManager mGutsManager; @Rule public MockitoRule mockito = MockitoJUnit.rule(); + @Mock private MetricsLogger mMetricsLogger; @Mock private NotificationPresenter mPresenter; @Mock private NotificationActivityStarter mNotificationActivityStarter; @Mock private NotificationStackScrollLayout mStackScroller; @@ -105,6 +109,7 @@ public class NotificationGutsManagerTest extends SysuiTestCase { Assert.sMainLooper = TestableLooper.get(this).getLooper(); mDependency.injectTestDependency(DeviceProvisionedController.class, mDeviceProvisionedController); + mDependency.injectTestDependency(MetricsLogger.class, mMetricsLogger); mHandler = Handler.createAsync(mTestableLooper.getLooper()); mHelper = new NotificationTestHelper(mContext); @@ -141,7 +146,7 @@ public class NotificationGutsManagerTest extends SysuiTestCase { when(row.getWindowToken()).thenReturn(new Binder()); when(row.getGuts()).thenReturn(guts); - mGutsManager.openGuts(row, 0, 0, menuItem); + assertTrue(mGutsManager.openGuts(row, 0, 0, menuItem)); assertEquals(View.INVISIBLE, guts.getVisibility()); mTestableLooper.processAllMessages(); verify(guts).openControls( @@ -189,7 +194,7 @@ public class NotificationGutsManagerTest extends SysuiTestCase { when(entry.getRow()).thenReturn(row); when(entry.getGuts()).thenReturn(guts); - mGutsManager.openGuts(row, 0, 0, menuItem); + assertTrue(mGutsManager.openGuts(row, 0, 0, menuItem)); mTestableLooper.processAllMessages(); verify(guts).openControls( eq(true), @@ -214,6 +219,34 @@ public class NotificationGutsManagerTest extends SysuiTestCase { verify(row, times(2)).setGutsView(any()); } + @Test + public void testOpenGutsLogging() { + NotificationGutsManager gutsManager = spy(mGutsManager); + doReturn(true).when(gutsManager).bindGuts(any(), any()); + + NotificationGuts guts = spy(new NotificationGuts(mContext)); + doReturn(true).when(guts).post(any()); + + ExpandableNotificationRow realRow = createTestNotificationRow(); + NotificationMenuRowPlugin.MenuItem menuItem = createTestMenuItem(realRow); + + ExpandableNotificationRow row = spy(realRow); + when(row.getWindowToken()).thenReturn(new Binder()); + when(row.getGuts()).thenReturn(guts); + StatusBarNotification notification = spy(realRow.getStatusBarNotification()); + when(row.getStatusBarNotification()).thenReturn(notification); + + assertTrue(gutsManager.openGuts(row, 0, 0, menuItem)); + + ArgumentCaptor logMakerCaptor = ArgumentCaptor.forClass(LogMaker.class); + verify(notification).getLogMaker(); + verify(mMetricsLogger).write(logMakerCaptor.capture()); + assertEquals(MetricsProto.MetricsEvent.ACTION_NOTE_CONTROLS, + logMakerCaptor.getValue().getCategory()); + assertEquals(MetricsProto.MetricsEvent.TYPE_ACTION, + logMakerCaptor.getValue().getType()); + } + @Test public void testAppOpsSettingsIntent_camera() { ArraySet ops = new ArraySet<>();