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

Commit babf7838 authored by Lyn Han's avatar Lyn Han Committed by Android (Google) Code Review
Browse files

Merge "Do not create conversation if classified" into main

parents f0f82f45 68adc2ad
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
@@ -4885,6 +4885,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));
@@ -7079,9 +7086,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 {
@@ -12561,6 +12590,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;