am c9d1d5f3: Adjust absolute volume only when the device is streaming music
* commit 'c9d1d5f35091226e96fcfa91817480f589eb36e2': Adjust absolute volume only when the device is streaming music
This commit is contained in:
@@ -322,6 +322,12 @@ public class AudioManager {
|
|||||||
*/
|
*/
|
||||||
public static final int FLAG_FIXED_VOLUME = 1 << 5;
|
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
|
* Ringer mode that will be silent and will not vibrate. (This overrides the
|
||||||
* vibrate setting.)
|
* 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}
|
* {@hide}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -843,6 +843,13 @@ public class AudioService extends IAudioService.Stub {
|
|||||||
boolean adjustVolume = true;
|
boolean adjustVolume = true;
|
||||||
int step;
|
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(),
|
if (mAppOps.noteOp(STEAM_VOLUME_OPS[streamTypeAlias], Binder.getCallingUid(),
|
||||||
callingPackage) != AppOpsManager.MODE_ALLOWED) {
|
callingPackage) != AppOpsManager.MODE_ALLOWED) {
|
||||||
return;
|
return;
|
||||||
@@ -892,15 +899,18 @@ public class AudioService extends IAudioService.Stub {
|
|||||||
int oldIndex = mStreamStates[streamType].getIndex(device);
|
int oldIndex = mStreamStates[streamType].getIndex(device);
|
||||||
|
|
||||||
if (adjustVolume && (direction != AudioManager.ADJUST_SAME)) {
|
if (adjustVolume && (direction != AudioManager.ADJUST_SAME)) {
|
||||||
|
|
||||||
// Check if volume update should be send to AVRCP
|
// Check if volume update should be send to AVRCP
|
||||||
synchronized (mA2dpAvrcpLock) {
|
if (streamTypeAlias == AudioSystem.STREAM_MUSIC &&
|
||||||
if (mA2dp != null && mAvrcpAbsVolSupported) {
|
(device & AudioSystem.DEVICE_OUT_ALL_A2DP) != 0 &&
|
||||||
mA2dp.adjustAvrcpAbsoluteVolume(direction);
|
(flags & AudioManager.FLAG_BLUETOOTH_ABS_VOLUME) == 0) {
|
||||||
return;
|
synchronized (mA2dpAvrcpLock) {
|
||||||
// No need to send volume update, because we will update the volume with a
|
if (mA2dp != null && mAvrcpAbsVolSupported) {
|
||||||
// callback from Avrcp.
|
mA2dp.adjustAvrcpAbsoluteVolume(direction);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((direction == AudioManager.ADJUST_RAISE) &&
|
if ((direction == AudioManager.ADJUST_RAISE) &&
|
||||||
!checkSafeMediaVolume(streamTypeAlias, aliasIndex + step, device)) {
|
!checkSafeMediaVolume(streamTypeAlias, aliasIndex + step, device)) {
|
||||||
Log.e(TAG, "adjustStreamVolume() safe volume index = "+oldIndex);
|
Log.e(TAG, "adjustStreamVolume() safe volume index = "+oldIndex);
|
||||||
@@ -985,6 +995,13 @@ public class AudioService extends IAudioService.Stub {
|
|||||||
final int device = getDeviceForStream(streamType);
|
final int device = getDeviceForStream(streamType);
|
||||||
int oldIndex;
|
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(),
|
if (mAppOps.noteOp(STEAM_VOLUME_OPS[streamTypeAlias], Binder.getCallingUid(),
|
||||||
callingPackage) != AppOpsManager.MODE_ALLOWED) {
|
callingPackage) != AppOpsManager.MODE_ALLOWED) {
|
||||||
return;
|
return;
|
||||||
@@ -998,12 +1015,13 @@ public class AudioService extends IAudioService.Stub {
|
|||||||
|
|
||||||
index = rescaleIndex(index * 10, streamType, streamTypeAlias);
|
index = rescaleIndex(index * 10, streamType, streamTypeAlias);
|
||||||
|
|
||||||
synchronized (mA2dpAvrcpLock) {
|
if (streamTypeAlias == AudioSystem.STREAM_MUSIC &&
|
||||||
if (mA2dp != null && mAvrcpAbsVolSupported) {
|
(device & AudioSystem.DEVICE_OUT_ALL_A2DP) != 0 &&
|
||||||
mA2dp.setAvrcpAbsoluteVolume(index);
|
(flags & AudioManager.FLAG_BLUETOOTH_ABS_VOLUME) == 0) {
|
||||||
return;
|
synchronized (mA2dpAvrcpLock) {
|
||||||
// No need to send volume update, because we will update the volume with a
|
if (mA2dp != null && mAvrcpAbsVolSupported) {
|
||||||
// callback from Avrcp.
|
mA2dp.setAvrcpAbsoluteVolume(index);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2835,7 +2853,12 @@ public class AudioService extends IAudioService.Stub {
|
|||||||
int index;
|
int index;
|
||||||
if (isMuted()) {
|
if (isMuted()) {
|
||||||
index = 0;
|
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;
|
index = (getIndex(device) + 5)/10;
|
||||||
}
|
}
|
||||||
AudioSystem.setStreamVolumeIndex(mStreamType, index, device);
|
AudioSystem.setStreamVolumeIndex(mStreamType, index, device);
|
||||||
@@ -3650,6 +3673,9 @@ public class AudioService extends IAudioService.Stub {
|
|||||||
private void makeA2dpDeviceAvailable(String address) {
|
private void makeA2dpDeviceAvailable(String address) {
|
||||||
// enable A2DP before notifying A2DP connection to avoid unecessary processing in
|
// enable A2DP before notifying A2DP connection to avoid unecessary processing in
|
||||||
// audio policy manager
|
// 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);
|
setBluetoothA2dpOnInt(true);
|
||||||
AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP,
|
AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP,
|
||||||
AudioSystem.DEVICE_STATE_AVAILABLE,
|
AudioSystem.DEVICE_STATE_AVAILABLE,
|
||||||
@@ -3666,6 +3692,9 @@ public class AudioService extends IAudioService.Stub {
|
|||||||
|
|
||||||
// must be called synchronized on mConnectedDevices
|
// must be called synchronized on mConnectedDevices
|
||||||
private void makeA2dpDeviceUnavailableNow(String address) {
|
private void makeA2dpDeviceUnavailableNow(String address) {
|
||||||
|
synchronized (mA2dpAvrcpLock) {
|
||||||
|
mAvrcpAbsVolSupported = false;
|
||||||
|
}
|
||||||
AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP,
|
AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP,
|
||||||
AudioSystem.DEVICE_STATE_UNAVAILABLE,
|
AudioSystem.DEVICE_STATE_UNAVAILABLE,
|
||||||
address);
|
address);
|
||||||
@@ -3706,19 +3735,6 @@ public class AudioService extends IAudioService.Stub {
|
|||||||
address = "";
|
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) {
|
synchronized (mConnectedDevices) {
|
||||||
boolean isConnected =
|
boolean isConnected =
|
||||||
(mConnectedDevices.containsKey(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP) &&
|
(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
|
// address is not used for now, but may be used when multiple a2dp devices are supported
|
||||||
synchronized (mA2dpAvrcpLock) {
|
synchronized (mA2dpAvrcpLock) {
|
||||||
mAvrcpAbsVolSupported = support;
|
mAvrcpAbsVolSupported = support;
|
||||||
if (support) {
|
VolumeStreamState streamState = mStreamStates[AudioSystem.STREAM_MUSIC];
|
||||||
VolumeStreamState streamState = mStreamStates[AudioSystem.STREAM_MUSIC];
|
sendMsg(mAudioHandler, MSG_SET_DEVICE_VOLUME, SENDMSG_QUEUE,
|
||||||
int device = getDeviceForStream(AudioSystem.STREAM_MUSIC);
|
AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP, 0, streamState, 0);
|
||||||
streamState.setIndex(streamState.getMaxIndex(), device);
|
|
||||||
sendMsg(mAudioHandler,
|
|
||||||
MSG_SET_DEVICE_VOLUME,
|
|
||||||
SENDMSG_QUEUE,
|
|
||||||
device,
|
|
||||||
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) {
|
private boolean handleDeviceConnection(boolean connected, int device, String params) {
|
||||||
synchronized (mConnectedDevices) {
|
synchronized (mConnectedDevices) {
|
||||||
boolean isConnected = (mConnectedDevices.containsKey(device) &&
|
boolean isConnected = (mConnectedDevices.containsKey(device) &&
|
||||||
|
|||||||
@@ -100,8 +100,6 @@ interface IAudioService {
|
|||||||
|
|
||||||
oneway void avrcpSupportsAbsoluteVolume(String address, boolean support);
|
oneway void avrcpSupportsAbsoluteVolume(String address, boolean support);
|
||||||
|
|
||||||
oneway void avrcpUpdateVolume(int oldVolume, int volume);
|
|
||||||
|
|
||||||
void setSpeakerphoneOn(boolean on);
|
void setSpeakerphoneOn(boolean on);
|
||||||
|
|
||||||
boolean isSpeakerphoneOn();
|
boolean isSpeakerphoneOn();
|
||||||
|
|||||||
Reference in New Issue
Block a user