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
This commit is contained in:
Michael Wright
2019-06-04 15:26:25 +01:00
parent 35e5db7a3f
commit 8b1f3c970c

View File

@@ -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]);
}
}