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

Commit ee6d33f4 authored by Iván Budnik's avatar Iván Budnik
Browse files

Fix IAE for bluetooth routes without set BT address

This change just adds a last resort check to avoid the exception and fix
the crash. Further checks will be added in the routing framework to avoid
this incongruent state.

Test: atest com.android.settingslib.media and manually with demo app
Bug: 347499404
Flag: EXEMPT bugfix
Change-Id: I87e6810467bcae0bac7f0418217b03e57c1d8c03
parent f74076cb
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -671,7 +671,7 @@ public abstract class InfoMediaManager {
    // MediaRoute2Info.getType was made public on API 34, but exists since API 30.
    @SuppressWarnings("NewApi")
    @VisibleForTesting
    void addMediaDevice(MediaRoute2Info route, RoutingSessionInfo activeSession) {
    void addMediaDevice(@NonNull MediaRoute2Info route, @NonNull RoutingSessionInfo activeSession) {
        final int deviceType = route.getType();
        MediaDevice mediaDevice = null;
        switch (deviceType) {
@@ -711,8 +711,13 @@ public abstract class InfoMediaManager {
            case TYPE_HEARING_AID:
            case TYPE_BLUETOOTH_A2DP:
            case TYPE_BLE_HEADSET:
                if (route.getAddress() == null) {
                    Log.e(TAG, "Ignoring bluetooth route with no set address: " + route);
                    break;
                }
                final BluetoothDevice device =
                        BluetoothAdapter.getDefaultAdapter().getRemoteDevice(route.getAddress());
                        BluetoothAdapter.getDefaultAdapter()
                                .getRemoteDevice(route.getAddress());
                final CachedBluetoothDevice cachedDevice =
                        mBluetoothManager.getCachedDeviceManager().findDevice(device);
                if (cachedDevice != null) {