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

Commit 89f590f7 authored by Łukasz Rymanowski's avatar Łukasz Rymanowski
Browse files

BassClientService: Fix NullPointerException

java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Object java.util.Map.get(java.lang.Object)' on a null object reference

Process
at com.android.bluetooth.bass_client.BassClientService.getActiveSyncedSource
at com.android.bluetooth.bass_client.BassClientStateMachine.cancelActiveSync

Also minor code style fix done by repo upload

Bug: 288002172
Test: atest BluetoothInstrumentationTests
Test: manual
Tag: #feature
Change-Id: If6430ef9a6100cb0887187572d9290499608b998
parent a5795b52
Loading
Loading
Loading
Loading
+19 −4
Original line number Diff line number Diff line
@@ -213,6 +213,11 @@ public class BassClientService extends ProfileService {
    }

    void setActiveSyncedSource(BluetoothDevice scanDelegator, BluetoothDevice sourceDevice) {
        if (mActiveSourceMap == null) {
            Log.e(TAG, "setActiveSyncedSource: mActiveSourceMap is null");
            return;
        }

        log("setActiveSyncedSource, scanDelegator: " + scanDelegator + ", sourceDevice: " +
            sourceDevice);
        if (sourceDevice == null) {
@@ -223,9 +228,17 @@ public class BassClientService extends ProfileService {
    }

    BluetoothDevice getActiveSyncedSource(BluetoothDevice scanDelegator) {
        if (mActiveSourceMap == null) {
            Log.e(TAG, "getActiveSyncedSource: mActiveSourceMap is null");
            return null;
        }

        BluetoothDevice currentSource = mActiveSourceMap.get(scanDelegator);
        log("getActiveSyncedSource: scanDelegator" + scanDelegator
                + "returning " + currentSource);
        log(
                "getActiveSyncedSource: scanDelegator: "
                        + scanDelegator
                        + ", returning: "
                        + currentSource);
        return currentSource;
    }

@@ -1599,7 +1612,8 @@ public class BassClientService extends ProfileService {
                    Log.e(TAG, "Service is null");
                    return false;
                }
                mService.enforceCallingOrSelfPermission(BLUETOOTH_CONNECT, "Need BLUETOOTH_CONNECT permission");
                mService.enforceCallingOrSelfPermission(
                        BLUETOOTH_CONNECT, "Need BLUETOOTH_CONNECT permission");
                return service.setConnectionPolicy(device, connectionPolicy);
            } catch (RuntimeException e) {
                Log.e(TAG, "Exception happened", e);
@@ -1615,7 +1629,8 @@ public class BassClientService extends ProfileService {
                    Log.e(TAG, "Service is null");
                    return BluetoothProfile.CONNECTION_POLICY_FORBIDDEN;
                }
                mService.enforceCallingOrSelfPermission(BLUETOOTH_CONNECT, "Need BLUETOOTH_CONNECT permission");
                mService.enforceCallingOrSelfPermission(
                        BLUETOOTH_CONNECT, "Need BLUETOOTH_CONNECT permission");
                return service.getConnectionPolicy(device);
            } catch (RuntimeException e) {
                Log.e(TAG, "Exception happened", e);