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

Commit 68adc2ad authored by lyn's avatar lyn Committed by Lyn
Browse files

Do not create conversation if classified

Fixes: 402358371
Test: NotificationManagerServiceTest
Flag: android.service.notification.notification_classification
Change-Id: I778322fbc185eeac9e5c725392541503e8c76897
parent 19232130
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@

package com.android.systemui.statusbar.notification;

import static android.app.NotificationChannel.SYSTEM_RESERVED_IDS;
import static android.service.notification.Flags.notificationClassification;

import android.app.INotificationManager;
import android.app.Notification;
import android.app.NotificationChannel;
@@ -40,6 +43,9 @@ public class NotificationChannelHelper {
            INotificationManager notificationManager,
            NotificationEntry entry,
            NotificationChannel channel) {
        if (notificationClassification() && SYSTEM_RESERVED_IDS.contains(channel.getId())) {
            return channel;
        }
        if (!TextUtils.isEmpty(channel.getConversationId())) {
            return channel;
        }
+15 −1
Original line number Diff line number Diff line
@@ -4874,6 +4874,13 @@ public class NotificationManagerService extends SystemService {
            checkNotNull(parentChannel);
            checkNotNull(conversationId);
            String parentId = parentChannel.getId();
            if (notificationClassification()) {
                if (SYSTEM_RESERVED_IDS.contains(parentId)) {
                    Log.v(TAG, "Cannot create conversation for classified notification with pkg:"
                            + pkg + " parentId:" + parentId + " conversationId:" + conversationId);
                    return;
                }
            }
            NotificationChannel conversationChannel = parentChannel;
            conversationChannel.setId(String.format(
                    CONVERSATION_CHANNEL_ID_FORMAT, parentId, conversationId));
@@ -7072,9 +7079,16 @@ public class NotificationManagerService extends SystemService {
            Objects.requireNonNull(user);
            Objects.requireNonNull(parentId);
            Objects.requireNonNull(conversationId);
            verifyPrivilegedListener(token, user, true);
            if (notificationClassification()) {
                if (SYSTEM_RESERVED_IDS.contains(parentId)) {
                    Log.v(TAG, "Cannot create conversation for classified notif from privileged " +
                            "listener with pkg:" + pkg + " user:" + user + " parentId:" + parentId
                            + " conversationId:" + conversationId);
                    return null;
                }
            }
            int uid = getUidForPackageAndUser(pkg, user);
            NotificationChannel conversationChannel =
                    mPreferencesHelper.getNotificationChannel(pkg, uid, parentId, false).copy();
+59 −0
Original line number Diff line number Diff line
@@ -4926,6 +4926,35 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        assertThat(parentChannelCopy).isEqualTo(mParentChannel);
    }
    @Test
    @EnableFlags({
            FLAG_NOTIFICATION_CONVERSATION_CHANNEL_MANAGEMENT,
            FLAG_NOTIFICATION_CLASSIFICATION
    })
    public void createConversationChannelForPkgFromPrivilegedListener_classified_fail()
            throws Exception {
        // Set up cdm
        mService.setPreferencesHelper(mPreferencesHelper);
        when(mCompanionMgr.getAssociations(mPkg, mUserId))
                .thenReturn(singletonList(mock(AssociationInfo.class)));
        // Set up parent channel
        setUpChannelsForConversationChannelTest();
        final NotificationChannel parentChannelCopy = mParentChannel.copy();
        for (String channelId : NotificationChannel.SYSTEM_RESERVED_IDS) {
            NotificationChannel createdChannel = mBinderService
                    .createConversationNotificationChannelForPackageFromPrivilegedListener(
                            null, mPkg, mUser, channelId, CONVERSATION_ID);
            // Verify that no channel is created and null is returned.
            verify(mPreferencesHelper, never()).createNotificationChannel(
                    eq(mPkg), eq(mUid), any(), anyBoolean(), anyBoolean(),
                    eq(mUid), anyBoolean());
            assertThat(createdChannel).isEqualTo(null);
        }
    }
    @Test
    @RequiresFlagsEnabled(FLAG_NOTIFICATION_CONVERSATION_CHANNEL_MANAGEMENT)
    public void createConversationChannelForPkgFromPrivilegedListener_cdm_noAccess() throws Exception {
@@ -12563,6 +12592,36 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        assertNotNull(friendChannel.getId());
    }
    @Test
    @EnableFlags(FLAG_NOTIFICATION_CLASSIFICATION)
    public void createConversationNotificationChannel_classified_noChannelCreated()
            throws Exception {
        int userId = UserManager.isHeadlessSystemUserMode()
                ? UserHandle.getUserId(UID_HEADLESS)
                : USER_SYSTEM;
        for (String channelId: NotificationChannel.SYSTEM_RESERVED_IDS) {
            NotificationChannel original =
                    new NotificationChannel(channelId,channelId, IMPORTANCE_HIGH);
            Parcel parcel = Parcel.obtain();
            original.writeToParcel(parcel, 0);
            parcel.setDataPosition(0);
            NotificationChannel orig = NotificationChannel.CREATOR.createFromParcel(parcel);
            mBinderService.createNotificationChannels(mPkg, new ParceledListSlice(Arrays.asList(
                    orig)));
            mBinderService.createConversationNotificationChannelForPackage(
                    mPkg, mUid, orig, "friend");
            NotificationChannel friendChannel = mBinderService.getConversationNotificationChannel(
                    mPkg, userId, mPkg, original.getId(), false, "friend");
            assertEquals(null, friendChannel);
        }
    }
    @Test
    public void testCorrectCategory_systemOn_appCannotTurnOff() {
        int requested = 0;