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

Commit 5d4a6d8c authored by Rongxuan Liu's avatar Rongxuan Liu Committed by Automerger Merge Worker
Browse files

Merge "[le audio] Broadcast service api throw security exception" am:...

Merge "[le audio] Broadcast service api throw security exception" am: e2c2f377 am: 1d326209 am: 52dab439

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/2551361



Change-Id: I905e3d3b3c642c625d0bf8276f3828b8e98f3a6b
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 52865dbd 52dab439
Loading
Loading
Loading
Loading
+33 −15
Original line number Diff line number Diff line
@@ -3551,33 +3551,51 @@ public class LeAudioService extends ProfileService {

        @Override
        public void startBroadcast(
                BluetoothLeBroadcastSettings broadcastSettings, AttributionSource source) {
                BluetoothLeBroadcastSettings broadcastSettings, AttributionSource source,
                SynchronousResultReceiver receiver) {
            try {
                LeAudioService service = getService(source);
                if (service != null) {
                    enforceBluetoothPrivilegedPermission(service);
                    service.createBroadcast(broadcastSettings);
                }
                receiver.send(null);
            } catch (RuntimeException e) {
                receiver.propagateException(e);
            }
        }

        @Override
        public void stopBroadcast(int broadcastId, AttributionSource source) {
        public void stopBroadcast(int broadcastId, AttributionSource source,
                SynchronousResultReceiver receiver) {
            try {
                LeAudioService service = getService(source);
                if (service != null) {
                    enforceBluetoothPrivilegedPermission(service);
                    service.stopBroadcast(broadcastId);
                }
                receiver.send(null);
            } catch (RuntimeException e) {
                receiver.propagateException(e);
            }
        }

        @Override
        public void updateBroadcast(
                int broadcastId,
                BluetoothLeBroadcastSettings broadcastSettings,
                AttributionSource source) {
                AttributionSource source,
                SynchronousResultReceiver receiver) {
            try {
                LeAudioService service = getService(source);
                if (service != null) {
                    enforceBluetoothPrivilegedPermission(service);
                    service.updateBroadcast(broadcastId, broadcastSettings);
                }
                receiver.send(null);
            } catch (RuntimeException e) {
                receiver.propagateException(e);
            }
        }

        @Override
+6 −3
Original line number Diff line number Diff line
@@ -315,8 +315,9 @@ public class LeAudioBinderTest {
    public void startBroadcast() {
        BluetoothLeBroadcastSettings broadcastSettings = buildBroadcastSettingsFromMetadata();
        AttributionSource source = new AttributionSource.Builder(0).build();
        final SynchronousResultReceiver<Void> recv = SynchronousResultReceiver.get();

        mBinder.startBroadcast(broadcastSettings, source);
        mBinder.startBroadcast(broadcastSettings, source, recv);
        verify(mMockService).createBroadcast(broadcastSettings);
    }

@@ -324,8 +325,9 @@ public class LeAudioBinderTest {
    public void stopBroadcast() {
        int id = 1;
        AttributionSource source = new AttributionSource.Builder(0).build();
        final SynchronousResultReceiver<Void> recv = SynchronousResultReceiver.get();

        mBinder.stopBroadcast(id, source);
        mBinder.stopBroadcast(id, source, recv);
        verify(mMockService).stopBroadcast(id);
    }

@@ -334,8 +336,9 @@ public class LeAudioBinderTest {
        int id = 1;
        BluetoothLeBroadcastSettings broadcastSettings = buildBroadcastSettingsFromMetadata();
        AttributionSource source = new AttributionSource.Builder(0).build();
        final SynchronousResultReceiver<Void> recv = SynchronousResultReceiver.get();

        mBinder.updateBroadcast(id, broadcastSettings, source);
        mBinder.updateBroadcast(id, broadcastSettings, source, recv);
        verify(mMockService).updateBroadcast(id, broadcastSettings);
    }

+35 −5
Original line number Diff line number Diff line
@@ -562,11 +562,17 @@ public final class BluetoothLeBroadcast implements AutoCloseable, BluetoothProfi
            if (DBG) log(Log.getStackTraceString(new Throwable()));
        } else if (isEnabled()) {
            try {
                final SynchronousResultReceiver<Integer> recv = SynchronousResultReceiver.get();
                service.startBroadcast(
                        buildBroadcastSettingsFromMetadata(contentMetadata, broadcastCode),
                        mAttributionSource);
                        mAttributionSource, recv);
                recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(null);
            } catch (TimeoutException e) {
                Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            } catch (SecurityException e) {
                throw e;
            }
        }
    }
@@ -595,9 +601,15 @@ public final class BluetoothLeBroadcast implements AutoCloseable, BluetoothProfi
            if (DBG) log(Log.getStackTraceString(new Throwable()));
        } else if (isEnabled()) {
            try {
                service.startBroadcast(broadcastSettings, mAttributionSource);
                final SynchronousResultReceiver<Integer> recv = SynchronousResultReceiver.get();
                service.startBroadcast(broadcastSettings, mAttributionSource, recv);
                recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(null);
            } catch (TimeoutException e) {
                Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            } catch (SecurityException e) {
                throw e;
            }
        }
    }
