From 8b1f3c970ceb5f54f4a31871c15e9bc72c23ebcb Mon Sep 17 00:00:00 2001 From: Michael Wright Date: Tue, 4 Jun 2019 15:26:25 +0100 Subject: [PATCH] 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 --- core/java/android/os/VibrationEffect.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/core/java/android/os/VibrationEffect.java b/core/java/android/os/VibrationEffect.java index 035061b614f87..702b41beb0710 100644 --- a/core/java/android/os/VibrationEffect.java +++ b/core/java/android/os/VibrationEffect.java @@ -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]); } }