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

Commit 70f4132b authored by Satheesh Kumar Pallemoni's avatar Satheesh Kumar Pallemoni Committed by Bruno Martins
Browse files

Keep a null check before accessing the BluetoothA2dpWrapper APIs.



When switching from default user mode to guest mode from system settings,
Bluetooth gets turn OFF and ON. Then, try connect to peer device which was
connected previousely in the default user mode. At this point if BluetoothA2dpWrapper
has not init, then its object would be null, and accessing the APIs of BluetoothA2dpWrapper
in A2dpProfile, results in NPE. So keep a null check on object of BluetoothA2dpWrapper
class before accessing APIs using it.

[wight554: updated code from LA.QSSI.11.0.r1-05600-qssi.0]

 Conflicts:
	packages/SettingsLib/src/com/android/settingslib/bluetooth/A2dpProfile.java

CRs-Fixed: 2454049
Change-Id: Idd949bc27fec10b46a149b5db67abc6f3b5097d1
Signed-off-by: default avatarVolodymyr Zhdanov <wight554@gmail.com>
parent 371694c1
Loading
Loading
Loading
Loading
+21 −4
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import java.util.List;

public class A2dpProfile implements LocalBluetoothProfile {
    private static final String TAG = "A2dpProfile";
    private static boolean V = true;

    private Context mContext;

@@ -218,6 +219,11 @@ public class A2dpProfile implements LocalBluetoothProfile {
    }

    public boolean supportsHighQualityAudio(BluetoothDevice device) {
        if (V) Log.d(TAG, " execute supportsHighQualityAudio()");
        if (mService == null) {
            if (V) Log.d(TAG,"mService is null.");
            return false;
        }
        BluetoothDevice bluetoothDevice = (device != null) ? device : mService.getActiveDevice();
        if (bluetoothDevice == null) {
            return false;
@@ -227,6 +233,11 @@ public class A2dpProfile implements LocalBluetoothProfile {
    }

    public boolean isHighQualityAudioEnabled(BluetoothDevice device) {
        if (V) Log.d(TAG, " execute isHighQualityAudioEnabled()");
        if (mService == null) {
            if (V) Log.d(TAG,"mService is null.");
            return false;
        }
        BluetoothDevice bluetoothDevice = (device != null) ? device : mService.getActiveDevice();
        if (bluetoothDevice == null) {
            return false;
@@ -253,13 +264,18 @@ public class A2dpProfile implements LocalBluetoothProfile {
    }

    public void setHighQualityAudioEnabled(BluetoothDevice device, boolean enabled) {
        if (V) Log.d(TAG, " execute setHighQualityAudioEnabled()");
        int prefValue = enabled
                ? BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED
                : BluetoothA2dp.OPTIONAL_CODECS_PREF_DISABLED;
        if (mService == null) {
            if (V) Log.d(TAG,"mService is null.");
            return;
        }
        BluetoothDevice bluetoothDevice = (device != null) ? device : mService.getActiveDevice();
        if (bluetoothDevice == null) {
            return;
        }
        int prefValue = enabled
                ? BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED
                : BluetoothA2dp.OPTIONAL_CODECS_PREF_DISABLED;
        mService.setOptionalCodecsEnabled(bluetoothDevice, prefValue);
        if (getConnectionStatus(bluetoothDevice) != BluetoothProfile.STATE_CONNECTED) {
            return;
@@ -272,6 +288,7 @@ public class A2dpProfile implements LocalBluetoothProfile {
    }

    public String getHighQualityAudioOptionLabel(BluetoothDevice device) {
        if (V) Log.d(TAG, " execute getHighQualityAudioOptionLabel()");
        BluetoothDevice bluetoothDevice = (device != null) ? device : mService.getActiveDevice();
        int unknownCodecId = R.string.bluetooth_profile_a2dp_high_quality_unknown_codec;
        if (bluetoothDevice == null || !supportsHighQualityAudio(device)
@@ -281,7 +298,7 @@ public class A2dpProfile implements LocalBluetoothProfile {
        // We want to get the highest priority codec, since that's the one that will be used with
        // this device, and see if it is high-quality (ie non-mandatory).
        BluetoothCodecConfig[] selectable = null;
        if (mService.getCodecStatus(device) != null) {
        if (mService != null && mService.getCodecStatus(device) != null) {
            selectable = mService.getCodecStatus(device).getCodecsSelectableCapabilities();
            // To get the highest priority, we sort in reverse.
            Arrays.sort(selectable,