Giter VIP home page Giter VIP logo

Comments (13)

philips77 avatar philips77 commented on August 16, 2024

Could you check now? Or do you want me to release beta-2?

from android-ble-library.

esensar avatar esensar commented on August 16, 2024

Sorry for the late response, I haven't had the chance to test it before. It is still not working and I think that the issue is that bluetooth state receiver is unregistered once bluetooth is turned off, meaning the new code won't be called in case described in the issue.

close() is called once bluetooth is turned off:

@Override
public void onReceive(final Context context, final Intent intent) {
final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.STATE_OFF);
final int previousState = intent.getIntExtra(BluetoothAdapter.EXTRA_PREVIOUS_STATE, BluetoothAdapter.STATE_OFF);
final String stateString = "[Broadcast] Action received: " + BluetoothAdapter.ACTION_STATE_CHANGED +
", state changed to " + state2String(state);
log(Level.DEBUG, stateString);
switch (state) {
case BluetoothAdapter.STATE_TURNING_OFF:
case BluetoothAdapter.STATE_OFF:
if (mConnected && previousState != BluetoothAdapter.STATE_TURNING_OFF
&& previousState != BluetoothAdapter.STATE_OFF) {
// No more calls are possible
mGattCallback.mOperationInProgress = true;
mGattCallback.cancelQueue();
mGattCallback.mInitQueue = null;
// Signal the current request, if any
if (mRequest != null && mRequest.type != Request.Type.DISCONNECT) {
mRequest.notifyFail(mBluetoothDevice, FailCallback.REASON_BLUETOOTH_DISABLED);
mRequest = null;
}
if (mValueChangedRequest != null) {
mValueChangedRequest.notifyFail(mBluetoothDevice, FailCallback.REASON_BLUETOOTH_DISABLED);
mValueChangedRequest = null;
}
if (mConnectRequest != null) {
mConnectRequest.notifyFail(mBluetoothDevice, FailCallback.REASON_BLUETOOTH_DISABLED);
mConnectRequest = null;
}
// The connection is killed by the system, no need to disconnect gently.
mUserDisconnected = true;
mGattCallback.notifyDeviceDisconnected(mBluetoothDevice);
}
// Calling close() will prevent the STATE_OFF event from being logged
// (this receiver will be unregistered). But it doesn't matter.
close();
break;
}
}

and that method is unregistering bluetooth receiver:
public void close() {
try {
mContext.unregisterReceiver(mBluetoothStateBroadcastReceiver);
mContext.unregisterReceiver(mBondingBroadcastReceiver);
mContext.unregisterReceiver(mPairingRequestBroadcastReceiver);
} catch (final Exception e) {
// the receiver must have been not registered or unregistered before.
}

from android-ble-library.

philips77 avatar philips77 commented on August 16, 2024

Oh, true. Let me think what can be done about this...

from android-ble-library.

esensar avatar esensar commented on August 16, 2024

Is there a specific reason why bluetooth state receiver is unregistered (since it is only doing something on bluetooth off state)?
Could that one be left registered? Others should be re-registered once device connects again.

from android-ble-library.

philips77 avatar philips77 commented on August 16, 2024

The initial intention was that you only call 'close()' or even 'disconnect()' and the manager is fully released. Connecting again registers the receiver again. But looks like i forgot about disabling BLE.

from android-ble-library.

esensar avatar esensar commented on August 16, 2024

But disabling BLE is currently different in that it sets the mOperationInProgress flag, which actually prevents further connections. Is the regular disconnect call disconnecting gracefully so it does not set these flags and does not clear the queue or? I am not sure if setting the flag is required, since queue is cleared too. I haven't analysed the library completely, so forgive me if I make some incorrect assumptions.

from android-ble-library.

philips77 avatar philips77 commented on August 16, 2024

You were right about unregistering the receiver. There's no need to handle STATE_ON them. Instead, I clear the mOperationInProgress flag. The reference to this object is nullified, but on next enqueue() it may be set again. Any thought? You need to listen for Bluetooth ON state on your own.

from android-ble-library.

esensar avatar esensar commented on August 16, 2024

Well, with the new fix I think it will clear up my issue. I need to test it now, I am not sure if there are some other use cases where something might go wrong. I don't think it should though, since whole queue is cleared and current calls are notified about the disconnection.

from android-ble-library.

esensar avatar esensar commented on August 16, 2024

I can confirm that this fix has resolved my issue. It would be nice if you could include this in beta2.
Thank you for the quick resolution

from android-ble-library.

philips77 avatar philips77 commented on August 16, 2024

I'll release in a second.

from android-ble-library.

philips77 avatar philips77 commented on August 16, 2024

Released in beta2.

from android-ble-library.

philips77 avatar philips77 commented on August 16, 2024

This needs verification again with 2.0-beta9. I had to revert one change that was introduced here.

from android-ble-library.

philips77 avatar philips77 commented on August 16, 2024

Fixed, tested and seems to be working. Released in 2.0-beta10.

from android-ble-library.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.