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

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

Merge "Fix NPE" into main

parents ff520f01 bf38944b
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -1166,7 +1166,11 @@ public final class NotificationRecord {
            mVibration = calculateVibration();
            if (restrictAudioAttributesCall() || restrictAudioAttributesAlarm()
                    || restrictAudioAttributesMedia()) {
                if (channel.getAudioAttributes() != null) {
                    mAttributes = channel.getAudioAttributes();
                } else {
                    mAttributes = Notification.AUDIO_ATTRIBUTES_DEFAULT;
                }
            }
        }
    }
+29 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
import static android.app.NotificationManager.IMPORTANCE_HIGH;
import static android.app.NotificationManager.IMPORTANCE_LOW;
import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED;
import static android.media.AudioAttributes.USAGE_ALARM;
import static android.service.notification.Adjustment.KEY_IMPORTANCE;
import static android.service.notification.Adjustment.KEY_NOT_CONVERSATION;
import static android.service.notification.NotificationListenerService.FLAG_FILTER_TYPE_ALERTING;
@@ -68,6 +69,7 @@ import android.os.Bundle;
import android.os.UserHandle;
import android.os.VibrationEffect;
import android.os.Vibrator;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Settings;
import android.service.notification.Adjustment;
@@ -1565,4 +1567,31 @@ public class NotificationRecordTest extends UiServiceTestCase {
        assertTrue(record.getPhoneNumbers().contains("16175552121"));
        assertTrue(record.getPhoneNumbers().contains("16175553434"));
    }

    @Test
    @EnableFlags(Flags.FLAG_RESTRICT_AUDIO_ATTRIBUTES_ALARM)
    public void updateChannel_nullAudioAttributes() {
        StatusBarNotification sbn = getStyledNotification(true, true, true,
                new Notification.DecoratedCustomViewStyle());
        NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel);

        record.updateNotificationChannel(new NotificationChannel("new", "new", 3));

        assertThat(record.getAudioAttributes()).isNotNull();
    }

    @Test
    @EnableFlags(Flags.FLAG_RESTRICT_AUDIO_ATTRIBUTES_ALARM)
    public void updateChannel_nonNullAudioAttributes() {
        StatusBarNotification sbn = getStyledNotification(true, true, true,
                new Notification.DecoratedCustomViewStyle());
        NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel);

        NotificationChannel update = new NotificationChannel("new", "new", 3);
        update.setSound(Uri.EMPTY,
                new AudioAttributes.Builder().setUsage(USAGE_ALARM).build());
        record.updateNotificationChannel(update);

        assertThat(record.getAudioAttributes().getUsage()).isEqualTo(USAGE_ALARM);
    }
}