Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(578)

Side by Side Diff: device/bluetooth/test/bluetooth_test_android.cc

Issue 2727683003: bluetooth: Clean up connection errors (Closed)
Patch Set: format Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 static_cast<BluetoothDeviceAndroid*>(device); 109 static_cast<BluetoothDeviceAndroid*>(device);
110 110
111 Java_FakeBluetoothDevice_connectionStateChange( 111 Java_FakeBluetoothDevice_connectionStateChange(
112 AttachCurrentThread(), device_android->GetJavaObject(), 112 AttachCurrentThread(), device_android->GetJavaObject(),
113 0, // android.bluetooth.BluetoothGatt.GATT_SUCCESS 113 0, // android.bluetooth.BluetoothGatt.GATT_SUCCESS
114 true); // connected 114 true); // connected
115 } 115 }
116 116
117 void BluetoothTestAndroid::SimulateGattConnectionError( 117 void BluetoothTestAndroid::SimulateGattConnectionError(
118 BluetoothDevice* device, 118 BluetoothDevice* device,
119 BluetoothDevice::ConnectErrorCode) { 119 BluetoothDevice::ConnectErrorCode error_code) {
120 BluetoothDeviceAndroid* device_android = 120 BluetoothDeviceAndroid* device_android =
121 static_cast<BluetoothDeviceAndroid*>(device); 121 static_cast<BluetoothDeviceAndroid*>(device);
122 int32_t android_error = 0;
123
124 switch (error_code) {
125 case BluetoothDevice::ERROR_AUTH_CANCELED:
126 case BluetoothDevice::ERROR_AUTH_FAILED:
127 case BluetoothDevice::ERROR_AUTH_REJECTED:
128 case BluetoothDevice::ERROR_AUTH_TIMEOUT:
129 // These errors are only relevant for pairing and therefore not relevant
130 // to our Android implementation, so we just return Unspecified Error
131 // (0x1f) from BT Spec 5.0 [Vol 2, Part D] 2.31.
132 android_error = 0x1f;
133 break;
134 case BluetoothDevice::ERROR_FAILED:
135 // 0x85 is the number returned by Bluedroid in gatt_api.h for GATT_ERROR
136 // which we map to ERROR_FAILED.
137 android_error = 0x85;
138 break;
139 case BluetoothDevice::ERROR_INPROGRESS:
140 // 0x87 is the number returned by Bluedroid in gatt_api.h for GATT_PENDING
141 // which we map to ERROR_INPROGRESS.
142 android_error = 0x87;
143 break;
144 case BluetoothDevice::ERROR_UNKNOWN:
145 case BluetoothDevice::ERROR_UNSUPPORTED_DEVICE:
146 // We don't know of any instances of Android returning errors that would
147 // map to these errors so we just return Unspecified Error
148 // (0x1f) from BT Spec 5.0 [Vol 2, Part D] 2.31.
149 android_error = 0x1f;
150 break;
151 case BluetoothDevice::NUM_CONNECT_ERROR_CODES:
152 NOTREACHED();
153 android_error = 0x1f;
154 break;
155 }
122 156
123 Java_FakeBluetoothDevice_connectionStateChange( 157 Java_FakeBluetoothDevice_connectionStateChange(
124 AttachCurrentThread(), device_android->GetJavaObject(), 158 AttachCurrentThread(), device_android->GetJavaObject(), android_error,
125 // TODO(ortuno): Add all types of errors Android can produce. For now we 159 false /* connected */);
126 // just return a timeout error.
127 // http://crbug.com/578191
128 0x08, // Connection Timeout from Bluetooth Spec.
129 false); // connected
130 } 160 }
131 161
132 void BluetoothTestAndroid::SimulateGattDisconnection(BluetoothDevice* device) { 162 void BluetoothTestAndroid::SimulateGattDisconnection(BluetoothDevice* device) {
133 BluetoothDeviceAndroid* device_android = 163 BluetoothDeviceAndroid* device_android =
134 static_cast<BluetoothDeviceAndroid*>(device); 164 static_cast<BluetoothDeviceAndroid*>(device);
135 165
136 Java_FakeBluetoothDevice_connectionStateChange( 166 Java_FakeBluetoothDevice_connectionStateChange(
137 AttachCurrentThread(), device_android->GetJavaObject(), 167 AttachCurrentThread(), device_android->GetJavaObject(),
138 0x13, // Connection terminate by peer user from Bluetooth Spec. 168 0x85, // GATT_ERROR from Bluedroid in gatt_api.h
139 false); // disconnected 169 false); // disconnected
140 } 170 }
141 171
142 void BluetoothTestAndroid::SimulateGattServicesDiscovered( 172 void BluetoothTestAndroid::SimulateGattServicesDiscovered(
143 BluetoothDevice* device, 173 BluetoothDevice* device,
144 const std::vector<std::string>& uuids) { 174 const std::vector<std::string>& uuids) {
145 BluetoothDeviceAndroid* device_android = nullptr; 175 BluetoothDeviceAndroid* device_android = nullptr;
146 if (device) { 176 if (device) {
147 device_android = static_cast<BluetoothDeviceAndroid*>(device); 177 device_android = static_cast<BluetoothDeviceAndroid*>(device);
148 } 178 }
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 } 549 }
520 550
521 void BluetoothTestAndroid::OnFakeAdapterStateChanged( 551 void BluetoothTestAndroid::OnFakeAdapterStateChanged(
522 JNIEnv* env, 552 JNIEnv* env,
523 const JavaParamRef<jobject>& caller, 553 const JavaParamRef<jobject>& caller,
524 const bool powered) { 554 const bool powered) {
525 adapter_->NotifyAdapterPoweredChanged(powered); 555 adapter_->NotifyAdapterPoweredChanged(powered);
526 } 556 }
527 557
528 } // namespace device 558 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698