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

Commit 0def6d1b authored by jiabin's avatar jiabin
Browse files

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
parent df08d493
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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;
+13 −1
Original line number Diff line number Diff line
@@ -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.
@@ -1099,6 +1100,17 @@ public class RingtoneManager {
        return AudioManager.hasHapticChannels(null, ringtoneUri);
    }

    /**
     * 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.
     *