Loading src/com/android/bluetooth/avrcp/AvrcpTargetService.java +12 −0 Original line number Diff line number Diff line Loading @@ -114,6 +114,17 @@ public class AvrcpTargetService extends ProfileService { Log.d(TAG, "request to disconnect device " + device); } } } else if (action.equals(AudioManager.VOLUME_CHANGED_ACTION)) { int streamType = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, -1); if (streamType == AudioManager.STREAM_MUSIC) { int volume = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_VALUE, 0); BluetoothDevice activeDevice = mFactory.getA2dpService().getActiveDevice(); if (activeDevice != null && !mVolumeManager.getAbsoluteVolumeSupported(activeDevice)) { Log.d(TAG, "stream volume change to " + volume + " " + activeDevice); mVolumeManager.storeVolumeForDevice(activeDevice, volume); } } } } } Loading Loading @@ -185,6 +196,7 @@ public class AvrcpTargetService extends ProfileService { IntentFilter filter = new IntentFilter(); filter.addAction(BluetoothA2dp.ACTION_ACTIVE_DEVICE_CHANGED); filter.addAction(BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED); filter.addAction(AudioManager.VOLUME_CHANGED_ACTION); registerReceiver(mReceiver, filter); // Only allow the service to be used once it is initialized Loading src/com/android/bluetooth/avrcp/AvrcpVolumeManager.java +17 −2 Original line number Diff line number Diff line Loading @@ -115,12 +115,11 @@ class AvrcpVolumeManager extends AudioDeviceCallback { volumeMapEditor.apply(); } synchronized void storeVolumeForDevice(@NonNull BluetoothDevice device) { synchronized void storeVolumeForDevice(@NonNull BluetoothDevice device, int storeVolume) { if (device.getBondState() != BluetoothDevice.BOND_BONDED) { return; } SharedPreferences.Editor pref = getVolumeMap().edit(); int storeVolume = mAudioManager.getStreamVolume(STREAM_MUSIC); Log.i(TAG, "storeVolume: Storing stream volume level for device " + device + " : " + storeVolume); mVolumeMap.put(device, storeVolume); Loading @@ -130,6 +129,11 @@ class AvrcpVolumeManager extends AudioDeviceCallback { pref.apply(); } synchronized void storeVolumeForDevice(@NonNull BluetoothDevice device) { int storeVolume = mAudioManager.getStreamVolume(STREAM_MUSIC); storeVolumeForDevice(device, storeVolume); } synchronized void removeStoredVolumeForDevice(@NonNull BluetoothDevice device) { if (device.getBondState() != BluetoothDevice.BOND_NONE) { return; Loading Loading @@ -183,6 +187,17 @@ class AvrcpVolumeManager extends AudioDeviceCallback { storeVolumeForDevice(device); } /** * True if remote device supported Absolute volume, false if remote device is not supported or * not connected. */ boolean getAbsoluteVolumeSupported(BluetoothDevice device) { if (mDeviceMap.containsKey(device)) { return mDeviceMap.get(device); } return false; } @Override public synchronized void onAudioDevicesAdded(AudioDeviceInfo[] addedDevices) { if (mCurrentDevice == null) { Loading Loading
src/com/android/bluetooth/avrcp/AvrcpTargetService.java +12 −0 Original line number Diff line number Diff line Loading @@ -114,6 +114,17 @@ public class AvrcpTargetService extends ProfileService { Log.d(TAG, "request to disconnect device " + device); } } } else if (action.equals(AudioManager.VOLUME_CHANGED_ACTION)) { int streamType = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, -1); if (streamType == AudioManager.STREAM_MUSIC) { int volume = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_VALUE, 0); BluetoothDevice activeDevice = mFactory.getA2dpService().getActiveDevice(); if (activeDevice != null && !mVolumeManager.getAbsoluteVolumeSupported(activeDevice)) { Log.d(TAG, "stream volume change to " + volume + " " + activeDevice); mVolumeManager.storeVolumeForDevice(activeDevice, volume); } } } } } Loading Loading @@ -185,6 +196,7 @@ public class AvrcpTargetService extends ProfileService { IntentFilter filter = new IntentFilter(); filter.addAction(BluetoothA2dp.ACTION_ACTIVE_DEVICE_CHANGED); filter.addAction(BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED); filter.addAction(AudioManager.VOLUME_CHANGED_ACTION); registerReceiver(mReceiver, filter); // Only allow the service to be used once it is initialized Loading
src/com/android/bluetooth/avrcp/AvrcpVolumeManager.java +17 −2 Original line number Diff line number Diff line Loading @@ -115,12 +115,11 @@ class AvrcpVolumeManager extends AudioDeviceCallback { volumeMapEditor.apply(); } synchronized void storeVolumeForDevice(@NonNull BluetoothDevice device) { synchronized void storeVolumeForDevice(@NonNull BluetoothDevice device, int storeVolume) { if (device.getBondState() != BluetoothDevice.BOND_BONDED) { return; } SharedPreferences.Editor pref = getVolumeMap().edit(); int storeVolume = mAudioManager.getStreamVolume(STREAM_MUSIC); Log.i(TAG, "storeVolume: Storing stream volume level for device " + device + " : " + storeVolume); mVolumeMap.put(device, storeVolume); Loading @@ -130,6 +129,11 @@ class AvrcpVolumeManager extends AudioDeviceCallback { pref.apply(); } synchronized void storeVolumeForDevice(@NonNull BluetoothDevice device) { int storeVolume = mAudioManager.getStreamVolume(STREAM_MUSIC); storeVolumeForDevice(device, storeVolume); } synchronized void removeStoredVolumeForDevice(@NonNull BluetoothDevice device) { if (device.getBondState() != BluetoothDevice.BOND_NONE) { return; Loading Loading @@ -183,6 +187,17 @@ class AvrcpVolumeManager extends AudioDeviceCallback { storeVolumeForDevice(device); } /** * True if remote device supported Absolute volume, false if remote device is not supported or * not connected. */ boolean getAbsoluteVolumeSupported(BluetoothDevice device) { if (mDeviceMap.containsKey(device)) { return mDeviceMap.get(device); } return false; } @Override public synchronized void onAudioDevicesAdded(AudioDeviceInfo[] addedDevices) { if (mCurrentDevice == null) { Loading