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

Commit 0eaa5d21 authored by Julia Reynolds's avatar Julia Reynolds Committed by Automerger Merge Worker
Browse files

Merge "Don't do un-needed work" into sc-dev am: d4cfd70d

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15081065

Change-Id: I8f6ddda0a7387c983678f448175362357f04bb78
parents 397582e4 d4cfd70d
Loading
Loading
Loading
Loading
+12 −9
Original line number Diff line number Diff line
@@ -3815,7 +3815,9 @@ public class NotificationManagerService extends SystemService {
            enforceDeletingChannelHasNoFgService(pkg, callingUser, channelId);
            cancelAllNotificationsInt(MY_UID, MY_PID, pkg, channelId, 0, 0, true,
                    callingUser, REASON_CHANNEL_REMOVED, null);
            mPreferencesHelper.deleteNotificationChannel(pkg, callingUid, channelId);
            boolean previouslyExisted = mPreferencesHelper.deleteNotificationChannel(
                    pkg, callingUid, channelId);
            if (previouslyExisted) {
                // Remove from both recent notification archive and notification history
                mArchive.removeChannelNotifications(pkg, callingUser, channelId);
                mHistoryManager.deleteNotificationChannel(pkg, callingUid, channelId);
@@ -3825,6 +3827,7 @@ public class NotificationManagerService extends SystemService {
                        NOTIFICATION_CHANNEL_OR_GROUP_DELETED);
                handleSavePolicyFile();
            }
        }

        @Override
        public NotificationChannelGroup getNotificationChannelGroup(String pkg, String groupId) {
+7 −4
Original line number Diff line number Diff line
@@ -1126,20 +1126,21 @@ public class PreferencesHelper implements RankingConfig {
    }

    @Override
    public void deleteNotificationChannel(String pkg, int uid, String channelId) {
    public boolean deleteNotificationChannel(String pkg, int uid, String channelId) {
        synchronized (mPackagePreferences) {
            PackagePreferences r = getPackagePreferencesLocked(pkg, uid);
            if (r == null) {
                return;
                return false;
            }
            NotificationChannel channel = r.channels.get(channelId);
            if (channel != null) {
                deleteNotificationChannelLocked(channel, pkg, uid);
                return deleteNotificationChannelLocked(channel, pkg, uid);
            }
            return false;
        }
    }

    private void deleteNotificationChannelLocked(NotificationChannel channel, String pkg, int uid) {
    private boolean deleteNotificationChannelLocked(NotificationChannel channel, String pkg, int uid) {
        if (!channel.isDeleted()) {
            channel.setDeleted(true);
            channel.setDeletedTimeMs(System.currentTimeMillis());
@@ -1151,7 +1152,9 @@ public class PreferencesHelper implements RankingConfig {
            if (mAreChannelsBypassingDnd && channel.canBypassDnd()) {
                updateChannelsBypassingDnd();
            }
            return true;
        }
        return false;
    }

    @Override
+1 −1
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ public interface RankingConfig {
    NotificationChannel getConversationNotificationChannel(String pkg, int uid, String channelId,
            String conversationId, boolean returnParentIfNoConversationChannel,
            boolean includeDeleted);
    void deleteNotificationChannel(String pkg, int uid, String channelId);
    boolean deleteNotificationChannel(String pkg, int uid, String channelId);
    void permanentlyDeleteNotificationChannel(String pkg, int uid, String channelId);
    void permanentlyDeleteNotificationChannels(String pkg, int uid);
    ParceledListSlice<NotificationChannel> getNotificationChannels(String pkg, int uid,
+19 −0
Original line number Diff line number Diff line
@@ -94,6 +94,7 @@ import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;

import android.app.ActivityManager;
@@ -2425,6 +2426,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        when(mPreferencesHelper.getNotificationChannel(eq(PKG), anyInt(),
                eq(mTestNotificationChannel.getId()), anyBoolean()))
                .thenReturn(mTestNotificationChannel);
        when(mPreferencesHelper.deleteNotificationChannel(eq(PKG), anyInt(),
                eq(mTestNotificationChannel.getId()))).thenReturn(true);
        reset(mListeners);
        mBinderService.deleteNotificationChannel(PKG, mTestNotificationChannel.getId());
        verify(mListeners, times(1)).notifyNotificationChannelChanged(eq(PKG),
@@ -2432,6 +2435,22 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
                eq(NotificationListenerService.NOTIFICATION_CHANNEL_OR_GROUP_DELETED));
    }

    @Test
    public void testDeleteChannelOnlyDoExtraWorkIfExisted() throws Exception {
        List<String> associations = new ArrayList<>();
        associations.add("a");
        when(mCompanionMgr.getAssociations(PKG, UserHandle.getUserId(mUid)))
                .thenReturn(associations);
        mService.setPreferencesHelper(mPreferencesHelper);
        when(mPreferencesHelper.getNotificationChannel(eq(PKG), anyInt(),
                eq(mTestNotificationChannel.getId()), anyBoolean()))
                .thenReturn(null);
        reset(mListeners);
        mBinderService.deleteNotificationChannel(PKG, mTestNotificationChannel.getId());
        verifyNoMoreInteractions(mListeners);
        verifyNoMoreInteractions(mHistoryManager);
    }

    @Test
    public void testDeleteChannelGroupNotifyListener() throws Exception {
        List<String> associations = new ArrayList<>();
+11 −0
Original line number Diff line number Diff line
@@ -3332,6 +3332,17 @@ public class PreferencesHelperTest extends UiServiceTestCase {
        assertNull(mHelper.getNotificationChannel(PKG_O, UID_O, "id", true));
    }

    @Test
    public void testDeleted_twice() throws Exception {
        mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger,
                mAppOpsManager, mStatsEventBuilderFactory);

        mHelper.createNotificationChannel(
                PKG_P, UID_P, createNotificationChannel("id", "id", 2), true, false);
        assertTrue(mHelper.deleteNotificationChannel(PKG_P, UID_P, "id"));
        assertFalse(mHelper.deleteNotificationChannel(PKG_P, UID_P, "id"));
    }

    @Test
    public void testDeleted_recentTime() throws Exception {
        mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger,