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

Side by Side Diff: device/bluetooth/bluetooth_adapter_android.cc

Issue 1215303006: bluetooth: android: Initial BluetoothDeviceAndroid implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bta-discovery-
Patch Set: Merge TOT Created 5 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
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/bluetooth_adapter_android.h" 5 #include "device/bluetooth/bluetooth_adapter_android.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h" 8 #include "base/android/jni_string.h"
9 #include "base/sequenced_task_runner.h" 9 #include "base/sequenced_task_runner.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
11 #include "base/thread_task_runner_handle.h" 11 #include "base/thread_task_runner_handle.h"
12 #include "device/bluetooth/android/wrappers.h" 12 #include "device/bluetooth/android/wrappers.h"
13 #include "device/bluetooth/bluetooth_advertisement.h" 13 #include "device/bluetooth/bluetooth_advertisement.h"
14 #include "device/bluetooth/bluetooth_device_android.h"
14 #include "jni/ChromeBluetoothAdapter_jni.h" 15 #include "jni/ChromeBluetoothAdapter_jni.h"
15 16
16 using base::android::AttachCurrentThread; 17 using base::android::AttachCurrentThread;
17 using base::android::ConvertJavaStringToUTF8; 18 using base::android::ConvertJavaStringToUTF8;
18 19
19 namespace device { 20 namespace device {
20 21
21 // static 22 // static
22 base::WeakPtr<BluetoothAdapter> BluetoothAdapter::CreateAdapter( 23 base::WeakPtr<BluetoothAdapter> BluetoothAdapter::CreateAdapter(
23 const InitCallback& init_callback) { 24 const InitCallback& init_callback) {
24 return BluetoothAdapterAndroid::Create( 25 return BluetoothAdapterAndroid::Create(
25 BluetoothAdapterWrapper_CreateWithDefaultAdapter().obj()); 26 BluetoothAdapterWrapper_CreateWithDefaultAdapter().obj());
26 } 27 }
27 28
28 // static 29 // static
29 base::WeakPtr<BluetoothAdapterAndroid> BluetoothAdapterAndroid::Create( 30 base::WeakPtr<BluetoothAdapterAndroid> BluetoothAdapterAndroid::Create(
30 jobject java_bluetooth_adapter_wrapper) { 31 jobject bluetooth_adapter_wrapper) { // Java Type: bluetoothAdapterWrapper
31 BluetoothAdapterAndroid* adapter = new BluetoothAdapterAndroid(); 32 BluetoothAdapterAndroid* adapter = new BluetoothAdapterAndroid();
32 33
33 adapter->j_adapter_.Reset(Java_ChromeBluetoothAdapter_create( 34 adapter->j_adapter_.Reset(Java_ChromeBluetoothAdapter_create(
34 AttachCurrentThread(), reinterpret_cast<intptr_t>(adapter), 35 AttachCurrentThread(), reinterpret_cast<intptr_t>(adapter),
35 java_bluetooth_adapter_wrapper)); 36 bluetooth_adapter_wrapper));
36 37
37 return adapter->weak_ptr_factory_.GetWeakPtr(); 38 return adapter->weak_ptr_factory_.GetWeakPtr();
38 } 39 }
39 40
40 // static 41 // static
41 bool BluetoothAdapterAndroid::RegisterJNI(JNIEnv* env) { 42 bool BluetoothAdapterAndroid::RegisterJNI(JNIEnv* env) {
42 return RegisterNativesImpl(env); // Generated in BluetoothAdapter_jni.h 43 return RegisterNativesImpl(env); // Generated in BluetoothAdapter_jni.h
43 } 44 }
44 45
45 std::string BluetoothAdapterAndroid::GetAddress() const { 46 std::string BluetoothAdapterAndroid::GetAddress() const {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 error_callback.Run(BluetoothAudioSink::ERROR_UNSUPPORTED_PLATFORM); 121 error_callback.Run(BluetoothAudioSink::ERROR_UNSUPPORTED_PLATFORM);
121 } 122 }
122 123
123 void BluetoothAdapterAndroid::RegisterAdvertisement( 124 void BluetoothAdapterAndroid::RegisterAdvertisement(
124 scoped_ptr<BluetoothAdvertisement::Data> advertisement_data, 125 scoped_ptr<BluetoothAdvertisement::Data> advertisement_data,
125 const CreateAdvertisementCallback& callback, 126 const CreateAdvertisementCallback& callback,
126 const CreateAdvertisementErrorCallback& error_callback) { 127 const CreateAdvertisementErrorCallback& error_callback) {
127 error_callback.Run(BluetoothAdvertisement::ERROR_UNSUPPORTED_PLATFORM); 128 error_callback.Run(BluetoothAdvertisement::ERROR_UNSUPPORTED_PLATFORM);
128 } 129 }
129 130
130 void BluetoothAdapterAndroid::OnScanFailed(JNIEnv* env, jobject obj) { 131 void BluetoothAdapterAndroid::OnScanFailed(JNIEnv* env, jobject caller) {
131 MarkDiscoverySessionsAsInactive(); 132 MarkDiscoverySessionsAsInactive();
132 } 133 }
133 134
135 void BluetoothAdapterAndroid::CreateOrUpdateDeviceOnScan(
136 JNIEnv* env,
137 jobject caller,
138 const jstring& address,
139 jobject bluetooth_device_wrapper, // Java Type: bluetoothDeviceWrapper
140 jobject advertised_uuids) { // Java Type: List<ParcelUuid>
141 BluetoothDevice*& device = devices_[ConvertJavaStringToUTF8(env, address)];
142 if (!device) {
143 device = BluetoothDeviceAndroid::Create(bluetooth_device_wrapper);
144 static_cast<BluetoothDeviceAndroid*>(device)
145 ->UpdateAdvertisedUUIDs(advertised_uuids);
146 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
147 DeviceAdded(this, device));
148 } else {
149 if (static_cast<BluetoothDeviceAndroid*>(device)
150 ->UpdateAdvertisedUUIDs(advertised_uuids)) {
151 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
152 DeviceChanged(this, device));
153 }
154 }
155 }
156
134 BluetoothAdapterAndroid::BluetoothAdapterAndroid() : weak_ptr_factory_(this) { 157 BluetoothAdapterAndroid::BluetoothAdapterAndroid() : weak_ptr_factory_(this) {
135 } 158 }
136 159
137 BluetoothAdapterAndroid::~BluetoothAdapterAndroid() { 160 BluetoothAdapterAndroid::~BluetoothAdapterAndroid() {
138 Java_ChromeBluetoothAdapter_onBluetoothAdapterAndroidDestruction( 161 Java_ChromeBluetoothAdapter_onBluetoothAdapterAndroidDestruction(
139 AttachCurrentThread(), j_adapter_.obj()); 162 AttachCurrentThread(), j_adapter_.obj());
140 } 163 }
141 164
142 void BluetoothAdapterAndroid::AddDiscoverySession( 165 void BluetoothAdapterAndroid::AddDiscoverySession(
143 BluetoothDiscoveryFilter* discovery_filter, 166 BluetoothDiscoveryFilter* discovery_filter,
(...skipping 27 matching lines...) Expand all
171 // TODO(scheib): Support filters crbug.com/490401 194 // TODO(scheib): Support filters crbug.com/490401
172 NOTIMPLEMENTED(); 195 NOTIMPLEMENTED();
173 error_callback.Run(); 196 error_callback.Run();
174 } 197 }
175 198
176 void BluetoothAdapterAndroid::RemovePairingDelegateInternal( 199 void BluetoothAdapterAndroid::RemovePairingDelegateInternal(
177 device::BluetoothDevice::PairingDelegate* pairing_delegate) { 200 device::BluetoothDevice::PairingDelegate* pairing_delegate) {
178 } 201 }
179 202
180 } // namespace device 203 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_adapter_android.h ('k') | device/bluetooth/bluetooth_adapter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698