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
This commit is contained in:
TreeHugger Robot
2019-01-18 19:26:40 +00:00
committed by Will Brockman
parent f9c42c76a0
commit ee8e1ae2db
2 changed files with 43 additions and 4 deletions

View File

@@ -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);

View File

@@ -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<LogMaker> 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<Integer> ops = new ArraySet<>();