OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "device/bluetooth/bluetooth_device_android.h" | 5 #include "device/bluetooth/bluetooth_device_android.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/jni_array.h" | 8 #include "base/android/jni_array.h" |
9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
10 #include "device/bluetooth/bluetooth_adapter_android.h" | 10 #include "device/bluetooth/bluetooth_adapter_android.h" |
11 #include "jni/ChromeBluetoothDevice_jni.h" | 11 #include "jni/ChromeBluetoothDevice_jni.h" |
12 | 12 |
13 using base::android::AttachCurrentThread; | 13 using base::android::AttachCurrentThread; |
14 using base::android::AppendJavaStringArrayToStringVector; | 14 using base::android::AppendJavaStringArrayToStringVector; |
15 | 15 |
16 namespace device { | 16 namespace device { |
17 | 17 |
18 BluetoothDeviceAndroid* BluetoothDeviceAndroid::Create( | 18 BluetoothDeviceAndroid* BluetoothDeviceAndroid::Create( |
19 BluetoothAdapterAndroid* adapter, | 19 BluetoothAdapterAndroid* adapter, |
20 jobject bluetooth_device_wrapper) { // Java Type: bluetoothDeviceWrapper | 20 jobject bluetooth_device_wrapper) { // Java Type: bluetoothDeviceWrapper |
21 BluetoothDeviceAndroid* device = new BluetoothDeviceAndroid(adapter); | 21 BluetoothDeviceAndroid* device = new BluetoothDeviceAndroid(adapter); |
22 | 22 |
23 device->j_device_.Reset(Java_ChromeBluetoothDevice_create( | 23 device->j_device_.Reset(Java_ChromeBluetoothDevice_create( |
24 AttachCurrentThread(), bluetooth_device_wrapper)); | 24 AttachCurrentThread(), reinterpret_cast<intptr_t>(device), |
25 bluetooth_device_wrapper)); | |
25 | 26 |
26 return device; | 27 return device; |
27 } | 28 } |
28 | 29 |
29 BluetoothDeviceAndroid::~BluetoothDeviceAndroid() { | 30 BluetoothDeviceAndroid::~BluetoothDeviceAndroid() { |
30 } | 31 } |
31 | 32 |
32 bool BluetoothDeviceAndroid::UpdateAdvertisedUUIDs(jobject advertised_uuids) { | 33 bool BluetoothDeviceAndroid::UpdateAdvertisedUUIDs(jobject advertised_uuids) { |
33 return Java_ChromeBluetoothDevice_updateAdvertisedUUIDs( | 34 return Java_ChromeBluetoothDevice_updateAdvertisedUUIDs( |
34 AttachCurrentThread(), j_device_.obj(), advertised_uuids); | 35 AttachCurrentThread(), j_device_.obj(), advertised_uuids); |
35 } | 36 } |
36 | 37 |
37 // static | 38 // static |
38 bool BluetoothDeviceAndroid::RegisterJNI(JNIEnv* env) { | 39 bool BluetoothDeviceAndroid::RegisterJNI(JNIEnv* env) { |
39 return RegisterNativesImpl(env); // Generated in ChromeBluetoothDevice_jni.h | 40 return RegisterNativesImpl(env); // Generated in ChromeBluetoothDevice_jni.h |
40 } | 41 } |
41 | 42 |
43 base::android::ScopedJavaLocalRef<jobject> | |
44 BluetoothDeviceAndroid::GetJavaObject() { | |
45 return base::android::ScopedJavaLocalRef<jobject>(j_device_); | |
46 } | |
47 | |
42 uint32 BluetoothDeviceAndroid::GetBluetoothClass() const { | 48 uint32 BluetoothDeviceAndroid::GetBluetoothClass() const { |
43 return Java_ChromeBluetoothDevice_getBluetoothClass(AttachCurrentThread(), | 49 return Java_ChromeBluetoothDevice_getBluetoothClass(AttachCurrentThread(), |
44 j_device_.obj()); | 50 j_device_.obj()); |
45 } | 51 } |
46 | 52 |
47 std::string BluetoothDeviceAndroid::GetAddress() const { | 53 std::string BluetoothDeviceAndroid::GetAddress() const { |
48 return ConvertJavaStringToUTF8(Java_ChromeBluetoothDevice_getAddress( | 54 return ConvertJavaStringToUTF8(Java_ChromeBluetoothDevice_getAddress( |
49 AttachCurrentThread(), j_device_.obj())); | 55 AttachCurrentThread(), j_device_.obj())); |
50 } | 56 } |
51 | 57 |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
181 NOTIMPLEMENTED(); | 187 NOTIMPLEMENTED(); |
182 } | 188 } |
183 | 189 |
184 void BluetoothDeviceAndroid::ConnectToServiceInsecurely( | 190 void BluetoothDeviceAndroid::ConnectToServiceInsecurely( |
185 const BluetoothUUID& uuid, | 191 const BluetoothUUID& uuid, |
186 const ConnectToServiceCallback& callback, | 192 const ConnectToServiceCallback& callback, |
187 const ConnectToServiceErrorCallback& error_callback) { | 193 const ConnectToServiceErrorCallback& error_callback) { |
188 NOTIMPLEMENTED(); | 194 NOTIMPLEMENTED(); |
189 } | 195 } |
190 | 196 |
197 void BluetoothDeviceAndroid::OnConnectionStateChange(JNIEnv* env, | |
198 jobject jcaller, | |
199 int32_t status, | |
200 bool connected) { | |
201 gatt_connected_ = connected; | |
202 if (gatt_connected_) { | |
203 DidConnectGatt(); | |
204 } else { | |
205 switch (status) { // Constants are from android.bluetooth.BluetoothGatt. | |
206 case 0x00000101: // GATT_FAILURE | |
207 return DidFailToConnectGatt(ERROR_FAILED); | |
208 case 0x00000005: // GATT_INSUFFICIENT_AUTHENTICATION | |
209 return DidFailToConnectGatt(ERROR_AUTH_FAILED); | |
210 case 0x00000000: // GATT_SUCCESS | |
211 return DidDisconnectGatt(); | |
212 default: | |
213 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.
| |
214 } | |
215 } | |
191 } | 216 } |
192 | 217 |
193 BluetoothDeviceAndroid::BluetoothDeviceAndroid(BluetoothAdapterAndroid* adapter) | 218 BluetoothDeviceAndroid::BluetoothDeviceAndroid(BluetoothAdapterAndroid* adapter) |
194 : BluetoothDevice(adapter) {} | 219 : BluetoothDevice(adapter) {} |
195 | 220 |
196 std::string BluetoothDeviceAndroid::GetDeviceName() const { | 221 std::string BluetoothDeviceAndroid::GetDeviceName() const { |
197 return ConvertJavaStringToUTF8(Java_ChromeBluetoothDevice_getDeviceName( | 222 return ConvertJavaStringToUTF8(Java_ChromeBluetoothDevice_getDeviceName( |
198 AttachCurrentThread(), j_device_.obj())); | 223 AttachCurrentThread(), j_device_.obj())); |
199 } | 224 } |
200 | 225 |
201 void BluetoothDeviceAndroid::CreateGattConnectionImpl() { | 226 void BluetoothDeviceAndroid::CreateGattConnectionImpl() { |
202 // Implemented in following patch https://codereview.chromium.org/1256313002 | 227 if (!Java_ChromeBluetoothDevice_createGattConnectionImpl( |
203 NOTIMPLEMENTED(); | 228 AttachCurrentThread(), j_device_.obj(), |
204 DidFailToConnectGatt(ERROR_UNKNOWN); | 229 base::android::GetApplicationContext())) |
230 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
| |
205 } | 231 } |
206 | 232 |
207 void BluetoothDeviceAndroid::DisconnectGatt() { | 233 void BluetoothDeviceAndroid::DisconnectGatt() { |
208 // Implemented in following patch https://codereview.chromium.org/1256313002 | 234 Java_ChromeBluetoothDevice_disconnectGatt(AttachCurrentThread(), |
209 NOTIMPLEMENTED(); | 235 j_device_.obj()); |
210 } | 236 } |
211 | 237 |
212 } // namespace device | 238 } // namespace device |
OLD | NEW |