Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

android: always propagate connection state changes #158

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 26 additions & 21 deletions src/android/BLE.java
Original file line number Diff line number Diff line change
Expand Up @@ -1445,29 +1445,34 @@ public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState
{
Log.i("@@@@@@", "@@@ onConnectionStateChange status: " + status + " newState: " + newState);

if (status == BluetoothGatt.GATT_SUCCESS)
// Report both status and newState to the API client
// newState should be one of:
// BluetoothProfile.STATE_CONNECTING
// BluetoothProfile.STATE_CONNECTED
// BluetoothProfile.STATE_DISCONNECTING
// BluetoothProfile.STATE_DISCONNECTED
// status will be BluetoothGatt.GATT_SUCCESS (0) for a successful connect or disconnect
// but could also be:
// Device went out of range - 8
// Disconnected by device - 19
// Issue with bond - 22
// Device not found - 133 or 62

try
{
try
{
JSONObject result = new JSONObject();
result.put("deviceHandle", mHandle);
result.put("state", newState);
Log.i("@@@@@@", "@@@ connect success");
keepCallback(mConnectContext, result);
}
catch(JSONException e)
{
Log.i("@@@@@@", "@@@ connect error: " + e);
e.printStackTrace();
mConnectContext.error("Connect error: " + e);
//assert(false);
}
}
else
JSONObject result = new JSONObject();
result.put("deviceHandle", mHandle);
result.put("state", newState);
result.put("status", status);
Log.i("@@@@@@", "@@@ connect success");
keepCallback(mConnectContext, result);
}
catch(JSONException e)
{
// Could this be where we get 133? Yes it is.
Log.i("@@@@@@", "@@@ connect error - status: " + status);
mConnectContext.error(status);
Log.i("@@@@@@", "@@@ connect error: " + e);
e.printStackTrace();
mConnectContext.error("Connect error: " + e);
//assert(false);
}
}

Expand Down