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

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: Split tests up into smaller tests Created 5 years, 3 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
« no previous file with comments | « device/bluetooth/bluetooth_device_android.h ('k') | device/bluetooth/bluetooth_device_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/bluetooth/bluetooth_device_android.cc
diff --git a/device/bluetooth/bluetooth_device_android.cc b/device/bluetooth/bluetooth_device_android.cc
index 483d95e05a0e4a3d46088439e5df7656f2ed9ffa..244ab0233d167c34fc1f3128da13ed13b0d161f3 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());
@@ -167,6 +173,7 @@ void BluetoothDeviceAndroid::CancelPairing() {
void BluetoothDeviceAndroid::Disconnect(const base::Closure& callback,
const ErrorCallback& error_callback) {
+ // TODO(scheib): Also update unit tests for BluetoothGattConnection.
NOTIMPLEMENTED();
}
@@ -188,6 +195,30 @@ void BluetoothDeviceAndroid::ConnectToServiceInsecurely(
NOTIMPLEMENTED();
}
+void BluetoothDeviceAndroid::OnConnectionStateChange(JNIEnv* env,
+ jobject jcaller,
+ int32_t status,
+ bool connected) {
+ gatt_connected_ = connected;
+ if (gatt_connected_) {
+ DidConnectGatt();
+ } else {
+ // TODO(scheib) Create new BluetoothDevice::ConnectErrorCode enums for
+ // android values not yet represented. http://crbug.com/531058
+ 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:
+ VLOG(1) << "Unhandled status: " << status;
+ return DidFailToConnectGatt(ERROR_UNKNOWN);
+ }
+ }
+}
+
BluetoothDeviceAndroid::BluetoothDeviceAndroid(BluetoothAdapterAndroid* adapter)
: BluetoothDevice(adapter) {}
@@ -197,14 +228,14 @@ std::string BluetoothDeviceAndroid::GetDeviceName() const {
}
void BluetoothDeviceAndroid::CreateGattConnectionImpl() {
- // Implemented in following patch https://codereview.chromium.org/1256313002
- NOTIMPLEMENTED();
- DidFailToConnectGatt(ERROR_UNKNOWN);
+ Java_ChromeBluetoothDevice_createGattConnectionImpl(
+ AttachCurrentThread(), j_device_.obj(),
+ base::android::GetApplicationContext());
}
void BluetoothDeviceAndroid::DisconnectGatt() {
- // Implemented in following patch https://codereview.chromium.org/1256313002
- NOTIMPLEMENTED();
+ Java_ChromeBluetoothDevice_disconnectGatt(AttachCurrentThread(),
+ j_device_.obj());
}
} // namespace device
« no previous file with comments | « device/bluetooth/bluetooth_device_android.h ('k') | device/bluetooth/bluetooth_device_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698