Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 743bc69e authored by Ted Wang's avatar Ted Wang Committed by android-build-merger
Browse files

Merge "Store volume for devices not support absolute volume"

am: 8b0956fa

Change-Id: I23313e4332ff8ad064aeab2107dd35c65a943e04
parents 903b7bae 8b0956fa
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -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);
                    }
                }
            }
        }
    }
@@ -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
+17 −2
Original line number Diff line number Diff line
@@ -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);
@@ -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;
@@ -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) {