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

Commit 61aacad9 authored by Julia Reynolds's avatar Julia Reynolds Committed by Android (Google) Code Review
Browse files

Merge "Remove app provided custom views" into main

parents 1aed687d a2632566
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -167,3 +167,10 @@ flag {
  description: "[Minimal HUN] Enables the compact heads up notification reply capability for Conversation Notifications"
  bug: "336229954"
}

flag {
  name: "remove_remote_views"
  namespace: "systemui"
  description: "Removes all custom views"
  bug: "342602960"
}
+32 −12
Original line number Diff line number Diff line
@@ -7774,6 +7774,25 @@ public class NotificationManagerService extends SystemService {
    }
    private void checkRemoteViews(String pkg, String tag, int id, Notification notification) {
        if (android.app.Flags.removeRemoteViews()) {
            if (notification.contentView != null || notification.bigContentView != null
                    ||  notification.headsUpContentView != null
                    || (notification.publicVersion != null
                    && (notification.publicVersion.contentView != null
                    || notification.publicVersion.bigContentView != null
                    || notification.publicVersion.headsUpContentView != null))) {
                Slog.i(TAG, "Removed customViews for " + pkg);
                mUsageStats.registerImageRemoved(pkg);
            }
            notification.contentView = null;
            notification.bigContentView = null;
            notification.headsUpContentView = null;
            if (notification.publicVersion != null) {
                notification.publicVersion.contentView = null;
                notification.publicVersion.bigContentView = null;
                notification.publicVersion.headsUpContentView = null;
            }
        } else {
            if (removeRemoteView(pkg, tag, id, notification.contentView)) {
                notification.contentView = null;
            }
@@ -7795,6 +7814,7 @@ public class NotificationManagerService extends SystemService {
                }
            }
        }
    }
    private boolean removeRemoteView(String pkg, String tag, int id, RemoteViews contentView) {
        if (contentView == null) {
+41 −0
Original line number Diff line number Diff line
@@ -10696,6 +10696,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
    }
    @Test
    @DisableFlags(android.app.Flags.FLAG_REMOVE_REMOTE_VIEWS)
    public void testRemoveLargeRemoteViews() throws Exception {
        int removeSize = mContext.getResources().getInteger(
                com.android.internal.R.integer.config_notificationStripRemoteViewSizeBytes);
@@ -10757,6 +10758,46 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        verify(mUsageStats, times(5)).registerImageRemoved(mPkg);
    }
    @Test
    @EnableFlags(android.app.Flags.FLAG_REMOVE_REMOTE_VIEWS)
    public void testRemoveRemoteViews() throws Exception {
        Notification np = new Notification.Builder(mContext, "test")
                .setSmallIcon(android.R.drawable.sym_def_app_icon)
                .setContentText("test")
                .setCustomContentView(mock(RemoteViews.class))
                .setCustomBigContentView(mock(RemoteViews.class))
                .setCustomHeadsUpContentView(mock(RemoteViews.class))
                .build();
        Notification n = new Notification.Builder(mContext, "test")
                .setSmallIcon(android.R.drawable.sym_def_app_icon)
                .setContentText("test")
                .setCustomContentView(mock(RemoteViews.class))
                .setCustomBigContentView(mock(RemoteViews.class))
                .setCustomHeadsUpContentView(mock(RemoteViews.class))
                .setPublicVersion(np)
                .build();
        assertNotNull(n.contentView);
        assertNotNull(n.bigContentView);
        assertNotNull(n.headsUpContentView);
        assertTrue(np.extras.containsKey(Notification.EXTRA_CONTAINS_CUSTOM_VIEW));
        assertNotNull(np.contentView);
        assertNotNull(np.bigContentView);
        assertNotNull(np.headsUpContentView);
        mService.fixNotification(n, mPkg, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE, true);
        assertNull(n.contentView);
        assertNull(n.bigContentView);
        assertNull(n.headsUpContentView);
        assertNull(n.publicVersion.contentView);
        assertNull(n.publicVersion.bigContentView);
        assertNull(n.publicVersion.headsUpContentView);
        verify(mUsageStats, times(1)).registerImageRemoved(mPkg);
    }
    @Test
    public void testNotificationBubbles_flagAutoExpandForeground_fails_notForeground()
            throws Exception {