diff options
author | jiabin <jiabin@google.com> | 2021-10-28 00:38:33 +0000 |
---|---|---|
committer | jiabin <jiabin@google.com> | 2021-10-28 00:38:33 +0000 |
commit | 0def6d1b51e23d539728d4fa43032de8d18c69ad (patch) | |
tree | 6db0cd34c31e4af124ca1b35689bb6ce60e964c4 | |
parent | df08d4937e6553ade3efc70cb30772adc418227a (diff) |
Add RingtoneManager.hasHapticChannels(Context, Uri).
Currently, RingtoneManager.hasHapticChannels(Uri) will use the context
from AudioService to resolve the given Uri. However, that may not always
work. In that case, add another API to ask apps to provide Context to
resolve given Uri can help the API returning correct result.
Test: atest RingtoneManagerTest
Bug: 196195517
Change-Id: I484e157e0d03e5eeabdd68908b11db534ad3c3ab
-rw-r--r-- | core/api/current.txt | 1 | ||||
-rw-r--r-- | media/java/android/media/RingtoneManager.java | 14 |
2 files changed, 14 insertions, 1 deletions
diff --git a/core/api/current.txt b/core/api/current.txt index 0f0e928194fd..1f2861a44c8f 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -23844,6 +23844,7 @@ package android.media { method public static android.net.Uri getValidRingtoneUri(android.content.Context); method public boolean hasHapticChannels(int); method public static boolean hasHapticChannels(@NonNull android.net.Uri); + method public static boolean hasHapticChannels(@NonNull android.content.Context, @NonNull android.net.Uri); method public int inferStreamType(); method public static boolean isDefault(android.net.Uri); method @Nullable public static android.content.res.AssetFileDescriptor openDefaultRingtoneUri(@NonNull android.content.Context, @NonNull android.net.Uri) throws java.io.FileNotFoundException; diff --git a/media/java/android/media/RingtoneManager.java b/media/java/android/media/RingtoneManager.java index 3e7b8860c818..ccbfb8ff84b9 100644 --- a/media/java/android/media/RingtoneManager.java +++ b/media/java/android/media/RingtoneManager.java @@ -1090,7 +1090,8 @@ public class RingtoneManager { * haptic channels or not. As this function doesn't has a context * to resolve the uri, the result may be wrong if the uri cannot be * resolved correctly. - * Use {@link #hasHapticChannels(int)} instead when possible. + * Use {@link #hasHapticChannels(int)} or {@link #hasHapticChannels(Context, Uri)} + * instead when possible. * * @param ringtoneUri The {@link Uri} of a sound or ringtone. * @return true if the ringtone contains haptic channels. @@ -1100,6 +1101,17 @@ public class RingtoneManager { } /** + * Returns if the {@link Ringtone} from a given sound URI contains haptics channels or not. + * + * @param context the {@link android.content.Context} to use when resolving the Uri. + * @param ringtoneUri the {@link Uri} of a sound or ringtone. + * @return true if the ringtone contains haptic channels. + */ + public static boolean hasHapticChannels(@NonNull Context context, @NonNull Uri ringtoneUri) { + return AudioManager.hasHapticChannels(context, ringtoneUri); + } + + /** * Attempts to create a context for the given user. * * @return created context, or null if package does not exist |