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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 void BluetoothDeviceAndroid::RejectPairing() { | 166 void BluetoothDeviceAndroid::RejectPairing() { |
161 NOTIMPLEMENTED(); | 167 NOTIMPLEMENTED(); |
162 } | 168 } |
163 | 169 |
164 void BluetoothDeviceAndroid::CancelPairing() { | 170 void BluetoothDeviceAndroid::CancelPairing() { |
165 NOTIMPLEMENTED(); | 171 NOTIMPLEMENTED(); |
166 } | 172 } |
167 | 173 |
168 void BluetoothDeviceAndroid::Disconnect(const base::Closure& callback, | 174 void BluetoothDeviceAndroid::Disconnect(const base::Closure& callback, |
169 const ErrorCallback& error_callback) { | 175 const ErrorCallback& error_callback) { |
176 // TODO(scheib): Also update unit tests for BluetoothGattConnection. | |
170 NOTIMPLEMENTED(); | 177 NOTIMPLEMENTED(); |
171 } | 178 } |
172 | 179 |
173 void BluetoothDeviceAndroid::Forget(const ErrorCallback& error_callback) { | 180 void BluetoothDeviceAndroid::Forget(const ErrorCallback& error_callback) { |
174 NOTIMPLEMENTED(); | 181 NOTIMPLEMENTED(); |
175 } | 182 } |
176 | 183 |
177 void BluetoothDeviceAndroid::ConnectToService( | 184 void BluetoothDeviceAndroid::ConnectToService( |
178 const BluetoothUUID& uuid, | 185 const BluetoothUUID& uuid, |
179 const ConnectToServiceCallback& callback, | 186 const ConnectToServiceCallback& callback, |
180 const ConnectToServiceErrorCallback& error_callback) { | 187 const ConnectToServiceErrorCallback& error_callback) { |
181 NOTIMPLEMENTED(); | 188 NOTIMPLEMENTED(); |
182 } | 189 } |
183 | 190 |
184 void BluetoothDeviceAndroid::ConnectToServiceInsecurely( | 191 void BluetoothDeviceAndroid::ConnectToServiceInsecurely( |
185 const BluetoothUUID& uuid, | 192 const BluetoothUUID& uuid, |
186 const ConnectToServiceCallback& callback, | 193 const ConnectToServiceCallback& callback, |
187 const ConnectToServiceErrorCallback& error_callback) { | 194 const ConnectToServiceErrorCallback& error_callback) { |
188 NOTIMPLEMENTED(); | 195 NOTIMPLEMENTED(); |
189 } | 196 } |
190 | 197 |
198 void BluetoothDeviceAndroid::OnConnectionStateChange(JNIEnv* env, | |
199 jobject jcaller, | |
200 int32_t status, | |
201 bool connected) { | |
202 gatt_connected_ = connected; | |
203 if (gatt_connected_) { | |
204 DidConnectGatt(); | |
205 } else { | |
206 // TODO(scheib) Increase BluetoothDevice::ConnectErrorCode enums for | |
Jeffrey Yasskin
2015/09/16 01:40:49
"Increase"? Maybe "Create new"?
scheib
2015/09/16 21:55:17
Done.
| |
207 // android values not yet represented. http://crbug.com/531058 | |
208 switch (status) { // Constants are from android.bluetooth.BluetoothGatt. | |
209 case 0x00000101: // GATT_FAILURE | |
210 return DidFailToConnectGatt(ERROR_FAILED); | |
211 case 0x00000005: // GATT_INSUFFICIENT_AUTHENTICATION | |
212 return DidFailToConnectGatt(ERROR_AUTH_FAILED); | |
213 case 0x00000000: // GATT_SUCCESS | |
214 return DidDisconnectGatt(); | |
215 default: | |
216 VLOG(1) << "Unhandled status: " << status; | |
217 return DidFailToConnectGatt(ERROR_UNKNOWN); | |
218 } | |
219 } | |
220 } | |
221 | |
191 BluetoothDeviceAndroid::BluetoothDeviceAndroid(BluetoothAdapterAndroid* adapter) | 222 BluetoothDeviceAndroid::BluetoothDeviceAndroid(BluetoothAdapterAndroid* adapter) |
192 : BluetoothDevice(adapter) {} | 223 : BluetoothDevice(adapter) {} |
193 | 224 |
194 std::string BluetoothDeviceAndroid::GetDeviceName() const { | 225 std::string BluetoothDeviceAndroid::GetDeviceName() const { |
195 return ConvertJavaStringToUTF8(Java_ChromeBluetoothDevice_getDeviceName( | 226 return ConvertJavaStringToUTF8(Java_ChromeBluetoothDevice_getDeviceName( |
196 AttachCurrentThread(), j_device_.obj())); | 227 AttachCurrentThread(), j_device_.obj())); |
197 } | 228 } |
198 | 229 |
199 void BluetoothDeviceAndroid::CreateGattConnectionImpl() { | 230 void BluetoothDeviceAndroid::CreateGattConnectionImpl() { |
200 // Implemented in following patch https://codereview.chromium.org/1256313002 | 231 Java_ChromeBluetoothDevice_createGattConnectionImpl( |
201 NOTIMPLEMENTED(); | 232 AttachCurrentThread(), j_device_.obj(), |
202 DidFailToConnectGatt(ERROR_UNKNOWN); | 233 base::android::GetApplicationContext()); |
203 } | 234 } |
204 | 235 |
205 void BluetoothDeviceAndroid::DisconnectGatt() { | 236 void BluetoothDeviceAndroid::DisconnectGatt() { |
206 // Implemented in following patch https://codereview.chromium.org/1256313002 | 237 Java_ChromeBluetoothDevice_disconnectGatt(AttachCurrentThread(), |
207 NOTIMPLEMENTED(); | 238 j_device_.obj()); |
208 } | 239 } |
209 | 240 |
210 } // namespace device | 241 } // namespace device |
OLD | NEW |