Make AudioManager device volume behavior APIs SystemApi
Allow privileged applications to control volume behavior of audio
devices.
Bug: 161878484
Test: atest AudioServiceHostTest
Change-Id: Ic6206369a69b4103f715565f387f652626b832d4
diff --git a/media/java/android/media/AudioManager.java b/media/java/android/media/AudioManager.java
index 3ac71b2..7b6c7f8 100755
--- a/media/java/android/media/AudioManager.java
+++ b/media/java/android/media/AudioManager.java
@@ -4600,36 +4600,41 @@
/**
* @hide
* Volume behavior for an audio device that has no particular volume behavior set. Invalid as
- * an argument to {@link #setDeviceVolumeBehavior(int, String, int)}.
+ * an argument to {@link #setDeviceVolumeBehavior(AudioDeviceAttributes, int)} and should not
+ * be returned by {@link #getDeviceVolumeBehavior(AudioDeviceAttributes)}.
*/
public static final int DEVICE_VOLUME_BEHAVIOR_UNSET = -1;
/**
* @hide
* Volume behavior for an audio device where a software attenuation is applied
- * @see #setDeviceVolumeBehavior(int, String, int)
+ * @see #setDeviceVolumeBehavior(AudioDeviceAttributes, int)
*/
+ @SystemApi
public static final int DEVICE_VOLUME_BEHAVIOR_VARIABLE = 0;
/**
* @hide
* Volume behavior for an audio device where the volume is always set to provide no attenuation
* nor gain (e.g. unit gain).
- * @see #setDeviceVolumeBehavior(int, String, int)
+ * @see #setDeviceVolumeBehavior(AudioDeviceAttributes, int)
*/
+ @SystemApi
public static final int DEVICE_VOLUME_BEHAVIOR_FULL = 1;
/**
* @hide
* Volume behavior for an audio device where the volume is either set to muted, or to provide
* no attenuation nor gain (e.g. unit gain).
- * @see #setDeviceVolumeBehavior(int, String, int)
+ * @see #setDeviceVolumeBehavior(AudioDeviceAttributes, int)
*/
+ @SystemApi
public static final int DEVICE_VOLUME_BEHAVIOR_FIXED = 2;
/**
* @hide
* Volume behavior for an audio device where no software attenuation is applied, and
* the volume is kept synchronized between the host and the device itself through a
* device-specific protocol such as BT AVRCP.
- * @see #setDeviceVolumeBehavior(int, String, int)
+ * @see #setDeviceVolumeBehavior(AudioDeviceAttributes, int)
*/
+ @SystemApi
public static final int DEVICE_VOLUME_BEHAVIOR_ABSOLUTE = 3;
/**
* @hide
@@ -4638,8 +4643,9 @@
* device-specific protocol (such as for hearing aids), based on the audio mode (e.g.
* normal vs in phone call).
* @see #setMode(int)
- * @see #setDeviceVolumeBehavior(int, String, int)
+ * @see #setDeviceVolumeBehavior(AudioDeviceAttributes, int)
*/
+ @SystemApi
public static final int DEVICE_VOLUME_BEHAVIOR_ABSOLUTE_MULTI_MODE = 4;
/** @hide */
@@ -4686,27 +4692,15 @@
/**
* @hide
* Sets the volume behavior for an audio output device.
- * @param deviceType the type of audio device to be affected. Currently only supports
- * {@link AudioDeviceInfo#TYPE_HDMI}, {@link AudioDeviceInfo#TYPE_HDMI_ARC},
- * {@link AudioDeviceInfo#TYPE_LINE_DIGITAL} and {@link AudioDeviceInfo#TYPE_AUX_LINE}
- * @param deviceAddress the address of the device, if any
+ * @see #DEVICE_VOLUME_BEHAVIOR_VARIABLE
+ * @see #DEVICE_VOLUME_BEHAVIOR_FULL
+ * @see #DEVICE_VOLUME_BEHAVIOR_FIXED
+ * @see #DEVICE_VOLUME_BEHAVIOR_ABSOLUTE
+ * @see #DEVICE_VOLUME_BEHAVIOR_ABSOLUTE_MULTI_MODE
+ * @param device the device to be affected
* @param deviceVolumeBehavior one of the device behaviors
*/
- @RequiresPermission(android.Manifest.permission.MODIFY_AUDIO_ROUTING)
- public void setDeviceVolumeBehavior(int deviceType, @Nullable String deviceAddress,
- @DeviceVolumeBehavior int deviceVolumeBehavior) {
- setDeviceVolumeBehavior(new AudioDeviceAttributes(AudioDeviceAttributes.ROLE_OUTPUT,
- deviceType, deviceAddress), deviceVolumeBehavior);
- }
-
- /**
- * @hide
- * Sets the volume behavior for an audio output device.
- * @param device the device to be affected. Currently only supports devices of type
- * {@link AudioDeviceInfo#TYPE_HDMI}, {@link AudioDeviceInfo#TYPE_HDMI_ARC},
- * {@link AudioDeviceInfo#TYPE_LINE_DIGITAL} and {@link AudioDeviceInfo#TYPE_AUX_LINE}
- * @param deviceVolumeBehavior one of the device behaviors
- */
+ @SystemApi
@RequiresPermission(android.Manifest.permission.MODIFY_AUDIO_ROUTING)
public void setDeviceVolumeBehavior(@NonNull AudioDeviceAttributes device,
@DeviceVolumeBehavior int deviceVolumeBehavior) {
@@ -4725,29 +4719,14 @@
/**
* @hide
- * Returns the volume device behavior for the given device type and address
- * @param deviceType an audio output device type, as defined in {@link AudioDeviceInfo}
- * @param deviceAddress the address of the audio device, if any.
- * @return the volume behavior for the device
- */
- @RequiresPermission(android.Manifest.permission.MODIFY_AUDIO_ROUTING)
- public @DeviceVolumeBehaviorState int getDeviceVolumeBehavior(int deviceType,
- @Nullable String deviceAddress) {
- // verify arguments
- AudioDeviceInfo.enforceValidAudioDeviceTypeOut(deviceType);
- return getDeviceVolumeBehavior(new AudioDeviceAttributes(AudioDeviceAttributes.ROLE_OUTPUT,
- deviceType, deviceAddress));
- }
-
- /**
- * @hide
* Returns the volume device behavior for the given audio device
* @param device the audio device
* @return the volume behavior for the device
*/
+ @SystemApi
@RequiresPermission(android.Manifest.permission.MODIFY_AUDIO_ROUTING)
- public @DeviceVolumeBehaviorState int getDeviceVolumeBehavior(
- @NonNull AudioDeviceAttributes device) {
+ public @DeviceVolumeBehavior
+ int getDeviceVolumeBehavior(@NonNull AudioDeviceAttributes device) {
// verify arguments (validity of device type is enforced in server)
Objects.requireNonNull(device);
// communicate with service