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

Commit 19f81654 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 am: 8d2e1ce0

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

Change-Id: I24c14a5ebd9b28234178e58249d80307243cfe62
parents 635b68f9 8d2e1ce0
Loading
Loading
Loading
Loading
+17 −19
Original line number Original line Diff line number Diff line
@@ -16,6 +16,8 @@


package com.android.bluetooth.hid;
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 static com.android.bluetooth.Utils.enforceBluetoothPrivilegedPermission;


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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