| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 bool BluetoothTestAndroid::DenyPermission() { | 75 bool BluetoothTestAndroid::DenyPermission() { |
| 76 Java_Fakes_setLocationServicesState( | 76 Java_Fakes_setLocationServicesState( |
| 77 AttachCurrentThread(), false /* hasPermission */, true /* isEnabled */); | 77 AttachCurrentThread(), false /* hasPermission */, true /* isEnabled */); |
| 78 return true; | 78 return true; |
| 79 } | 79 } |
| 80 | 80 |
| 81 BluetoothDevice* BluetoothTestAndroid::SimulateLowEnergyDevice( | 81 BluetoothDevice* BluetoothTestAndroid::SimulateLowEnergyDevice( |
| 82 int device_ordinal) { | 82 int device_ordinal) { |
| 83 TestBluetoothAdapterObserver observer(adapter_); | 83 TestBluetoothAdapterObserver observer(adapter_); |
| 84 Java_FakeBluetoothAdapter_simulateLowEnergyDevice( | 84 Java_FakeBluetoothAdapter_simulateLowEnergyDevice( |
| 85 AttachCurrentThread(), j_fake_bluetooth_adapter_.obj(), device_ordinal); | 85 AttachCurrentThread(), j_fake_bluetooth_adapter_, device_ordinal); |
| 86 return observer.last_device(); | 86 return observer.last_device(); |
| 87 } | 87 } |
| 88 | 88 |
| 89 void BluetoothTestAndroid::RememberDeviceForSubsequentAction( | 89 void BluetoothTestAndroid::RememberDeviceForSubsequentAction( |
| 90 BluetoothDevice* device) { | 90 BluetoothDevice* device) { |
| 91 BluetoothDeviceAndroid* device_android = | 91 BluetoothDeviceAndroid* device_android = |
| 92 static_cast<BluetoothDeviceAndroid*>(device); | 92 static_cast<BluetoothDeviceAndroid*>(device); |
| 93 | 93 |
| 94 Java_FakeBluetoothDevice_rememberDeviceForSubsequentAction( | 94 Java_FakeBluetoothDevice_rememberDeviceForSubsequentAction( |
| 95 base::android::AttachCurrentThread(), | 95 base::android::AttachCurrentThread(), device_android->GetJavaObject()); |
| 96 device_android->GetJavaObject().obj()); | |
| 97 } | 96 } |
| 98 | 97 |
| 99 void BluetoothTestAndroid::SimulateLocationServicesOff() { | 98 void BluetoothTestAndroid::SimulateLocationServicesOff() { |
| 100 Java_Fakes_setLocationServicesState( | 99 Java_Fakes_setLocationServicesState( |
| 101 AttachCurrentThread(), true /* hasPermission */, false /* isEnabled */); | 100 AttachCurrentThread(), true /* hasPermission */, false /* isEnabled */); |
| 102 } | 101 } |
| 103 | 102 |
| 104 void BluetoothTestAndroid::ForceIllegalStateException() { | 103 void BluetoothTestAndroid::ForceIllegalStateException() { |
| 105 Java_FakeBluetoothAdapter_forceIllegalStateException( | 104 Java_FakeBluetoothAdapter_forceIllegalStateException( |
| 106 AttachCurrentThread(), j_fake_bluetooth_adapter_.obj()); | 105 AttachCurrentThread(), j_fake_bluetooth_adapter_); |
| 107 } | 106 } |
| 108 | 107 |
| 109 void BluetoothTestAndroid::SimulateGattConnection(BluetoothDevice* device) { | 108 void BluetoothTestAndroid::SimulateGattConnection(BluetoothDevice* device) { |
| 110 BluetoothDeviceAndroid* device_android = | 109 BluetoothDeviceAndroid* device_android = |
| 111 static_cast<BluetoothDeviceAndroid*>(device); | 110 static_cast<BluetoothDeviceAndroid*>(device); |
| 112 | 111 |
| 113 Java_FakeBluetoothDevice_connectionStateChange( | 112 Java_FakeBluetoothDevice_connectionStateChange( |
| 114 AttachCurrentThread(), device_android->GetJavaObject().obj(), | 113 AttachCurrentThread(), device_android->GetJavaObject(), |
| 115 0, // android.bluetooth.BluetoothGatt.GATT_SUCCESS | 114 0, // android.bluetooth.BluetoothGatt.GATT_SUCCESS |
| 116 true); // connected | 115 true); // connected |
| 117 } | 116 } |
| 118 | 117 |
| 119 void BluetoothTestAndroid::SimulateGattConnectionError( | 118 void BluetoothTestAndroid::SimulateGattConnectionError( |
| 120 BluetoothDevice* device, | 119 BluetoothDevice* device, |
| 121 BluetoothDevice::ConnectErrorCode) { | 120 BluetoothDevice::ConnectErrorCode) { |
| 122 BluetoothDeviceAndroid* device_android = | 121 BluetoothDeviceAndroid* device_android = |
| 123 static_cast<BluetoothDeviceAndroid*>(device); | 122 static_cast<BluetoothDeviceAndroid*>(device); |
| 124 | 123 |
| 125 Java_FakeBluetoothDevice_connectionStateChange( | 124 Java_FakeBluetoothDevice_connectionStateChange( |
| 126 AttachCurrentThread(), device_android->GetJavaObject().obj(), | 125 AttachCurrentThread(), device_android->GetJavaObject(), |
| 127 // TODO(ortuno): Add all types of errors Android can produce. For now we | 126 // TODO(ortuno): Add all types of errors Android can produce. For now we |
| 128 // just return a timeout error. | 127 // just return a timeout error. |
| 129 // http://crbug.com/578191 | 128 // http://crbug.com/578191 |
| 130 0x08, // Connection Timeout from Bluetooth Spec. | 129 0x08, // Connection Timeout from Bluetooth Spec. |
| 131 false); // connected | 130 false); // connected |
| 132 } | 131 } |
| 133 | 132 |
| 134 void BluetoothTestAndroid::SimulateGattDisconnection(BluetoothDevice* device) { | 133 void BluetoothTestAndroid::SimulateGattDisconnection(BluetoothDevice* device) { |
| 135 BluetoothDeviceAndroid* device_android = | 134 BluetoothDeviceAndroid* device_android = |
| 136 static_cast<BluetoothDeviceAndroid*>(device); | 135 static_cast<BluetoothDeviceAndroid*>(device); |
| 137 | 136 |
| 138 Java_FakeBluetoothDevice_connectionStateChange( | 137 Java_FakeBluetoothDevice_connectionStateChange( |
| 139 AttachCurrentThread(), device_android->GetJavaObject().obj(), | 138 AttachCurrentThread(), device_android->GetJavaObject(), |
| 140 0x13, // Connection terminate by peer user from Bluetooth Spec. | 139 0x13, // Connection terminate by peer user from Bluetooth Spec. |
| 141 false); // disconnected | 140 false); // disconnected |
| 142 } | 141 } |
| 143 | 142 |
| 144 void BluetoothTestAndroid::SimulateGattServicesDiscovered( | 143 void BluetoothTestAndroid::SimulateGattServicesDiscovered( |
| 145 BluetoothDevice* device, | 144 BluetoothDevice* device, |
| 146 const std::vector<std::string>& uuids) { | 145 const std::vector<std::string>& uuids) { |
| 147 BluetoothDeviceAndroid* device_android = nullptr; | 146 BluetoothDeviceAndroid* device_android = nullptr; |
| 148 if (device) { | 147 if (device) { |
| 149 device_android = static_cast<BluetoothDeviceAndroid*>(device); | 148 device_android = static_cast<BluetoothDeviceAndroid*>(device); |
| 150 } | 149 } |
| 151 | 150 |
| 152 // Join UUID strings into a single string. | 151 // Join UUID strings into a single string. |
| 153 std::ostringstream uuids_space_delimited; | 152 std::ostringstream uuids_space_delimited; |
| 154 std::copy(uuids.begin(), uuids.end(), | 153 std::copy(uuids.begin(), uuids.end(), |
| 155 std::ostream_iterator<std::string>(uuids_space_delimited, " ")); | 154 std::ostream_iterator<std::string>(uuids_space_delimited, " ")); |
| 156 | 155 |
| 157 JNIEnv* env = base::android::AttachCurrentThread(); | 156 JNIEnv* env = base::android::AttachCurrentThread(); |
| 158 Java_FakeBluetoothDevice_servicesDiscovered( | 157 Java_FakeBluetoothDevice_servicesDiscovered( |
| 159 env, device_android ? device_android->GetJavaObject().obj() : nullptr, | 158 env, device_android ? device_android->GetJavaObject().obj() : nullptr, |
| 160 0, // android.bluetooth.BluetoothGatt.GATT_SUCCESS | 159 0, // android.bluetooth.BluetoothGatt.GATT_SUCCESS |
| 161 base::android::ConvertUTF8ToJavaString(env, uuids_space_delimited.str()) | 160 base::android::ConvertUTF8ToJavaString(env, uuids_space_delimited.str())); |
| 162 .obj()); | |
| 163 } | 161 } |
| 164 | 162 |
| 165 void BluetoothTestAndroid::SimulateGattServicesDiscoveryError( | 163 void BluetoothTestAndroid::SimulateGattServicesDiscoveryError( |
| 166 BluetoothDevice* device) { | 164 BluetoothDevice* device) { |
| 167 BluetoothDeviceAndroid* device_android = nullptr; | 165 BluetoothDeviceAndroid* device_android = nullptr; |
| 168 if (device) { | 166 if (device) { |
| 169 device_android = static_cast<BluetoothDeviceAndroid*>(device); | 167 device_android = static_cast<BluetoothDeviceAndroid*>(device); |
| 170 } | 168 } |
| 171 | 169 |
| 172 Java_FakeBluetoothDevice_servicesDiscovered( | 170 Java_FakeBluetoothDevice_servicesDiscovered( |
| 173 AttachCurrentThread(), | 171 AttachCurrentThread(), |
| 174 device_android ? device_android->GetJavaObject().obj() : nullptr, | 172 device_android ? device_android->GetJavaObject().obj() : nullptr, |
| 175 0x00000101, // android.bluetooth.BluetoothGatt.GATT_FAILURE | 173 0x00000101, // android.bluetooth.BluetoothGatt.GATT_FAILURE |
| 176 nullptr); | 174 nullptr); |
| 177 } | 175 } |
| 178 | 176 |
| 179 void BluetoothTestAndroid::SimulateGattCharacteristic( | 177 void BluetoothTestAndroid::SimulateGattCharacteristic( |
| 180 BluetoothRemoteGattService* service, | 178 BluetoothRemoteGattService* service, |
| 181 const std::string& uuid, | 179 const std::string& uuid, |
| 182 int properties) { | 180 int properties) { |
| 183 BluetoothRemoteGattServiceAndroid* service_android = | 181 BluetoothRemoteGattServiceAndroid* service_android = |
| 184 static_cast<BluetoothRemoteGattServiceAndroid*>(service); | 182 static_cast<BluetoothRemoteGattServiceAndroid*>(service); |
| 185 JNIEnv* env = base::android::AttachCurrentThread(); | 183 JNIEnv* env = base::android::AttachCurrentThread(); |
| 186 | 184 |
| 187 Java_FakeBluetoothGattService_addCharacteristic( | 185 Java_FakeBluetoothGattService_addCharacteristic( |
| 188 env, service_android->GetJavaObject().obj(), | 186 env, service_android->GetJavaObject().obj(), |
| 189 base::android::ConvertUTF8ToJavaString(env, uuid).obj(), properties); | 187 base::android::ConvertUTF8ToJavaString(env, uuid), properties); |
| 190 } | 188 } |
| 191 | 189 |
| 192 void BluetoothTestAndroid::RememberCharacteristicForSubsequentAction( | 190 void BluetoothTestAndroid::RememberCharacteristicForSubsequentAction( |
| 193 BluetoothRemoteGattCharacteristic* characteristic) { | 191 BluetoothRemoteGattCharacteristic* characteristic) { |
| 194 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = | 192 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = |
| 195 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); | 193 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); |
| 196 | 194 |
| 197 Java_FakeBluetoothGattCharacteristic_rememberCharacteristicForSubsequentAction
( | 195 Java_FakeBluetoothGattCharacteristic_rememberCharacteristicForSubsequentAction
( |
| 198 base::android::AttachCurrentThread(), | 196 base::android::AttachCurrentThread(), |
| 199 characteristic_android->GetJavaObject().obj()); | 197 characteristic_android->GetJavaObject()); |
| 200 } | 198 } |
| 201 | 199 |
| 202 void BluetoothTestAndroid::RememberCCCDescriptorForSubsequentAction( | 200 void BluetoothTestAndroid::RememberCCCDescriptorForSubsequentAction( |
| 203 BluetoothRemoteGattCharacteristic* characteristic) { | 201 BluetoothRemoteGattCharacteristic* characteristic) { |
| 204 remembered_ccc_descriptor_ = | 202 remembered_ccc_descriptor_ = |
| 205 characteristic | 203 characteristic |
| 206 ->GetDescriptorsByUUID(BluetoothRemoteGattDescriptor:: | 204 ->GetDescriptorsByUUID(BluetoothRemoteGattDescriptor:: |
| 207 ClientCharacteristicConfigurationUuid()) | 205 ClientCharacteristicConfigurationUuid()) |
| 208 .at(0); | 206 .at(0); |
| 209 DCHECK(remembered_ccc_descriptor_); | 207 DCHECK(remembered_ccc_descriptor_); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 } | 242 } |
| 245 | 243 |
| 246 void BluetoothTestAndroid:: | 244 void BluetoothTestAndroid:: |
| 247 SimulateGattCharacteristicSetNotifyWillFailSynchronouslyOnce( | 245 SimulateGattCharacteristicSetNotifyWillFailSynchronouslyOnce( |
| 248 BluetoothRemoteGattCharacteristic* characteristic) { | 246 BluetoothRemoteGattCharacteristic* characteristic) { |
| 249 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = | 247 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = |
| 250 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); | 248 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); |
| 251 JNIEnv* env = base::android::AttachCurrentThread(); | 249 JNIEnv* env = base::android::AttachCurrentThread(); |
| 252 | 250 |
| 253 Java_FakeBluetoothGattCharacteristic_setCharacteristicNotificationWillFailSync
hronouslyOnce( | 251 Java_FakeBluetoothGattCharacteristic_setCharacteristicNotificationWillFailSync
hronouslyOnce( |
| 254 env, characteristic_android->GetJavaObject().obj()); | 252 env, characteristic_android->GetJavaObject()); |
| 255 } | 253 } |
| 256 | 254 |
| 257 void BluetoothTestAndroid::SimulateGattCharacteristicChanged( | 255 void BluetoothTestAndroid::SimulateGattCharacteristicChanged( |
| 258 BluetoothRemoteGattCharacteristic* characteristic, | 256 BluetoothRemoteGattCharacteristic* characteristic, |
| 259 const std::vector<uint8_t>& value) { | 257 const std::vector<uint8_t>& value) { |
| 260 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = | 258 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = |
| 261 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); | 259 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); |
| 262 JNIEnv* env = base::android::AttachCurrentThread(); | 260 JNIEnv* env = base::android::AttachCurrentThread(); |
| 263 | 261 |
| 264 Java_FakeBluetoothGattCharacteristic_valueChanged( | 262 Java_FakeBluetoothGattCharacteristic_valueChanged( |
| 265 env, | 263 env, |
| 266 characteristic_android ? characteristic_android->GetJavaObject().obj() | 264 characteristic_android ? characteristic_android->GetJavaObject().obj() |
| 267 : nullptr, | 265 : nullptr, |
| 268 base::android::ToJavaByteArray(env, value).obj()); | 266 base::android::ToJavaByteArray(env, value)); |
| 269 } | 267 } |
| 270 | 268 |
| 271 void BluetoothTestAndroid::SimulateGattCharacteristicRead( | 269 void BluetoothTestAndroid::SimulateGattCharacteristicRead( |
| 272 BluetoothRemoteGattCharacteristic* characteristic, | 270 BluetoothRemoteGattCharacteristic* characteristic, |
| 273 const std::vector<uint8_t>& value) { | 271 const std::vector<uint8_t>& value) { |
| 274 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = | 272 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = |
| 275 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); | 273 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); |
| 276 JNIEnv* env = base::android::AttachCurrentThread(); | 274 JNIEnv* env = base::android::AttachCurrentThread(); |
| 277 | 275 |
| 278 Java_FakeBluetoothGattCharacteristic_valueRead( | 276 Java_FakeBluetoothGattCharacteristic_valueRead( |
| 279 env, | 277 env, |
| 280 characteristic_android ? characteristic_android->GetJavaObject().obj() | 278 characteristic_android ? characteristic_android->GetJavaObject().obj() |
| 281 : nullptr, | 279 : nullptr, |
| 282 0, // android.bluetooth.BluetoothGatt.GATT_SUCCESS | 280 0, // android.bluetooth.BluetoothGatt.GATT_SUCCESS |
| 283 base::android::ToJavaByteArray(env, value).obj()); | 281 base::android::ToJavaByteArray(env, value)); |
| 284 } | 282 } |
| 285 | 283 |
| 286 void BluetoothTestAndroid::SimulateGattCharacteristicReadError( | 284 void BluetoothTestAndroid::SimulateGattCharacteristicReadError( |
| 287 BluetoothRemoteGattCharacteristic* characteristic, | 285 BluetoothRemoteGattCharacteristic* characteristic, |
| 288 BluetoothRemoteGattService::GattErrorCode error_code) { | 286 BluetoothRemoteGattService::GattErrorCode error_code) { |
| 289 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = | 287 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = |
| 290 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); | 288 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); |
| 291 JNIEnv* env = base::android::AttachCurrentThread(); | 289 JNIEnv* env = base::android::AttachCurrentThread(); |
| 292 std::vector<uint8_t> empty_value; | 290 std::vector<uint8_t> empty_value; |
| 293 | 291 |
| 294 Java_FakeBluetoothGattCharacteristic_valueRead( | 292 Java_FakeBluetoothGattCharacteristic_valueRead( |
| 295 env, characteristic_android->GetJavaObject().obj(), | 293 env, characteristic_android->GetJavaObject().obj(), |
| 296 BluetoothRemoteGattServiceAndroid::GetAndroidErrorCode(error_code), | 294 BluetoothRemoteGattServiceAndroid::GetAndroidErrorCode(error_code), |
| 297 base::android::ToJavaByteArray(env, empty_value).obj()); | 295 base::android::ToJavaByteArray(env, empty_value)); |
| 298 } | 296 } |
| 299 | 297 |
| 300 void BluetoothTestAndroid:: | 298 void BluetoothTestAndroid:: |
| 301 SimulateGattCharacteristicReadWillFailSynchronouslyOnce( | 299 SimulateGattCharacteristicReadWillFailSynchronouslyOnce( |
| 302 BluetoothRemoteGattCharacteristic* characteristic) { | 300 BluetoothRemoteGattCharacteristic* characteristic) { |
| 303 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = | 301 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = |
| 304 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); | 302 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); |
| 305 JNIEnv* env = base::android::AttachCurrentThread(); | 303 JNIEnv* env = base::android::AttachCurrentThread(); |
| 306 | 304 |
| 307 Java_FakeBluetoothGattCharacteristic_setReadCharacteristicWillFailSynchronousl
yOnce( | 305 Java_FakeBluetoothGattCharacteristic_setReadCharacteristicWillFailSynchronousl
yOnce( |
| 308 env, characteristic_android->GetJavaObject().obj()); | 306 env, characteristic_android->GetJavaObject()); |
| 309 } | 307 } |
| 310 | 308 |
| 311 void BluetoothTestAndroid::SimulateGattCharacteristicWrite( | 309 void BluetoothTestAndroid::SimulateGattCharacteristicWrite( |
| 312 BluetoothRemoteGattCharacteristic* characteristic) { | 310 BluetoothRemoteGattCharacteristic* characteristic) { |
| 313 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = | 311 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = |
| 314 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); | 312 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); |
| 315 Java_FakeBluetoothGattCharacteristic_valueWrite( | 313 Java_FakeBluetoothGattCharacteristic_valueWrite( |
| 316 base::android::AttachCurrentThread(), | 314 base::android::AttachCurrentThread(), |
| 317 characteristic_android ? characteristic_android->GetJavaObject().obj() | 315 characteristic_android ? characteristic_android->GetJavaObject().obj() |
| 318 : nullptr, | 316 : nullptr, |
| 319 0); // android.bluetooth.BluetoothGatt.GATT_SUCCESS | 317 0); // android.bluetooth.BluetoothGatt.GATT_SUCCESS |
| 320 } | 318 } |
| 321 | 319 |
| 322 void BluetoothTestAndroid::SimulateGattCharacteristicWriteError( | 320 void BluetoothTestAndroid::SimulateGattCharacteristicWriteError( |
| 323 BluetoothRemoteGattCharacteristic* characteristic, | 321 BluetoothRemoteGattCharacteristic* characteristic, |
| 324 BluetoothRemoteGattService::GattErrorCode error_code) { | 322 BluetoothRemoteGattService::GattErrorCode error_code) { |
| 325 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = | 323 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = |
| 326 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); | 324 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); |
| 327 Java_FakeBluetoothGattCharacteristic_valueWrite( | 325 Java_FakeBluetoothGattCharacteristic_valueWrite( |
| 328 base::android::AttachCurrentThread(), | 326 base::android::AttachCurrentThread(), |
| 329 characteristic_android->GetJavaObject().obj(), | 327 characteristic_android->GetJavaObject(), |
| 330 BluetoothRemoteGattServiceAndroid::GetAndroidErrorCode(error_code)); | 328 BluetoothRemoteGattServiceAndroid::GetAndroidErrorCode(error_code)); |
| 331 } | 329 } |
| 332 | 330 |
| 333 void BluetoothTestAndroid:: | 331 void BluetoothTestAndroid:: |
| 334 SimulateGattCharacteristicWriteWillFailSynchronouslyOnce( | 332 SimulateGattCharacteristicWriteWillFailSynchronouslyOnce( |
| 335 BluetoothRemoteGattCharacteristic* characteristic) { | 333 BluetoothRemoteGattCharacteristic* characteristic) { |
| 336 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = | 334 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = |
| 337 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); | 335 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); |
| 338 Java_FakeBluetoothGattCharacteristic_setWriteCharacteristicWillFailSynchronous
lyOnce( | 336 Java_FakeBluetoothGattCharacteristic_setWriteCharacteristicWillFailSynchronous
lyOnce( |
| 339 base::android::AttachCurrentThread(), | 337 base::android::AttachCurrentThread(), |
| 340 characteristic_android->GetJavaObject().obj()); | 338 characteristic_android->GetJavaObject()); |
| 341 } | 339 } |
| 342 | 340 |
| 343 void BluetoothTestAndroid::SimulateGattDescriptor( | 341 void BluetoothTestAndroid::SimulateGattDescriptor( |
| 344 BluetoothRemoteGattCharacteristic* characteristic, | 342 BluetoothRemoteGattCharacteristic* characteristic, |
| 345 const std::string& uuid) { | 343 const std::string& uuid) { |
| 346 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = | 344 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = |
| 347 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); | 345 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); |
| 348 JNIEnv* env = base::android::AttachCurrentThread(); | 346 JNIEnv* env = base::android::AttachCurrentThread(); |
| 349 | 347 |
| 350 Java_FakeBluetoothGattCharacteristic_addDescriptor( | 348 Java_FakeBluetoothGattCharacteristic_addDescriptor( |
| 351 env, characteristic_android->GetJavaObject().obj(), | 349 env, characteristic_android->GetJavaObject().obj(), |
| 352 base::android::ConvertUTF8ToJavaString(env, uuid).obj()); | 350 base::android::ConvertUTF8ToJavaString(env, uuid)); |
| 353 } | 351 } |
| 354 | 352 |
| 355 void BluetoothTestAndroid::RememberDescriptorForSubsequentAction( | 353 void BluetoothTestAndroid::RememberDescriptorForSubsequentAction( |
| 356 BluetoothRemoteGattDescriptor* descriptor) { | 354 BluetoothRemoteGattDescriptor* descriptor) { |
| 357 BluetoothRemoteGattDescriptorAndroid* descriptor_android = | 355 BluetoothRemoteGattDescriptorAndroid* descriptor_android = |
| 358 static_cast<BluetoothRemoteGattDescriptorAndroid*>(descriptor); | 356 static_cast<BluetoothRemoteGattDescriptorAndroid*>(descriptor); |
| 359 | 357 |
| 360 Java_FakeBluetoothGattDescriptor_rememberDescriptorForSubsequentAction( | 358 Java_FakeBluetoothGattDescriptor_rememberDescriptorForSubsequentAction( |
| 361 base::android::AttachCurrentThread(), | 359 base::android::AttachCurrentThread(), |
| 362 descriptor_android->GetJavaObject().obj()); | 360 descriptor_android->GetJavaObject()); |
| 363 } | 361 } |
| 364 | 362 |
| 365 void BluetoothTestAndroid::SimulateGattDescriptorRead( | 363 void BluetoothTestAndroid::SimulateGattDescriptorRead( |
| 366 BluetoothRemoteGattDescriptor* descriptor, | 364 BluetoothRemoteGattDescriptor* descriptor, |
| 367 const std::vector<uint8_t>& value) { | 365 const std::vector<uint8_t>& value) { |
| 368 BluetoothRemoteGattDescriptorAndroid* descriptor_android = | 366 BluetoothRemoteGattDescriptorAndroid* descriptor_android = |
| 369 static_cast<BluetoothRemoteGattDescriptorAndroid*>(descriptor); | 367 static_cast<BluetoothRemoteGattDescriptorAndroid*>(descriptor); |
| 370 JNIEnv* env = base::android::AttachCurrentThread(); | 368 JNIEnv* env = base::android::AttachCurrentThread(); |
| 371 | 369 |
| 372 Java_FakeBluetoothGattDescriptor_valueRead( | 370 Java_FakeBluetoothGattDescriptor_valueRead( |
| 373 env, | 371 env, |
| 374 descriptor_android ? descriptor_android->GetJavaObject().obj() : nullptr, | 372 descriptor_android ? descriptor_android->GetJavaObject().obj() : nullptr, |
| 375 0, // android.bluetooth.BluetoothGatt.GATT_SUCCESS | 373 0, // android.bluetooth.BluetoothGatt.GATT_SUCCESS |
| 376 base::android::ToJavaByteArray(env, value).obj()); | 374 base::android::ToJavaByteArray(env, value)); |
| 377 } | 375 } |
| 378 | 376 |
| 379 void BluetoothTestAndroid::SimulateGattDescriptorReadError( | 377 void BluetoothTestAndroid::SimulateGattDescriptorReadError( |
| 380 BluetoothRemoteGattDescriptor* descriptor, | 378 BluetoothRemoteGattDescriptor* descriptor, |
| 381 BluetoothRemoteGattService::GattErrorCode error_code) { | 379 BluetoothRemoteGattService::GattErrorCode error_code) { |
| 382 BluetoothRemoteGattDescriptorAndroid* descriptor_android = | 380 BluetoothRemoteGattDescriptorAndroid* descriptor_android = |
| 383 static_cast<BluetoothRemoteGattDescriptorAndroid*>(descriptor); | 381 static_cast<BluetoothRemoteGattDescriptorAndroid*>(descriptor); |
| 384 JNIEnv* env = base::android::AttachCurrentThread(); | 382 JNIEnv* env = base::android::AttachCurrentThread(); |
| 385 std::vector<uint8_t> empty_value; | 383 std::vector<uint8_t> empty_value; |
| 386 | 384 |
| 387 Java_FakeBluetoothGattDescriptor_valueRead( | 385 Java_FakeBluetoothGattDescriptor_valueRead( |
| 388 env, descriptor_android->GetJavaObject().obj(), | 386 env, descriptor_android->GetJavaObject().obj(), |
| 389 BluetoothRemoteGattServiceAndroid::GetAndroidErrorCode(error_code), | 387 BluetoothRemoteGattServiceAndroid::GetAndroidErrorCode(error_code), |
| 390 base::android::ToJavaByteArray(env, empty_value).obj()); | 388 base::android::ToJavaByteArray(env, empty_value)); |
| 391 } | 389 } |
| 392 | 390 |
| 393 void BluetoothTestAndroid::SimulateGattDescriptorReadWillFailSynchronouslyOnce( | 391 void BluetoothTestAndroid::SimulateGattDescriptorReadWillFailSynchronouslyOnce( |
| 394 BluetoothRemoteGattDescriptor* descriptor) { | 392 BluetoothRemoteGattDescriptor* descriptor) { |
| 395 BluetoothRemoteGattDescriptorAndroid* descriptor_android = | 393 BluetoothRemoteGattDescriptorAndroid* descriptor_android = |
| 396 static_cast<BluetoothRemoteGattDescriptorAndroid*>(descriptor); | 394 static_cast<BluetoothRemoteGattDescriptorAndroid*>(descriptor); |
| 397 JNIEnv* env = base::android::AttachCurrentThread(); | 395 JNIEnv* env = base::android::AttachCurrentThread(); |
| 398 | 396 |
| 399 Java_FakeBluetoothGattDescriptor_setReadDescriptorWillFailSynchronouslyOnce( | 397 Java_FakeBluetoothGattDescriptor_setReadDescriptorWillFailSynchronouslyOnce( |
| 400 env, descriptor_android->GetJavaObject().obj()); | 398 env, descriptor_android->GetJavaObject()); |
| 401 } | 399 } |
| 402 | 400 |
| 403 void BluetoothTestAndroid::SimulateGattDescriptorWrite( | 401 void BluetoothTestAndroid::SimulateGattDescriptorWrite( |
| 404 BluetoothRemoteGattDescriptor* descriptor) { | 402 BluetoothRemoteGattDescriptor* descriptor) { |
| 405 BluetoothRemoteGattDescriptorAndroid* descriptor_android = | 403 BluetoothRemoteGattDescriptorAndroid* descriptor_android = |
| 406 static_cast<BluetoothRemoteGattDescriptorAndroid*>(descriptor); | 404 static_cast<BluetoothRemoteGattDescriptorAndroid*>(descriptor); |
| 407 Java_FakeBluetoothGattDescriptor_valueWrite( | 405 Java_FakeBluetoothGattDescriptor_valueWrite( |
| 408 base::android::AttachCurrentThread(), | 406 base::android::AttachCurrentThread(), |
| 409 descriptor_android ? descriptor_android->GetJavaObject().obj() : nullptr, | 407 descriptor_android ? descriptor_android->GetJavaObject().obj() : nullptr, |
| 410 0); // android.bluetooth.BluetoothGatt.GATT_SUCCESS | 408 0); // android.bluetooth.BluetoothGatt.GATT_SUCCESS |
| 411 } | 409 } |
| 412 | 410 |
| 413 void BluetoothTestAndroid::SimulateGattDescriptorWriteError( | 411 void BluetoothTestAndroid::SimulateGattDescriptorWriteError( |
| 414 BluetoothRemoteGattDescriptor* descriptor, | 412 BluetoothRemoteGattDescriptor* descriptor, |
| 415 BluetoothRemoteGattService::GattErrorCode error_code) { | 413 BluetoothRemoteGattService::GattErrorCode error_code) { |
| 416 BluetoothRemoteGattDescriptorAndroid* descriptor_android = | 414 BluetoothRemoteGattDescriptorAndroid* descriptor_android = |
| 417 static_cast<BluetoothRemoteGattDescriptorAndroid*>(descriptor); | 415 static_cast<BluetoothRemoteGattDescriptorAndroid*>(descriptor); |
| 418 Java_FakeBluetoothGattDescriptor_valueWrite( | 416 Java_FakeBluetoothGattDescriptor_valueWrite( |
| 419 base::android::AttachCurrentThread(), | 417 base::android::AttachCurrentThread(), descriptor_android->GetJavaObject(), |
| 420 descriptor_android->GetJavaObject().obj(), | |
| 421 BluetoothRemoteGattServiceAndroid::GetAndroidErrorCode(error_code)); | 418 BluetoothRemoteGattServiceAndroid::GetAndroidErrorCode(error_code)); |
| 422 } | 419 } |
| 423 | 420 |
| 424 void BluetoothTestAndroid::SimulateGattDescriptorWriteWillFailSynchronouslyOnce( | 421 void BluetoothTestAndroid::SimulateGattDescriptorWriteWillFailSynchronouslyOnce( |
| 425 BluetoothRemoteGattDescriptor* descriptor) { | 422 BluetoothRemoteGattDescriptor* descriptor) { |
| 426 BluetoothRemoteGattDescriptorAndroid* descriptor_android = | 423 BluetoothRemoteGattDescriptorAndroid* descriptor_android = |
| 427 static_cast<BluetoothRemoteGattDescriptorAndroid*>(descriptor); | 424 static_cast<BluetoothRemoteGattDescriptorAndroid*>(descriptor); |
| 428 Java_FakeBluetoothGattDescriptor_setWriteDescriptorWillFailSynchronouslyOnce( | 425 Java_FakeBluetoothGattDescriptor_setWriteDescriptorWillFailSynchronouslyOnce( |
| 429 base::android::AttachCurrentThread(), | 426 base::android::AttachCurrentThread(), |
| 430 descriptor_android->GetJavaObject().obj()); | 427 descriptor_android->GetJavaObject()); |
| 431 } | 428 } |
| 432 | 429 |
| 433 void BluetoothTestAndroid::OnFakeBluetoothDeviceConnectGattCalled( | 430 void BluetoothTestAndroid::OnFakeBluetoothDeviceConnectGattCalled( |
| 434 JNIEnv* env, | 431 JNIEnv* env, |
| 435 const JavaParamRef<jobject>& caller) { | 432 const JavaParamRef<jobject>& caller) { |
| 436 gatt_open_connections_++; | 433 gatt_open_connections_++; |
| 437 gatt_connection_attempts_++; | 434 gatt_connection_attempts_++; |
| 438 } | 435 } |
| 439 | 436 |
| 440 void BluetoothTestAndroid::OnFakeBluetoothGattDisconnect( | 437 void BluetoothTestAndroid::OnFakeBluetoothGattDisconnect( |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 } | 490 } |
| 494 | 491 |
| 495 void BluetoothTestAndroid::OnFakeAdapterStateChanged( | 492 void BluetoothTestAndroid::OnFakeAdapterStateChanged( |
| 496 JNIEnv* env, | 493 JNIEnv* env, |
| 497 const JavaParamRef<jobject>& caller, | 494 const JavaParamRef<jobject>& caller, |
| 498 const bool powered) { | 495 const bool powered) { |
| 499 adapter_->NotifyAdapterPoweredChanged(powered); | 496 adapter_->NotifyAdapterPoweredChanged(powered); |
| 500 } | 497 } |
| 501 | 498 |
| 502 } // namespace device | 499 } // namespace device |
| OLD | NEW |