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

Commit d5d48fa7 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.

CRs-Fixed: 2454049
Change-Id: Idd949bc27fec10b46a149b5db67abc6f3b5097d1
parent 131c2933
Loading
Loading
Loading
Loading
+18 −1
Original line number Original line Diff line number Diff line
@@ -35,6 +35,7 @@ import java.util.List;


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


    private Context mContext;
    private Context mContext;


@@ -210,11 +211,21 @@ public class A2dpProfile implements LocalBluetoothProfile {
    }
    }


    public boolean supportsHighQualityAudio(BluetoothDevice device) {
    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;
        }
        int support = mService.supportsOptionalCodecs(device);
        int support = mService.supportsOptionalCodecs(device);
        return support == BluetoothA2dp.OPTIONAL_CODECS_SUPPORTED;
        return support == BluetoothA2dp.OPTIONAL_CODECS_SUPPORTED;
    }
    }


    public boolean isHighQualityAudioEnabled(BluetoothDevice device) {
    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;
        }
        int enabled = mService.getOptionalCodecsEnabled(device);
        int enabled = mService.getOptionalCodecsEnabled(device);
        if (enabled != BluetoothA2dp.OPTIONAL_CODECS_PREF_UNKNOWN) {
        if (enabled != BluetoothA2dp.OPTIONAL_CODECS_PREF_UNKNOWN) {
            return enabled == BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED;
            return enabled == BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED;
@@ -237,9 +248,14 @@ public class A2dpProfile implements LocalBluetoothProfile {
    }
    }


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


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