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

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

Merge "Add notification information to logging for ACTION_NOTE_CONTROLS."

parents 68f20a07 ee8e1ae2
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -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);
+35 −2
Original line number Diff line number Diff line
@@ -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<>();