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

Commit 8d43185c authored by Shareef Ali's avatar Shareef Ali Committed by codeworkx
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: I188c6e59fdf1b30bef41d8e1aa84ac5319f3bcc3
parent fd9a957e
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -1105,4 +1105,7 @@
         applied. -->
    <bool name="config_hasRemovableLid">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
@@ -1839,6 +1839,7 @@
  <java-symbol type="string" name="config_legacyUmsLunFile" />
  <java-symbol type="bool" name="config_hasRemovableLid" />
  <java-symbol type="bool" name="config_hasDockBattery" />
  <java-symbol type="bool" name="config_noDelayInATwoDP" />

  <!-- Telephony -->
  <java-symbol type="bool" name="config_smsSamsungCdmaAlternateMessageIDEncoding" />
+45 −20
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.database.ContentObserver;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnErrorListener;
@@ -61,6 +62,7 @@ import android.os.UserHandle;
import android.os.Vibrator;
import android.provider.Settings;
import android.provider.Settings.System;
import android.provider.Settings.SettingNotFoundException;
import android.speech.RecognizerIntent;
import android.telephony.PhoneStateListener;
import android.telephony.ServiceState;
@@ -177,6 +179,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
@@ -503,6 +507,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);
@@ -1882,6 +1888,9 @@ public class AudioService extends IAudioService.Stub implements OnFinished {

    /** @see AudioManager#setBluetoothA2dpOn() */
    public void setBluetoothA2dpOn(boolean on) {
        if (!checkAudioSettingsPermission("setBluetoothA2dpOn()") && noDelayInATwoDP) {
            return;
        }
        synchronized (mBluetoothA2dpEnabledLock) {
            mBluetoothA2dpEnabled = on;
            sendMsg(mAudioHandler, MSG_SET_FORCE_BT_A2DP_USE, SENDMSG_QUEUE,
@@ -2188,6 +2197,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(
@@ -2200,6 +2210,9 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
		                            btDevice,
		                            delay);
                        }
                    } else {
                        onSetA2dpConnectionState(btDevice, a2dp.getConnectionState(btDevice));
                    }
                }
                break;

@@ -2617,6 +2630,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);
@@ -2627,6 +2641,9 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
		                device,
		                delay);
            }
        } else {
            delay = 0;
        }
        return delay;
    }

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

    // must be called synchronized on mConnectedDevices
    private void makeA2dpDeviceUnavailableNow(String address) {
        if (noDelayInATwoDP)
            onSendBecomingNoisyIntent();
        AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP,
                AudioSystem.DEVICE_STATE_UNAVAILABLE,
                address);
@@ -3806,6 +3825,12 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
                }

                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);