@@ -633,11 +645,17 @@ public final class BluetoothLeBroadcast implements AutoCloseable, BluetoothProfi
            if (DBG) log(Log.getStackTraceString(new Throwable()));
        } else if (isEnabled()) {
            try {
                final SynchronousResultReceiver<Integer> recv = SynchronousResultReceiver.get();
                service.updateBroadcast(broadcastId,
                        buildBroadcastSettingsFromMetadata(contentMetadata, null),
                        mAttributionSource);
                        mAttributionSource, recv);
                recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(null);
            } catch (TimeoutException e) {
                Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            } catch (SecurityException e) {
                throw e;
            }
        }
    }
@@ -672,9 +690,15 @@ public final class BluetoothLeBroadcast implements AutoCloseable, BluetoothProfi
            if (DBG) log(Log.getStackTraceString(new Throwable()));
        } else if (isEnabled()) {
            try {
                service.updateBroadcast(broadcastId, broadcastSettings, mAttributionSource);
                final SynchronousResultReceiver<Integer> recv = SynchronousResultReceiver.get();
                service.updateBroadcast(broadcastId, broadcastSettings, mAttributionSource, recv);
                recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(null);
            } catch (TimeoutException e) {
                Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            } catch (SecurityException e) {
                throw e;
            }
        }
    }
@@ -704,9 +728,15 @@ public final class BluetoothLeBroadcast implements AutoCloseable, BluetoothProfi
            if (DBG) log(Log.getStackTraceString(new Throwable()));
        } else if (isEnabled()) {
            try {
                service.stopBroadcast(broadcastId, mAttributionSource);
                final SynchronousResultReceiver<Integer> recv = SynchronousResultReceiver.get();
                service.stopBroadcast(broadcastId, mAttributionSource, recv);
                recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(null);
            } catch (TimeoutException e) {
                Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            } catch (SecurityException e) {
                throw e;
            }
        }
    }
+3 −3
Original line number Diff line number Diff line
@@ -104,11 +104,11 @@ oneway interface IBluetoothLeAudio {
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
    void unregisterLeBroadcastCallback(in IBluetoothLeBroadcastCallback callback, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
    void startBroadcast(in BluetoothLeBroadcastSettings broadcastSettings, in AttributionSource attributionSource);
    void startBroadcast(in BluetoothLeBroadcastSettings broadcastSettings, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
    void stopBroadcast(int broadcastId, in AttributionSource attributionSource);
    void stopBroadcast(int broadcastId, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
    void updateBroadcast(int broadcastId, in BluetoothLeBroadcastSettings broadcastSettings, in AttributionSource attributionSource);
    void updateBroadcast(int broadcastId, in BluetoothLeBroadcastSettings broadcastSettings, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT})")
    void isPlaying(int broadcastId, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")