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

Commit 88807636 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Refine BluetoothLeAdvertiser permissions.

Technically these APIs required both ADVERTISE and CONNECT, since
internally it would attempt getting the device name as part of
calculating packet lengths.  These methods shouldn't require the
CONNECT permission, so we add a getNameLengthForAdvertise() method
internally to remove this dependency.

Bug: 183626724
Test: ./build/soong/soong_ui.bash --make-mode Bluetooth RUN_ERROR_PRONE=true
Change-Id: Ic6c9528034ee7d4bdab6253394724294471b49f1
parent cf9f5fa3
Loading
Loading
Loading
Loading
+15 −0
Original line number Original line Diff line number Diff line
@@ -1275,6 +1275,17 @@ public class AdapterService extends Service {
            return service.getName();
            return service.getName();
        }
        }


        @Override
        public int getNameLengthForAdvertise() {
            AdapterService service = getService();
            if (service == null || !callerIsSystemOrActiveUser(TAG, "getNameLengthForAdvertise")
                    || !Utils.checkAdvertisePermissionForPreflight(service)) {
                return -1;
            }

            return service.getNameLengthForAdvertise();
        }

        @Override
        @Override
        public boolean setName(String name) {
        public boolean setName(String name) {
            AdapterService service = getService();
            AdapterService service = getService();
@@ -2354,6 +2365,10 @@ public class AdapterService extends Service {
        return mAdapterProperties.getName();
        return mAdapterProperties.getName();
    }
    }


    public int getNameLengthForAdvertise() {
        return mAdapterProperties.getName().length();
    }

    private static boolean isValidIoCapability(int capability) {
    private static boolean isValidIoCapability(int capability) {
        if (capability < 0 || capability >= BluetoothAdapter.IO_CAPABILITY_MAX) {
        if (capability < 0 || capability >= BluetoothAdapter.IO_CAPABILITY_MAX) {
            Log.e(TAG, "Invalid IO capability value - " + capability);
            Log.e(TAG, "Invalid IO capability value - " + capability);