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() { |
143 } | 149 } |
144 | 150 |
145 void BluetoothAdapterAndroid::AddDiscoverySession( | 151 void BluetoothAdapterAndroid::AddDiscoverySession( |
146 BluetoothDiscoveryFilter* discovery_filter, | 152 BluetoothDiscoveryFilter* discovery_filter, |
147 const base::Closure& callback, | 153 const base::Closure& callback, |
148 const ErrorCallback& error_callback) { | 154 const ErrorCallback& error_callback) { |
149 error_callback.Run(); | 155 // TODO(scheib): Support filters crbug.com/490401 |
| 156 if (Java_BluetoothAdapter_addDiscoverySession(AttachCurrentThread(), |
| 157 j_bluetooth_adapter_.obj())) { |
| 158 callback.Run(); |
| 159 } else { |
| 160 error_callback.Run(); |
| 161 } |
150 } | 162 } |
151 | 163 |
152 void BluetoothAdapterAndroid::RemoveDiscoverySession( | 164 void BluetoothAdapterAndroid::RemoveDiscoverySession( |
153 BluetoothDiscoveryFilter* discovery_filter, | 165 BluetoothDiscoveryFilter* discovery_filter, |
154 const base::Closure& callback, | 166 const base::Closure& callback, |
155 const ErrorCallback& error_callback) { | 167 const ErrorCallback& error_callback) { |
156 error_callback.Run(); | 168 if (Java_BluetoothAdapter_removeDiscoverySession( |
| 169 AttachCurrentThread(), j_bluetooth_adapter_.obj())) { |
| 170 callback.Run(); |
| 171 } else { |
| 172 error_callback.Run(); |
| 173 } |
157 } | 174 } |
158 | 175 |
159 void BluetoothAdapterAndroid::SetDiscoveryFilter( | 176 void BluetoothAdapterAndroid::SetDiscoveryFilter( |
160 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter, | 177 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter, |
161 const base::Closure& callback, | 178 const base::Closure& callback, |
162 const ErrorCallback& error_callback) { | 179 const ErrorCallback& error_callback) { |
| 180 NOTIMPLEMENTED(); |
163 error_callback.Run(); | 181 error_callback.Run(); |
164 } | 182 } |
165 | 183 |
166 void BluetoothAdapterAndroid::RemovePairingDelegateInternal( | 184 void BluetoothAdapterAndroid::RemovePairingDelegateInternal( |
167 device::BluetoothDevice::PairingDelegate* pairing_delegate) { | 185 device::BluetoothDevice::PairingDelegate* pairing_delegate) { |
168 } | 186 } |
169 | 187 |
170 } // namespace device | 188 } // namespace device |
OLD | NEW |