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

Commit 8d2e1ce0 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Roll-back permission enforcement for BluetoothHidHost APIs...

Merge "Roll-back permission enforcement for BluetoothHidHost APIs getConnectedDevices and getConnectionState to BLUETOOTH permission. Move permission enforcement for HidHostService to the binder stub." am: 8ea1c379

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

Change-Id: I0767b28cd8dc323c6fe61d689d257b2c5f71e144
parents b73944ba 8ea1c379
Loading
Loading
Loading
Loading
+17 −19
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.bluetooth.hid;

import static com.android.bluetooth.Utils.enforceBluetoothAdminPermission;
import static com.android.bluetooth.Utils.enforceBluetoothPermission;
import static com.android.bluetooth.Utils.enforceBluetoothPrivilegedPermission;

import android.bluetooth.BluetoothDevice;
@@ -339,6 +341,7 @@ public class HidHostService extends ProfileService {
            if (service == null) {
                return false;
            }
            enforceBluetoothPrivilegedPermission(service);
            return service.connect(device);
        }

@@ -348,6 +351,7 @@ public class HidHostService extends ProfileService {
            if (service == null) {
                return false;
            }
            enforceBluetoothPrivilegedPermission(service);
            return service.disconnect(device);
        }

@@ -357,7 +361,7 @@ public class HidHostService extends ProfileService {
            if (service == null) {
                return BluetoothHidHost.STATE_DISCONNECTED;
            }
            enforceBluetoothPrivilegedPermission(service);
            enforceBluetoothPermission(service);
            return service.getConnectionState(device);
        }

@@ -367,7 +371,7 @@ public class HidHostService extends ProfileService {
            if (service == null) {
                return new ArrayList<>();
            }
            enforceBluetoothPrivilegedPermission(service);
            enforceBluetoothPermission(service);
            return getDevicesMatchingConnectionStates(new int[]{BluetoothProfile.STATE_CONNECTED});
        }

@@ -377,6 +381,7 @@ public class HidHostService extends ProfileService {
            if (service == null) {
                return new ArrayList<BluetoothDevice>(0);
            }
            enforceBluetoothPermission(service);
            return service.getDevicesMatchingConnectionStates(states);
        }

@@ -386,6 +391,7 @@ public class HidHostService extends ProfileService {
            if (service == null) {
                return false;
            }
            enforceBluetoothPrivilegedPermission(service);
            return service.setConnectionPolicy(device, connectionPolicy);
        }

@@ -395,6 +401,7 @@ public class HidHostService extends ProfileService {
            if (service == null) {
                return BluetoothProfile.CONNECTION_POLICY_UNKNOWN;
            }
            enforceBluetoothPrivilegedPermission(service);
            return service.getConnectionPolicy(device);
        }

@@ -405,6 +412,7 @@ public class HidHostService extends ProfileService {
            if (service == null) {
                return false;
            }
            enforceBluetoothAdminPermission(service);
            return service.getProtocolMode(device);
        }

@@ -414,6 +422,7 @@ public class HidHostService extends ProfileService {
            if (service == null) {
                return false;
            }
            enforceBluetoothAdminPermission(service);
            return service.virtualUnplug(device);
        }

@@ -423,6 +432,7 @@ public class HidHostService extends ProfileService {
            if (service == null) {
                return false;
            }
            enforceBluetoothAdminPermission(service);
            return service.setProtocolMode(device, protocolMode);
        }

@@ -433,6 +443,7 @@ public class HidHostService extends ProfileService {
            if (service == null) {
                return false;
            }
            enforceBluetoothAdminPermission(service);
            return service.getReport(device, reportType, reportId, bufferSize);
        }

@@ -442,6 +453,7 @@ public class HidHostService extends ProfileService {
            if (service == null) {
                return false;
            }
            enforceBluetoothAdminPermission(service);
            return service.setReport(device, reportType, report);
        }

@@ -451,6 +463,7 @@ public class HidHostService extends ProfileService {
            if (service == null) {
                return false;
            }
            enforceBluetoothAdminPermission(service);
            return service.sendData(device, report);
        }

@@ -460,6 +473,7 @@ public class HidHostService extends ProfileService {
            if (service == null) {
                return false;
            }
            enforceBluetoothAdminPermission(service);
            return service.setIdleTime(device, idleTime);
        }

@@ -469,6 +483,7 @@ public class HidHostService extends ProfileService {
            if (service == null) {
                return false;
            }
            enforceBluetoothAdminPermission(service);
            return service.getIdleTime(device);
        }
    }
