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

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

Issue 1150833002: bluetooth: android: Initial Low Energy Discovery Sessions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bta-manifest-
Patch Set: Add tests 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"
(...skipping 13 matching lines...) Expand all
24 return BluetoothAdapterAndroid::Create( 24 return BluetoothAdapterAndroid::Create(
25 BluetoothAdapterWrapper_CreateWithDefaultAdapter().obj()); 25 BluetoothAdapterWrapper_CreateWithDefaultAdapter().obj());
26 } 26 }
27 27
28 // static 28 // static
29 base::WeakPtr<BluetoothAdapterAndroid> BluetoothAdapterAndroid::Create( 29 base::WeakPtr<BluetoothAdapterAndroid> BluetoothAdapterAndroid::Create(
30 jobject java_bluetooth_adapter_wrapper) { 30 jobject java_bluetooth_adapter_wrapper) {
31 BluetoothAdapterAndroid* adapter = new BluetoothAdapterAndroid(); 31 BluetoothAdapterAndroid* adapter = new BluetoothAdapterAndroid();
32 32
33 adapter->j_adapter_.Reset(Java_ChromeBluetoothAdapter_create( 33 adapter->j_adapter_.Reset(Java_ChromeBluetoothAdapter_create(
34 AttachCurrentThread(), java_bluetooth_adapter_wrapper)); 34 AttachCurrentThread(), reinterpret_cast<intptr_t>(adapter),
35 java_bluetooth_adapter_wrapper));
35 36
36 return adapter->weak_ptr_factory_.GetWeakPtr(); 37 return adapter->weak_ptr_factory_.GetWeakPtr();
37 } 38 }
38 39
39 // static 40 // static
40 bool BluetoothAdapterAndroid::RegisterJNI(JNIEnv* env) { 41 bool BluetoothAdapterAndroid::RegisterJNI(JNIEnv* env) {
41 return RegisterNativesImpl(env); // Generated in BluetoothAdapter_jni.h 42 return RegisterNativesImpl(env); // Generated in BluetoothAdapter_jni.h
42 } 43 }
43 44
44 std::string BluetoothAdapterAndroid::GetAddress() const { 45 std::string BluetoothAdapterAndroid::GetAddress() const {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 error_callback.Run(BluetoothAudioSink::ERROR_UNSUPPORTED_PLATFORM); 120 error_callback.Run(BluetoothAudioSink::ERROR_UNSUPPORTED_PLATFORM);
120 } 121 }
121 122
122 void BluetoothAdapterAndroid::RegisterAdvertisement( 123 void BluetoothAdapterAndroid::RegisterAdvertisement(
123 scoped_ptr<BluetoothAdvertisement::Data> advertisement_data, 124 scoped_ptr<BluetoothAdvertisement::Data> advertisement_data,
124 const CreateAdvertisementCallback& callback, 125 const CreateAdvertisementCallback& callback,
125 const CreateAdvertisementErrorCallback& error_callback) { 126 const CreateAdvertisementErrorCallback& error_callback) {
126 error_callback.Run(BluetoothAdvertisement::ERROR_UNSUPPORTED_PLATFORM); 127 error_callback.Run(BluetoothAdvertisement::ERROR_UNSUPPORTED_PLATFORM);
127 } 128 }
128 129
130 void BluetoothAdapterAndroid::OnScanFailed(JNIEnv* env, jobject obj) {
131 MarkDiscoverySessionsAsInactive();
132 }
133
129 BluetoothAdapterAndroid::BluetoothAdapterAndroid() : weak_ptr_factory_(this) { 134 BluetoothAdapterAndroid::BluetoothAdapterAndroid() : weak_ptr_factory_(this) {
130 } 135 }
131 136
132 BluetoothAdapterAndroid::~BluetoothAdapterAndroid() { 137 BluetoothAdapterAndroid::~BluetoothAdapterAndroid() {
138 Java_ChromeBluetoothAdapter_onBluetoothAdapterAndroidDestruction(
139 AttachCurrentThread(), j_adapter_.obj());
133 } 140 }
134 141
135 void BluetoothAdapterAndroid::AddDiscoverySession( 142 void BluetoothAdapterAndroid::AddDiscoverySession(
136 BluetoothDiscoveryFilter* discovery_filter, 143 BluetoothDiscoveryFilter* discovery_filter,
137 const base::Closure& callback, 144 const base::Closure& callback,
138 const ErrorCallback& error_callback) { 145 const ErrorCallback& error_callback) {
139 error_callback.Run(); 146 // TODO(scheib): Support filters crbug.com/490401
147 if (Java_ChromeBluetoothAdapter_addDiscoverySession(AttachCurrentThread(),
148 j_adapter_.obj())) {
149 callback.Run();
150 } else {
151 error_callback.Run();
152 }
140 } 153 }
141 154
142 void BluetoothAdapterAndroid::RemoveDiscoverySession( 155 void BluetoothAdapterAndroid::RemoveDiscoverySession(
143 BluetoothDiscoveryFilter* discovery_filter, 156 BluetoothDiscoveryFilter* discovery_filter,
144 const base::Closure& callback, 157 const base::Closure& callback,
145 const ErrorCallback& error_callback) { 158 const ErrorCallback& error_callback) {
146 error_callback.Run(); 159 if (Java_ChromeBluetoothAdapter_removeDiscoverySession(AttachCurrentThread(),
160 j_adapter_.obj())) {
161 callback.Run();
162 } else {
163 error_callback.Run();
164 }
147 } 165 }
148 166
149 void BluetoothAdapterAndroid::SetDiscoveryFilter( 167 void BluetoothAdapterAndroid::SetDiscoveryFilter(
150 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter, 168 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter,
151 const base::Closure& callback, 169 const base::Closure& callback,
152 const ErrorCallback& error_callback) { 170 const ErrorCallback& error_callback) {
171 // TODO(scheib): Support filters crbug.com/490401
172 NOTIMPLEMENTED();
153 error_callback.Run(); 173 error_callback.Run();
154 } 174 }
155 175
156 void BluetoothAdapterAndroid::RemovePairingDelegateInternal( 176 void BluetoothAdapterAndroid::RemovePairingDelegateInternal(
157 device::BluetoothDevice::PairingDelegate* pairing_delegate) { 177 device::BluetoothDevice::PairingDelegate* pairing_delegate) {
158 } 178 }
159 179
160 } // namespace device 180 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698