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

Commit 8ed3d9cb authored by Hyundo Moon's avatar Hyundo Moon
Browse files

Add Binder tests for ProfileServices

This CL adds test for binder in below ProfileServices:
- AvrcpControllerService
- HeadsetClientService
- HidHostService
- BluetoothPbapService
- BluetoothMapService
- PanService

Bug: 237467631
Test: For each service, atest (ServiceName)BinderTest
Change-Id: I0fee4e330afde78b4a925a9c674e8fe7dc3232bc
parent 605153ab
Loading
Loading
Loading
Loading
+5 −1
Original line number Original line Diff line number Diff line
@@ -359,12 +359,16 @@ public class AvrcpControllerService extends ProfileService {
    }
    }


    //Binder object: Must be static class or memory leak may occur
    //Binder object: Must be static class or memory leak may occur
    private static class AvrcpControllerServiceBinder extends IBluetoothAvrcpController.Stub
    @VisibleForTesting
    static class AvrcpControllerServiceBinder extends IBluetoothAvrcpController.Stub
            implements IProfileServiceBinder {
            implements IProfileServiceBinder {
        private AvrcpControllerService mService;
        private AvrcpControllerService mService;


        @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
        @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
        private AvrcpControllerService getService(AttributionSource source) {
        private AvrcpControllerService getService(AttributionSource source) {
            if (Utils.isInstrumentationTestMode()) {
                return mService;
            }
            if (!Utils.checkServiceAvailable(mService, TAG)
            if (!Utils.checkServiceAvailable(mService, TAG)
                    || !Utils.checkCallerIsSystemOrActiveOrManagedUser(mService, TAG)
                    || !Utils.checkCallerIsSystemOrActiveOrManagedUser(mService, TAG)
                    || !Utils.checkConnectPermissionForDataDelivery(mService, source, TAG)) {
                    || !Utils.checkConnectPermissionForDataDelivery(mService, source, TAG)) {
+6 −2
Original line number Original line Diff line number Diff line
@@ -259,7 +259,8 @@ public class HeadsetClientService extends ProfileService {
    /**
    /**
     * Handlers for incoming service calls
     * Handlers for incoming service calls
     */
     */
    private static class BluetoothHeadsetClientBinder extends IBluetoothHeadsetClient.Stub
    @VisibleForTesting
    static class BluetoothHeadsetClientBinder extends IBluetoothHeadsetClient.Stub
            implements IProfileServiceBinder {
            implements IProfileServiceBinder {
        private HeadsetClientService mService;
        private HeadsetClientService mService;


@@ -274,6 +275,9 @@ public class HeadsetClientService extends ProfileService {


        @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
        @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
        private HeadsetClientService getService(AttributionSource source) {
        private HeadsetClientService getService(AttributionSource source) {
            if (Utils.isInstrumentationTestMode()) {
                return mService;
            }
            if (!Utils.checkServiceAvailable(mService, TAG)
            if (!Utils.checkServiceAvailable(mService, TAG)
                    || !Utils.checkCallerIsSystemOrActiveOrManagedUser(mService, TAG)
                    || !Utils.checkCallerIsSystemOrActiveOrManagedUser(mService, TAG)
                    || !Utils.checkConnectPermissionForDataDelivery(mService, source, TAG)) {
                    || !Utils.checkConnectPermissionForDataDelivery(mService, source, TAG)) {
@@ -776,7 +780,7 @@ public class HeadsetClientService extends ProfileService {
        return connectedDevices;
        return connectedDevices;
    }
    }


    private List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) {
    List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) {
        List<BluetoothDevice> devices = new ArrayList<BluetoothDevice>();
        List<BluetoothDevice> devices = new ArrayList<BluetoothDevice>();
        synchronized (mStateMachineMap) {
        synchronized (mStateMachineMap) {
            for (BluetoothDevice bd : mStateMachineMap.keySet()) {
            for (BluetoothDevice bd : mStateMachineMap.keySet()) {
+5 −1
Original line number Original line Diff line number Diff line
@@ -325,7 +325,8 @@ public class HidHostService extends ProfileService {
    /**
    /**
     * Handlers for incoming service calls
     * Handlers for incoming service calls
     */
     */
    private static class BluetoothHidHostBinder extends IBluetoothHidHost.Stub
    @VisibleForTesting
    static class BluetoothHidHostBinder extends IBluetoothHidHost.Stub
            implements IProfileServiceBinder {
            implements IProfileServiceBinder {
        private HidHostService mService;
        private HidHostService mService;


@@ -340,6 +341,9 @@ public class HidHostService extends ProfileService {


        @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
        @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
        private HidHostService getService(AttributionSource source) {
        private HidHostService getService(AttributionSource source) {
            if (Utils.isInstrumentationTestMode()) {
                return mService;
            }
            if (!Utils.checkServiceAvailable(mService, TAG)
            if (!Utils.checkServiceAvailable(mService, TAG)
                    || !Utils.checkCallerIsSystemOrActiveOrManagedUser(mService, TAG)
                    || !Utils.checkCallerIsSystemOrActiveOrManagedUser(mService, TAG)
                    || !Utils.checkConnectPermissionForDataDelivery(mService, source, TAG)) {
                    || !Utils.checkConnectPermissionForDataDelivery(mService, source, TAG)) {
+6 −2
Original line number Original line Diff line number Diff line
@@ -556,7 +556,7 @@ public class BluetoothMapService extends ProfileService {
        }
        }
    }
    }


    private List<BluetoothDevice> getConnectedDevices() {
    List<BluetoothDevice> getConnectedDevices() {
        List<BluetoothDevice> devices = new ArrayList<>();
        List<BluetoothDevice> devices = new ArrayList<>();
        synchronized (this) {
        synchronized (this) {
            if (mState == BluetoothMap.STATE_CONNECTED && sRemoteDevice != null) {
            if (mState == BluetoothMap.STATE_CONNECTED && sRemoteDevice != null) {
@@ -1209,12 +1209,16 @@ public class BluetoothMapService extends ProfileService {
     * This class implements the IBluetoothMap interface - or actually it validates the
     * This class implements the IBluetoothMap interface - or actually it validates the
     * preconditions for calling the actual functionality in the MapService, and calls it.
     * preconditions for calling the actual functionality in the MapService, and calls it.
     */
     */
    private static class BluetoothMapBinder extends IBluetoothMap.Stub
    @VisibleForTesting
    static class BluetoothMapBinder extends IBluetoothMap.Stub
            implements IProfileServiceBinder {
            implements IProfileServiceBinder {
        private BluetoothMapService mService;
        private BluetoothMapService mService;


        @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
        @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
        private BluetoothMapService getService(AttributionSource source) {
        private BluetoothMapService getService(AttributionSource source) {
            if (Utils.isInstrumentationTestMode()) {
                return mService;
            }
            if (!Utils.checkServiceAvailable(mService, TAG)
            if (!Utils.checkServiceAvailable(mService, TAG)
                    || !Utils.checkCallerIsSystemOrActiveOrManagedUser(mService, TAG)
                    || !Utils.checkCallerIsSystemOrActiveOrManagedUser(mService, TAG)
                    || !Utils.checkConnectPermissionForDataDelivery(mService, source, TAG)) {
                    || !Utils.checkConnectPermissionForDataDelivery(mService, source, TAG)) {
+5 −1
Original line number Original line Diff line number Diff line
@@ -270,7 +270,8 @@ public class PanService extends ProfileService {
    /**
    /**
     * Handlers for incoming service calls
     * Handlers for incoming service calls
     */
     */
    private static class BluetoothPanBinder extends IBluetoothPan.Stub
    @VisibleForTesting
    static class BluetoothPanBinder extends IBluetoothPan.Stub
            implements IProfileServiceBinder {
            implements IProfileServiceBinder {
        private PanService mService;
        private PanService mService;


@@ -285,6 +286,9 @@ public class PanService extends ProfileService {


        @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
        @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
        private PanService getService(AttributionSource source) {
        private PanService getService(AttributionSource source) {
            if (Utils.isInstrumentationTestMode()) {
                return mService;
            }
            if (!Utils.checkServiceAvailable(mService, TAG)
            if (!Utils.checkServiceAvailable(mService, TAG)
                    || !Utils.checkCallerIsSystemOrActiveOrManagedUser(mService, TAG)
                    || !Utils.checkCallerIsSystemOrActiveOrManagedUser(mService, TAG)
                    || !Utils.checkConnectPermissionForDataDelivery(mService, source, TAG)) {
                    || !Utils.checkConnectPermissionForDataDelivery(mService, source, TAG)) {
Loading