summaryrefslogtreecommitdiffstats
path: root/media/java
diff options
context:
space:
mode:
authorMatthew Xie <mattx@google.com>2013-09-12 00:32:22 -0700
committerMatthew Xie <mattx@google.com>2013-09-17 23:48:19 +0000
commitc9d1d5f35091226e96fcfa91817480f589eb36e2 (patch)
treeb8a6cdb9697d09bbd511444eda8af72facae785f /media/java
parent019f8cb8a78c5584618655f5478d9a9f3dedc3f0 (diff)
downloadframeworks_base-c9d1d5f35091226e96fcfa91817480f589eb36e2.zip
frameworks_base-c9d1d5f35091226e96fcfa91817480f589eb36e2.tar.gz
frameworks_base-c9d1d5f35091226e96fcfa91817480f589eb36e2.tar.bz2
Adjust absolute volume only when the device is streaming music
The device has to be A2DP device Remove AudioManager#avrcpUpdateVolume bug 10681804 Change-Id: I2bc85e48fdff374638b984af593c6f1c4ddd3ee6
Diffstat (limited to 'media/java')
-rw-r--r--media/java/android/media/AudioManager.java20
-rw-r--r--media/java/android/media/AudioService.java89
-rw-r--r--media/java/android/media/IAudioService.aidl2
3 files changed, 51 insertions, 60 deletions
diff --git a/media/java/android/media/AudioManager.java b/media/java/android/media/AudioManager.java
index 845baaf..4542643 100644
--- a/media/java/android/media/AudioManager.java
+++ b/media/java/android/media/AudioManager.java
@@ -323,6 +323,12 @@ public class AudioManager {
public static final int FLAG_FIXED_VOLUME = 1 << 5;
/**
+ * Indicates the volume set/adjust call is for Bluetooth absolute volume
+ * @hide
+ */
+ public static final int FLAG_BLUETOOTH_ABS_VOLUME = 1 << 6;
+
+ /**
* Ringer mode that will be silent and will not vibrate. (This overrides the
* vibrate setting.)
*
@@ -2397,20 +2403,6 @@ public class AudioManager {
}
}
- /**
- * @hide
- * Notifies AudioService of the volume set on the A2DP device as a callback, so AudioService
- * is able to update the UI.
- */
- public void avrcpUpdateVolume(int oldVolume, int volume) {
- IAudioService service = getService();
- try {
- service.avrcpUpdateVolume(oldVolume, volume);
- } catch (RemoteException e) {
- Log.e(TAG, "Dead object in avrcpUpdateVolume", e);
- }
- }
-
/**
* {@hide}
*/
diff --git a/media/java/android/media/AudioService.java b/media/java/android/media/AudioService.java
index b72551a..07f0858 100644
--- a/media/java/android/media/AudioService.java
+++ b/media/java/android/media/AudioService.java
@@ -843,6 +843,13 @@ public class AudioService extends IAudioService.Stub {
boolean adjustVolume = true;
int step;
+ // skip a2dp absolute volume control request when the device
+ // is not an a2dp device
+ if ((device & AudioSystem.DEVICE_OUT_ALL_A2DP) == 0 &&
+ (flags & AudioManager.FLAG_BLUETOOTH_ABS_VOLUME) != 0) {
+ return;
+ }
+
if (mAppOps.noteOp(STEAM_VOLUME_OPS[streamTypeAlias], Binder.getCallingUid(),
callingPackage) != AppOpsManager.MODE_ALLOWED) {
return;
@@ -892,15 +899,18 @@ public class AudioService extends IAudioService.Stub {
int oldIndex = mStreamStates[streamType].getIndex(device);
if (adjustVolume && (direction != AudioManager.ADJUST_SAME)) {
+
// Check if volume update should be send to AVRCP
- synchronized (mA2dpAvrcpLock) {
- if (mA2dp != null && mAvrcpAbsVolSupported) {
- mA2dp.adjustAvrcpAbsoluteVolume(direction);
- return;
- // No need to send volume update, because we will update the volume with a
- // callback from Avrcp.
+ if (streamTypeAlias == AudioSystem.STREAM_MUSIC &&
+ (device & AudioSystem.DEVICE_OUT_ALL_A2DP) != 0 &&
+ (flags & AudioManager.FLAG_BLUETOOTH_ABS_VOLUME) == 0) {
+ synchronized (mA2dpAvrcpLock) {
+ if (mA2dp != null && mAvrcpAbsVolSupported) {
+ mA2dp.adjustAvrcpAbsoluteVolume(direction);
+ }
}
}
+
if ((direction == AudioManager.ADJUST_RAISE) &&
!checkSafeMediaVolume(streamTypeAlias, aliasIndex + step, device)) {
Log.e(TAG, "adjustStreamVolume() safe volume index = "+oldIndex);
@@ -985,6 +995,13 @@ public class AudioService extends IAudioService.Stub {
final int device = getDeviceForStream(streamType);
int oldIndex;
+ // skip a2dp absolute volume control request when the device
+ // is not an a2dp device
+ if ((device & AudioSystem.DEVICE_OUT_ALL_A2DP) == 0 &&
+ (flags & AudioManager.FLAG_BLUETOOTH_ABS_VOLUME) != 0) {
+ return;
+ }
+
if (mAppOps.noteOp(STEAM_VOLUME_OPS[streamTypeAlias], Binder.getCallingUid(),
callingPackage) != AppOpsManager.MODE_ALLOWED) {
return;
@@ -998,12 +1015,13 @@ public class AudioService extends IAudioService.Stub {
index = rescaleIndex(index * 10, streamType, streamTypeAlias);
- synchronized (mA2dpAvrcpLock) {
- if (mA2dp != null && mAvrcpAbsVolSupported) {
- mA2dp.setAvrcpAbsoluteVolume(index);
- return;
- // No need to send volume update, because we will update the volume with a
- // callback from Avrcp.
+ if (streamTypeAlias == AudioSystem.STREAM_MUSIC &&
+ (device & AudioSystem.DEVICE_OUT_ALL_A2DP) != 0 &&
+ (flags & AudioManager.FLAG_BLUETOOTH_ABS_VOLUME) == 0) {
+ synchronized (mA2dpAvrcpLock) {
+ if (mA2dp != null && mAvrcpAbsVolSupported) {
+ mA2dp.setAvrcpAbsoluteVolume(index);
+ }
}
}
@@ -2835,7 +2853,12 @@ public class AudioService extends IAudioService.Stub {
int index;
if (isMuted()) {
index = 0;
- } else {
+ } else if (mStreamVolumeAlias[mStreamType] == AudioSystem.STREAM_MUSIC &&
+ (device & AudioSystem.DEVICE_OUT_ALL_A2DP) != 0 &&
+ mAvrcpAbsVolSupported) {
+ index = (mIndexMax + 5)/10;
+ }
+ else {
index = (getIndex(device) + 5)/10;
}
AudioSystem.setStreamVolumeIndex(mStreamType, index, device);
@@ -3650,6 +3673,9 @@ public class AudioService extends IAudioService.Stub {
private void makeA2dpDeviceAvailable(String address) {
// enable A2DP before notifying A2DP connection to avoid unecessary processing in
// audio policy manager
+ VolumeStreamState streamState = mStreamStates[AudioSystem.STREAM_MUSIC];
+ sendMsg(mAudioHandler, MSG_SET_DEVICE_VOLUME, SENDMSG_QUEUE,
+ AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP, 0, streamState, 0);
setBluetoothA2dpOnInt(true);
AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP,
AudioSystem.DEVICE_STATE_AVAILABLE,
@@ -3666,6 +3692,9 @@ public class AudioService extends IAudioService.Stub {
// must be called synchronized on mConnectedDevices
private void makeA2dpDeviceUnavailableNow(String address) {
+ synchronized (mA2dpAvrcpLock) {
+ mAvrcpAbsVolSupported = false;
+ }
AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP,
AudioSystem.DEVICE_STATE_UNAVAILABLE,
address);
@@ -3706,19 +3735,6 @@ public class AudioService extends IAudioService.Stub {
address = "";
}
- // Disable absolute volume, if device is disconnected
- synchronized (mA2dpAvrcpLock) {
- if (state == BluetoothProfile.STATE_DISCONNECTED && mAvrcpAbsVolSupported) {
- mAvrcpAbsVolSupported = false;
- sendMsg(mAudioHandler,
- MSG_SET_DEVICE_VOLUME,
- SENDMSG_QUEUE,
- getDeviceForStream(AudioSystem.STREAM_MUSIC),
- 0,
- mStreamStates[AudioSystem.STREAM_MUSIC],
- 0);
- }
- }
synchronized (mConnectedDevices) {
boolean isConnected =
(mConnectedDevices.containsKey(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP) &&
@@ -3773,27 +3789,12 @@ public class AudioService extends IAudioService.Stub {
// address is not used for now, but may be used when multiple a2dp devices are supported
synchronized (mA2dpAvrcpLock) {
mAvrcpAbsVolSupported = support;
- if (support) {
- VolumeStreamState streamState = mStreamStates[AudioSystem.STREAM_MUSIC];
- int device = getDeviceForStream(AudioSystem.STREAM_MUSIC);
- streamState.setIndex(streamState.getMaxIndex(), device);
- sendMsg(mAudioHandler,
- MSG_SET_DEVICE_VOLUME,
- SENDMSG_QUEUE,
- device,
- 0,
- streamState,
- 0);
- }
+ VolumeStreamState streamState = mStreamStates[AudioSystem.STREAM_MUSIC];
+ sendMsg(mAudioHandler, MSG_SET_DEVICE_VOLUME, SENDMSG_QUEUE,
+ AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP, 0, streamState, 0);
}
}
- public void avrcpUpdateVolume(int oldVolume, int volume) {
- mStreamStates[AudioSystem.STREAM_MUSIC].
- setIndex(volume, getDeviceForStream(AudioSystem.STREAM_MUSIC));
- sendVolumeUpdate(AudioSystem.STREAM_MUSIC, oldVolume, volume, AudioManager.FLAG_SHOW_UI);
- }
-
private boolean handleDeviceConnection(boolean connected, int device, String params) {
synchronized (mConnectedDevices) {
boolean isConnected = (mConnectedDevices.containsKey(device) &&
diff --git a/media/java/android/media/IAudioService.aidl b/media/java/android/media/IAudioService.aidl
index fe060f8..e08ecbf 100644
--- a/media/java/android/media/IAudioService.aidl
+++ b/media/java/android/media/IAudioService.aidl
@@ -100,8 +100,6 @@ interface IAudioService {
oneway void avrcpSupportsAbsoluteVolume(String address, boolean support);
- oneway void avrcpUpdateVolume(int oldVolume, int volume);
-
void setSpeakerphoneOn(boolean on);
boolean isSpeakerphoneOn();