Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1944)

Unified Diff: device/bluetooth/bluetooth_device_android.cc

Issue 1256313002: bluetooth: android: Implement & test CreateGattConnection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated patchset dependency Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: device/bluetooth/bluetooth_device_android.cc
diff --git a/device/bluetooth/bluetooth_device_android.cc b/device/bluetooth/bluetooth_device_android.cc
index 6dac465163bc8c2f4e47def44be3abd22ed536b0..5e5b204f6e6a9acd8a5f6320a9b26dc8090d663a 100644
--- a/device/bluetooth/bluetooth_device_android.cc
+++ b/device/bluetooth/bluetooth_device_android.cc
@@ -21,7 +21,8 @@ BluetoothDeviceAndroid* BluetoothDeviceAndroid::Create(
BluetoothDeviceAndroid* device = new BluetoothDeviceAndroid(adapter);
device->j_device_.Reset(Java_ChromeBluetoothDevice_create(
- AttachCurrentThread(), bluetooth_device_wrapper));
+ AttachCurrentThread(), reinterpret_cast<intptr_t>(device),
+ bluetooth_device_wrapper));
return device;
}
@@ -39,6 +40,11 @@ bool BluetoothDeviceAndroid::RegisterJNI(JNIEnv* env) {
return RegisterNativesImpl(env); // Generated in ChromeBluetoothDevice_jni.h
}
+base::android::ScopedJavaLocalRef<jobject>
+BluetoothDeviceAndroid::GetJavaObject() {
+ return base::android::ScopedJavaLocalRef<jobject>(j_device_);
+}
+
uint32 BluetoothDeviceAndroid::GetBluetoothClass() const {
return Java_ChromeBluetoothDevice_getBluetoothClass(AttachCurrentThread(),
j_device_.obj());
@@ -188,6 +194,25 @@ void BluetoothDeviceAndroid::ConnectToServiceInsecurely(
NOTIMPLEMENTED();
}
+void BluetoothDeviceAndroid::OnConnectionStateChange(JNIEnv* env,
+ jobject jcaller,
+ int32_t status,
+ bool connected) {
+ gatt_connected_ = connected;
+ if (gatt_connected_) {
+ DidConnectGatt();
+ } else {
+ switch (status) { // Constants are from android.bluetooth.BluetoothGatt.
+ case 0x00000101: // GATT_FAILURE
+ return DidFailToConnectGatt(ERROR_FAILED);
+ case 0x00000005: // GATT_INSUFFICIENT_AUTHENTICATION
+ return DidFailToConnectGatt(ERROR_AUTH_FAILED);
+ case 0x00000000: // GATT_SUCCESS
+ return DidDisconnectGatt();
+ default:
+ return DidFailToConnectGatt(ERROR_UNKNOWN);
Jeffrey Yasskin 2015/08/20 21:35:14 Log here so we know what error to add a translatio
scheib 2015/09/13 02:41:01 Done.
+ }
+ }
}
BluetoothDeviceAndroid::BluetoothDeviceAndroid(BluetoothAdapterAndroid* adapter)
@@ -199,14 +224,15 @@ std::string BluetoothDeviceAndroid::GetDeviceName() const {
}
void BluetoothDeviceAndroid::CreateGattConnectionImpl() {
- // Implemented in following patch https://codereview.chromium.org/1256313002
- NOTIMPLEMENTED();
- DidFailToConnectGatt(ERROR_UNKNOWN);
+ if (!Java_ChromeBluetoothDevice_createGattConnectionImpl(
+ AttachCurrentThread(), j_device_.obj(),
+ base::android::GetApplicationContext()))
+ DidFailToConnectGatt(ERROR_UNKNOWN);
Jeffrey Yasskin 2015/08/20 21:35:14 Pick a better error enum.
scheib 2015/09/13 02:41:01 Done. This method no longer has synchronous errors
}
void BluetoothDeviceAndroid::DisconnectGatt() {
- // Implemented in following patch https://codereview.chromium.org/1256313002
- NOTIMPLEMENTED();
+ Java_ChromeBluetoothDevice_disconnectGatt(AttachCurrentThread(),
+ j_device_.obj());
}
} // namespace device

Powered by Google App Engine
This is Rietveld 408576698