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> |
| 8 #include <sstream> |
| 9 |
| 10 #include "base/android/jni_string.h" |
7 #include "base/logging.h" | 11 #include "base/logging.h" |
8 #include "device/bluetooth/android/wrappers.h" | 12 #include "device/bluetooth/android/wrappers.h" |
9 #include "device/bluetooth/bluetooth_adapter_android.h" | 13 #include "device/bluetooth/bluetooth_adapter_android.h" |
10 #include "device/bluetooth/bluetooth_device_android.h" | 14 #include "device/bluetooth/bluetooth_device_android.h" |
11 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h" | 15 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h" |
12 #include "jni/Fakes_jni.h" | 16 #include "jni/Fakes_jni.h" |
13 | 17 |
14 using base::android::AttachCurrentThread; | 18 using base::android::AttachCurrentThread; |
15 using base::android::ScopedJavaLocalRef; | 19 using base::android::ScopedJavaLocalRef; |
16 | 20 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 BluetoothDeviceAndroid* device_android = | 104 BluetoothDeviceAndroid* device_android = |
101 static_cast<BluetoothDeviceAndroid*>(device); | 105 static_cast<BluetoothDeviceAndroid*>(device); |
102 | 106 |
103 Java_FakeBluetoothDevice_connectionStateChange( | 107 Java_FakeBluetoothDevice_connectionStateChange( |
104 AttachCurrentThread(), device_android->GetJavaObject().obj(), | 108 AttachCurrentThread(), device_android->GetJavaObject().obj(), |
105 0, // android.bluetooth.BluetoothGatt.GATT_SUCCESS | 109 0, // android.bluetooth.BluetoothGatt.GATT_SUCCESS |
106 false); // disconnected | 110 false); // disconnected |
107 } | 111 } |
108 | 112 |
109 void BluetoothTestAndroid::SimulateGattServicesDiscovered( | 113 void BluetoothTestAndroid::SimulateGattServicesDiscovered( |
110 BluetoothDevice* device) { | 114 BluetoothDevice* device, |
| 115 const std::vector<std::string>& uuids) { |
111 BluetoothDeviceAndroid* device_android = | 116 BluetoothDeviceAndroid* device_android = |
112 static_cast<BluetoothDeviceAndroid*>(device); | 117 static_cast<BluetoothDeviceAndroid*>(device); |
| 118 JNIEnv* env = base::android::AttachCurrentThread(); |
| 119 |
| 120 // Join UUID strings into a single string. |
| 121 std::ostringstream uuids_space_delimited; |
| 122 std::copy(uuids.begin(), uuids.end(), |
| 123 std::ostream_iterator<std::string>(uuids_space_delimited, " ")); |
113 | 124 |
114 Java_FakeBluetoothDevice_servicesDiscovered( | 125 Java_FakeBluetoothDevice_servicesDiscovered( |
115 AttachCurrentThread(), device_android->GetJavaObject().obj(), | 126 env, device_android->GetJavaObject().obj(), |
116 0); // android.bluetooth.BluetoothGatt.GATT_SUCCESS | 127 0, // android.bluetooth.BluetoothGatt.GATT_SUCCESS |
| 128 base::android::ConvertUTF8ToJavaString(env, uuids_space_delimited.str()) |
| 129 .obj()); |
117 } | 130 } |
118 | 131 |
119 void BluetoothTestAndroid::SimulateGattServicesDiscoveryError( | 132 void BluetoothTestAndroid::SimulateGattServicesDiscoveryError( |
120 BluetoothDevice* device) { | 133 BluetoothDevice* device) { |
121 BluetoothDeviceAndroid* device_android = | 134 BluetoothDeviceAndroid* device_android = |
122 static_cast<BluetoothDeviceAndroid*>(device); | 135 static_cast<BluetoothDeviceAndroid*>(device); |
123 | 136 |
124 Java_FakeBluetoothDevice_servicesDiscovered( | 137 Java_FakeBluetoothDevice_servicesDiscovered( |
125 AttachCurrentThread(), device_android->GetJavaObject().obj(), | 138 AttachCurrentThread(), device_android->GetJavaObject().obj(), |
126 0x00000101); // android.bluetooth.BluetoothGatt.GATT_FAILURE | 139 0x00000101, // android.bluetooth.BluetoothGatt.GATT_FAILURE |
| 140 nullptr); |
127 } | 141 } |
128 | 142 |
129 void BluetoothTestAndroid::OnFakeBluetoothDeviceConnectGattCalled( | 143 void BluetoothTestAndroid::OnFakeBluetoothDeviceConnectGattCalled( |
130 JNIEnv* env, | 144 JNIEnv* env, |
131 jobject caller) { | 145 jobject caller) { |
132 gatt_connection_attempts_++; | 146 gatt_connection_attempts_++; |
133 } | 147 } |
134 | 148 |
135 void BluetoothTestAndroid::OnFakeBluetoothGattDisconnect(JNIEnv* env, | 149 void BluetoothTestAndroid::OnFakeBluetoothGattDisconnect(JNIEnv* env, |
136 jobject caller) { | 150 jobject caller) { |
137 gatt_disconnection_attempts_++; | 151 gatt_disconnection_attempts_++; |
138 } | 152 } |
139 | 153 |
140 void BluetoothTestAndroid::OnFakeBluetoothGattDiscoverServices(JNIEnv* env, | 154 void BluetoothTestAndroid::OnFakeBluetoothGattDiscoverServices(JNIEnv* env, |
141 jobject caller) { | 155 jobject caller) { |
142 gatt_discovery_attempts_++; | 156 gatt_discovery_attempts_++; |
143 } | 157 } |
144 | 158 |
145 } // namespace device | 159 } // namespace device |
OLD | NEW |