OLD | NEW |
---|---|
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 10 matching lines...) Expand all Loading... | |
21 base::WeakPtr<BluetoothAdapter> BluetoothAdapter::CreateAdapter( | 21 base::WeakPtr<BluetoothAdapter> BluetoothAdapter::CreateAdapter( |
22 const InitCallback& init_callback) { | 22 const InitCallback& init_callback) { |
23 return BluetoothAdapterAndroid::CreateAdapter(); | 23 return BluetoothAdapterAndroid::CreateAdapter(); |
24 } | 24 } |
25 | 25 |
26 // static | 26 // static |
27 base::WeakPtr<BluetoothAdapterAndroid> | 27 base::WeakPtr<BluetoothAdapterAndroid> |
28 BluetoothAdapterAndroid::CreateAdapter() { | 28 BluetoothAdapterAndroid::CreateAdapter() { |
29 BluetoothAdapterAndroid* adapter = new BluetoothAdapterAndroid(); | 29 BluetoothAdapterAndroid* adapter = new BluetoothAdapterAndroid(); |
30 adapter->j_bluetooth_adapter_.Reset(Java_BluetoothAdapter_create( | 30 adapter->j_bluetooth_adapter_.Reset(Java_BluetoothAdapter_create( |
31 AttachCurrentThread(), base::android::GetApplicationContext())); | 31 AttachCurrentThread(), base::android::GetApplicationContext(), |
32 reinterpret_cast<jlong>(adapter))); | |
32 return adapter->weak_ptr_factory_.GetWeakPtr(); | 33 return adapter->weak_ptr_factory_.GetWeakPtr(); |
33 } | 34 } |
34 | 35 |
35 base::WeakPtr<BluetoothAdapterAndroid> | 36 base::WeakPtr<BluetoothAdapterAndroid> |
36 BluetoothAdapterAndroid::CreateAdapterWithoutPermissionForTesting() { | 37 BluetoothAdapterAndroid::CreateAdapterWithoutPermissionForTesting() { |
37 BluetoothAdapterAndroid* adapter = new BluetoothAdapterAndroid(); | 38 BluetoothAdapterAndroid* adapter = new BluetoothAdapterAndroid(); |
38 adapter->j_bluetooth_adapter_.Reset( | 39 adapter->j_bluetooth_adapter_.Reset( |
39 Java_BluetoothAdapter_createWithoutPermissionForTesting( | 40 Java_BluetoothAdapter_createWithoutPermissionForTesting( |
40 AttachCurrentThread(), base::android::GetApplicationContext())); | 41 AttachCurrentThread(), base::android::GetApplicationContext(), |
42 reinterpret_cast<jlong>(adapter))); | |
41 return adapter->weak_ptr_factory_.GetWeakPtr(); | 43 return adapter->weak_ptr_factory_.GetWeakPtr(); |
42 } | 44 } |
43 | 45 |
44 // static | 46 // static |
45 bool BluetoothAdapterAndroid::RegisterJNI(JNIEnv* env) { | 47 bool BluetoothAdapterAndroid::RegisterJNI(JNIEnv* env) { |
46 return RegisterNativesImpl(env); // Generated in BluetoothAdapter_jni.h | 48 return RegisterNativesImpl(env); // Generated in BluetoothAdapter_jni.h |
47 } | 49 } |
48 | 50 |
49 bool BluetoothAdapterAndroid::HasBluetoothPermission() const { | 51 bool BluetoothAdapterAndroid::HasBluetoothCapability() const { |
50 return Java_BluetoothAdapter_hasBluetoothPermission( | 52 return Java_BluetoothAdapter_hasBluetoothCapability( |
51 AttachCurrentThread(), j_bluetooth_adapter_.obj()); | 53 AttachCurrentThread(), j_bluetooth_adapter_.obj()); |
52 } | 54 } |
53 | 55 |
54 std::string BluetoothAdapterAndroid::GetAddress() const { | 56 std::string BluetoothAdapterAndroid::GetAddress() const { |
55 return ConvertJavaStringToUTF8(Java_BluetoothAdapter_getAddress( | 57 return ConvertJavaStringToUTF8(Java_BluetoothAdapter_getAddress( |
56 AttachCurrentThread(), j_bluetooth_adapter_.obj())); | 58 AttachCurrentThread(), j_bluetooth_adapter_.obj())); |
57 } | 59 } |
58 | 60 |
59 std::string BluetoothAdapterAndroid::GetName() const { | 61 std::string BluetoothAdapterAndroid::GetName() const { |
60 return ConvertJavaStringToUTF8(Java_BluetoothAdapter_getName( | 62 return ConvertJavaStringToUTF8(Java_BluetoothAdapter_getName( |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
129 error_callback.Run(BluetoothAudioSink::ERROR_UNSUPPORTED_PLATFORM); | 131 error_callback.Run(BluetoothAudioSink::ERROR_UNSUPPORTED_PLATFORM); |
130 } | 132 } |
131 | 133 |
132 void BluetoothAdapterAndroid::RegisterAdvertisement( | 134 void BluetoothAdapterAndroid::RegisterAdvertisement( |
133 scoped_ptr<BluetoothAdvertisement::Data> advertisement_data, | 135 scoped_ptr<BluetoothAdvertisement::Data> advertisement_data, |
134 const CreateAdvertisementCallback& callback, | 136 const CreateAdvertisementCallback& callback, |
135 const CreateAdvertisementErrorCallback& error_callback) { | 137 const CreateAdvertisementErrorCallback& error_callback) { |
136 error_callback.Run(BluetoothAdvertisement::ERROR_UNSUPPORTED_PLATFORM); | 138 error_callback.Run(BluetoothAdvertisement::ERROR_UNSUPPORTED_PLATFORM); |
137 } | 139 } |
138 | 140 |
141 void BluetoothAdapterAndroid::OnScanFailed(JNIEnv* env, jobject obj) { | |
142 MarkDiscoverySessionsAsInactive(); | |
143 } | |
144 | |
139 BluetoothAdapterAndroid::BluetoothAdapterAndroid() : weak_ptr_factory_(this) { | 145 BluetoothAdapterAndroid::BluetoothAdapterAndroid() : weak_ptr_factory_(this) { |
140 } | 146 } |
141 | 147 |
142 BluetoothAdapterAndroid::~BluetoothAdapterAndroid() { | 148 BluetoothAdapterAndroid::~BluetoothAdapterAndroid() { |
149 Java_BluetoothAdapter_onBluetoothAdapterAndroidDestruction( | |
150 AttachCurrentThread(), j_bluetooth_adapter_.obj()); | |
143 } | 151 } |
144 | 152 |
145 void BluetoothAdapterAndroid::AddDiscoverySession( | 153 void BluetoothAdapterAndroid::AddDiscoverySession( |
146 BluetoothDiscoveryFilter* discovery_filter, | 154 BluetoothDiscoveryFilter* discovery_filter, |
147 const base::Closure& callback, | 155 const base::Closure& callback, |
148 const ErrorCallback& error_callback) { | 156 const ErrorCallback& error_callback) { |
149 error_callback.Run(); | 157 // TODO(scheib): Support filters crbug.com/490401 |
158 if (Java_BluetoothAdapter_addDiscoverySession(AttachCurrentThread(), | |
159 j_bluetooth_adapter_.obj())) { | |
160 callback.Run(); | |
161 } else { | |
162 error_callback.Run(); | |
163 } | |
150 } | 164 } |
151 | 165 |
152 void BluetoothAdapterAndroid::RemoveDiscoverySession( | 166 void BluetoothAdapterAndroid::RemoveDiscoverySession( |
153 BluetoothDiscoveryFilter* discovery_filter, | 167 BluetoothDiscoveryFilter* discovery_filter, |
154 const base::Closure& callback, | 168 const base::Closure& callback, |
155 const ErrorCallback& error_callback) { | 169 const ErrorCallback& error_callback) { |
156 error_callback.Run(); | 170 if (Java_BluetoothAdapter_removeDiscoverySession( |
171 AttachCurrentThread(), j_bluetooth_adapter_.obj())) { | |
172 callback.Run(); | |
173 } else { | |
174 error_callback.Run(); | |
175 } | |
157 } | 176 } |
158 | 177 |
159 void BluetoothAdapterAndroid::SetDiscoveryFilter( | 178 void BluetoothAdapterAndroid::SetDiscoveryFilter( |
160 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter, | 179 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter, |
161 const base::Closure& callback, | 180 const base::Closure& callback, |
162 const ErrorCallback& error_callback) { | 181 const ErrorCallback& error_callback) { |
armansito
2015/05/28 04:04:11
Add TODO about filters (and link to the bug) here.
scheib
2015/06/30 17:55:14
Done.
| |
182 NOTIMPLEMENTED(); | |
163 error_callback.Run(); | 183 error_callback.Run(); |
164 } | 184 } |
165 | 185 |
166 void BluetoothAdapterAndroid::RemovePairingDelegateInternal( | 186 void BluetoothAdapterAndroid::RemovePairingDelegateInternal( |
167 device::BluetoothDevice::PairingDelegate* pairing_delegate) { | 187 device::BluetoothDevice::PairingDelegate* pairing_delegate) { |
168 } | 188 } |
169 | 189 |
170 } // namespace device | 190 } // namespace device |
OLD | NEW |