| 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/test/bluetooth_test_android.h" | 5 #include "device/bluetooth/test/bluetooth_test_android.h" |
| 6 | 6 |
| 7 #include <iterator> | 7 #include <iterator> |
| 8 #include <sstream> | 8 #include <sstream> |
| 9 | 9 |
| 10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 } | 48 } |
| 49 EXPECT_EQ(0, gatt_open_connections_); | 49 EXPECT_EQ(0, gatt_open_connections_); |
| 50 BluetoothTestBase::TearDown(); | 50 BluetoothTestBase::TearDown(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 bool BluetoothTestAndroid::PlatformSupportsLowEnergy() { | 53 bool BluetoothTestAndroid::PlatformSupportsLowEnergy() { |
| 54 return true; | 54 return true; |
| 55 } | 55 } |
| 56 | 56 |
| 57 void BluetoothTestAndroid::InitWithDefaultAdapter() { | 57 void BluetoothTestAndroid::InitWithDefaultAdapter() { |
| 58 adapter_ = | 58 adapter_ = BluetoothAdapterAndroid::Create( |
| 59 BluetoothAdapterAndroid::Create( | 59 BluetoothAdapterWrapper_CreateWithDefaultAdapter()) |
| 60 BluetoothAdapterWrapper_CreateWithDefaultAdapter().obj()).get(); | 60 .get(); |
| 61 } | 61 } |
| 62 | 62 |
| 63 void BluetoothTestAndroid::InitWithoutDefaultAdapter() { | 63 void BluetoothTestAndroid::InitWithoutDefaultAdapter() { |
| 64 adapter_ = BluetoothAdapterAndroid::Create(NULL).get(); | 64 adapter_ = BluetoothAdapterAndroid::Create(NULL).get(); |
| 65 } | 65 } |
| 66 | 66 |
| 67 void BluetoothTestAndroid::InitWithFakeAdapter() { | 67 void BluetoothTestAndroid::InitWithFakeAdapter() { |
| 68 j_fake_bluetooth_adapter_.Reset(Java_FakeBluetoothAdapter_create( | 68 j_fake_bluetooth_adapter_.Reset(Java_FakeBluetoothAdapter_create( |
| 69 AttachCurrentThread(), reinterpret_cast<intptr_t>(this))); | 69 AttachCurrentThread(), reinterpret_cast<intptr_t>(this))); |
| 70 | 70 |
| 71 adapter_ = | 71 adapter_ = BluetoothAdapterAndroid::Create(j_fake_bluetooth_adapter_).get(); |
| 72 BluetoothAdapterAndroid::Create(j_fake_bluetooth_adapter_.obj()).get(); | |
| 73 } | 72 } |
| 74 | 73 |
| 75 bool BluetoothTestAndroid::DenyPermission() { | 74 bool BluetoothTestAndroid::DenyPermission() { |
| 76 Java_Fakes_setLocationServicesState( | 75 Java_Fakes_setLocationServicesState( |
| 77 AttachCurrentThread(), false /* hasPermission */, true /* isEnabled */); | 76 AttachCurrentThread(), false /* hasPermission */, true /* isEnabled */); |
| 78 return true; | 77 return true; |
| 79 } | 78 } |
| 80 | 79 |
| 81 BluetoothDevice* BluetoothTestAndroid::SimulateLowEnergyDevice( | 80 BluetoothDevice* BluetoothTestAndroid::SimulateLowEnergyDevice( |
| 82 int device_ordinal) { | 81 int device_ordinal) { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 device_android = static_cast<BluetoothDeviceAndroid*>(device); | 147 device_android = static_cast<BluetoothDeviceAndroid*>(device); |
| 149 } | 148 } |
| 150 | 149 |
| 151 // Join UUID strings into a single string. | 150 // Join UUID strings into a single string. |
| 152 std::ostringstream uuids_space_delimited; | 151 std::ostringstream uuids_space_delimited; |
| 153 std::copy(uuids.begin(), uuids.end(), | 152 std::copy(uuids.begin(), uuids.end(), |
| 154 std::ostream_iterator<std::string>(uuids_space_delimited, " ")); | 153 std::ostream_iterator<std::string>(uuids_space_delimited, " ")); |
| 155 | 154 |
| 156 JNIEnv* env = base::android::AttachCurrentThread(); | 155 JNIEnv* env = base::android::AttachCurrentThread(); |
| 157 Java_FakeBluetoothDevice_servicesDiscovered( | 156 Java_FakeBluetoothDevice_servicesDiscovered( |
| 158 env, device_android ? device_android->GetJavaObject().obj() : nullptr, | 157 env, device_android ? device_android->GetJavaObject() : nullptr, |
| 159 0, // android.bluetooth.BluetoothGatt.GATT_SUCCESS | 158 0, // android.bluetooth.BluetoothGatt.GATT_SUCCESS |
| 160 base::android::ConvertUTF8ToJavaString(env, uuids_space_delimited.str())); | 159 base::android::ConvertUTF8ToJavaString(env, uuids_space_delimited.str())); |
| 161 } | 160 } |
| 162 | 161 |
| 163 void BluetoothTestAndroid::SimulateGattServicesDiscoveryError( | 162 void BluetoothTestAndroid::SimulateGattServicesDiscoveryError( |
| 164 BluetoothDevice* device) { | 163 BluetoothDevice* device) { |
| 165 BluetoothDeviceAndroid* device_android = nullptr; | 164 BluetoothDeviceAndroid* device_android = nullptr; |
| 166 if (device) { | 165 if (device) { |
| 167 device_android = static_cast<BluetoothDeviceAndroid*>(device); | 166 device_android = static_cast<BluetoothDeviceAndroid*>(device); |
| 168 } | 167 } |
| 169 | 168 |
| 170 Java_FakeBluetoothDevice_servicesDiscovered( | 169 Java_FakeBluetoothDevice_servicesDiscovered( |
| 171 AttachCurrentThread(), | 170 AttachCurrentThread(), |
| 172 device_android ? device_android->GetJavaObject().obj() : nullptr, | 171 device_android ? device_android->GetJavaObject() : nullptr, |
| 173 0x00000101, // android.bluetooth.BluetoothGatt.GATT_FAILURE | 172 0x00000101, // android.bluetooth.BluetoothGatt.GATT_FAILURE |
| 174 nullptr); | 173 nullptr); |
| 175 } | 174 } |
| 176 | 175 |
| 177 void BluetoothTestAndroid::SimulateGattCharacteristic( | 176 void BluetoothTestAndroid::SimulateGattCharacteristic( |
| 178 BluetoothRemoteGattService* service, | 177 BluetoothRemoteGattService* service, |
| 179 const std::string& uuid, | 178 const std::string& uuid, |
| 180 int properties) { | 179 int properties) { |
| 181 BluetoothRemoteGattServiceAndroid* service_android = | 180 BluetoothRemoteGattServiceAndroid* service_android = |
| 182 static_cast<BluetoothRemoteGattServiceAndroid*>(service); | 181 static_cast<BluetoothRemoteGattServiceAndroid*>(service); |
| 183 JNIEnv* env = base::android::AttachCurrentThread(); | 182 JNIEnv* env = base::android::AttachCurrentThread(); |
| 184 | 183 |
| 185 Java_FakeBluetoothGattService_addCharacteristic( | 184 Java_FakeBluetoothGattService_addCharacteristic( |
| 186 env, service_android->GetJavaObject().obj(), | 185 env, service_android->GetJavaObject(), |
| 187 base::android::ConvertUTF8ToJavaString(env, uuid), properties); | 186 base::android::ConvertUTF8ToJavaString(env, uuid), properties); |
| 188 } | 187 } |
| 189 | 188 |
| 190 void BluetoothTestAndroid::RememberCharacteristicForSubsequentAction( | 189 void BluetoothTestAndroid::RememberCharacteristicForSubsequentAction( |
| 191 BluetoothRemoteGattCharacteristic* characteristic) { | 190 BluetoothRemoteGattCharacteristic* characteristic) { |
| 192 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = | 191 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = |
| 193 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); | 192 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); |
| 194 | 193 |
| 195 Java_FakeBluetoothGattCharacteristic_rememberCharacteristicForSubsequentAction
( | 194 Java_FakeBluetoothGattCharacteristic_rememberCharacteristicForSubsequentAction
( |
| 196 base::android::AttachCurrentThread(), | 195 base::android::AttachCurrentThread(), |
| (...skipping 16 matching lines...) Expand all Loading... |
| 213 BluetoothRemoteGattDescriptorAndroid* descriptor_android = nullptr; | 212 BluetoothRemoteGattDescriptorAndroid* descriptor_android = nullptr; |
| 214 if (characteristic) { | 213 if (characteristic) { |
| 215 descriptor_android = static_cast<BluetoothRemoteGattDescriptorAndroid*>( | 214 descriptor_android = static_cast<BluetoothRemoteGattDescriptorAndroid*>( |
| 216 characteristic | 215 characteristic |
| 217 ->GetDescriptorsByUUID(BluetoothRemoteGattDescriptor:: | 216 ->GetDescriptorsByUUID(BluetoothRemoteGattDescriptor:: |
| 218 ClientCharacteristicConfigurationUuid()) | 217 ClientCharacteristicConfigurationUuid()) |
| 219 .at(0)); | 218 .at(0)); |
| 220 } | 219 } |
| 221 Java_FakeBluetoothGattDescriptor_valueWrite( | 220 Java_FakeBluetoothGattDescriptor_valueWrite( |
| 222 base::android::AttachCurrentThread(), | 221 base::android::AttachCurrentThread(), |
| 223 descriptor_android ? descriptor_android->GetJavaObject().obj() : nullptr, | 222 descriptor_android ? descriptor_android->GetJavaObject() : nullptr, |
| 224 0); // android.bluetooth.BluetoothGatt.GATT_SUCCESS | 223 0); // android.bluetooth.BluetoothGatt.GATT_SUCCESS |
| 225 } | 224 } |
| 226 | 225 |
| 227 void BluetoothTestAndroid::SimulateGattNotifySessionStartError( | 226 void BluetoothTestAndroid::SimulateGattNotifySessionStartError( |
| 228 BluetoothRemoteGattCharacteristic* characteristic, | 227 BluetoothRemoteGattCharacteristic* characteristic, |
| 229 BluetoothRemoteGattService::GattErrorCode error_code) { | 228 BluetoothRemoteGattService::GattErrorCode error_code) { |
| 230 BluetoothRemoteGattDescriptorAndroid* descriptor_android = nullptr; | 229 BluetoothRemoteGattDescriptorAndroid* descriptor_android = nullptr; |
| 231 if (characteristic) { | 230 if (characteristic) { |
| 232 descriptor_android = static_cast<BluetoothRemoteGattDescriptorAndroid*>( | 231 descriptor_android = static_cast<BluetoothRemoteGattDescriptorAndroid*>( |
| 233 characteristic | 232 characteristic |
| 234 ->GetDescriptorsByUUID(BluetoothRemoteGattDescriptor:: | 233 ->GetDescriptorsByUUID(BluetoothRemoteGattDescriptor:: |
| 235 ClientCharacteristicConfigurationUuid()) | 234 ClientCharacteristicConfigurationUuid()) |
| 236 .at(0)); | 235 .at(0)); |
| 237 } | 236 } |
| 238 Java_FakeBluetoothGattDescriptor_valueWrite( | 237 Java_FakeBluetoothGattDescriptor_valueWrite( |
| 239 base::android::AttachCurrentThread(), | 238 base::android::AttachCurrentThread(), |
| 240 descriptor_android ? descriptor_android->GetJavaObject().obj() : nullptr, | 239 descriptor_android ? descriptor_android->GetJavaObject() : nullptr, |
| 241 BluetoothRemoteGattServiceAndroid::GetAndroidErrorCode(error_code)); | 240 BluetoothRemoteGattServiceAndroid::GetAndroidErrorCode(error_code)); |
| 242 } | 241 } |
| 243 | 242 |
| 244 void BluetoothTestAndroid::SimulateGattNotifySessionStopped( | 243 void BluetoothTestAndroid::SimulateGattNotifySessionStopped( |
| 245 BluetoothRemoteGattCharacteristic* characteristic) { | 244 BluetoothRemoteGattCharacteristic* characteristic) { |
| 246 BluetoothRemoteGattDescriptorAndroid* descriptor_android = nullptr; | 245 BluetoothRemoteGattDescriptorAndroid* descriptor_android = nullptr; |
| 247 if (characteristic) { | 246 if (characteristic) { |
| 248 descriptor_android = static_cast<BluetoothRemoteGattDescriptorAndroid*>( | 247 descriptor_android = static_cast<BluetoothRemoteGattDescriptorAndroid*>( |
| 249 characteristic | 248 characteristic |
| 250 ->GetDescriptorsByUUID(BluetoothRemoteGattDescriptor:: | 249 ->GetDescriptorsByUUID(BluetoothRemoteGattDescriptor:: |
| 251 ClientCharacteristicConfigurationUuid()) | 250 ClientCharacteristicConfigurationUuid()) |
| 252 .at(0)); | 251 .at(0)); |
| 253 } | 252 } |
| 254 Java_FakeBluetoothGattDescriptor_valueWrite( | 253 Java_FakeBluetoothGattDescriptor_valueWrite( |
| 255 base::android::AttachCurrentThread(), | 254 base::android::AttachCurrentThread(), |
| 256 descriptor_android ? descriptor_android->GetJavaObject().obj() : nullptr, | 255 descriptor_android ? descriptor_android->GetJavaObject() : nullptr, |
| 257 0); // android.bluetooth.BluetoothGatt.GATT_SUCCESS | 256 0); // android.bluetooth.BluetoothGatt.GATT_SUCCESS |
| 258 } | 257 } |
| 259 | 258 |
| 260 void BluetoothTestAndroid::SimulateGattNotifySessionStopError( | 259 void BluetoothTestAndroid::SimulateGattNotifySessionStopError( |
| 261 BluetoothRemoteGattCharacteristic* characteristic, | 260 BluetoothRemoteGattCharacteristic* characteristic, |
| 262 BluetoothRemoteGattService::GattErrorCode error_code) { | 261 BluetoothRemoteGattService::GattErrorCode error_code) { |
| 263 BluetoothRemoteGattDescriptorAndroid* descriptor_android = nullptr; | 262 BluetoothRemoteGattDescriptorAndroid* descriptor_android = nullptr; |
| 264 if (characteristic) { | 263 if (characteristic) { |
| 265 descriptor_android = static_cast<BluetoothRemoteGattDescriptorAndroid*>( | 264 descriptor_android = static_cast<BluetoothRemoteGattDescriptorAndroid*>( |
| 266 characteristic | 265 characteristic |
| 267 ->GetDescriptorsByUUID(BluetoothRemoteGattDescriptor:: | 266 ->GetDescriptorsByUUID(BluetoothRemoteGattDescriptor:: |
| 268 ClientCharacteristicConfigurationUuid()) | 267 ClientCharacteristicConfigurationUuid()) |
| 269 .at(0)); | 268 .at(0)); |
| 270 } | 269 } |
| 271 Java_FakeBluetoothGattDescriptor_valueWrite( | 270 Java_FakeBluetoothGattDescriptor_valueWrite( |
| 272 base::android::AttachCurrentThread(), | 271 base::android::AttachCurrentThread(), |
| 273 descriptor_android ? descriptor_android->GetJavaObject().obj() : nullptr, | 272 descriptor_android ? descriptor_android->GetJavaObject() : nullptr, |
| 274 BluetoothRemoteGattServiceAndroid::GetAndroidErrorCode(error_code)); | 273 BluetoothRemoteGattServiceAndroid::GetAndroidErrorCode(error_code)); |
| 275 } | 274 } |
| 276 | 275 |
| 277 void BluetoothTestAndroid:: | 276 void BluetoothTestAndroid:: |
| 278 SimulateGattCharacteristicSetNotifyWillFailSynchronouslyOnce( | 277 SimulateGattCharacteristicSetNotifyWillFailSynchronouslyOnce( |
| 279 BluetoothRemoteGattCharacteristic* characteristic) { | 278 BluetoothRemoteGattCharacteristic* characteristic) { |
| 280 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = | 279 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = |
| 281 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); | 280 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); |
| 282 JNIEnv* env = base::android::AttachCurrentThread(); | 281 JNIEnv* env = base::android::AttachCurrentThread(); |
| 283 | 282 |
| 284 Java_FakeBluetoothGattCharacteristic_setCharacteristicNotificationWillFailSync
hronouslyOnce( | 283 Java_FakeBluetoothGattCharacteristic_setCharacteristicNotificationWillFailSync
hronouslyOnce( |
| 285 env, characteristic_android->GetJavaObject()); | 284 env, characteristic_android->GetJavaObject()); |
| 286 } | 285 } |
| 287 | 286 |
| 288 void BluetoothTestAndroid::SimulateGattCharacteristicChanged( | 287 void BluetoothTestAndroid::SimulateGattCharacteristicChanged( |
| 289 BluetoothRemoteGattCharacteristic* characteristic, | 288 BluetoothRemoteGattCharacteristic* characteristic, |
| 290 const std::vector<uint8_t>& value) { | 289 const std::vector<uint8_t>& value) { |
| 291 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = | 290 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = |
| 292 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); | 291 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); |
| 293 JNIEnv* env = base::android::AttachCurrentThread(); | 292 JNIEnv* env = base::android::AttachCurrentThread(); |
| 294 | 293 |
| 295 Java_FakeBluetoothGattCharacteristic_valueChanged( | 294 Java_FakeBluetoothGattCharacteristic_valueChanged( |
| 296 env, | 295 env, characteristic_android ? characteristic_android->GetJavaObject() |
| 297 characteristic_android ? characteristic_android->GetJavaObject().obj() | 296 : nullptr, |
| 298 : nullptr, | |
| 299 base::android::ToJavaByteArray(env, value)); | 297 base::android::ToJavaByteArray(env, value)); |
| 300 } | 298 } |
| 301 | 299 |
| 302 void BluetoothTestAndroid::SimulateGattCharacteristicRead( | 300 void BluetoothTestAndroid::SimulateGattCharacteristicRead( |
| 303 BluetoothRemoteGattCharacteristic* characteristic, | 301 BluetoothRemoteGattCharacteristic* characteristic, |
| 304 const std::vector<uint8_t>& value) { | 302 const std::vector<uint8_t>& value) { |
| 305 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = | 303 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = |
| 306 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); | 304 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); |
| 307 JNIEnv* env = base::android::AttachCurrentThread(); | 305 JNIEnv* env = base::android::AttachCurrentThread(); |
| 308 | 306 |
| 309 Java_FakeBluetoothGattCharacteristic_valueRead( | 307 Java_FakeBluetoothGattCharacteristic_valueRead( |
| 310 env, | 308 env, characteristic_android ? characteristic_android->GetJavaObject() |
| 311 characteristic_android ? characteristic_android->GetJavaObject().obj() | 309 : nullptr, |
| 312 : nullptr, | |
| 313 0, // android.bluetooth.BluetoothGatt.GATT_SUCCESS | 310 0, // android.bluetooth.BluetoothGatt.GATT_SUCCESS |
| 314 base::android::ToJavaByteArray(env, value)); | 311 base::android::ToJavaByteArray(env, value)); |
| 315 } | 312 } |
| 316 | 313 |
| 317 void BluetoothTestAndroid::SimulateGattCharacteristicReadError( | 314 void BluetoothTestAndroid::SimulateGattCharacteristicReadError( |
| 318 BluetoothRemoteGattCharacteristic* characteristic, | 315 BluetoothRemoteGattCharacteristic* characteristic, |
| 319 BluetoothRemoteGattService::GattErrorCode error_code) { | 316 BluetoothRemoteGattService::GattErrorCode error_code) { |
| 320 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = | 317 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = |
| 321 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); | 318 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); |
| 322 JNIEnv* env = base::android::AttachCurrentThread(); | 319 JNIEnv* env = base::android::AttachCurrentThread(); |
| 323 std::vector<uint8_t> empty_value; | 320 std::vector<uint8_t> empty_value; |
| 324 | 321 |
| 325 Java_FakeBluetoothGattCharacteristic_valueRead( | 322 Java_FakeBluetoothGattCharacteristic_valueRead( |
| 326 env, characteristic_android->GetJavaObject().obj(), | 323 env, characteristic_android->GetJavaObject(), |
| 327 BluetoothRemoteGattServiceAndroid::GetAndroidErrorCode(error_code), | 324 BluetoothRemoteGattServiceAndroid::GetAndroidErrorCode(error_code), |
| 328 base::android::ToJavaByteArray(env, empty_value)); | 325 base::android::ToJavaByteArray(env, empty_value)); |
| 329 } | 326 } |
| 330 | 327 |
| 331 void BluetoothTestAndroid:: | 328 void BluetoothTestAndroid:: |
| 332 SimulateGattCharacteristicReadWillFailSynchronouslyOnce( | 329 SimulateGattCharacteristicReadWillFailSynchronouslyOnce( |
| 333 BluetoothRemoteGattCharacteristic* characteristic) { | 330 BluetoothRemoteGattCharacteristic* characteristic) { |
| 334 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = | 331 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = |
| 335 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); | 332 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); |
| 336 JNIEnv* env = base::android::AttachCurrentThread(); | 333 JNIEnv* env = base::android::AttachCurrentThread(); |
| 337 | 334 |
| 338 Java_FakeBluetoothGattCharacteristic_setReadCharacteristicWillFailSynchronousl
yOnce( | 335 Java_FakeBluetoothGattCharacteristic_setReadCharacteristicWillFailSynchronousl
yOnce( |
| 339 env, characteristic_android->GetJavaObject()); | 336 env, characteristic_android->GetJavaObject()); |
| 340 } | 337 } |
| 341 | 338 |
| 342 void BluetoothTestAndroid::SimulateGattCharacteristicWrite( | 339 void BluetoothTestAndroid::SimulateGattCharacteristicWrite( |
| 343 BluetoothRemoteGattCharacteristic* characteristic) { | 340 BluetoothRemoteGattCharacteristic* characteristic) { |
| 344 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = | 341 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = |
| 345 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); | 342 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); |
| 346 Java_FakeBluetoothGattCharacteristic_valueWrite( | 343 Java_FakeBluetoothGattCharacteristic_valueWrite( |
| 347 base::android::AttachCurrentThread(), | 344 base::android::AttachCurrentThread(), |
| 348 characteristic_android ? characteristic_android->GetJavaObject().obj() | 345 characteristic_android ? characteristic_android->GetJavaObject() |
| 349 : nullptr, | 346 : nullptr, |
| 350 0); // android.bluetooth.BluetoothGatt.GATT_SUCCESS | 347 0); // android.bluetooth.BluetoothGatt.GATT_SUCCESS |
| 351 } | 348 } |
| 352 | 349 |
| 353 void BluetoothTestAndroid::SimulateGattCharacteristicWriteError( | 350 void BluetoothTestAndroid::SimulateGattCharacteristicWriteError( |
| 354 BluetoothRemoteGattCharacteristic* characteristic, | 351 BluetoothRemoteGattCharacteristic* characteristic, |
| 355 BluetoothRemoteGattService::GattErrorCode error_code) { | 352 BluetoothRemoteGattService::GattErrorCode error_code) { |
| 356 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = | 353 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = |
| 357 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); | 354 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); |
| 358 Java_FakeBluetoothGattCharacteristic_valueWrite( | 355 Java_FakeBluetoothGattCharacteristic_valueWrite( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 372 } | 369 } |
| 373 | 370 |
| 374 void BluetoothTestAndroid::SimulateGattDescriptor( | 371 void BluetoothTestAndroid::SimulateGattDescriptor( |
| 375 BluetoothRemoteGattCharacteristic* characteristic, | 372 BluetoothRemoteGattCharacteristic* characteristic, |
| 376 const std::string& uuid) { | 373 const std::string& uuid) { |
| 377 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = | 374 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = |
| 378 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); | 375 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); |
| 379 JNIEnv* env = base::android::AttachCurrentThread(); | 376 JNIEnv* env = base::android::AttachCurrentThread(); |
| 380 | 377 |
| 381 Java_FakeBluetoothGattCharacteristic_addDescriptor( | 378 Java_FakeBluetoothGattCharacteristic_addDescriptor( |
| 382 env, characteristic_android->GetJavaObject().obj(), | 379 env, characteristic_android->GetJavaObject(), |
| 383 base::android::ConvertUTF8ToJavaString(env, uuid)); | 380 base::android::ConvertUTF8ToJavaString(env, uuid)); |
| 384 } | 381 } |
| 385 | 382 |
| 386 void BluetoothTestAndroid::RememberDescriptorForSubsequentAction( | 383 void BluetoothTestAndroid::RememberDescriptorForSubsequentAction( |
| 387 BluetoothRemoteGattDescriptor* descriptor) { | 384 BluetoothRemoteGattDescriptor* descriptor) { |
| 388 BluetoothRemoteGattDescriptorAndroid* descriptor_android = | 385 BluetoothRemoteGattDescriptorAndroid* descriptor_android = |
| 389 static_cast<BluetoothRemoteGattDescriptorAndroid*>(descriptor); | 386 static_cast<BluetoothRemoteGattDescriptorAndroid*>(descriptor); |
| 390 | 387 |
| 391 Java_FakeBluetoothGattDescriptor_rememberDescriptorForSubsequentAction( | 388 Java_FakeBluetoothGattDescriptor_rememberDescriptorForSubsequentAction( |
| 392 base::android::AttachCurrentThread(), | 389 base::android::AttachCurrentThread(), |
| 393 descriptor_android->GetJavaObject()); | 390 descriptor_android->GetJavaObject()); |
| 394 } | 391 } |
| 395 | 392 |
| 396 void BluetoothTestAndroid::SimulateGattDescriptorRead( | 393 void BluetoothTestAndroid::SimulateGattDescriptorRead( |
| 397 BluetoothRemoteGattDescriptor* descriptor, | 394 BluetoothRemoteGattDescriptor* descriptor, |
| 398 const std::vector<uint8_t>& value) { | 395 const std::vector<uint8_t>& value) { |
| 399 BluetoothRemoteGattDescriptorAndroid* descriptor_android = | 396 BluetoothRemoteGattDescriptorAndroid* descriptor_android = |
| 400 static_cast<BluetoothRemoteGattDescriptorAndroid*>(descriptor); | 397 static_cast<BluetoothRemoteGattDescriptorAndroid*>(descriptor); |
| 401 JNIEnv* env = base::android::AttachCurrentThread(); | 398 JNIEnv* env = base::android::AttachCurrentThread(); |
| 402 | 399 |
| 403 Java_FakeBluetoothGattDescriptor_valueRead( | 400 Java_FakeBluetoothGattDescriptor_valueRead( |
| 404 env, | 401 env, descriptor_android ? descriptor_android->GetJavaObject() : nullptr, |
| 405 descriptor_android ? descriptor_android->GetJavaObject().obj() : nullptr, | |
| 406 0, // android.bluetooth.BluetoothGatt.GATT_SUCCESS | 402 0, // android.bluetooth.BluetoothGatt.GATT_SUCCESS |
| 407 base::android::ToJavaByteArray(env, value)); | 403 base::android::ToJavaByteArray(env, value)); |
| 408 } | 404 } |
| 409 | 405 |
| 410 void BluetoothTestAndroid::SimulateGattDescriptorReadError( | 406 void BluetoothTestAndroid::SimulateGattDescriptorReadError( |
| 411 BluetoothRemoteGattDescriptor* descriptor, | 407 BluetoothRemoteGattDescriptor* descriptor, |
| 412 BluetoothRemoteGattService::GattErrorCode error_code) { | 408 BluetoothRemoteGattService::GattErrorCode error_code) { |
| 413 BluetoothRemoteGattDescriptorAndroid* descriptor_android = | 409 BluetoothRemoteGattDescriptorAndroid* descriptor_android = |
| 414 static_cast<BluetoothRemoteGattDescriptorAndroid*>(descriptor); | 410 static_cast<BluetoothRemoteGattDescriptorAndroid*>(descriptor); |
| 415 JNIEnv* env = base::android::AttachCurrentThread(); | 411 JNIEnv* env = base::android::AttachCurrentThread(); |
| 416 std::vector<uint8_t> empty_value; | 412 std::vector<uint8_t> empty_value; |
| 417 | 413 |
| 418 Java_FakeBluetoothGattDescriptor_valueRead( | 414 Java_FakeBluetoothGattDescriptor_valueRead( |
| 419 env, descriptor_android->GetJavaObject().obj(), | 415 env, descriptor_android->GetJavaObject(), |
| 420 BluetoothRemoteGattServiceAndroid::GetAndroidErrorCode(error_code), | 416 BluetoothRemoteGattServiceAndroid::GetAndroidErrorCode(error_code), |
| 421 base::android::ToJavaByteArray(env, empty_value)); | 417 base::android::ToJavaByteArray(env, empty_value)); |
| 422 } | 418 } |
| 423 | 419 |
| 424 void BluetoothTestAndroid::SimulateGattDescriptorReadWillFailSynchronouslyOnce( | 420 void BluetoothTestAndroid::SimulateGattDescriptorReadWillFailSynchronouslyOnce( |
| 425 BluetoothRemoteGattDescriptor* descriptor) { | 421 BluetoothRemoteGattDescriptor* descriptor) { |
| 426 BluetoothRemoteGattDescriptorAndroid* descriptor_android = | 422 BluetoothRemoteGattDescriptorAndroid* descriptor_android = |
| 427 static_cast<BluetoothRemoteGattDescriptorAndroid*>(descriptor); | 423 static_cast<BluetoothRemoteGattDescriptorAndroid*>(descriptor); |
| 428 JNIEnv* env = base::android::AttachCurrentThread(); | 424 JNIEnv* env = base::android::AttachCurrentThread(); |
| 429 | 425 |
| 430 Java_FakeBluetoothGattDescriptor_setReadDescriptorWillFailSynchronouslyOnce( | 426 Java_FakeBluetoothGattDescriptor_setReadDescriptorWillFailSynchronouslyOnce( |
| 431 env, descriptor_android->GetJavaObject()); | 427 env, descriptor_android->GetJavaObject()); |
| 432 } | 428 } |
| 433 | 429 |
| 434 void BluetoothTestAndroid::SimulateGattDescriptorWrite( | 430 void BluetoothTestAndroid::SimulateGattDescriptorWrite( |
| 435 BluetoothRemoteGattDescriptor* descriptor) { | 431 BluetoothRemoteGattDescriptor* descriptor) { |
| 436 BluetoothRemoteGattDescriptorAndroid* descriptor_android = | 432 BluetoothRemoteGattDescriptorAndroid* descriptor_android = |
| 437 static_cast<BluetoothRemoteGattDescriptorAndroid*>(descriptor); | 433 static_cast<BluetoothRemoteGattDescriptorAndroid*>(descriptor); |
| 438 Java_FakeBluetoothGattDescriptor_valueWrite( | 434 Java_FakeBluetoothGattDescriptor_valueWrite( |
| 439 base::android::AttachCurrentThread(), | 435 base::android::AttachCurrentThread(), |
| 440 descriptor_android ? descriptor_android->GetJavaObject().obj() : nullptr, | 436 descriptor_android ? descriptor_android->GetJavaObject() : nullptr, |
| 441 0); // android.bluetooth.BluetoothGatt.GATT_SUCCESS | 437 0); // android.bluetooth.BluetoothGatt.GATT_SUCCESS |
| 442 } | 438 } |
| 443 | 439 |
| 444 void BluetoothTestAndroid::SimulateGattDescriptorWriteError( | 440 void BluetoothTestAndroid::SimulateGattDescriptorWriteError( |
| 445 BluetoothRemoteGattDescriptor* descriptor, | 441 BluetoothRemoteGattDescriptor* descriptor, |
| 446 BluetoothRemoteGattService::GattErrorCode error_code) { | 442 BluetoothRemoteGattService::GattErrorCode error_code) { |
| 447 BluetoothRemoteGattDescriptorAndroid* descriptor_android = | 443 BluetoothRemoteGattDescriptorAndroid* descriptor_android = |
| 448 static_cast<BluetoothRemoteGattDescriptorAndroid*>(descriptor); | 444 static_cast<BluetoothRemoteGattDescriptorAndroid*>(descriptor); |
| 449 Java_FakeBluetoothGattDescriptor_valueWrite( | 445 Java_FakeBluetoothGattDescriptor_valueWrite( |
| 450 base::android::AttachCurrentThread(), descriptor_android->GetJavaObject(), | 446 base::android::AttachCurrentThread(), descriptor_android->GetJavaObject(), |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 } | 519 } |
| 524 | 520 |
| 525 void BluetoothTestAndroid::OnFakeAdapterStateChanged( | 521 void BluetoothTestAndroid::OnFakeAdapterStateChanged( |
| 526 JNIEnv* env, | 522 JNIEnv* env, |
| 527 const JavaParamRef<jobject>& caller, | 523 const JavaParamRef<jobject>& caller, |
| 528 const bool powered) { | 524 const bool powered) { |
| 529 adapter_->NotifyAdapterPoweredChanged(powered); | 525 adapter_->NotifyAdapterPoweredChanged(powered); |
| 530 } | 526 } |
| 531 | 527 |
| 532 } // namespace device | 528 } // namespace device |
| OLD | NEW |