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

Commit 8b1f3c97 authored by Michael Wright's avatar Michael Wright
Browse files

Uncanonicalize URIs when searching for audio-coupled haptics.

It's possible that the Ringtone URIs will be pre-canonicalized, which
don't maintain equality when compared to uncanonicalized URIs. In order
to handle this case, we just need to uncanonicalize both URIs before
comparing.

Fixes: 134394754
Test: manual, verified audio-coupled haptics works again on B1C1
Change-Id: I2e216db1013d5bc0db0a1622e0670853663f0db8
parent 35e5db7a
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -330,18 +330,25 @@ public abstract class VibrationEffect implements Parcelable {
    @TestApi
    @Nullable
    public static VibrationEffect get(Uri uri, Context context) {
        final ContentResolver cr = context.getContentResolver();
        Uri uncanonicalUri = cr.uncanonicalize(uri);
        if (uncanonicalUri == null) {
            // If we already had an uncanonical URI, it's possible we'll get null back here. In
            // this case, just use the URI as passed in since it wasn't canonicalized in the first
            // place.
            uncanonicalUri = uri;
        }
        String[] uris = context.getResources().getStringArray(
                com.android.internal.R.array.config_ringtoneEffectUris);
        for (int i = 0; i < uris.length && i < RINGTONES.length; i++) {
            if (uris[i] == null) {
                continue;
            }
            ContentResolver cr = context.getContentResolver();
            Uri mappedUri = cr.uncanonicalize(Uri.parse(uris[i]));
            if (mappedUri == null) {
                continue;
            }
            if (mappedUri.equals(uri)) {
            if (mappedUri.equals(uncanonicalUri)) {
                return get(RINGTONES[i]);
            }
        }