| 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/context_utils.h" | 7 #include "base/android/context_utils.h" |
| 8 #include "base/android/jni_android.h" | 8 #include "base/android/jni_android.h" |
| 9 #include "base/android/jni_array.h" | 9 #include "base/android/jni_array.h" |
| 10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 bluetooth_device_wrapper)); | 43 bluetooth_device_wrapper)); |
| 44 | 44 |
| 45 return device; | 45 return device; |
| 46 } | 46 } |
| 47 | 47 |
| 48 BluetoothDeviceAndroid::~BluetoothDeviceAndroid() { | 48 BluetoothDeviceAndroid::~BluetoothDeviceAndroid() { |
| 49 Java_ChromeBluetoothDevice_onBluetoothDeviceAndroidDestruction( | 49 Java_ChromeBluetoothDevice_onBluetoothDeviceAndroidDestruction( |
| 50 AttachCurrentThread(), j_device_.obj()); | 50 AttachCurrentThread(), j_device_.obj()); |
| 51 } | 51 } |
| 52 | 52 |
| 53 bool BluetoothDeviceAndroid::UpdateAdvertisedUUIDs(jobject advertised_uuids) { | 53 void BluetoothDeviceAndroid::UpdateAdvertisedUUIDs( |
| 54 return Java_ChromeBluetoothDevice_updateAdvertisedUUIDs( | 54 jobjectArray advertised_uuids) { |
| 55 AttachCurrentThread(), j_device_.obj(), advertised_uuids); | 55 JNIEnv* env = AttachCurrentThread(); |
| 56 std::vector<std::string> uuid_strings; |
| 57 AppendJavaStringArrayToStringVector(env, advertised_uuids, &uuid_strings); |
| 58 |
| 59 advertised_uuids_ = UUIDList(uuid_strings.begin(), uuid_strings.end()); |
| 56 } | 60 } |
| 57 | 61 |
| 58 // static | 62 // static |
| 59 bool BluetoothDeviceAndroid::RegisterJNI(JNIEnv* env) { | 63 bool BluetoothDeviceAndroid::RegisterJNI(JNIEnv* env) { |
| 60 return RegisterNativesImpl(env); // Generated in ChromeBluetoothDevice_jni.h | 64 return RegisterNativesImpl(env); // Generated in ChromeBluetoothDevice_jni.h |
| 61 } | 65 } |
| 62 | 66 |
| 63 base::android::ScopedJavaLocalRef<jobject> | 67 base::android::ScopedJavaLocalRef<jobject> |
| 64 BluetoothDeviceAndroid::GetJavaObject() { | 68 BluetoothDeviceAndroid::GetJavaObject() { |
| 65 return base::android::ScopedJavaLocalRef<jobject>(j_device_); | 69 return base::android::ScopedJavaLocalRef<jobject>(j_device_); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 bool BluetoothDeviceAndroid::IsConnectable() const { | 131 bool BluetoothDeviceAndroid::IsConnectable() const { |
| 128 NOTIMPLEMENTED(); | 132 NOTIMPLEMENTED(); |
| 129 return false; | 133 return false; |
| 130 } | 134 } |
| 131 | 135 |
| 132 bool BluetoothDeviceAndroid::IsConnecting() const { | 136 bool BluetoothDeviceAndroid::IsConnecting() const { |
| 133 NOTIMPLEMENTED(); | 137 NOTIMPLEMENTED(); |
| 134 return false; | 138 return false; |
| 135 } | 139 } |
| 136 | 140 |
| 137 BluetoothDevice::UUIDList BluetoothDeviceAndroid::GetUUIDs() const { | |
| 138 JNIEnv* env = AttachCurrentThread(); | |
| 139 std::vector<std::string> uuid_strings; | |
| 140 AppendJavaStringArrayToStringVector( | |
| 141 env, Java_ChromeBluetoothDevice_getUuids(env, j_device_.obj()).obj(), | |
| 142 &uuid_strings); | |
| 143 BluetoothDevice::UUIDList uuids; | |
| 144 uuids.reserve(uuid_strings.size()); | |
| 145 for (auto uuid_string : uuid_strings) { | |
| 146 uuids.push_back(BluetoothUUID(uuid_string)); | |
| 147 } | |
| 148 return uuids; | |
| 149 } | |
| 150 | |
| 151 int16_t BluetoothDeviceAndroid::GetInquiryRSSI() const { | 141 int16_t BluetoothDeviceAndroid::GetInquiryRSSI() const { |
| 152 NOTIMPLEMENTED(); | 142 NOTIMPLEMENTED(); |
| 153 return kUnknownPower; | 143 return kUnknownPower; |
| 154 } | 144 } |
| 155 | 145 |
| 156 int16_t BluetoothDeviceAndroid::GetInquiryTxPower() const { | 146 int16_t BluetoothDeviceAndroid::GetInquiryTxPower() const { |
| 157 NOTIMPLEMENTED(); | 147 NOTIMPLEMENTED(); |
| 158 return kUnknownPower; | 148 return kUnknownPower; |
| 159 } | 149 } |
| 160 | 150 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 // We assume that if there are any pending connection callbacks there | 234 // We assume that if there are any pending connection callbacks there |
| 245 // was a failed connection attempt. | 235 // was a failed connection attempt. |
| 246 RecordConnectionFailureResult(status); | 236 RecordConnectionFailureResult(status); |
| 247 // TODO(ortuno): Return an error code based on |status| | 237 // TODO(ortuno): Return an error code based on |status| |
| 248 // http://crbug.com/578191 | 238 // http://crbug.com/578191 |
| 249 DidFailToConnectGatt(ERROR_FAILED); | 239 DidFailToConnectGatt(ERROR_FAILED); |
| 250 } else { | 240 } else { |
| 251 // Otherwise an existing connection was terminated. | 241 // Otherwise an existing connection was terminated. |
| 252 RecordConnectionTerminatedResult(status); | 242 RecordConnectionTerminatedResult(status); |
| 253 gatt_services_.clear(); | 243 gatt_services_.clear(); |
| 244 service_uuids_.clear(); |
| 254 SetGattServicesDiscoveryComplete(false); | 245 SetGattServicesDiscoveryComplete(false); |
| 255 DidDisconnectGatt(); | 246 DidDisconnectGatt(); |
| 256 } | 247 } |
| 257 } | 248 } |
| 258 | 249 |
| 259 void BluetoothDeviceAndroid::OnGattServicesDiscovered( | 250 void BluetoothDeviceAndroid::OnGattServicesDiscovered( |
| 260 JNIEnv* env, | 251 JNIEnv* env, |
| 261 const JavaParamRef<jobject>& jcaller) { | 252 const JavaParamRef<jobject>& jcaller) { |
| 253 UpdateServiceUUIDs(); |
| 262 SetGattServicesDiscoveryComplete(true); | 254 SetGattServicesDiscoveryComplete(true); |
| 263 adapter_->NotifyGattServicesDiscovered(this); | 255 adapter_->NotifyGattServicesDiscovered(this); |
| 264 } | 256 } |
| 265 | 257 |
| 266 void BluetoothDeviceAndroid::CreateGattRemoteService( | 258 void BluetoothDeviceAndroid::CreateGattRemoteService( |
| 267 JNIEnv* env, | 259 JNIEnv* env, |
| 268 const JavaParamRef<jobject>& caller, | 260 const JavaParamRef<jobject>& caller, |
| 269 const JavaParamRef<jstring>& instance_id, | 261 const JavaParamRef<jstring>& instance_id, |
| 270 const JavaParamRef<jobject>& | 262 const JavaParamRef<jobject>& |
| 271 bluetooth_gatt_service_wrapper) { // BluetoothGattServiceWrapper | 263 bluetooth_gatt_service_wrapper) { // BluetoothGattServiceWrapper |
| (...skipping 21 matching lines...) Expand all Loading... |
| 293 AttachCurrentThread(), j_device_.obj(), | 285 AttachCurrentThread(), j_device_.obj(), |
| 294 base::android::GetApplicationContext()); | 286 base::android::GetApplicationContext()); |
| 295 } | 287 } |
| 296 | 288 |
| 297 void BluetoothDeviceAndroid::DisconnectGatt() { | 289 void BluetoothDeviceAndroid::DisconnectGatt() { |
| 298 Java_ChromeBluetoothDevice_disconnectGatt(AttachCurrentThread(), | 290 Java_ChromeBluetoothDevice_disconnectGatt(AttachCurrentThread(), |
| 299 j_device_.obj()); | 291 j_device_.obj()); |
| 300 } | 292 } |
| 301 | 293 |
| 302 } // namespace device | 294 } // namespace device |
| OLD | NEW |