Merge "Make connection / disconnect failure more robust." into honeycomb
This commit is contained in:
committed by
Android (Google) Code Review
commit
7457b36b92
@@ -85,6 +85,19 @@ public final class BluetoothInputDevice {
|
||||
*/
|
||||
public static final int PRIORITY_UNDEFINED = -1;
|
||||
|
||||
/**
|
||||
* Return codes for the connect and disconnect Bluez / Dbus calls.
|
||||
*/
|
||||
public static final int INPUT_DISCONNECT_FAILED_NOT_CONNECTED = 5000;
|
||||
|
||||
public static final int INPUT_CONNECT_FAILED_ALREADY_CONNECTED = 5001;
|
||||
|
||||
public static final int INPUT_CONNECT_FAILED_ATTEMPT_FAILED = 5002;
|
||||
|
||||
public static final int INPUT_OPERATION_GENERIC_FAILURE = 5003;
|
||||
|
||||
public static final int INPUT_OPERATION_SUCCESS = 5004;
|
||||
|
||||
private final IBluetooth mService;
|
||||
private final Context mContext;
|
||||
|
||||
|
||||
@@ -70,6 +70,19 @@ public final class BluetoothPan {
|
||||
public static final int STATE_CONNECTED = 2;
|
||||
public static final int STATE_DISCONNECTING = 3;
|
||||
|
||||
/**
|
||||
* Return codes for the connect and disconnect Bluez / Dbus calls.
|
||||
*/
|
||||
public static final int PAN_DISCONNECT_FAILED_NOT_CONNECTED = 1000;
|
||||
|
||||
public static final int PAN_CONNECT_FAILED_ALREADY_CONNECTED = 1001;
|
||||
|
||||
public static final int PAN_CONNECT_FAILED_ATTEMPT_FAILED = 1002;
|
||||
|
||||
public static final int PAN_OPERATION_GENERIC_FAILURE = 1003;
|
||||
|
||||
public static final int PAN_OPERATION_SUCCESS = 1004;
|
||||
|
||||
private final IBluetooth mService;
|
||||
private final Context mContext;
|
||||
|
||||
|
||||
@@ -748,9 +748,9 @@ class BluetoothEventLoop {
|
||||
}
|
||||
}
|
||||
|
||||
private void onInputDeviceConnectionResult(String path, boolean result) {
|
||||
private void onInputDeviceConnectionResult(String path, int result) {
|
||||
// Success case gets handled by Property Change signal
|
||||
if (!result) {
|
||||
if (result != BluetoothInputDevice.INPUT_OPERATION_SUCCESS) {
|
||||
String address = mBluetoothService.getAddressFromObjectPath(path);
|
||||
if (address == null) return;
|
||||
|
||||
@@ -758,9 +758,18 @@ class BluetoothEventLoop {
|
||||
BluetoothDevice device = mAdapter.getRemoteDevice(address);
|
||||
int state = mBluetoothService.getInputDeviceState(device);
|
||||
if (state == BluetoothInputDevice.STATE_CONNECTING) {
|
||||
connected = false;
|
||||
if (result == BluetoothInputDevice.INPUT_CONNECT_FAILED_ALREADY_CONNECTED) {
|
||||
connected = true;
|
||||
} else {
|
||||
connected = false;
|
||||
}
|
||||
} else if (state == BluetoothInputDevice.STATE_DISCONNECTING) {
|
||||
connected = true;
|
||||
if (result == BluetoothInputDevice.INPUT_DISCONNECT_FAILED_NOT_CONNECTED) {
|
||||
connected = false;
|
||||
} else {
|
||||
// There is no better way to handle this, this shouldn't happen
|
||||
connected = true;
|
||||
}
|
||||
} else {
|
||||
Log.e(TAG, "Error onInputDeviceConnectionResult. State is:" + state);
|
||||
}
|
||||
@@ -768,10 +777,10 @@ class BluetoothEventLoop {
|
||||
}
|
||||
}
|
||||
|
||||
private void onPanDeviceConnectionResult(String path, boolean result) {
|
||||
private void onPanDeviceConnectionResult(String path, int result) {
|
||||
log ("onPanDeviceConnectionResult " + path + " " + result);
|
||||
// Success case gets handled by Property Change signal
|
||||
if (!result) {
|
||||
if (result != BluetoothPan.PAN_OPERATION_SUCCESS) {
|
||||
String address = mBluetoothService.getAddressFromObjectPath(path);
|
||||
if (address == null) return;
|
||||
|
||||
@@ -779,9 +788,18 @@ class BluetoothEventLoop {
|
||||
BluetoothDevice device = mAdapter.getRemoteDevice(address);
|
||||
int state = mBluetoothService.getPanDeviceState(device);
|
||||
if (state == BluetoothPan.STATE_CONNECTING) {
|
||||
connected = false;
|
||||
if (result == BluetoothPan.PAN_CONNECT_FAILED_ALREADY_CONNECTED) {
|
||||
connected = true;
|
||||
} else {
|
||||
connected = false;
|
||||
}
|
||||
} else if (state == BluetoothPan.STATE_DISCONNECTING) {
|
||||
connected = true;
|
||||
if (result == BluetoothPan.PAN_DISCONNECT_FAILED_NOT_CONNECTED) {
|
||||
connected = false;
|
||||
} else {
|
||||
// There is no better way to handle this, this shouldn't happen
|
||||
connected = true;
|
||||
}
|
||||
} else {
|
||||
Log.e(TAG, "Error onPanDeviceConnectionResult. State is: "
|
||||
+ state + " result: "+ result);
|
||||
|
||||
@@ -38,6 +38,7 @@ namespace android {
|
||||
#ifdef HAVE_BLUETOOTH
|
||||
#define BLUEZ_DBUS_BASE_PATH "/org/bluez"
|
||||
#define BLUEZ_DBUS_BASE_IFC "org.bluez"
|
||||
#define BLUEZ_ERROR_IFC "org.bluez.Error"
|
||||
|
||||
// It would be nicer to retrieve this from bluez using GetDefaultAdapter,
|
||||
// but this is only possible when the adapter is up (and hcid is running).
|
||||
@@ -171,6 +172,30 @@ void get_bdaddr_as_string(const bdaddr_t *ba, char *str);
|
||||
|
||||
bool debug_no_encrypt();
|
||||
|
||||
|
||||
// Result codes from Bluez DBus calls
|
||||
#define BOND_RESULT_ERROR -1
|
||||
#define BOND_RESULT_SUCCESS 0
|
||||
#define BOND_RESULT_AUTH_FAILED 1
|
||||
#define BOND_RESULT_AUTH_REJECTED 2
|
||||
#define BOND_RESULT_AUTH_CANCELED 3
|
||||
#define BOND_RESULT_REMOTE_DEVICE_DOWN 4
|
||||
#define BOND_RESULT_DISCOVERY_IN_PROGRESS 5
|
||||
#define BOND_RESULT_AUTH_TIMEOUT 6
|
||||
#define BOND_RESULT_REPEATED_ATTEMPTS 7
|
||||
|
||||
#define PAN_DISCONNECT_FAILED_NOT_CONNECTED 1000
|
||||
#define PAN_CONNECT_FAILED_ALREADY_CONNECTED 1001
|
||||
#define PAN_CONNECT_FAILED_ATTEMPT_FAILED 1002
|
||||
#define PAN_OPERATION_GENERIC_FAILURE 1003
|
||||
#define PAN_OPERATION_SUCCESS 1004
|
||||
|
||||
#define INPUT_DISCONNECT_FAILED_NOT_CONNECTED 5000
|
||||
#define INPUT_CONNECT_FAILED_ALREADY_CONNECTED 5001
|
||||
#define INPUT_CONNECT_FAILED_ATTEMPT_FAILED 5002
|
||||
#define INPUT_OPERATION_GENERIC_FAILURE 5003
|
||||
#define INPUT_OPERATION_SUCCESS 5004
|
||||
|
||||
#endif
|
||||
} /* namespace android */
|
||||
|
||||
|
||||
@@ -134,11 +134,11 @@ static void classInitNative(JNIEnv* env, jclass clazz) {
|
||||
method_onInputDevicePropertyChanged = env->GetMethodID(clazz, "onInputDevicePropertyChanged",
|
||||
"(Ljava/lang/String;[Ljava/lang/String;)V");
|
||||
method_onInputDeviceConnectionResult = env->GetMethodID(clazz, "onInputDeviceConnectionResult",
|
||||
"(Ljava/lang/String;Z)V");
|
||||
"(Ljava/lang/String;I)V");
|
||||
method_onPanDevicePropertyChanged = env->GetMethodID(clazz, "onPanDevicePropertyChanged",
|
||||
"(Ljava/lang/String;[Ljava/lang/String;)V");
|
||||
method_onPanDeviceConnectionResult = env->GetMethodID(clazz, "onPanDeviceConnectionResult",
|
||||
"(Ljava/lang/String;Z)V");
|
||||
"(Ljava/lang/String;I)V");
|
||||
method_onRequestOobData = env->GetMethodID(clazz, "onRequestOobData",
|
||||
"(Ljava/lang/String;I)V");
|
||||
|
||||
@@ -1227,16 +1227,6 @@ success:
|
||||
|
||||
|
||||
#ifdef HAVE_BLUETOOTH
|
||||
//TODO: Unify result codes in a header
|
||||
#define BOND_RESULT_ERROR -1000
|
||||
#define BOND_RESULT_SUCCESS 0
|
||||
#define BOND_RESULT_AUTH_FAILED 1
|
||||
#define BOND_RESULT_AUTH_REJECTED 2
|
||||
#define BOND_RESULT_AUTH_CANCELED 3
|
||||
#define BOND_RESULT_REMOTE_DEVICE_DOWN 4
|
||||
#define BOND_RESULT_DISCOVERY_IN_PROGRESS 5
|
||||
#define BOND_RESULT_AUTH_TIMEOUT 6
|
||||
#define BOND_RESULT_REPEATED_ATTEMPTS 7
|
||||
|
||||
void onCreatePairedDeviceResult(DBusMessage *msg, void *user, void *n) {
|
||||
LOGV(__FUNCTION__);
|
||||
@@ -1406,11 +1396,25 @@ void onInputDeviceConnectionResult(DBusMessage *msg, void *user, void *n) {
|
||||
JNIEnv *env;
|
||||
nat->vm->GetEnv((void**)&env, nat->envVer);
|
||||
|
||||
bool result = JNI_TRUE;
|
||||
jint result = INPUT_OPERATION_SUCCESS;
|
||||
if (dbus_set_error_from_message(&err, msg)) {
|
||||
if (!strcmp(err.name, BLUEZ_ERROR_IFC ".ConnectionAttemptFailed")) {
|
||||
result = INPUT_CONNECT_FAILED_ATTEMPT_FAILED;
|
||||
} else if (!strcmp(err.name, BLUEZ_ERROR_IFC ".AlreadyConnected")) {
|
||||
result = INPUT_CONNECT_FAILED_ALREADY_CONNECTED;
|
||||
} else if (!strcmp(err.name, BLUEZ_ERROR_IFC ".Failed")) {
|
||||
// TODO():This is flaky, need to change Bluez to add new error codes
|
||||
if (!strcmp(err.message, "Transport endpoint is not connected")) {
|
||||
result = INPUT_DISCONNECT_FAILED_NOT_CONNECTED;
|
||||
} else {
|
||||
result = INPUT_OPERATION_GENERIC_FAILURE;
|
||||
}
|
||||
} else {
|
||||
result = INPUT_OPERATION_GENERIC_FAILURE;
|
||||
}
|
||||
LOG_AND_FREE_DBUS_ERROR(&err);
|
||||
result = JNI_FALSE;
|
||||
}
|
||||
|
||||
LOGV("... Device Path = %s, result = %d", path, result);
|
||||
jstring jPath = env->NewStringUTF(path);
|
||||
env->CallVoidMethod(nat->me,
|
||||
@@ -1431,11 +1435,25 @@ void onPanDeviceConnectionResult(DBusMessage *msg, void *user, void *n) {
|
||||
JNIEnv *env;
|
||||
nat->vm->GetEnv((void**)&env, nat->envVer);
|
||||
|
||||
bool result = JNI_TRUE;
|
||||
jint result = PAN_OPERATION_SUCCESS;
|
||||
if (dbus_set_error_from_message(&err, msg)) {
|
||||
if (!strcmp(err.name, BLUEZ_ERROR_IFC ".ConnectionAttemptFailed")) {
|
||||
result = PAN_CONNECT_FAILED_ATTEMPT_FAILED;
|
||||
} else if (!strcmp(err.name, BLUEZ_ERROR_IFC ".Failed")) {
|
||||
// TODO():This is flaky, need to change Bluez to add new error codes
|
||||
if (!strcmp(err.message, "Device already connected")) {
|
||||
result = PAN_CONNECT_FAILED_ALREADY_CONNECTED;
|
||||
} else if (!strcmp(err.message, "Device not connected")) {
|
||||
result = PAN_DISCONNECT_FAILED_NOT_CONNECTED;
|
||||
} else {
|
||||
result = PAN_OPERATION_GENERIC_FAILURE;
|
||||
}
|
||||
} else {
|
||||
result = PAN_OPERATION_GENERIC_FAILURE;
|
||||
}
|
||||
LOG_AND_FREE_DBUS_ERROR(&err);
|
||||
result = JNI_FALSE;
|
||||
}
|
||||
|
||||
LOGV("... Pan Device Path = %s, result = %d", path, result);
|
||||
jstring jPath = env->NewStringUTF(path);
|
||||
env->CallVoidMethod(nat->me,
|
||||
|
||||
Reference in New Issue
Block a user