diff options
| author | 2022-06-10 19:49:16 +0900 | |
|---|---|---|
| committer | 2022-06-14 15:33:09 +0900 | |
| commit | c376e8c11204135e3ee2bf72ef7af6b1de6d42cf (patch) | |
| tree | 9060b788569542bb6a84c93701bd6233a63304fe | |
| parent | 47ecbaf0add19dab37c93d76a289f1e0f67eeb37 (diff) | |
Handle NPE from BluetoothRouteProvider
NPE could be thrown if ACTION_ACTIVE_DEVICE_CHANGED
is sent before ACTION_CONNECTION_STATE_CHANGED (connected)
is sent.
This CL handles the case by creating a new bluetooth route.
If ACTION_CONNECTION_STATE_CHANGED is followed, connectedProfiles
of the route will be managed.
Bug: 235311641
Test: build successful
Change-Id: I931b3eb38704f23b96c80d70d121c27bef297c7b
| -rw-r--r-- | services/core/java/com/android/server/media/BluetoothRouteProvider.java | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/services/core/java/com/android/server/media/BluetoothRouteProvider.java b/services/core/java/com/android/server/media/BluetoothRouteProvider.java index 91de9e559e13..b44ad922dd05 100644 --- a/services/core/java/com/android/server/media/BluetoothRouteProvider.java +++ b/services/core/java/com/android/server/media/BluetoothRouteProvider.java @@ -345,18 +345,14 @@ class BluetoothRouteProvider { private void addActiveRoute(BluetoothRouteInfo btRoute) { if (btRoute == null) { - if (DEBUG) { - Log.d(TAG, " btRoute is null"); - } + Slog.w(TAG, "addActiveRoute: btRoute is null"); return; } if (DEBUG) { Log.d(TAG, "Adding active route: " + btRoute.route); } if (mActiveRoutes.contains(btRoute)) { - if (DEBUG) { - Log.d(TAG, " btRoute is already added."); - } + Slog.w(TAG, "addActiveRoute: btRoute is already added."); return; } setRouteConnectionState(btRoute, STATE_CONNECTED); @@ -389,6 +385,12 @@ class BluetoothRouteProvider { private void addActiveDevices(BluetoothDevice device) { // Let the given device be the first active device BluetoothRouteInfo activeBtRoute = mBluetoothRoutes.get(device.getAddress()); + // This could happen if ACTION_ACTIVE_DEVICE_CHANGED is sent before + // ACTION_CONNECTION_STATE_CHANGED is sent. + if (activeBtRoute == null) { + activeBtRoute = createBluetoothRoute(device); + mBluetoothRoutes.put(device.getAddress(), activeBtRoute); + } addActiveRoute(activeBtRoute); // A bluetooth route with the same route ID should be added. |