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

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

Merge "Fix error when backing up channels" into main

parents 8766d30f 064466fe
Loading
Loading
Loading
Loading
+10 −4
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import android.provider.Settings;
import android.service.notification.NotificationListenerService;
import android.text.TextUtils;
import android.util.Log;
import android.util.Slog;
import android.util.proto.ProtoOutputStream;

import com.android.internal.util.Preconditions;
@@ -1369,12 +1370,17 @@ public final class NotificationChannel implements Parcelable {
        if (sound == null || Uri.EMPTY.equals(sound)) {
            return null;
        }
        try {
            Uri canonicalSound = getCanonicalizedSoundUri(context.getContentResolver(), sound);
            if (canonicalSound == null) {
                // The content provider does not support canonical uris so we backup the default
                return Settings.System.DEFAULT_NOTIFICATION_URI;
            }
            return canonicalSound;
        } catch (Exception e) {
            Slog.e(TAG, "Cannot find file for sound " + sound + " using default");
            return Settings.System.DEFAULT_NOTIFICATION_URI;
        }
    }

    /**
+25 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

@@ -51,6 +52,7 @@ import android.platform.test.annotations.UsesFlags;
import android.platform.test.flag.junit.FlagsParameterization;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.MediaStore.Audio.AudioColumns;
import android.provider.Settings;
import android.test.mock.MockContentResolver;
import android.util.Xml;

@@ -398,6 +400,29 @@ public class NotificationChannelTest {
        assertThat(restoredChannel.getSound()).isEqualTo(uriAfterRestoredCanonicalized);
    }

    @Test
    public void testWriteXmlForBackup_noAccessToFile() throws Exception {
        Uri uri = Uri.parse("content://media/1");

        AudioAttributes mAudioAttributes =
                new AudioAttributes.Builder()
                        .setContentType(AudioAttributes.CONTENT_TYPE_UNKNOWN)
                        .setUsage(AudioAttributes.USAGE_NOTIFICATION)
                        .setFlags(AudioAttributes.FLAG_AUDIBILITY_ENFORCED)
                        .build();

        NotificationChannel channel = new NotificationChannel("id", "name", 3);
        channel.setSound(uri, mAudioAttributes);

        when(mIContentProvider.canonicalize(any(), any())).thenThrow(new SecurityException(""));
        doThrow(new SecurityException("")).when(mIContentProvider)
                .canonicalizeAsync(any(), any(), any());

        NotificationChannel restoredChannel = backUpAndRestore(channel);
        assertThat(restoredChannel.getSound())
                .isEqualTo(Settings.System.DEFAULT_NOTIFICATION_URI);
    }

    @Test
    public void testVibrationGetters_nonPatternBasedVibrationEffect_waveform() throws Exception {
        mSetFlagsRule.enableFlags(Flags.FLAG_NOTIFICATION_CHANNEL_VIBRATION_EFFECT_API);