@@ -485,8 +500,6 @@ public class HidHostService extends ProfileService {
     */
    public boolean connect(BluetoothDevice device) {
        if (DBG) Log.d(TAG, "connect: " + device.getAddress());
        enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED,
                "Need BLUETOOTH_PRIVILEGED permission");
        if (getConnectionState(device) != BluetoothHidHost.STATE_DISCONNECTED) {
            Log.e(TAG, "Hid Device not disconnected: " + device);
            return false;
@@ -509,8 +522,6 @@ public class HidHostService extends ProfileService {
     */
    public boolean disconnect(BluetoothDevice device) {
        if (DBG) Log.d(TAG, "disconnect: " + device.getAddress());
        enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED,
                "Need BLUETOOTH_PRIVILEGED permission");
        Message msg = mHandler.obtainMessage(MESSAGE_DISCONNECT, device);
        mHandler.sendMessage(msg);
        return true;
@@ -535,7 +546,6 @@ public class HidHostService extends ProfileService {

    List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) {
        if (DBG) Log.d(TAG, "getDevicesMatchingConnectionStates()");
        enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
        List<BluetoothDevice> inputDevices = new ArrayList<BluetoothDevice>();

        for (BluetoothDevice device : mInputDevices.keySet()) {
@@ -566,8 +576,6 @@ public class HidHostService extends ProfileService {
     * @return true if connectionPolicy is set, false on error
     */
    public boolean setConnectionPolicy(BluetoothDevice device, int connectionPolicy) {
        enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED,
                "Need BLUETOOTH_PRIVILEGED permission");
        if (DBG) {
            Log.d(TAG, "setConnectionPolicy: " + device.getAddress());
        }
@@ -597,8 +605,6 @@ public class HidHostService extends ProfileService {
     * @hide
     */
    public int getConnectionPolicy(BluetoothDevice device) {
        enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED,
                "Need BLUETOOTH_PRIVILEGED permission");
        if (DBG) {
            Log.d(TAG, "getConnectionPolicy: " + device.getAddress());
        }
@@ -608,7 +614,6 @@ public class HidHostService extends ProfileService {

    /* The following APIs regarding test app for compliance */
    boolean getProtocolMode(BluetoothDevice device) {
        enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH_ADMIN permission");
        if (DBG) {
            Log.d(TAG, "getProtocolMode: " + device.getAddress());
        }
@@ -624,7 +629,6 @@ public class HidHostService extends ProfileService {
    }

    boolean virtualUnplug(BluetoothDevice device) {
        enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH_ADMIN permission");
        if (DBG) {
            Log.d(TAG, "virtualUnplug: " + device.getAddress());
        }
@@ -638,7 +642,6 @@ public class HidHostService extends ProfileService {
    }

    boolean setProtocolMode(BluetoothDevice device, int protocolMode) {
        enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH_ADMIN permission");
        if (DBG) {
            Log.d(TAG, "setProtocolMode: " + device.getAddress());
        }
@@ -654,7 +657,6 @@ public class HidHostService extends ProfileService {
    }

    boolean getReport(BluetoothDevice device, byte reportType, byte reportId, int bufferSize) {
        enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH_ADMIN permission");
        if (DBG) {
            Log.d(TAG, "getReport: " + device.getAddress());
        }
@@ -674,7 +676,6 @@ public class HidHostService extends ProfileService {
    }

    boolean setReport(BluetoothDevice device, byte reportType, String report) {
        enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH_ADMIN permission");
        if (DBG) {
            Log.d(TAG, "setReport: " + device.getAddress());
        }
@@ -694,7 +695,6 @@ public class HidHostService extends ProfileService {
    }

    boolean sendData(BluetoothDevice device, String report) {
        enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH_ADMIN permission");
        if (DBG) {
            Log.d(TAG, "sendData: " + device.getAddress());
        }
@@ -707,7 +707,6 @@ public class HidHostService extends ProfileService {
    }

    boolean getIdleTime(BluetoothDevice device) {
        enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH_ADMIN permission");
        if (DBG) Log.d(TAG, "getIdleTime: " + device.getAddress());
        int state = this.getConnectionState(device);
        if (state != BluetoothHidHost.STATE_CONNECTED) {
@@ -719,7 +718,6 @@ public class HidHostService extends ProfileService {
    }

    boolean setIdleTime(BluetoothDevice device, byte idleTime) {
        enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH_ADMIN permission");
        if (DBG) Log.d(TAG, "setIdleTime: " + device.getAddress());
        int state = this.getConnectionState(device);
        if (state != BluetoothHidHost.STATE_CONNECTED) {