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

Commit 3af6fab3 authored by Jakub Tyszkowski's avatar Jakub Tyszkowski Committed by Jack He
Browse files

Broadcaster: Fix handling invalid broadcastId

This adds checking for a known broadcast ID and calls proper
error callbacks instead of calling in to the native stack.

Bug: 150670922
Bug: 229696151
Fixes: 229696151
Tag: #feature
Test: atest BluetoothInstrumentationTests
Sponsor: jpawlowski@
Change-Id: I7f564b12597f92a7f0b0885c8054dc3110a547c3
parent 86ed7405
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -631,6 +631,12 @@ public class LeAudioService extends ProfileService {
            Log.w(TAG, "Native interface not available.");
            return;
        }
        if (!mBroadcastStateMap.containsKey(broadcastId)) {
            notifyBroadcastUpdateFailed(broadcastId,
                    BluetoothStatusCodes.ERROR_LE_BROADCAST_INVALID_BROADCAST_ID);
            return;
        }

        if (DBG) Log.d(TAG, "updateBroadcast");
        mLeAudioBroadcasterNativeInterface.updateMetadata(broadcastId, metadata.getRawMetadata());
    }
@@ -644,6 +650,12 @@ public class LeAudioService extends ProfileService {
            Log.w(TAG, "Native interface not available.");
            return;
        }
        if (!mBroadcastStateMap.containsKey(broadcastId)) {
            notifyOnBroadcastStopFailed(
                    BluetoothStatusCodes.ERROR_LE_BROADCAST_INVALID_BROADCAST_ID);
            return;
        }

        if (DBG) Log.d(TAG, "stopBroadcast");
        mLeAudioBroadcasterNativeInterface.stopBroadcast(broadcastId);
    }
@@ -657,6 +669,12 @@ public class LeAudioService extends ProfileService {
            Log.w(TAG, "Native interface not available.");
            return;
        }
        if (!mBroadcastStateMap.containsKey(broadcastId)) {
            notifyOnBroadcastStopFailed(
                    BluetoothStatusCodes.ERROR_LE_BROADCAST_INVALID_BROADCAST_ID);
            return;
        }

        if (DBG) Log.d(TAG, "destroyBroadcast");
        mLeAudioBroadcasterNativeInterface.destroyBroadcast(broadcastId);
    }
+21 −0
Original line number Diff line number Diff line
@@ -341,6 +341,27 @@ public class LeAudioBroadcastServiceTest {
        verifyBroadcastStopped(broadcastId);
    }

    @Test
    public void testBroadcastInvalidBroadcastIdRequest() {
        int broadcastId = 243;

        mService.mBroadcastCallbacks.register(mCallbacks);

        // Stop non-existing broadcast
        mService.stopBroadcast(broadcastId);
        Assert.assertFalse(mOnBroadcastStoppedCalled);
        Assert.assertTrue(mOnBroadcastStopFailedCalled);

        // Update metadata for non-existing broadcast
        BluetoothLeAudioContentMetadata.Builder meta_builder =
        new BluetoothLeAudioContentMetadata.Builder();
        meta_builder.setLanguage("eng");
        meta_builder.setProgramInfo("Public broadcast info");
        mService.updateBroadcast(broadcastId, meta_builder.build());
        Assert.assertFalse(mOnBroadcastUpdatedCalled);
        Assert.assertTrue(mOnBroadcastUpdateFailedCalled);
    }

    private BluetoothLeBroadcastSubgroup createBroadcastSubgroup() {
        BluetoothLeAudioCodecConfigMetadata codecMetadata =
                new BluetoothLeAudioCodecConfigMetadata.Builder()