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

Commit d3b54eae authored by Jakub Pawlowski's avatar Jakub Pawlowski Committed by Gerrit Code Review
Browse files

Merge "Fix connecting to profiles when bonding from local device (2/3)"

parents be4507f6 66734225
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -1123,6 +1123,13 @@ public class AdapterService extends Service {
            return service.getBondState(device);
        }

        public boolean isBondingInitiatedLocally(BluetoothDevice device) {
            // don't check caller, may be called from system UI
            AdapterService service = getService();
            if (service == null) return false;
            return service.isBondingInitiatedLocally(device);
        }

        public int getConnectionState(BluetoothDevice device) {
            AdapterService service = getService();
            if (service == null) return 0;
@@ -1599,6 +1606,8 @@ public class AdapterService extends Service {
            return false;
        }

        deviceProp.setBondingInitiatedLocally(true);

        // Pairing is unreliable while scanning, so cancel discovery
        // Note, remove this when native stack improves
        cancelDiscoveryNative();
@@ -1878,6 +1887,12 @@ public class AdapterService extends Service {
     boolean cancelBondProcess(BluetoothDevice device) {
        enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH ADMIN permission");
        byte[] addr = Utils.getBytesFromAddress(device.getAddress());

        DeviceProperties deviceProp = mRemoteDevices.getDeviceProperties(device);
        if (deviceProp != null) {
            deviceProp.setBondingInitiatedLocally(false);
        }

        return cancelBondNative(addr);
    }

@@ -1887,6 +1902,8 @@ public class AdapterService extends Service {
        if (deviceProp == null || deviceProp.getBondState() != BluetoothDevice.BOND_BONDED) {
            return false;
        }
        deviceProp.setBondingInitiatedLocally(false);

        Message msg = mBondStateMachine.obtainMessage(BondStateMachine.REMOVE_BOND);
        msg.obj = device;
        mBondStateMachine.sendMessage(msg);
@@ -1902,6 +1919,15 @@ public class AdapterService extends Service {
        return deviceProp.getBondState();
    }

    boolean isBondingInitiatedLocally(BluetoothDevice device) {
        enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
        DeviceProperties deviceProp = mRemoteDevices.getDeviceProperties(device);
        if (deviceProp == null) {
            return false;
        }
        return deviceProp.isBondingInitiatedLocally();
    }

    int getConnectionState(BluetoothDevice device) {
        enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
        byte[] addr = Utils.getBytesFromAddress(device.getAddress());
+19 −0
Original line number Diff line number Diff line
@@ -100,6 +100,7 @@ final class RemoteDevices {
        private String mAlias;
        private int mBondState;
        private BluetoothDevice mDevice;
        private boolean isBondingInitiatedLocally;

        DeviceProperties() {
            mBondState = BluetoothDevice.BOND_NONE;
@@ -217,6 +218,24 @@ final class RemoteDevices {
                return mBondState;
            }
        }

        /**
         * @param isBondingInitiatedLocally wether bonding is initiated locally
         */
        void setBondingInitiatedLocally(boolean isBondingInitiatedLocally) {
            synchronized (mObject) {
                this.isBondingInitiatedLocally = isBondingInitiatedLocally;
            }
        }

        /**
         * @return the isBondingInitiatedLocally
         */
        boolean isBondingInitiatedLocally() {
            synchronized (mObject) {
                return isBondingInitiatedLocally;
            }
        }
    }

    private void sendUuidIntent(BluetoothDevice device) {