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

Commit deec8a3b authored by Shareef Ali's avatar Shareef Ali Committed by Gerrit Code Review
Browse files

Audioservice: fix A2dp support on Samsung's Audio Policy HAL.

Samsung's audio policy HAL doesn't handle A2DP delay commands
correctly which was merged in JB.
Adds a nodelaya2dp config option.

Change-Id: Ib2a1648876ad7b5b21194bd2ad27f5767e46dbb2
parent 3c64f7c9
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -918,4 +918,7 @@
    <!-- Asus dock compatibility disabled by default -->
    <bool name="config_hasDockBattery">false</bool>

    <!-- If true, adds support for no delay A2DP in Samsung devices -->
    <bool name="config_noDelayInATwoDP">false</bool>

</resources>
+1 −0
Original line number Diff line number Diff line
@@ -3678,6 +3678,7 @@
  <java-symbol type="bool" name="config_screenOffAnimation" />
  <java-symbol type="bool" name="config_hasRotationLockSwitch" />
  <java-symbol type="bool" name="config_hasDockBattery" />
  <java-symbol type="bool" name="config_noDelayInATwoDP" />

  <!-- Notification and battery light -->
  <java-symbol type="bool" name="config_intrusiveBatteryLed" />
+50 −20
Original line number Diff line number Diff line
@@ -68,6 +68,7 @@ import android.util.Log;
import android.view.KeyEvent;
import android.view.VolumePanel;
import android.provider.Settings.SettingNotFoundException;
import android.content.res.Resources;

import com.android.internal.app.ThemeUtils;
import com.android.internal.telephony.ITelephony;
@@ -170,6 +171,8 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
    /** @see VolumeStreamState */
    private VolumeStreamState[] mStreamStates;
    private SettingsObserver mSettingsObserver;
    //nodelay in a2dp
    private boolean noDelayInATwoDP = Resources.getSystem().getBoolean(com.android.internal.R.bool.config_noDelayInATwoDP);

    private int mMode;
    // protects mRingerMode
@@ -489,6 +492,8 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
        // Register for device connection intent broadcasts.
        IntentFilter intentFilter =
                new IntentFilter(BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED);
        if (noDelayInATwoDP)
            intentFilter.addAction(BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED);
        intentFilter.addAction(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED);
        intentFilter.addAction(Intent.ACTION_DOCK_EVENT);
        intentFilter.addAction(Intent.ACTION_USB_AUDIO_ACCESSORY_PLUG);
@@ -1772,6 +1777,9 @@ public class AudioService extends IAudioService.Stub implements OnFinished {

    /** @see AudioManager#setBluetoothA2dpOn() */
    public void setBluetoothA2dpOn(boolean on) {
        if (!checkAudioSettingsPermission("setBluetoothA2dpOn()") && noDelayInATwoDP) {
            return;
        }
        setBluetoothA2dpOnInt(on);
    }

@@ -2072,6 +2080,7 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
                deviceList = a2dp.getConnectedDevices();
                if (deviceList.size() > 0) {
                    btDevice = deviceList.get(0);
                    if (!noDelayInATwoDP){
                        synchronized (mConnectedDevices) {
                            int state = a2dp.getConnectionState(btDevice);
                            int delay = checkSendBecomingNoisyIntent(
@@ -2084,6 +2093,9 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
                                    btDevice,
                                    delay);
                        }
                    } else {
                        onSetA2dpConnectionState(btDevice, a2dp.getConnectionState(btDevice));
                    }
                }
                break;

@@ -2429,6 +2441,7 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
    public int setBluetoothA2dpDeviceConnectionState(BluetoothDevice device, int state)
    {
        int delay;
        if(!noDelayInATwoDP) {
            synchronized (mConnectedDevices) {
                delay = checkSendBecomingNoisyIntent(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP,
                                                (state == BluetoothA2dp.STATE_CONNECTED) ? 1 : 0);
@@ -2439,6 +2452,9 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
                        device,
                        delay);
            }
        } else {
            delay = 0;
        }
        return delay;
    }

@@ -3257,6 +3273,8 @@ public class AudioService extends IAudioService.Stub implements OnFinished {

    // must be called synchronized on mConnectedDevices
    private void makeA2dpDeviceUnavailableNow(String address) {
        if (noDelayInATwoDP)
            sendBecomingNoisyIntent();
        AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP,
                AudioSystem.DEVICE_STATE_UNAVAILABLE,
                address);
@@ -3495,6 +3513,12 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
                        config = AudioSystem.FORCE_NONE;
                }
                AudioSystem.setForceUse(AudioSystem.FOR_DOCK, config);
        } else if (action.equals(BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED) && noDelayInATwoDP) {
                state = intent.getIntExtra(BluetoothProfile.EXTRA_STATE,
                                           BluetoothProfile.STATE_DISCONNECTED);
                BluetoothDevice btDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

                onSetA2dpConnectionState(btDevice, state);
            } else if (action.equals(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED)) {
                state = intent.getIntExtra(BluetoothProfile.EXTRA_STATE,
                                               BluetoothProfile.STATE_DISCONNECTED);
@@ -3540,6 +3564,9 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
                state = intent.getIntExtra("state", 0);
                int lastVolume;
                if (state == 1) {
                    //avoids connection glitches
                    if (noDelayInATwoDP)
                        setBluetoothA2dpOnInt(false);
                    // Headset plugged in
                    final boolean capVolumeRestore = Settings.System.getInt(mContentResolver,
                            Settings.System.SAFE_HEADSET_VOLUME_RESTORE, 1) == 1;
@@ -3580,6 +3607,9 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
                        }
                    }
                } else {
                    //avoid connection glitches
                    if (noDelayInATwoDP)
                        setBluetoothA2dpOnInt(true);
                    // Headset disconnected
                    for (int stream = 0; stream < STREAM_VOLUME_SPEAKER_SETTINGS.length; stream++) {
                        final int streamAlias = mStreamVolumeAlias[stream];