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

Commit f487d722 authored by Jaikumar Ganesh's avatar Jaikumar Ganesh
Browse files

Add ability to parse keyboard fixed pin auto pair blacklist.

Try auto pairing with such keyboards.
Also fix bug where dynamic auto pairing file was not being created.

Change-Id: I93afb96fee8bc4f245f96ec5961979c620de7948
parent ac6f13dc
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -551,7 +551,14 @@ class BluetoothEventLoop {
        if (btDeviceClass == BluetoothClass.Device.PERIPHERAL_KEYBOARD ||
            btDeviceClass == BluetoothClass.Device.PERIPHERAL_KEYBOARD_POINTING) {
            // Its a keyboard. Follow the HID spec recommendation of creating the
            // passkey and displaying it to the user.
            // passkey and displaying it to the user. If the keyboard doesn't follow
            // the spec recommendation, check if the keyboard has a fixed PIN zero
            // and pair.
            if (mBluetoothService.isFixedPinZerosAutoPairKeyboard(address)) {
                mBluetoothService.setPin(address, BluetoothDevice.convertPinToBytes("0000"));
                return;
            }

            // Generate a variable PIN. This is not truly random but good enough.
            int pin = (int) Math.floor(Math.random() * 10000);
            sendDisplayPinIntent(address, pin);
+22 −1
Original line number Diff line number Diff line
@@ -678,6 +678,11 @@ public class BluetoothService extends IBluetooth.Stub {
        return false;
    }

    /*package*/ synchronized boolean isFixedPinZerosAutoPairKeyboard(String address) {
        // Check for keyboards which have fixed PIN 0000 as the pairing pin
        return mBondState.isFixedPinZerosAutoPairKeyboard(address);
    }

    /*package*/ synchronized void onCreatePairedDeviceResult(String address, int result) {
        if (result == BluetoothDevice.BOND_SUCCESS) {
            setBondState(address, BluetoothDevice.BOND_BONDED);
@@ -748,6 +753,7 @@ public class BluetoothService extends IBluetooth.Stub {
        private ArrayList<String>  mAutoPairingAddressBlacklist;
        private ArrayList<String> mAutoPairingExactNameBlacklist;
        private ArrayList<String> mAutoPairingPartialNameBlacklist;
        private ArrayList<String> mAutoPairingFixedPinZerosKeyboardList;
        // Addresses added to blacklist dynamically based on usage.
        private ArrayList<String> mAutoPairingDynamicAddressBlacklist;

@@ -863,6 +869,19 @@ public class BluetoothService extends IBluetooth.Stub {
            return false;
        }

        public boolean isFixedPinZerosAutoPairKeyboard(String address) {
            // Note: the meaning of blacklist is reversed in this case.
            // If its in the list, we can go ahead and auto pair since
            // by default keyboard should have a variable PIN that we don't
            // auto pair using 0000.
            if (mAutoPairingFixedPinZerosKeyboardList != null) {
                for (String blacklistAddress : mAutoPairingFixedPinZerosKeyboardList) {
                    if (address.startsWith(blacklistAddress)) return true;
                }
            }
            return false;
        }

        public synchronized int getBondState(String address) {
            Integer state = mState.get(address);
            if (state == null) {
@@ -929,7 +948,6 @@ public class BluetoothService extends IBluetooth.Stub {
            FileOutputStream out = null;
            try {
                file = new File(DYNAMIC_AUTO_PAIRING_BLACKLIST);
                if (file.exists()) return;

                in = new FileInputStream(AUTO_PAIRING_BLACKLIST);
                out= new FileOutputStream(DYNAMIC_AUTO_PAIRING_BLACKLIST);
@@ -975,6 +993,9 @@ public class BluetoothService extends IBluetooth.Stub {
                        } else if (value[0].equalsIgnoreCase("PartialNameBlacklist")) {
                            mAutoPairingPartialNameBlacklist =
                                new ArrayList<String>(Arrays.asList(val));
                        } else if (value[0].equalsIgnoreCase("FixedPinZerosKeyboardBlacklist")) {
                            mAutoPairingFixedPinZerosKeyboardList =
                                new ArrayList<String>(Arrays.asList(val));
                        } else if (value[0].equalsIgnoreCase("DynamicAddressBlacklist")) {
                            mAutoPairingDynamicAddressBlacklist =
                                new ArrayList<String>(Arrays.asList(val));