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

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

Merge "Migrate pre-Oreo app handling to permissions"

parents 59e5fa40 808d3a58
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -2824,6 +2824,12 @@ public class NotificationManagerService extends SystemService {
                mPreferencesHelper.getNotificationChannel(pkg, uid, channel.getId(), true);

        mPreferencesHelper.updateNotificationChannel(pkg, uid, channel, true);
        if (mEnableAppSettingMigration) {
            if (mPreferencesHelper.onlyHasDefaultChannel(pkg, uid)) {
                mPermissionHelper.setNotificationPermission(pkg, UserHandle.getUserId(uid),
                        channel.getImportance() != IMPORTANCE_NONE, true);
            }
        }
        maybeNotifyChannelOwner(pkg, uid, preUpdate, channel);

        if (!fromListener) {
+5 −3
Original line number Diff line number Diff line
@@ -1043,9 +1043,11 @@ public class PreferencesHelper implements RankingConfig {
            r.channels.put(updatedChannel.getId(), updatedChannel);

            if (onlyHasDefaultChannel(pkg, uid)) {
                if (!mPermissionHelper.isMigrationEnabled()) {
                    // copy settings to app level so they are inherited by new channels
                    // when the app migrates
                    r.importance = updatedChannel.getImportance();
                }
                r.priority = updatedChannel.canBypassDnd()
                        ? Notification.PRIORITY_MAX : Notification.PRIORITY_DEFAULT;
                r.visibility = updatedChannel.getLockscreenVisibility();
+2 −0
Original line number Diff line number Diff line
@@ -3708,6 +3708,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {

        assertEquals(IMPORTANCE_LOW,
                mService.getNotificationRecord(sbn.getKey()).getImportance());
        assertEquals(IMPORTANCE_UNSPECIFIED, mBinderService.getPackageImportance(
                sbn.getPackageName()));

        nb = new Notification.Builder(mContext)
                .setContentTitle("foo")
+15 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static android.app.AppOpsManager.MODE_IGNORED;
import static android.app.NotificationManager.EXTRA_BLOCKED_STATE;
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
import static android.app.NotificationManager.IMPORTANCE_NONE;
import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED;
import static android.content.pm.PackageManager.FEATURE_WATCH;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static android.os.UserHandle.USER_SYSTEM;
@@ -123,6 +124,7 @@ import com.android.server.wm.ActivityTaskManagerInternal;
import com.android.server.wm.WindowManagerInternal;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -663,4 +665,17 @@ public class NotificationPermissionMigrationTest extends UiServiceTestCase {
        verify(mWorkerHandler, never()).post(
                any(NotificationManagerService.EnqueueNotificationRunnable.class));
    }

    @Test
    public void testDefaultChannelDoesNotUpdateApp_postMigrationToPermissions() throws Exception {
        final NotificationChannel defaultChannel = mBinderService.getNotificationChannel(
                PKG_N_MR1, ActivityManager.getCurrentUser(), PKG_N_MR1,
                NotificationChannel.DEFAULT_CHANNEL_ID);
        defaultChannel.setImportance(IMPORTANCE_NONE);

        mBinderService.updateNotificationChannelForPackage(PKG_N_MR1, mUid, defaultChannel);

        verify(mPermissionHelper).setNotificationPermission(
                PKG_N_MR1, ActivityManager.getCurrentUser(), false, true);
    }
}
+22 −0
Original line number Diff line number Diff line
@@ -4072,6 +4072,28 @@ public class PreferencesHelperTest extends UiServiceTestCase {
        assertTrue((channelA.getUserLockedFields() & USER_LOCKED_IMPORTANCE) == 0);
        assertTrue((channelB.getUserLockedFields() & USER_LOCKED_IMPORTANCE) == 0);
        assertTrue((channelC.getUserLockedFields() & USER_LOCKED_IMPORTANCE) == 0);
    }

    @Test
    public void testDefaultChannelUpdatesApp_preMigrationToPermissions() throws Exception {
        final NotificationChannel defaultChannel = mHelper.getNotificationChannel(PKG_N_MR1,
                UID_N_MR1,
                NotificationChannel.DEFAULT_CHANNEL_ID, false);
        defaultChannel.setImportance(IMPORTANCE_NONE);
        mHelper.updateNotificationChannel(PKG_N_MR1, UID_N_MR1, defaultChannel, true);

        assertEquals(IMPORTANCE_NONE, mHelper.getImportance(PKG_N_MR1, UID_N_MR1));
    }

    @Test
    public void testDefaultChannelDoesNotUpdateApp_postMigrationToPermissions() throws Exception {
        when(mPermissionHelper.isMigrationEnabled()).thenReturn(true);
        final NotificationChannel defaultChannel = mHelper.getNotificationChannel(PKG_N_MR1,
                UID_N_MR1,
                NotificationChannel.DEFAULT_CHANNEL_ID, false);
        defaultChannel.setImportance(IMPORTANCE_NONE);
        mHelper.updateNotificationChannel(PKG_N_MR1, UID_N_MR1, defaultChannel, true);

        assertEquals(IMPORTANCE_UNSPECIFIED, mHelper.getImportance(PKG_N_MR1, UID_N_MR1));
    }
}