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

Side by Side Diff: components/arc/bluetooth/arc_bluetooth_bridge.cc

Issue 2104043002: arc: bluetooth: Implement Gatt Server add/delete/start/stop service (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gs1
Patch Set: Use running id / implement add descriptor Created 4 years, 5 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
« no previous file with comments | « components/arc/bluetooth/arc_bluetooth_bridge.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "components/arc/bluetooth/arc_bluetooth_bridge.h" 5 #include "components/arc/bluetooth/arc_bluetooth_bridge.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <iomanip> 10 #include <iomanip>
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 using device::BluetoothLocalGattService; 42 using device::BluetoothLocalGattService;
43 using device::BluetoothRemoteGattCharacteristic; 43 using device::BluetoothRemoteGattCharacteristic;
44 using device::BluetoothRemoteGattDescriptor; 44 using device::BluetoothRemoteGattDescriptor;
45 using device::BluetoothRemoteGattService; 45 using device::BluetoothRemoteGattService;
46 using device::BluetoothTransport; 46 using device::BluetoothTransport;
47 using device::BluetoothUUID; 47 using device::BluetoothUUID;
48 48
49 namespace { 49 namespace {
50 constexpr int32_t kMinBtleVersion = 1; 50 constexpr int32_t kMinBtleVersion = 1;
51 constexpr int32_t kMinBtleNotifyVersion = 2; 51 constexpr int32_t kMinBtleNotifyVersion = 2;
52 constexpr int32_t kMinGattServerVersion = 3;
52 constexpr uint32_t kGattReadPermission = 53 constexpr uint32_t kGattReadPermission =
53 BluetoothGattCharacteristic::Permission::PERMISSION_READ | 54 BluetoothGattCharacteristic::Permission::PERMISSION_READ |
54 BluetoothGattCharacteristic::Permission::PERMISSION_READ_ENCRYPTED | 55 BluetoothGattCharacteristic::Permission::PERMISSION_READ_ENCRYPTED |
55 BluetoothGattCharacteristic::Permission:: 56 BluetoothGattCharacteristic::Permission::
56 PERMISSION_READ_ENCRYPTED_AUTHENTICATED; 57 PERMISSION_READ_ENCRYPTED_AUTHENTICATED;
57 constexpr uint32_t kGattWritePermission = 58 constexpr uint32_t kGattWritePermission =
58 BluetoothGattCharacteristic::Permission::PERMISSION_WRITE | 59 BluetoothGattCharacteristic::Permission::PERMISSION_WRITE |
59 BluetoothGattCharacteristic::Permission::PERMISSION_WRITE_ENCRYPTED | 60 BluetoothGattCharacteristic::Permission::PERMISSION_WRITE_ENCRYPTED |
60 BluetoothGattCharacteristic::Permission:: 61 BluetoothGattCharacteristic::Permission::
61 PERMISSION_WRITE_ENCRYPTED_AUTHENTICATED; 62 PERMISSION_WRITE_ENCRYPTED_AUTHENTICATED;
63 constexpr int32_t kInvalidGattAttributeHandle = -1;
62 } // namespace 64 } // namespace
63 65
64 namespace arc { 66 namespace arc {
65 67
66 ArcBluetoothBridge::ArcBluetoothBridge(ArcBridgeService* bridge_service) 68 ArcBluetoothBridge::ArcBluetoothBridge(ArcBridgeService* bridge_service)
67 : ArcService(bridge_service), binding_(this), weak_factory_(this) { 69 : ArcService(bridge_service), binding_(this), weak_factory_(this) {
68 if (BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) { 70 if (BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) {
69 VLOG(1) << "registering bluetooth adapter"; 71 VLOG(1) << "registering bluetooth adapter";
70 BluetoothAdapterFactory::GetAdapter(base::Bind( 72 BluetoothAdapterFactory::GetAdapter(base::Bind(
71 &ArcBluetoothBridge::OnAdapterInitialized, weak_factory_.GetWeakPtr())); 73 &ArcBluetoothBridge::OnAdapterInitialized, weak_factory_.GetWeakPtr()));
(...skipping 782 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 mojom::BluetoothGattIDPtr desc_id) const { 856 mojom::BluetoothGattIDPtr desc_id) const {
855 BluetoothRemoteGattCharacteristic* characteristic = FindGattCharacteristic( 857 BluetoothRemoteGattCharacteristic* characteristic = FindGattCharacteristic(
856 std::move(remote_addr), std::move(service_id), std::move(char_id)); 858 std::move(remote_addr), std::move(service_id), std::move(char_id));
857 if (!characteristic) 859 if (!characteristic)
858 return nullptr; 860 return nullptr;
859 861
860 return FindGattObjectFromUuid<BluetoothRemoteGattDescriptor>( 862 return FindGattObjectFromUuid<BluetoothRemoteGattDescriptor>(
861 characteristic->GetDescriptors(), desc_id->uuid.To<BluetoothUUID>()); 863 characteristic->GetDescriptors(), desc_id->uuid.To<BluetoothUUID>());
862 } 864 }
863 865
866 // Common callback function for Gatt operation that only need to report
867 // Gatt status back to Android.
868 void ArcBluetoothBridge::OnGattOperationDone(
869 const GattStatusCallback& callback) const {
870 callback.Run(mojom::BluetoothGattStatus::GATT_SUCCESS);
871 }
872
873 void ArcBluetoothBridge::OnGattOperationError(
874 const GattStatusCallback& callback,
875 BluetoothGattService::GattErrorCode error_code) const {
876 callback.Run(mojo::ConvertTo<mojom::BluetoothGattStatus>(error_code));
877 }
878
864 // Same callback for both ReadGattCharacteristic and ReadGattDescriptor 879 // Same callback for both ReadGattCharacteristic and ReadGattDescriptor
865 void ArcBluetoothBridge::OnGattReadDone( 880 void ArcBluetoothBridge::OnGattReadDone(
866 const GattReadCallback& callback, 881 const GattReadCallback& callback,
867 const std::vector<uint8_t>& result) const { 882 const std::vector<uint8_t>& result) const {
868 mojom::BluetoothGattValuePtr gattValue = mojom::BluetoothGattValue::New(); 883 mojom::BluetoothGattValuePtr gattValue = mojom::BluetoothGattValue::New();
869 gattValue->status = mojom::BluetoothGattStatus::GATT_SUCCESS; 884 gattValue->status = mojom::BluetoothGattStatus::GATT_SUCCESS;
870 gattValue->value = mojo::Array<uint8_t>::From(result); 885 gattValue->value = mojo::Array<uint8_t>::From(result);
871 callback.Run(std::move(gattValue)); 886 callback.Run(std::move(gattValue));
872 } 887 }
873 888
874 void ArcBluetoothBridge::OnGattReadError( 889 void ArcBluetoothBridge::OnGattReadError(
875 const GattReadCallback& callback, 890 const GattReadCallback& callback,
876 BluetoothGattService::GattErrorCode error_code) const { 891 BluetoothGattService::GattErrorCode error_code) const {
877 mojom::BluetoothGattValuePtr gattValue = mojom::BluetoothGattValue::New(); 892 mojom::BluetoothGattValuePtr gattValue = mojom::BluetoothGattValue::New();
878 gattValue->status = mojo::ConvertTo<mojom::BluetoothGattStatus>(error_code); 893 gattValue->status = mojo::ConvertTo<mojom::BluetoothGattStatus>(error_code);
879 gattValue->value = nullptr; 894 gattValue->value = nullptr;
880 895
881 callback.Run(std::move(gattValue)); 896 callback.Run(std::move(gattValue));
882 } 897 }
883 898
884 // Same callback for both WriteGattCharacteristic and WriteGattDescriptor
885 void ArcBluetoothBridge::OnGattWriteDone(
886 const GattWriteCallback& callback) const {
887 callback.Run(mojom::BluetoothGattStatus::GATT_SUCCESS);
888 }
889
890 void ArcBluetoothBridge::OnGattWriteError(
891 const GattWriteCallback& callback,
892 BluetoothGattService::GattErrorCode error_code) const {
893 callback.Run(mojo::ConvertTo<mojom::BluetoothGattStatus>(error_code));
894 }
895
896 void ArcBluetoothBridge::ReadGattCharacteristic( 899 void ArcBluetoothBridge::ReadGattCharacteristic(
897 mojom::BluetoothAddressPtr remote_addr, 900 mojom::BluetoothAddressPtr remote_addr,
898 mojom::BluetoothGattServiceIDPtr service_id, 901 mojom::BluetoothGattServiceIDPtr service_id,
899 mojom::BluetoothGattIDPtr char_id, 902 mojom::BluetoothGattIDPtr char_id,
900 const ReadGattCharacteristicCallback& callback) { 903 const ReadGattCharacteristicCallback& callback) {
901 BluetoothRemoteGattCharacteristic* characteristic = FindGattCharacteristic( 904 BluetoothRemoteGattCharacteristic* characteristic = FindGattCharacteristic(
902 std::move(remote_addr), std::move(service_id), std::move(char_id)); 905 std::move(remote_addr), std::move(service_id), std::move(char_id));
903 DCHECK(characteristic); 906 DCHECK(characteristic);
904 DCHECK(characteristic->GetPermissions() & kGattReadPermission); 907 DCHECK(characteristic->GetPermissions() & kGattReadPermission);
905 908
(...skipping 10 matching lines...) Expand all
916 mojom::BluetoothGattIDPtr char_id, 919 mojom::BluetoothGattIDPtr char_id,
917 mojom::BluetoothGattValuePtr value, 920 mojom::BluetoothGattValuePtr value,
918 const WriteGattCharacteristicCallback& callback) { 921 const WriteGattCharacteristicCallback& callback) {
919 BluetoothRemoteGattCharacteristic* characteristic = FindGattCharacteristic( 922 BluetoothRemoteGattCharacteristic* characteristic = FindGattCharacteristic(
920 std::move(remote_addr), std::move(service_id), std::move(char_id)); 923 std::move(remote_addr), std::move(service_id), std::move(char_id));
921 DCHECK(characteristic); 924 DCHECK(characteristic);
922 DCHECK(characteristic->GetPermissions() & kGattWritePermission); 925 DCHECK(characteristic->GetPermissions() & kGattWritePermission);
923 926
924 characteristic->WriteRemoteCharacteristic( 927 characteristic->WriteRemoteCharacteristic(
925 value->value.To<std::vector<uint8_t>>(), 928 value->value.To<std::vector<uint8_t>>(),
926 base::Bind(&ArcBluetoothBridge::OnGattWriteDone, 929 base::Bind(&ArcBluetoothBridge::OnGattOperationDone,
927 weak_factory_.GetWeakPtr(), callback), 930 weak_factory_.GetWeakPtr(), callback),
928 base::Bind(&ArcBluetoothBridge::OnGattWriteError, 931 base::Bind(&ArcBluetoothBridge::OnGattOperationError,
929 weak_factory_.GetWeakPtr(), callback)); 932 weak_factory_.GetWeakPtr(), callback));
930 } 933 }
931 934
932 void ArcBluetoothBridge::ReadGattDescriptor( 935 void ArcBluetoothBridge::ReadGattDescriptor(
933 mojom::BluetoothAddressPtr remote_addr, 936 mojom::BluetoothAddressPtr remote_addr,
934 mojom::BluetoothGattServiceIDPtr service_id, 937 mojom::BluetoothGattServiceIDPtr service_id,
935 mojom::BluetoothGattIDPtr char_id, 938 mojom::BluetoothGattIDPtr char_id,
936 mojom::BluetoothGattIDPtr desc_id, 939 mojom::BluetoothGattIDPtr desc_id,
937 const ReadGattDescriptorCallback& callback) { 940 const ReadGattDescriptorCallback& callback) {
938 BluetoothRemoteGattDescriptor* descriptor = 941 BluetoothRemoteGattDescriptor* descriptor =
(...skipping 24 matching lines...) Expand all
963 966
964 // To register / deregister GATT notification, we need to 967 // To register / deregister GATT notification, we need to
965 // 1) Write to CCC Descriptor to enable/disable the notification 968 // 1) Write to CCC Descriptor to enable/disable the notification
966 // 2) Ask BT hw to register / deregister the notification 969 // 2) Ask BT hw to register / deregister the notification
967 // The Chrome API groups both steps into one API, and does not support writing 970 // The Chrome API groups both steps into one API, and does not support writing
968 // directly to the CCC Descriptor. Therefore, until we fix 971 // directly to the CCC Descriptor. Therefore, until we fix
969 // https://crbug.com/622832, we return successfully when we encounter this. 972 // https://crbug.com/622832, we return successfully when we encounter this.
970 // TODO(http://crbug.com/622832) 973 // TODO(http://crbug.com/622832)
971 if (descriptor->GetUUID() == 974 if (descriptor->GetUUID() ==
972 BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid()) { 975 BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid()) {
973 OnGattWriteDone(callback); 976 OnGattOperationDone(callback);
974 return; 977 return;
975 } 978 }
976 979
977 descriptor->WriteRemoteDescriptor( 980 descriptor->WriteRemoteDescriptor(
978 value->value.To<std::vector<uint8_t>>(), 981 value->value.To<std::vector<uint8_t>>(),
979 base::Bind(&ArcBluetoothBridge::OnGattWriteDone, 982 base::Bind(&ArcBluetoothBridge::OnGattOperationDone,
980 weak_factory_.GetWeakPtr(), callback), 983 weak_factory_.GetWeakPtr(), callback),
981 base::Bind(&ArcBluetoothBridge::OnGattWriteError, 984 base::Bind(&ArcBluetoothBridge::OnGattOperationError,
982 weak_factory_.GetWeakPtr(), callback)); 985 weak_factory_.GetWeakPtr(), callback));
983 } 986 }
984 987
985 void ArcBluetoothBridge::OnGattNotifyStartDone( 988 void ArcBluetoothBridge::OnGattNotifyStartDone(
986 const RegisterForGattNotificationCallback& callback, 989 const RegisterForGattNotificationCallback& callback,
987 const std::string char_string_id, 990 const std::string char_string_id,
988 std::unique_ptr<BluetoothGattNotifySession> notify_session) { 991 std::unique_ptr<BluetoothGattNotifySession> notify_session) {
989 notification_session_[char_string_id] = std::move(notify_session); 992 notification_session_[char_string_id] = std::move(notify_session);
990 callback.Run(mojom::BluetoothGattStatus::GATT_SUCCESS); 993 callback.Run(mojom::BluetoothGattStatus::GATT_SUCCESS);
991 } 994 }
992 995
993 void ArcBluetoothBridge::OnGattNotifyStartError(
994 const RegisterForGattNotificationCallback& callback,
995 BluetoothGattService::GattErrorCode error_code) const {
996 callback.Run(mojo::ConvertTo<mojom::BluetoothGattStatus>(error_code));
997 }
998
999 void ArcBluetoothBridge::OnGattNotifyStopDone(
1000 const DeregisterForGattNotificationCallback& callback) const {
1001 callback.Run(mojom::BluetoothGattStatus::GATT_SUCCESS);
1002 }
1003
1004 void ArcBluetoothBridge::RegisterForGattNotification( 996 void ArcBluetoothBridge::RegisterForGattNotification(
1005 mojom::BluetoothAddressPtr remote_addr, 997 mojom::BluetoothAddressPtr remote_addr,
1006 mojom::BluetoothGattServiceIDPtr service_id, 998 mojom::BluetoothGattServiceIDPtr service_id,
1007 mojom::BluetoothGattIDPtr char_id, 999 mojom::BluetoothGattIDPtr char_id,
1008 const RegisterForGattNotificationCallback& callback) { 1000 const RegisterForGattNotificationCallback& callback) {
1009 BluetoothRemoteGattCharacteristic* characteristic = FindGattCharacteristic( 1001 BluetoothRemoteGattCharacteristic* characteristic = FindGattCharacteristic(
1010 std::move(remote_addr), std::move(service_id), std::move(char_id)); 1002 std::move(remote_addr), std::move(service_id), std::move(char_id));
1011 1003
1012 if (!characteristic) { 1004 if (!characteristic) {
1013 LOG(WARNING) << __func__ << " Characteristic is not existed."; 1005 LOG(WARNING) << __func__ << " Characteristic is not existed.";
1014 return; 1006 return;
1015 } 1007 }
1016 1008
1017 if (characteristic->IsNotifying()) { 1009 if (characteristic->IsNotifying()) {
1018 callback.Run(mojom::BluetoothGattStatus::GATT_SUCCESS); 1010 callback.Run(mojom::BluetoothGattStatus::GATT_SUCCESS);
1019 return; 1011 return;
1020 } 1012 }
1021 1013
1022 characteristic->StartNotifySession( 1014 characteristic->StartNotifySession(
1023 base::Bind(&ArcBluetoothBridge::OnGattNotifyStartDone, 1015 base::Bind(&ArcBluetoothBridge::OnGattNotifyStartDone,
1024 weak_factory_.GetWeakPtr(), callback, 1016 weak_factory_.GetWeakPtr(), callback,
1025 characteristic->GetIdentifier()), 1017 characteristic->GetIdentifier()),
1026 base::Bind(&ArcBluetoothBridge::OnGattNotifyStartError, 1018 base::Bind(&ArcBluetoothBridge::OnGattOperationError,
1027 weak_factory_.GetWeakPtr(), callback)); 1019 weak_factory_.GetWeakPtr(), callback));
1028 } 1020 }
1029 1021
1030 void ArcBluetoothBridge::DeregisterForGattNotification( 1022 void ArcBluetoothBridge::DeregisterForGattNotification(
1031 mojom::BluetoothAddressPtr remote_addr, 1023 mojom::BluetoothAddressPtr remote_addr,
1032 mojom::BluetoothGattServiceIDPtr service_id, 1024 mojom::BluetoothGattServiceIDPtr service_id,
1033 mojom::BluetoothGattIDPtr char_id, 1025 mojom::BluetoothGattIDPtr char_id,
1034 const DeregisterForGattNotificationCallback& callback) { 1026 const DeregisterForGattNotificationCallback& callback) {
1035 BluetoothRemoteGattCharacteristic* characteristic = FindGattCharacteristic( 1027 BluetoothRemoteGattCharacteristic* characteristic = FindGattCharacteristic(
1036 std::move(remote_addr), std::move(service_id), std::move(char_id)); 1028 std::move(remote_addr), std::move(service_id), std::move(char_id));
1037 1029
1038 if (!characteristic) { 1030 if (!characteristic) {
1039 LOG(WARNING) << __func__ << " Characteristic is not existed."; 1031 LOG(WARNING) << __func__ << " Characteristic is not existed.";
1040 return; 1032 return;
1041 } 1033 }
1042 1034
1043 if (!characteristic->IsNotifying()) { 1035 if (!characteristic->IsNotifying()) {
1044 callback.Run(mojom::BluetoothGattStatus::GATT_SUCCESS); 1036 callback.Run(mojom::BluetoothGattStatus::GATT_SUCCESS);
1045 return; 1037 return;
1046 } 1038 }
1047 1039
1048 std::string char_id_str = characteristic->GetIdentifier(); 1040 std::string char_id_str = characteristic->GetIdentifier();
1049 std::unique_ptr<BluetoothGattNotifySession> notify = 1041 std::unique_ptr<BluetoothGattNotifySession> notify =
1050 std::move(notification_session_[char_id_str]); 1042 std::move(notification_session_[char_id_str]);
1051 notification_session_.erase(char_id_str); 1043 notification_session_.erase(char_id_str);
1052 notify->Stop(base::Bind(&ArcBluetoothBridge::OnGattNotifyStopDone, 1044 notify->Stop(base::Bind(&ArcBluetoothBridge::OnGattOperationDone,
1053 weak_factory_.GetWeakPtr(), callback)); 1045 weak_factory_.GetWeakPtr(), callback));
1054 } 1046 }
1055 1047
1056 void ArcBluetoothBridge::ReadRemoteRssi( 1048 void ArcBluetoothBridge::ReadRemoteRssi(
1057 mojom::BluetoothAddressPtr remote_addr, 1049 mojom::BluetoothAddressPtr remote_addr,
1058 const ReadRemoteRssiCallback& callback) { 1050 const ReadRemoteRssiCallback& callback) {
1059 BluetoothDevice* device = 1051 BluetoothDevice* device =
1060 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); 1052 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>());
1061 int rssi = device->GetInquiryRSSI(); 1053 int rssi = device->GetInquiryRSSI();
1062 callback.Run(rssi); 1054 callback.Run(rssi);
1063 } 1055 }
1064 1056
1057 template <class T>
rkc 2016/07/14 23:15:25 template <class Attribute>
puthik_chromium 2016/07/15 21:49:33 Done. I think LocalGattObjectT sound better as we
1058 int32_t ArcBluetoothBridge::CreateGattAttributeHandle(T* gatt_obj) {
1059 if (!gatt_obj)
1060 return kInvalidGattAttributeHandle;
1061 gatt_server_obj_handle++;
1062 std::string identifier = gatt_obj->GetIdentifier();
1063 gatt_identifier_[gatt_server_obj_handle] = identifier;
1064 return gatt_server_obj_handle;
1065 }
1066
1065 void ArcBluetoothBridge::AddService(mojom::BluetoothGattServiceIDPtr service_id, 1067 void ArcBluetoothBridge::AddService(mojom::BluetoothGattServiceIDPtr service_id,
1066 int32_t num_handles, 1068 int32_t num_handles,
1067 const AddServiceCallback& callback) {} 1069 const AddServiceCallback& callback) {
1070 base::WeakPtr<BluetoothLocalGattService> service =
1071 BluetoothLocalGattService::Create(
1072 bluetooth_adapter_.get(), service_id->id->uuid.To<BluetoothUUID>(),
1073 service_id->is_primary, nullptr /*included_service */,
1074 this /* delegate*/);
1075 callback.Run(
1076 CreateGattAttributeHandle<BluetoothLocalGattService>(service.get()));
1077 }
1068 1078
1069 void ArcBluetoothBridge::AddCharacteristic( 1079 void ArcBluetoothBridge::AddCharacteristic(
1070 int32_t service_handle, 1080 int32_t service_handle,
1071 mojom::BluetoothUUIDPtr uuid, 1081 mojom::BluetoothUUIDPtr uuid,
1072 int32_t properties, 1082 int32_t properties,
1073 int32_t permissions, 1083 int32_t permissions,
1074 const AddCharacteristicCallback& callback) {} 1084 const AddCharacteristicCallback& callback) {
1085 base::WeakPtr<BluetoothLocalGattCharacteristic> characteristic =
1086 BluetoothLocalGattCharacteristic::Create(
1087 uuid.To<BluetoothUUID>(), properties, permissions,
1088 bluetooth_adapter_->GetGattService(gatt_identifier_[service_handle]));
1089 int32_t characteristic_handle =
1090 CreateGattAttributeHandle<BluetoothLocalGattCharacteristic>(
1091 characteristic.get());
1092 last_characteristic_[service_handle] = characteristic_handle;
1093 callback.Run(characteristic_handle);
1094 }
1075 1095
1076 void ArcBluetoothBridge::AddDescriptor(int32_t service_handle, 1096 void ArcBluetoothBridge::AddDescriptor(int32_t service_handle,
1077 mojom::BluetoothUUIDPtr uuid, 1097 mojom::BluetoothUUIDPtr uuid,
1078 int32_t permissions, 1098 int32_t permissions,
1079 const AddDescriptorCallback& callback) {} 1099 const AddDescriptorCallback& callback) {
1100 // Chrome automatically add CCC Descriptor to a characteristic when needed.
1101 // So we will just generate bogus handle for android.
1102 if (uuid.To<BluetoothUUID>() ==
1103 BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid()) {
1104 gatt_server_obj_handle++;
1105 callback.Run(gatt_server_obj_handle);
1106 return;
1107 }
1108
1109 BluetoothLocalGattService* service =
1110 bluetooth_adapter_->GetGattService(gatt_identifier_[service_handle]);
1111 // Since Android API does not give information which characteristic is the
1112 // parent of the new descriptor. We will just assume that it would be the
1113 // last characteristic that was added to the given service. This matches the
1114 BluetoothLocalGattCharacteristic* characteristic = service->GetCharacteristic(
1115 gatt_identifier_[last_characteristic_[service_handle]]);
1116
1117 base::WeakPtr<BluetoothLocalGattDescriptor> descriptor =
1118 BluetoothLocalGattDescriptor::Create(uuid.To<BluetoothUUID>(),
1119 permissions, characteristic);
1120 callback.Run(CreateGattAttributeHandle<BluetoothLocalGattDescriptor>(
1121 descriptor.get()));
1122 }
1080 1123
1081 void ArcBluetoothBridge::StartService(int32_t service_handle, 1124 void ArcBluetoothBridge::StartService(int32_t service_handle,
1082 const StartServiceCallback& callback) {} 1125 const StartServiceCallback& callback) {
1126 BluetoothLocalGattService* service =
1127 bluetooth_adapter_->GetGattService(gatt_identifier_[service_handle]);
1128 service->Register(base::Bind(&ArcBluetoothBridge::OnGattOperationDone,
1129 weak_factory_.GetWeakPtr(), callback),
1130 base::Bind(&ArcBluetoothBridge::OnGattOperationError,
1131 weak_factory_.GetWeakPtr(), callback));
1132 }
1083 1133
1084 void ArcBluetoothBridge::StopService(int32_t service_handle, 1134 void ArcBluetoothBridge::StopService(int32_t service_handle,
1085 const StopServiceCallback& callback) {} 1135 const StopServiceCallback& callback) {
1136 BluetoothLocalGattService* service =
1137 bluetooth_adapter_->GetGattService(gatt_identifier_[service_handle]);
1138 service->Unregister(base::Bind(&ArcBluetoothBridge::OnGattOperationDone,
1139 weak_factory_.GetWeakPtr(), callback),
1140 base::Bind(&ArcBluetoothBridge::OnGattOperationError,
1141 weak_factory_.GetWeakPtr(), callback));
1142 }
1086 1143
1087 void ArcBluetoothBridge::DeleteService(int32_t service_handle, 1144 void ArcBluetoothBridge::DeleteService(int32_t service_handle,
1088 const DeleteServiceCallback& callback) {} 1145 const DeleteServiceCallback& callback) {
1146 BluetoothLocalGattService* service =
1147 bluetooth_adapter_->GetGattService(gatt_identifier_[service_handle]);
1148 service->Delete();
1149 gatt_identifier_.erase(service_handle);
1150 OnGattOperationDone(callback);
1151 }
1089 1152
1090 void ArcBluetoothBridge::SendIndication( 1153 void ArcBluetoothBridge::SendIndication(
1091 int32_t attribute_handle, 1154 int32_t attribute_handle,
1092 mojom::BluetoothAddressPtr address, 1155 mojom::BluetoothAddressPtr address,
1093 bool confirm, 1156 bool confirm,
1094 mojo::Array<uint8_t> value, 1157 mojo::Array<uint8_t> value,
1095 const SendIndicationCallback& callback) {} 1158 const SendIndicationCallback& callback) {}
1096 1159
1097 void ArcBluetoothBridge::SendResponse(int32_t trans_id, 1160 void ArcBluetoothBridge::SendResponse(int32_t trans_id,
1098 int32_t status, 1161 int32_t status,
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
1430 uint32_t version_need) const { 1493 uint32_t version_need) const {
1431 uint32_t version = arc_bridge_service()->bluetooth()->version(); 1494 uint32_t version = arc_bridge_service()->bluetooth()->version();
1432 if (version >= version_need) 1495 if (version >= version_need)
1433 return true; 1496 return true;
1434 LOG(WARNING) << "Bluetooth instance is too old (version " << version 1497 LOG(WARNING) << "Bluetooth instance is too old (version " << version
1435 << ") need version " << version_need; 1498 << ") need version " << version_need;
1436 return false; 1499 return false;
1437 } 1500 }
1438 1501
1439 } // namespace arc 1502 } // namespace arc
OLDNEW
« no previous file with comments | « components/arc/bluetooth/arc_bluetooth_bridge.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698