| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_remote_gatt_service_android.h" | 5 #include "device/bluetooth/bluetooth_remote_gatt_service_android.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 return RegisterNativesImpl( | 48 return RegisterNativesImpl( |
| 49 env); // Generated in ChromeBluetoothRemoteGattService_jni.h | 49 env); // Generated in ChromeBluetoothRemoteGattService_jni.h |
| 50 } | 50 } |
| 51 | 51 |
| 52 base::android::ScopedJavaLocalRef<jobject> | 52 base::android::ScopedJavaLocalRef<jobject> |
| 53 BluetoothRemoteGattServiceAndroid::GetJavaObject() { | 53 BluetoothRemoteGattServiceAndroid::GetJavaObject() { |
| 54 return base::android::ScopedJavaLocalRef<jobject>(j_service_); | 54 return base::android::ScopedJavaLocalRef<jobject>(j_service_); |
| 55 } | 55 } |
| 56 | 56 |
| 57 // static | 57 // static |
| 58 BluetoothGattService::GattErrorCode | 58 BluetoothRemoteGattService::GattErrorCode |
| 59 BluetoothRemoteGattServiceAndroid::GetGattErrorCode(int bluetooth_gatt_code) { | 59 BluetoothRemoteGattServiceAndroid::GetGattErrorCode(int bluetooth_gatt_code) { |
| 60 DCHECK(bluetooth_gatt_code != 0) << "Only errors valid. 0 == GATT_SUCCESS."; | 60 DCHECK(bluetooth_gatt_code != 0) << "Only errors valid. 0 == GATT_SUCCESS."; |
| 61 | 61 |
| 62 // TODO(scheib) Create new BluetoothGattService::GattErrorCode enums for | 62 // TODO(scheib) Create new BluetoothRemoteGattService::GattErrorCode enums for |
| 63 // android values not yet represented. http://crbug.com/548498 | 63 // android values not yet represented. http://crbug.com/548498 |
| 64 switch (bluetooth_gatt_code) { // android.bluetooth.BluetoothGatt values: | 64 switch (bluetooth_gatt_code) { // android.bluetooth.BluetoothGatt values: |
| 65 case 0x00000101: // GATT_FAILURE | 65 case 0x00000101: // GATT_FAILURE |
| 66 return GATT_ERROR_FAILED; | 66 return GATT_ERROR_FAILED; |
| 67 case 0x0000000d: // GATT_INVALID_ATTRIBUTE_LENGTH | 67 case 0x0000000d: // GATT_INVALID_ATTRIBUTE_LENGTH |
| 68 return GATT_ERROR_INVALID_LENGTH; | 68 return GATT_ERROR_INVALID_LENGTH; |
| 69 case 0x00000002: // GATT_READ_NOT_PERMITTED | 69 case 0x00000002: // GATT_READ_NOT_PERMITTED |
| 70 return GATT_ERROR_NOT_PERMITTED; | 70 return GATT_ERROR_NOT_PERMITTED; |
| 71 case 0x00000006: // GATT_REQUEST_NOT_SUPPORTED | 71 case 0x00000006: // GATT_REQUEST_NOT_SUPPORTED |
| 72 return GATT_ERROR_NOT_SUPPORTED; | 72 return GATT_ERROR_NOT_SUPPORTED; |
| 73 case 0x00000003: // GATT_WRITE_NOT_PERMITTED | 73 case 0x00000003: // GATT_WRITE_NOT_PERMITTED |
| 74 return GATT_ERROR_NOT_PERMITTED; | 74 return GATT_ERROR_NOT_PERMITTED; |
| 75 default: | 75 default: |
| 76 VLOG(1) << "Unhandled status: " << bluetooth_gatt_code; | 76 VLOG(1) << "Unhandled status: " << bluetooth_gatt_code; |
| 77 return BluetoothGattService::GATT_ERROR_UNKNOWN; | 77 return BluetoothRemoteGattService::GATT_ERROR_UNKNOWN; |
| 78 } | 78 } |
| 79 } | 79 } |
| 80 | 80 |
| 81 // static | 81 // static |
| 82 int BluetoothRemoteGattServiceAndroid::GetAndroidErrorCode( | 82 int BluetoothRemoteGattServiceAndroid::GetAndroidErrorCode( |
| 83 BluetoothGattService::GattErrorCode error_code) { | 83 BluetoothRemoteGattService::GattErrorCode error_code) { |
| 84 // TODO(scheib) Create new BluetoothGattService::GattErrorCode enums for | 84 // TODO(scheib) Create new BluetoothRemoteGattService::GattErrorCode enums for |
| 85 // android values not yet represented. http://crbug.com/548498 | 85 // android values not yet represented. http://crbug.com/548498 |
| 86 switch (error_code) { // Return values from android.bluetooth.BluetoothGatt: | 86 switch (error_code) { // Return values from android.bluetooth.BluetoothGatt: |
| 87 case GATT_ERROR_UNKNOWN: | 87 case GATT_ERROR_UNKNOWN: |
| 88 return 0x00000101; // GATT_FAILURE. No good match. | 88 return 0x00000101; // GATT_FAILURE. No good match. |
| 89 case GATT_ERROR_FAILED: | 89 case GATT_ERROR_FAILED: |
| 90 return 0x00000101; // GATT_FAILURE | 90 return 0x00000101; // GATT_FAILURE |
| 91 case GATT_ERROR_IN_PROGRESS: | 91 case GATT_ERROR_IN_PROGRESS: |
| 92 return 0x00000101; // GATT_FAILURE. No good match. | 92 return 0x00000101; // GATT_FAILURE. No good match. |
| 93 case GATT_ERROR_INVALID_LENGTH: | 93 case GATT_ERROR_INVALID_LENGTH: |
| 94 return 0x0000000d; // GATT_INVALID_ATTRIBUTE_LENGTH | 94 return 0x0000000d; // GATT_INVALID_ATTRIBUTE_LENGTH |
| (...skipping 16 matching lines...) Expand all Loading... |
| 111 std::string BluetoothRemoteGattServiceAndroid::GetIdentifier() const { | 111 std::string BluetoothRemoteGattServiceAndroid::GetIdentifier() const { |
| 112 return instance_id_; | 112 return instance_id_; |
| 113 } | 113 } |
| 114 | 114 |
| 115 device::BluetoothUUID BluetoothRemoteGattServiceAndroid::GetUUID() const { | 115 device::BluetoothUUID BluetoothRemoteGattServiceAndroid::GetUUID() const { |
| 116 return device::BluetoothUUID( | 116 return device::BluetoothUUID( |
| 117 ConvertJavaStringToUTF8(Java_ChromeBluetoothRemoteGattService_getUUID( | 117 ConvertJavaStringToUTF8(Java_ChromeBluetoothRemoteGattService_getUUID( |
| 118 AttachCurrentThread(), j_service_.obj()))); | 118 AttachCurrentThread(), j_service_.obj()))); |
| 119 } | 119 } |
| 120 | 120 |
| 121 bool BluetoothRemoteGattServiceAndroid::IsLocal() const { | |
| 122 return false; | |
| 123 } | |
| 124 | |
| 125 bool BluetoothRemoteGattServiceAndroid::IsPrimary() const { | 121 bool BluetoothRemoteGattServiceAndroid::IsPrimary() const { |
| 126 NOTIMPLEMENTED(); | 122 NOTIMPLEMENTED(); |
| 127 return true; | 123 return true; |
| 128 } | 124 } |
| 129 | 125 |
| 130 device::BluetoothDevice* BluetoothRemoteGattServiceAndroid::GetDevice() const { | 126 device::BluetoothDevice* BluetoothRemoteGattServiceAndroid::GetDevice() const { |
| 131 return device_; | 127 return device_; |
| 132 } | 128 } |
| 133 | 129 |
| 134 std::vector<device::BluetoothGattCharacteristic*> | 130 std::vector<device::BluetoothRemoteGattCharacteristic*> |
| 135 BluetoothRemoteGattServiceAndroid::GetCharacteristics() const { | 131 BluetoothRemoteGattServiceAndroid::GetCharacteristics() const { |
| 136 EnsureCharacteristicsCreated(); | 132 EnsureCharacteristicsCreated(); |
| 137 std::vector<device::BluetoothGattCharacteristic*> characteristics; | 133 std::vector<device::BluetoothRemoteGattCharacteristic*> characteristics; |
| 138 for (const auto& map_iter : characteristics_) | 134 for (const auto& map_iter : characteristics_) |
| 139 characteristics.push_back(map_iter.second); | 135 characteristics.push_back(map_iter.second); |
| 140 return characteristics; | 136 return characteristics; |
| 141 } | 137 } |
| 142 | 138 |
| 143 std::vector<device::BluetoothGattService*> | 139 std::vector<device::BluetoothRemoteGattService*> |
| 144 BluetoothRemoteGattServiceAndroid::GetIncludedServices() const { | 140 BluetoothRemoteGattServiceAndroid::GetIncludedServices() const { |
| 145 NOTIMPLEMENTED(); | 141 NOTIMPLEMENTED(); |
| 146 return std::vector<device::BluetoothGattService*>(); | 142 return std::vector<device::BluetoothRemoteGattService*>(); |
| 147 } | 143 } |
| 148 | 144 |
| 149 device::BluetoothGattCharacteristic* | 145 device::BluetoothRemoteGattCharacteristic* |
| 150 BluetoothRemoteGattServiceAndroid::GetCharacteristic( | 146 BluetoothRemoteGattServiceAndroid::GetCharacteristic( |
| 151 const std::string& identifier) const { | 147 const std::string& identifier) const { |
| 152 EnsureCharacteristicsCreated(); | 148 EnsureCharacteristicsCreated(); |
| 153 const auto& iter = characteristics_.find(identifier); | 149 const auto& iter = characteristics_.find(identifier); |
| 154 if (iter == characteristics_.end()) | 150 if (iter == characteristics_.end()) |
| 155 return nullptr; | 151 return nullptr; |
| 156 return iter->second; | 152 return iter->second; |
| 157 } | 153 } |
| 158 | 154 |
| 159 bool BluetoothRemoteGattServiceAndroid::AddCharacteristic( | |
| 160 device::BluetoothGattCharacteristic* characteristic) { | |
| 161 return false; | |
| 162 } | |
| 163 | |
| 164 bool BluetoothRemoteGattServiceAndroid::AddIncludedService( | |
| 165 device::BluetoothGattService* service) { | |
| 166 return false; | |
| 167 } | |
| 168 | |
| 169 void BluetoothRemoteGattServiceAndroid::Register( | |
| 170 const base::Closure& callback, | |
| 171 const ErrorCallback& error_callback) { | |
| 172 error_callback.Run(GATT_ERROR_NOT_SUPPORTED); | |
| 173 } | |
| 174 | |
| 175 void BluetoothRemoteGattServiceAndroid::Unregister( | |
| 176 const base::Closure& callback, | |
| 177 const ErrorCallback& error_callback) { | |
| 178 error_callback.Run(GATT_ERROR_NOT_SUPPORTED); | |
| 179 } | |
| 180 | |
| 181 void BluetoothRemoteGattServiceAndroid::CreateGattRemoteCharacteristic( | 155 void BluetoothRemoteGattServiceAndroid::CreateGattRemoteCharacteristic( |
| 182 JNIEnv* env, | 156 JNIEnv* env, |
| 183 const JavaParamRef<jobject>& caller, | 157 const JavaParamRef<jobject>& caller, |
| 184 const JavaParamRef<jstring>& instance_id, | 158 const JavaParamRef<jstring>& instance_id, |
| 185 const JavaParamRef<jobject>& /* BluetoothGattCharacteristicWrapper */ | 159 const JavaParamRef<jobject>& /* BluetoothGattCharacteristicWrapper */ |
| 186 bluetooth_gatt_characteristic_wrapper, | 160 bluetooth_gatt_characteristic_wrapper, |
| 187 const JavaParamRef< | 161 const JavaParamRef< |
| 188 jobject>& /* ChromeBluetoothDevice */ chrome_bluetooth_device) { | 162 jobject>& /* ChromeBluetoothDevice */ chrome_bluetooth_device) { |
| 189 std::string instance_id_string = | 163 std::string instance_id_string = |
| 190 base::android::ConvertJavaStringToUTF8(env, instance_id); | 164 base::android::ConvertJavaStringToUTF8(env, instance_id); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 207 void BluetoothRemoteGattServiceAndroid::EnsureCharacteristicsCreated() const { | 181 void BluetoothRemoteGattServiceAndroid::EnsureCharacteristicsCreated() const { |
| 208 if (!characteristics_.empty()) | 182 if (!characteristics_.empty()) |
| 209 return; | 183 return; |
| 210 | 184 |
| 211 // Java call | 185 // Java call |
| 212 Java_ChromeBluetoothRemoteGattService_createCharacteristics( | 186 Java_ChromeBluetoothRemoteGattService_createCharacteristics( |
| 213 AttachCurrentThread(), j_service_.obj()); | 187 AttachCurrentThread(), j_service_.obj()); |
| 214 } | 188 } |
| 215 | 189 |
| 216 } // namespace device | 190 } // namespace device |
| OLD | NEW |