From e67bc4d484028de8a38237f21074dc4e7256c9d6 Mon Sep 17 00:00:00 2001 From: Jean-Michel Trivi Date: Mon, 27 Mar 2017 11:52:18 -0700 Subject: [PATCH] AudioAttributes: make getVolumeControlStream() non static In AudioAttributes class: - deprecate static getVolumeControlStream(AudioAttributes) method, - add non-static getVolumeControlStream() method. Test: cts-tradefed run cts -m CtsMediaTestCases -t android.media.cts.AudioAttributesTest Change-Id: Ic2276cb7367e0bcb0c07e1fe63de68dafddbccb5 --- api/current.txt | 3 ++- api/system-current.txt | 3 ++- api/test-current.txt | 3 ++- media/java/android/media/AudioAttributes.java | 21 +++++++++++++++++++ 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/api/current.txt b/api/current.txt index 5d94dbd50bb02..8c85b33fe3004 100644 --- a/api/current.txt +++ b/api/current.txt @@ -20890,7 +20890,8 @@ package android.media { method public int getContentType(); method public int getFlags(); method public int getUsage(); - method public static int getVolumeControlStream(android.media.AudioAttributes); + method public static deprecated int getVolumeControlStream(android.media.AudioAttributes); + method public int getVolumeControlStream(); method public void writeToParcel(android.os.Parcel, int); field public static final int CONTENT_TYPE_MOVIE = 3; // 0x3 field public static final int CONTENT_TYPE_MUSIC = 2; // 0x2 diff --git a/api/system-current.txt b/api/system-current.txt index c7b377e3d6fb5..afd3103467149 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -22626,7 +22626,8 @@ package android.media { method public int getContentType(); method public int getFlags(); method public int getUsage(); - method public static int getVolumeControlStream(android.media.AudioAttributes); + method public static deprecated int getVolumeControlStream(android.media.AudioAttributes); + method public int getVolumeControlStream(); method public void writeToParcel(android.os.Parcel, int); field public static final int CONTENT_TYPE_MOVIE = 3; // 0x3 field public static final int CONTENT_TYPE_MUSIC = 2; // 0x2 diff --git a/api/test-current.txt b/api/test-current.txt index d22f7d388a732..b73497ee38da9 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -21003,7 +21003,8 @@ package android.media { method public int getContentType(); method public int getFlags(); method public int getUsage(); - method public static int getVolumeControlStream(android.media.AudioAttributes); + method public static deprecated int getVolumeControlStream(android.media.AudioAttributes); + method public int getVolumeControlStream(); method public void writeToParcel(android.os.Parcel, int); field public static final int CONTENT_TYPE_MOVIE = 3; // 0x3 field public static final int CONTENT_TYPE_MUSIC = 2; // 0x2 diff --git a/media/java/android/media/AudioAttributes.java b/media/java/android/media/AudioAttributes.java index ce58a9c4b91e7..77a82ec8cacdd 100644 --- a/media/java/android/media/AudioAttributes.java +++ b/media/java/android/media/AudioAttributes.java @@ -912,6 +912,8 @@ public final class AudioAttributes implements Parcelable { return USAGE_UNKNOWN; } } + + // TODO remove, replaced by non-static API getVolumeControlStream() /** * Returns the stream type matching the given attributes for volume control. * Use this method to derive the stream type needed to configure the volume @@ -925,6 +927,7 @@ public final class AudioAttributes implements Parcelable { * the attributes, or {@link AudioManager#USE_DEFAULT_STREAM_TYPE} if there isn't a direct * match. Note that USE_DEFAULT_STREAM_TYPE is not a valid value * for {@link AudioManager#setStreamVolume(int, int, int)}. + * @deprecated use {@link #getVolumeControlStream()} */ public static int getVolumeControlStream(@NonNull AudioAttributes aa) { if (aa == null) { @@ -933,6 +936,24 @@ public final class AudioAttributes implements Parcelable { return toVolumeStreamType(true /*fromGetVolumeControlStream*/, aa); } + /** + * Returns the stream type matching this {@code AudioAttributes} instance for volume control. + * Use this method to derive the stream type needed to configure the volume + * control slider in an {@link android.app.Activity} with + * {@link android.app.Activity#setVolumeControlStream(int)} for playback conducted with these + * attributes. + *
Do not use this method to set the stream type on an audio player object + * (e.g. {@link AudioTrack}, {@link MediaPlayer}) as this is deprecated, + * use {@code AudioAttributes} instead. + * @return a valid stream type for {@code Activity} or stream volume control that matches + * the attributes, or {@link AudioManager#USE_DEFAULT_STREAM_TYPE} if there isn't a direct + * match. Note that {@code USE_DEFAULT_STREAM_TYPE} is not a valid value + * for {@link AudioManager#setStreamVolume(int, int, int)}. + */ + public int getVolumeControlStream() { + return toVolumeStreamType(true /*fromGetVolumeControlStream*/, this); + } + /** * @hide * Only use to get which stream type should be used for volume control, NOT for audio playback