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

Commit cef0e5c7 authored by Ted Wang's avatar Ted Wang Committed by Android (Google) Code Review
Browse files

Merge "Set volume to 50% for new paired headset" into qt-dev

parents 7deb544d 46e35252
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -993,6 +993,10 @@ public class A2dpService extends ProfileService {
            if (sm.getConnectionState() != BluetoothProfile.STATE_DISCONNECTED) {
                return;
            }
            if (mFactory.getAvrcpTargetService() != null) {
                mFactory.getAvrcpTargetService().removeStoredVolumeForDevice(device);
            }

            removeStateMachine(device);
        }
    }
@@ -1090,6 +1094,10 @@ public class A2dpService extends ProfileService {
            if (toState == BluetoothProfile.STATE_DISCONNECTED) {
                int bondState = mAdapterService.getBondState(device);
                if (bondState == BluetoothDevice.BOND_NONE) {
                    if (mFactory.getAvrcpTargetService() != null) {
                        mFactory.getAvrcpTargetService().removeStoredVolumeForDevice(device);
                    }

                    removeStateMachine(device);
                }
            }
+10 −1
Original line number Diff line number Diff line
@@ -230,6 +230,15 @@ public class AvrcpTargetService extends ProfileService {
        mVolumeManager.storeVolumeForDevice(device);
    }

    /**
     * Remove the stored volume for a device.
     */
    public void removeStoredVolumeForDevice(BluetoothDevice device) {
        if (device == null) return;

        mVolumeManager.removeStoredVolumeForDevice(device);
    }

    /**
     * Retrieve the remembered volume for a device. Returns -1 if there is no volume for the
     * device.
@@ -237,7 +246,7 @@ public class AvrcpTargetService extends ProfileService {
    public int getRememberedVolumeForDevice(BluetoothDevice device) {
        if (device == null) return -1;

        return mVolumeManager.getVolume(device, -1);
        return mVolumeManager.getVolume(device, mVolumeManager.getNewDeviceVolume());
    }

    // TODO (apanicke): Add checks to blacklist Absolute Volume devices if they behave poorly.
+20 −1
Original line number Diff line number Diff line
@@ -115,14 +115,29 @@ class AvrcpVolumeManager extends AudioDeviceCallback {
        volumeMapEditor.apply();
    }

    synchronized void storeVolumeForDevice(BluetoothDevice device) {
    synchronized void storeVolumeForDevice(@NonNull BluetoothDevice device) {
        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);
        pref.putInt(device.getAddress(), storeVolume);
        // Always use apply() since it is asynchronous, otherwise the call can hang waiting for
        // storage to be written.
        pref.apply();
    }

    synchronized void removeStoredVolumeForDevice(@NonNull BluetoothDevice device) {
        if (device.getBondState() != BluetoothDevice.BOND_NONE) {
            return;
        }
        SharedPreferences.Editor pref = getVolumeMap().edit();
        Log.i(TAG, "RemoveStoredVolume: Remove stored stream volume level for device " + device);
        mVolumeMap.remove(device);
        pref.remove(device.getAddress());
        // Always use apply() since it is asynchronous, otherwise the call can hang waiting for
        // storage to be written.
        pref.apply();
@@ -138,6 +153,10 @@ class AvrcpVolumeManager extends AudioDeviceCallback {
        return mVolumeMap.get(device);
    }

    public int getNewDeviceVolume() {
        return sNewDeviceVolume;
    }

    @Override
    public synchronized void onAudioDevicesAdded(AudioDeviceInfo[] addedDevices) {
        if (mCurrentDevice == null) {