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

Commit 3a7f3685 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 12091711 from a982733b to 24Q4-release

Change-Id: Ibf7d5d2605ea99219b9cee3a2aeb36c12be14e03
parents 587bc87f a982733b
Loading
Loading
Loading
Loading
+83 −149
Original line number Original line Diff line number Diff line
@@ -3744,86 +3744,62 @@ public class BassClientService extends ProfileService {


        @Override
        @Override
        public int getConnectionState(BluetoothDevice sink) {
        public int getConnectionState(BluetoothDevice sink) {
            try {
            BassClientService service = getService();
            BassClientService service = getService();
            if (service == null) {
            if (service == null) {
                Log.e(TAG, "Service is null");
                Log.e(TAG, "Service is null");
                return BluetoothProfile.STATE_DISCONNECTED;
                return BluetoothProfile.STATE_DISCONNECTED;
            }
            }
            return service.getConnectionState(sink);
            return service.getConnectionState(sink);
            } catch (RuntimeException e) {
                Log.e(TAG, "Exception happened", e);
                return BluetoothProfile.STATE_DISCONNECTED;
            }
        }
        }


        @Override
        @Override
        public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) {
        public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) {
            try {
            BassClientService service = getService();
            BassClientService service = getService();
            if (service == null) {
            if (service == null) {
                Log.e(TAG, "Service is null");
                Log.e(TAG, "Service is null");
                return Collections.emptyList();
                return Collections.emptyList();
            }
            }
            return service.getDevicesMatchingConnectionStates(states);
            return service.getDevicesMatchingConnectionStates(states);
            } catch (RuntimeException e) {
                Log.e(TAG, "Exception happened", e);
                return Collections.emptyList();
            }
        }
        }


        @Override
        @Override
        public List<BluetoothDevice> getConnectedDevices() {
        public List<BluetoothDevice> getConnectedDevices() {
            try {
            BassClientService service = getService();
            BassClientService service = getService();
            if (service == null) {
            if (service == null) {
                Log.e(TAG, "Service is null");
                Log.e(TAG, "Service is null");
                return Collections.emptyList();
                return Collections.emptyList();
            }
            }
            return service.getConnectedDevices();
            return service.getConnectedDevices();
            } catch (RuntimeException e) {
                Log.e(TAG, "Exception happened", e);
                return Collections.emptyList();
            }
        }
        }


        @Override
        @Override
        public boolean setConnectionPolicy(BluetoothDevice device, int connectionPolicy) {
        public boolean setConnectionPolicy(BluetoothDevice device, int connectionPolicy) {
            try {
            BassClientService service = getService();
            BassClientService service = getService();
            if (service == null) {
            if (service == null) {
                Log.e(TAG, "Service is null");
                Log.e(TAG, "Service is null");
                return false;
                return false;
            }
            }
                mService.enforceCallingOrSelfPermission(

                        BLUETOOTH_CONNECT, "Need BLUETOOTH_CONNECT permission");
            service.enforceCallingOrSelfPermission(BLUETOOTH_CONNECT, null);

            return service.setConnectionPolicy(device, connectionPolicy);
            return service.setConnectionPolicy(device, connectionPolicy);
            } catch (RuntimeException e) {
                Log.e(TAG, "Exception happened", e);
                return false;
            }
        }
        }


        @Override
        @Override
        public int getConnectionPolicy(BluetoothDevice device) {
        public int getConnectionPolicy(BluetoothDevice device) {
            try {
            BassClientService service = getService();
            BassClientService service = getService();
            if (service == null) {
            if (service == null) {
                Log.e(TAG, "Service is null");
                Log.e(TAG, "Service is null");
                return BluetoothProfile.CONNECTION_POLICY_FORBIDDEN;
                return BluetoothProfile.CONNECTION_POLICY_FORBIDDEN;
            }
            }
                mService.enforceCallingOrSelfPermission(

                        BLUETOOTH_CONNECT, "Need BLUETOOTH_CONNECT permission");
            service.enforceCallingOrSelfPermission(BLUETOOTH_CONNECT, null);

            return service.getConnectionPolicy(device);
            return service.getConnectionPolicy(device);
            } catch (RuntimeException e) {
                Log.e(TAG, "Exception happened", e);
                return BluetoothProfile.CONNECTION_POLICY_FORBIDDEN;
            }
        }
        }


        @Override
        @Override
        public void registerCallback(IBluetoothLeBroadcastAssistantCallback cb) {
        public void registerCallback(IBluetoothLeBroadcastAssistantCallback cb) {
            try {
            BassClientService service = getService();
            BassClientService service = getService();
            if (service == null) {
            if (service == null) {
                Log.e(TAG, "Service is null");
                Log.e(TAG, "Service is null");
@@ -3831,14 +3807,10 @@ public class BassClientService extends ProfileService {
            }
            }
            enforceBluetoothPrivilegedPermission(service);
            enforceBluetoothPrivilegedPermission(service);
            service.registerCallback(cb);
            service.registerCallback(cb);
            } catch (RuntimeException e) {
                Log.e(TAG, "Exception happened", e);
            }
        }
        }


        @Override
        @Override
        public void unregisterCallback(IBluetoothLeBroadcastAssistantCallback cb) {
        public void unregisterCallback(IBluetoothLeBroadcastAssistantCallback cb) {
            try {
            BassClientService service = getService();
            BassClientService service = getService();
            if (service == null) {
            if (service == null) {
                Log.e(TAG, "Service is null");
                Log.e(TAG, "Service is null");
@@ -3846,14 +3818,10 @@ public class BassClientService extends ProfileService {
            }
            }
            enforceBluetoothPrivilegedPermission(service);
            enforceBluetoothPrivilegedPermission(service);
            service.unregisterCallback(cb);
            service.unregisterCallback(cb);
            } catch (RuntimeException e) {
                Log.e(TAG, "Exception happened", e);
            }
        }
        }


        @Override
        @Override
        public void startSearchingForSources(List<ScanFilter> filters) {
        public void startSearchingForSources(List<ScanFilter> filters) {
            try {
            BassClientService service = getService();
            BassClientService service = getService();
            if (service == null) {
            if (service == null) {
                Log.e(TAG, "Service is null");
                Log.e(TAG, "Service is null");
@@ -3861,14 +3829,10 @@ public class BassClientService extends ProfileService {
            }
            }
            enforceBluetoothPrivilegedPermission(service);
            enforceBluetoothPrivilegedPermission(service);
            service.startSearchingForSources(filters);
            service.startSearchingForSources(filters);
            } catch (RuntimeException e) {
                Log.e(TAG, "Exception happened", e);
            }
        }
        }


        @Override
        @Override
        public void stopSearchingForSources() {
        public void stopSearchingForSources() {
            try {
            BassClientService service = getService();
            BassClientService service = getService();
            if (service == null) {
            if (service == null) {
                Log.e(TAG, "Service is null");
                Log.e(TAG, "Service is null");
@@ -3876,14 +3840,10 @@ public class BassClientService extends ProfileService {
            }
            }
            enforceBluetoothPrivilegedPermission(service);
            enforceBluetoothPrivilegedPermission(service);
            service.stopSearchingForSources();
            service.stopSearchingForSources();
            } catch (RuntimeException e) {
                Log.e(TAG, "Exception happened", e);
            }
        }
        }


        @Override
        @Override
        public boolean isSearchInProgress() {
        public boolean isSearchInProgress() {
            try {
            BassClientService service = getService();
            BassClientService service = getService();
            if (service == null) {
            if (service == null) {
                Log.e(TAG, "Service is null");
                Log.e(TAG, "Service is null");
@@ -3891,10 +3851,6 @@ public class BassClientService extends ProfileService {
            }
            }
            enforceBluetoothPrivilegedPermission(service);
            enforceBluetoothPrivilegedPermission(service);
            return service.isSearchInProgress();
            return service.isSearchInProgress();
            } catch (RuntimeException e) {
                Log.e(TAG, "Exception happened", e);
                return false;
            }
        }
        }


        @Override
        @Override
@@ -3902,7 +3858,6 @@ public class BassClientService extends ProfileService {
                BluetoothDevice sink,
                BluetoothDevice sink,
                BluetoothLeBroadcastMetadata sourceMetadata,
                BluetoothLeBroadcastMetadata sourceMetadata,
                boolean isGroupOp) {
                boolean isGroupOp) {
            try {
            BassClientService service = getService();
            BassClientService service = getService();
            if (service == null) {
            if (service == null) {
                Log.e(TAG, "Service is null");
                Log.e(TAG, "Service is null");
@@ -3910,15 +3865,11 @@ public class BassClientService extends ProfileService {
            }
            }
            enforceBluetoothPrivilegedPermission(service);
            enforceBluetoothPrivilegedPermission(service);
            service.addSource(sink, sourceMetadata, isGroupOp);
            service.addSource(sink, sourceMetadata, isGroupOp);
            } catch (RuntimeException e) {
                Log.e(TAG, "Exception happened", e);
            }
        }
        }


        @Override
        @Override
        public void modifySource(
        public void modifySource(
                BluetoothDevice sink, int sourceId, BluetoothLeBroadcastMetadata updatedMetadata) {
                BluetoothDevice sink, int sourceId, BluetoothLeBroadcastMetadata updatedMetadata) {
            try {
            BassClientService service = getService();
            BassClientService service = getService();
            if (service == null) {
            if (service == null) {
                Log.e(TAG, "Service is null");
                Log.e(TAG, "Service is null");
@@ -3926,14 +3877,10 @@ public class BassClientService extends ProfileService {
            }
            }
            enforceBluetoothPrivilegedPermission(service);
            enforceBluetoothPrivilegedPermission(service);
            service.modifySource(sink, sourceId, updatedMetadata);
            service.modifySource(sink, sourceId, updatedMetadata);
            } catch (RuntimeException e) {
                Log.e(TAG, "Exception happened", e);
            }
        }
        }


        @Override
        @Override
        public void removeSource(BluetoothDevice sink, int sourceId) {
        public void removeSource(BluetoothDevice sink, int sourceId) {
            try {
            BassClientService service = getService();
            BassClientService service = getService();
            if (service == null) {
            if (service == null) {
                Log.e(TAG, "Service is null");
                Log.e(TAG, "Service is null");
@@ -3941,30 +3888,21 @@ public class BassClientService extends ProfileService {
            }
            }
            enforceBluetoothPrivilegedPermission(service);
            enforceBluetoothPrivilegedPermission(service);
            service.removeSource(sink, sourceId);
            service.removeSource(sink, sourceId);
            } catch (RuntimeException e) {
                Log.e(TAG, "Exception happened", e);
            }
        }
        }


        @Override
        @Override
        public List<BluetoothLeBroadcastReceiveState> getAllSources(BluetoothDevice sink) {
        public List<BluetoothLeBroadcastReceiveState> getAllSources(BluetoothDevice sink) {
            try {
            BassClientService service = getService();
            BassClientService service = getService();
                if (sink == null) {
            if (service == null) {
                Log.e(TAG, "Service is null");
                Log.e(TAG, "Service is null");
                return Collections.emptyList();
                return Collections.emptyList();
            }
            }
            enforceBluetoothPrivilegedPermission(service);
            enforceBluetoothPrivilegedPermission(service);
            return service.getAllSources(sink);
            return service.getAllSources(sink);
            } catch (RuntimeException e) {
                Log.e(TAG, "Exception happened", e);
                return Collections.emptyList();
            }
        }
        }


        @Override
        @Override
        public int getMaximumSourceCapacity(BluetoothDevice sink) {
        public int getMaximumSourceCapacity(BluetoothDevice sink) {
            try {
            BassClientService service = getService();
            BassClientService service = getService();
            if (service == null) {
            if (service == null) {
                Log.e(TAG, "Service is null");
                Log.e(TAG, "Service is null");
@@ -3972,10 +3910,6 @@ public class BassClientService extends ProfileService {
            }
            }
            enforceBluetoothPrivilegedPermission(service);
            enforceBluetoothPrivilegedPermission(service);
            return service.getMaximumSourceCapacity(sink);
            return service.getMaximumSourceCapacity(sink);
            } catch (RuntimeException e) {
                Log.e(TAG, "Exception happened", e);
                return 0;
            }
        }
        }
    }
    }
}
}
+57 −108
Original line number Original line Diff line number Diff line
@@ -21,7 +21,6 @@ import static android.bluetooth.BluetoothProfile.STATE_DISCONNECTED;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertThat;


import static org.mockito.Mockito.any;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verify;


@@ -51,15 +50,16 @@ public class BleBroadcastAssistantBinderTest {


    @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
    @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();


    private final BluetoothAdapter mAdapter = BluetoothAdapter.getDefaultAdapter();
    private final BluetoothDevice mDevice = TestUtils.getTestDevice(mAdapter, 0);

    @Mock private BassClientService mService;
    @Mock private BassClientService mService;


    private BassClientService.BluetoothLeBroadcastAssistantBinder mBinder;
    private BassClientService.BluetoothLeBroadcastAssistantBinder mBinder;
    private BluetoothAdapter mAdapter;


    @Before
    @Before
    public void setUp() {
    public void setUp() {
        mBinder = new BassClientService.BluetoothLeBroadcastAssistantBinder(mService);
        mBinder = new BassClientService.BluetoothLeBroadcastAssistantBinder(mService);
        mAdapter = BluetoothAdapter.getDefaultAdapter();
    }
    }


    @Test
    @Test
@@ -70,15 +70,11 @@ public class BleBroadcastAssistantBinderTest {


    @Test
    @Test
    public void getConnectionState() {
    public void getConnectionState() {
        BluetoothDevice device = TestUtils.getTestDevice(mAdapter, 0);
        mBinder.getConnectionState(mDevice);
        mBinder.getConnectionState(device);
        verify(mService).getConnectionState(mDevice);
        verify(mService).getConnectionState(device);

        doThrow(new RuntimeException()).when(mService).getConnectionState(device);
        assertThat(mBinder.getConnectionState(device)).isEqualTo(STATE_DISCONNECTED);


        mBinder.cleanup();
        mBinder.cleanup();
        assertThat(mBinder.getConnectionState(device)).isEqualTo(STATE_DISCONNECTED);
        assertThat(mBinder.getConnectionState(mDevice)).isEqualTo(STATE_DISCONNECTED);
    }
    }


    @Test
    @Test
@@ -87,10 +83,6 @@ public class BleBroadcastAssistantBinderTest {
        mBinder.getDevicesMatchingConnectionStates(states);
        mBinder.getDevicesMatchingConnectionStates(states);
        verify(mService).getDevicesMatchingConnectionStates(states);
        verify(mService).getDevicesMatchingConnectionStates(states);


        doThrow(new RuntimeException()).when(mService).getDevicesMatchingConnectionStates(states);
        assertThat(mBinder.getDevicesMatchingConnectionStates(states))
                .isEqualTo(Collections.emptyList());

        mBinder.cleanup();
        mBinder.cleanup();
        assertThat(mBinder.getDevicesMatchingConnectionStates(states))
        assertThat(mBinder.getDevicesMatchingConnectionStates(states))
                .isEqualTo(Collections.emptyList());
                .isEqualTo(Collections.emptyList());
@@ -101,42 +93,27 @@ public class BleBroadcastAssistantBinderTest {
        mBinder.getConnectedDevices();
        mBinder.getConnectedDevices();
        verify(mService).getConnectedDevices();
        verify(mService).getConnectedDevices();


        doThrow(new RuntimeException()).when(mService).getConnectedDevices();
        assertThat(mBinder.getConnectedDevices()).isEqualTo(Collections.emptyList());

        mBinder.cleanup();
        mBinder.cleanup();
        assertThat(mBinder.getConnectedDevices()).isEqualTo(Collections.emptyList());
        assertThat(mBinder.getConnectedDevices()).isEqualTo(Collections.emptyList());
    }
    }


    @Test
    @Test
    public void setConnectionPolicy() {
    public void setConnectionPolicy() {
        BluetoothDevice device = TestUtils.getTestDevice(mAdapter, 0);
        mBinder.setConnectionPolicy(mDevice, BluetoothProfile.CONNECTION_POLICY_ALLOWED);
        mBinder.setConnectionPolicy(device, BluetoothProfile.CONNECTION_POLICY_ALLOWED);
        verify(mService).setConnectionPolicy(mDevice, BluetoothProfile.CONNECTION_POLICY_ALLOWED);
        verify(mService).setConnectionPolicy(device, BluetoothProfile.CONNECTION_POLICY_ALLOWED);

        doThrow(new RuntimeException())
                .when(mService)
                .setConnectionPolicy(device, BluetoothProfile.CONNECTION_POLICY_ALLOWED);
        assertThat(mBinder.setConnectionPolicy(device, BluetoothProfile.CONNECTION_POLICY_ALLOWED))
                .isFalse();


        mBinder.cleanup();
        mBinder.cleanup();
        assertThat(mBinder.setConnectionPolicy(device, BluetoothProfile.CONNECTION_POLICY_ALLOWED))
        assertThat(mBinder.setConnectionPolicy(mDevice, BluetoothProfile.CONNECTION_POLICY_ALLOWED))
                .isFalse();
                .isFalse();
    }
    }


    @Test
    @Test
    public void getConnectionPolicy() {
    public void getConnectionPolicy() {
        BluetoothDevice device = TestUtils.getTestDevice(mAdapter, 0);
        mBinder.getConnectionPolicy(mDevice);
        mBinder.getConnectionPolicy(device);
        verify(mService).getConnectionPolicy(mDevice);
        verify(mService).getConnectionPolicy(device);

        doThrow(new RuntimeException()).when(mService).getConnectionPolicy(device);
        assertThat(mBinder.getConnectionPolicy(device))
                .isEqualTo(BluetoothProfile.CONNECTION_POLICY_FORBIDDEN);


        mBinder.cleanup();
        mBinder.cleanup();
        assertThat(mBinder.getConnectionPolicy(device))
        assertThat(mBinder.getConnectionPolicy(mDevice))
                .isEqualTo(BluetoothProfile.CONNECTION_POLICY_FORBIDDEN);
                .isEqualTo(BluetoothProfile.CONNECTION_POLICY_FORBIDDEN);
    }
    }


@@ -146,15 +123,13 @@ public class BleBroadcastAssistantBinderTest {
                Mockito.mock(IBluetoothLeBroadcastAssistantCallback.class);
                Mockito.mock(IBluetoothLeBroadcastAssistantCallback.class);
        mBinder.registerCallback(cb);
        mBinder.registerCallback(cb);
        verify(mService).registerCallback(cb);
        verify(mService).registerCallback(cb);
    }


        Mockito.clearInvocations(mService);
    @Test
        doThrow(new RuntimeException()).when(mService).enforceCallingOrSelfPermission(any(), any());
    public void registerCallback_afterCleanup_doNothing() {
        mBinder.registerCallback(cb);
        verify(mService, never()).registerCallback(cb);

        mBinder.cleanup();
        mBinder.cleanup();
        mBinder.registerCallback(cb);
        mBinder.registerCallback(null);
        verify(mService, never()).registerCallback(cb);
        verify(mService, never()).registerCallback(any());
    }
    }


    @Test
    @Test
@@ -163,15 +138,13 @@ public class BleBroadcastAssistantBinderTest {
                Mockito.mock(IBluetoothLeBroadcastAssistantCallback.class);
                Mockito.mock(IBluetoothLeBroadcastAssistantCallback.class);
        mBinder.unregisterCallback(cb);
        mBinder.unregisterCallback(cb);
        verify(mService).unregisterCallback(cb);
        verify(mService).unregisterCallback(cb);
    }


        Mockito.clearInvocations(mService);
    @Test
        doThrow(new RuntimeException()).when(mService).enforceCallingOrSelfPermission(any(), any());
    public void unregisterCallback_afterCleanup_doNothing() {
        mBinder.unregisterCallback(cb);
        verify(mService, never()).unregisterCallback(cb);

        mBinder.cleanup();
        mBinder.cleanup();
        mBinder.unregisterCallback(cb);
        mBinder.unregisterCallback(null);
        verify(mService, never()).unregisterCallback(cb);
        verify(mService, never()).unregisterCallback(any());
    }
    }


    @Test
    @Test
@@ -179,27 +152,23 @@ public class BleBroadcastAssistantBinderTest {
        List<ScanFilter> filters = Collections.EMPTY_LIST;
        List<ScanFilter> filters = Collections.EMPTY_LIST;
        mBinder.startSearchingForSources(filters);
        mBinder.startSearchingForSources(filters);
        verify(mService).startSearchingForSources(filters);
        verify(mService).startSearchingForSources(filters);
    }


        Mockito.clearInvocations(mService);
    @Test
        doThrow(new RuntimeException()).when(mService).enforceCallingOrSelfPermission(any(), any());
    public void startSearchingForSources_afterCleanup_doNothing() {
        mBinder.startSearchingForSources(filters);
        verify(mService, never()).startSearchingForSources(filters);

        mBinder.cleanup();
        mBinder.cleanup();
        mBinder.startSearchingForSources(filters);
        mBinder.startSearchingForSources(null);
        verify(mService, never()).startSearchingForSources(filters);
        verify(mService, never()).startSearchingForSources(any());
    }
    }


    @Test
    @Test
    public void stopSearchingForSources() {
    public void stopSearchingForSources() {
        mBinder.stopSearchingForSources();
        mBinder.stopSearchingForSources();
        verify(mService).stopSearchingForSources();
        verify(mService).stopSearchingForSources();
    }


        Mockito.clearInvocations(mService);
    @Test
        doThrow(new RuntimeException()).when(mService).enforceCallingOrSelfPermission(any(), any());
    public void stopSearchingForSources_afterCleanup_doNothing() {
        mBinder.stopSearchingForSources();
        verify(mService, never()).stopSearchingForSources();

        mBinder.cleanup();
        mBinder.cleanup();
        mBinder.stopSearchingForSources();
        mBinder.stopSearchingForSources();
        verify(mService, never()).stopSearchingForSources();
        verify(mService, never()).stopSearchingForSources();
@@ -210,84 +179,64 @@ public class BleBroadcastAssistantBinderTest {
        mBinder.isSearchInProgress();
        mBinder.isSearchInProgress();
        verify(mService).isSearchInProgress();
        verify(mService).isSearchInProgress();


        doThrow(new RuntimeException()).when(mService).enforceCallingOrSelfPermission(any(), any());
        assertThat(mBinder.isSearchInProgress()).isFalse();

        mBinder.cleanup();
        mBinder.cleanup();
        assertThat(mBinder.isSearchInProgress()).isFalse();
        assertThat(mBinder.isSearchInProgress()).isFalse();
    }
    }


    @Test
    @Test
    public void addSource() {
    public void addSource() {
        BluetoothDevice device = TestUtils.getTestDevice(mAdapter, 0);
        mBinder.addSource(mDevice, null, false);
        mBinder.addSource(device, null, false);
        verify(mService).addSource(mDevice, null, false);
        verify(mService).addSource(device, null, false);
    }

        Mockito.clearInvocations(mService);
        doThrow(new RuntimeException()).when(mService).enforceCallingOrSelfPermission(any(), any());
        mBinder.addSource(device, null, false);
        verify(mService, never()).addSource(device, null, false);


    @Test
    public void addSource_afterCleanup_doNothing() {
        mBinder.cleanup();
        mBinder.cleanup();
        mBinder.addSource(device, null, false);
        mBinder.addSource(mDevice, null, false);
        verify(mService, never()).addSource(device, null, false);
        verify(mService, never()).addSource(mDevice, null, false);
    }
    }


    @Test
    @Test
    public void modifySource() {
    public void modifySource() {
        BluetoothDevice device = TestUtils.getTestDevice(mAdapter, 0);
        mBinder.modifySource(mDevice, 0, null);
        mBinder.modifySource(device, 0, null);
        verify(mService).modifySource(mDevice, 0, null);
        verify(mService).modifySource(device, 0, null);
    }

        Mockito.clearInvocations(mService);
        doThrow(new RuntimeException()).when(mService).enforceCallingOrSelfPermission(any(), any());
        mBinder.modifySource(device, 0, null);
        verify(mService, never()).modifySource(device, 0, null);


    @Test
    public void modifySource_afterCleanup_doNothing() {
        mBinder.cleanup();
        mBinder.cleanup();
        mBinder.modifySource(device, 0, null);
        mBinder.modifySource(mDevice, 0, null);
        verify(mService, never()).modifySource(device, 0, null);
        verify(mService, never()).modifySource(mDevice, 0, null);
    }
    }


    @Test
    @Test
    public void removeSource() {
    public void removeSource() {
        BluetoothDevice device = TestUtils.getTestDevice(mAdapter, 0);
        mBinder.removeSource(mDevice, 0);
        mBinder.removeSource(device, 0);
        verify(mService).removeSource(mDevice, 0);
        verify(mService).removeSource(device, 0);
    }

        Mockito.clearInvocations(mService);
        doThrow(new RuntimeException()).when(mService).enforceCallingOrSelfPermission(any(), any());
        mBinder.removeSource(device, 0);
        verify(mService, never()).removeSource(device, 0);


    @Test
    public void removeSource_afterCleanup_doNothing() {
        mBinder.cleanup();
        mBinder.cleanup();
        mBinder.removeSource(device, 0);
        mBinder.removeSource(mDevice, 0);
        verify(mService, never()).removeSource(device, 0);
        verify(mService, never()).removeSource(mDevice, 0);
    }
    }


    @Test
    @Test
    public void getAllSources() {
    public void getAllSources() {
        BluetoothDevice device = TestUtils.getTestDevice(mAdapter, 0);
        mBinder.getAllSources(mDevice);
        mBinder.getAllSources(device);
        verify(mService).getAllSources(mDevice);
        verify(mService).getAllSources(device);

        doThrow(new RuntimeException()).when(mService).getConnectionPolicy(device);
        assertThat(mBinder.getAllSources(device)).isEqualTo(Collections.emptyList());


        mBinder.cleanup();
        mBinder.cleanup();
        assertThat(mBinder.getAllSources(device)).isEqualTo(Collections.emptyList());
        assertThat(mBinder.getAllSources(mDevice)).isEqualTo(Collections.emptyList());
    }
    }


    @Test
    @Test
    public void getMaximumSourceCapacity() {
    public void getMaximumSourceCapacity() {
        BluetoothDevice device = TestUtils.getTestDevice(mAdapter, 0);
        mBinder.getMaximumSourceCapacity(mDevice);
        mBinder.getMaximumSourceCapacity(device);
        verify(mService).getMaximumSourceCapacity(mDevice);
        verify(mService).getMaximumSourceCapacity(device);

        doThrow(new RuntimeException()).when(mService).getMaximumSourceCapacity(device);
        assertThat(mBinder.getMaximumSourceCapacity(device)).isEqualTo(0);


        mBinder.cleanup();
        mBinder.cleanup();
        assertThat(mBinder.getMaximumSourceCapacity(device)).isEqualTo(0);
        assertThat(mBinder.getMaximumSourceCapacity(mDevice)).isEqualTo(0);
    }
    }
}
}
+1 −1
Original line number Original line Diff line number Diff line
@@ -133,7 +133,7 @@ genrule {
    ],
    ],
    cmd: "mkdir -p $(genDir)/files && " +
    cmd: "mkdir -p $(genDir)/files && " +
        "$(location aprotoc) -Ipackages/modules/Bluetooth/system -Iexternal/protobuf/src --plugin=protoc-gen-grpc=$(location protoc-gen-grpc-python-plugin) $(locations :BlueberryFacadeProto) --grpc_out=$(genDir)/files --python_out=$(genDir)/files && " +
        "$(location aprotoc) -Ipackages/modules/Bluetooth/system -Iexternal/protobuf/src --plugin=protoc-gen-grpc=$(location protoc-gen-grpc-python-plugin) $(locations :BlueberryFacadeProto) --grpc_out=$(genDir)/files --python_out=$(genDir)/files && " +
        "find $(genDir)/files -type d -exec touch {}/__init__.py \\; &&" +
        "for dir in `find $(genDir)/files -type d`; do touch $$dir/__init__.py; done &&" +
        "$(location soong_zip) -C $(genDir)/files -D $(genDir)/files -o $(out)",
        "$(location soong_zip) -C $(genDir)/files -D $(genDir)/files -o $(out)",
    srcs: [
    srcs: [
        ":BlueberryFacadeProto",
        ":BlueberryFacadeProto",
+1 −1
Original line number Original line Diff line number Diff line
@@ -98,7 +98,7 @@ $(bluetooth_cert_src_and_bin_zip): PRIVATE_host_python_smp_packets_library := $(
$(bluetooth_cert_src_and_bin_zip): PRIVATE_target_executables := $(LOCAL_target_executables)
$(bluetooth_cert_src_and_bin_zip): PRIVATE_target_executables := $(LOCAL_target_executables)
$(bluetooth_cert_src_and_bin_zip): PRIVATE_target_libraries := $(LOCAL_target_libraries)
$(bluetooth_cert_src_and_bin_zip): PRIVATE_target_libraries := $(LOCAL_target_libraries)
$(bluetooth_cert_src_and_bin_zip): $(SOONG_ZIP) $(LOCAL_cert_test_sources) \
$(bluetooth_cert_src_and_bin_zip): $(SOONG_ZIP) $(LOCAL_cert_test_sources) \
		$(LOCAL_host_executables) $(LOCAL_host_libraries) $(LOCAL_host_python_libraries) \
		$(LOCAL_host_executables) $(LOCAL_host_libraries) \
		$(LOCAL_host_python_hci_packets_library) \
		$(LOCAL_host_python_hci_packets_library) \
		$(LOCAL_host_python_smp_packets_library) \
		$(LOCAL_host_python_smp_packets_library) \
		$(LOCAL_target_executables) $(LOCAL_target_libraries)
		$(LOCAL_target_executables) $(LOCAL_target_libraries)
+1 −0
Original line number Original line Diff line number Diff line
@@ -698,6 +698,7 @@ cc_test {
        ":TestMockMainShimDumpsys",
        ":TestMockMainShimDumpsys",
        ":TestMockMainShimEntry",
        ":TestMockMainShimEntry",
        ":TestMockStack",
        ":TestMockStack",
        ":TestMockStackSecurityClientInterface",
        ":TestMockUdrv",
        ":TestMockUdrv",
        "test/btif_core_test.cc",
        "test/btif_core_test.cc",
    ],
    ],
Loading