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

Commit 2cbb33c3 authored by Jaikumar Ganesh's avatar Jaikumar Ganesh
Browse files

Fix PAN bug for reverse tethering.

We were the setting the iface as null while disconnecting
and so when disconnected the iface used was null - which would
lead to a crash. During connecting we don't know the interface,
so we use null.

Change-Id: I970f2f1886fa32237936eff439c359187a798832
parent 62c7b375
Loading
Loading
Loading
Loading
+9 −13
Original line number Diff line number Diff line
@@ -145,13 +145,14 @@ final class BluetoothPanProfileHandler {
            return false;
        }

        handlePanDeviceStateChange(device, BluetoothPan.STATE_CONNECTING,
        // Send interface as null as it is not known
        handlePanDeviceStateChange(device, null, BluetoothPan.STATE_CONNECTING,
                                           BluetoothPan.LOCAL_PANU_ROLE);
        if (mBluetoothService.connectPanDeviceNative(objectPath, "nap")) {
            debugLog("connecting to PAN");
            return true;
        } else {
            handlePanDeviceStateChange(device, BluetoothPan.STATE_DISCONNECTED,
            handlePanDeviceStateChange(device, null, BluetoothPan.STATE_DISCONNECTED,
                                                BluetoothPan.LOCAL_PANU_ROLE);
            errorLog("could not connect to PAN");
            return false;
@@ -168,8 +169,8 @@ final class BluetoothPanProfileHandler {
                    panDevice.mLocalRole == BluetoothPan.LOCAL_NAP_ROLE) {
                String objectPath = mBluetoothService.getObjectPathFromAddress(device.getAddress());

                handlePanDeviceStateChange(device, BluetoothPan.STATE_DISCONNECTING,
                        panDevice.mLocalRole);
                handlePanDeviceStateChange(device, panDevice.mIface,
                        BluetoothPan.STATE_DISCONNECTING, panDevice.mLocalRole);

                if (!mBluetoothService.disconnectPanServerDeviceNative(objectPath,
                        device.getAddress(),
@@ -177,7 +178,7 @@ final class BluetoothPanProfileHandler {
                    errorLog("could not disconnect Pan Server Device "+device.getAddress());

                    // Restore prev state
                    handlePanDeviceStateChange(device, state,
                    handlePanDeviceStateChange(device, panDevice.mIface, state,
                            panDevice.mLocalRole);

                    return false;
@@ -230,19 +231,19 @@ final class BluetoothPanProfileHandler {
            return false;
        }

        handlePanDeviceStateChange(device, BluetoothPan.STATE_DISCONNECTING,
        handlePanDeviceStateChange(device, panDevice.mIface, BluetoothPan.STATE_DISCONNECTING,
                                    panDevice.mLocalRole);
        if (panDevice.mLocalRole == BluetoothPan.LOCAL_NAP_ROLE) {
            if (!mBluetoothService.disconnectPanServerDeviceNative(objectPath, device.getAddress(),
                    panDevice.mIface)) {
                // Restore prev state, this shouldn't happen
                handlePanDeviceStateChange(device, state, panDevice.mLocalRole);
                handlePanDeviceStateChange(device, panDevice.mIface, state, panDevice.mLocalRole);
                return false;
            }
        } else {
            if (!mBluetoothService.disconnectPanDeviceNative(objectPath)) {
                // Restore prev state, this shouldn't happen
                handlePanDeviceStateChange(device, state, panDevice.mLocalRole);
                handlePanDeviceStateChange(device, panDevice.mIface, state, panDevice.mLocalRole);
                return false;
            }
        }
@@ -304,11 +305,6 @@ final class BluetoothPanProfileHandler {
        mBluetoothService.sendConnectionStateChange(device, state, prevState);
    }

    void handlePanDeviceStateChange(BluetoothDevice device,
                                                 int state, int role) {
        handlePanDeviceStateChange(device, null, state, role);
    }

    private class BluetoothPanDevice {
        private int mState;
        private String mIfaceAddr;