Port Chromium's blink_tests target to GN.
[chromium-blink-merge.git] / device / bluetooth / bluetooth_adapter_android.cc
blob0b8bea30de428369c8bd34823eaa8acef26e85bd
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
3 // found in the LICENSE file.
5 #include "device/bluetooth/bluetooth_adapter_android.h"
7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h"
9 #include "base/sequenced_task_runner.h"
10 #include "base/single_thread_task_runner.h"
11 #include "base/thread_task_runner_handle.h"
12 #include "device/bluetooth/bluetooth_advertisement.h"
13 #include "jni/BluetoothAdapter_jni.h"
15 using base::android::AttachCurrentThread;
16 using base::android::ConvertJavaStringToUTF8;
18 namespace device {
20 // static
21 base::WeakPtr<BluetoothAdapter> BluetoothAdapter::CreateAdapter(
22 const InitCallback& init_callback) {
23 return BluetoothAdapterAndroid::CreateAdapter();
26 // static
27 base::WeakPtr<BluetoothAdapterAndroid>
28 BluetoothAdapterAndroid::CreateAdapter() {
29 BluetoothAdapterAndroid* adapter = new BluetoothAdapterAndroid();
30 adapter->j_bluetooth_adapter_.Reset(Java_BluetoothAdapter_create(
31 AttachCurrentThread(), base::android::GetApplicationContext()));
32 return adapter->weak_ptr_factory_.GetWeakPtr();
35 base::WeakPtr<BluetoothAdapterAndroid>
36 BluetoothAdapterAndroid::CreateAdapterWithoutPermissionForTesting() {
37 BluetoothAdapterAndroid* adapter = new BluetoothAdapterAndroid();
38 adapter->j_bluetooth_adapter_.Reset(
39 Java_BluetoothAdapter_createWithoutPermissionForTesting(
40 AttachCurrentThread(), base::android::GetApplicationContext()));
41 return adapter->weak_ptr_factory_.GetWeakPtr();
44 // static
45 bool BluetoothAdapterAndroid::RegisterJNI(JNIEnv* env) {
46 return RegisterNativesImpl(env); // Generated in BluetoothAdapter_jni.h
49 bool BluetoothAdapterAndroid::HasBluetoothPermission() const {
50 return Java_BluetoothAdapter_hasBluetoothPermission(
51 AttachCurrentThread(), j_bluetooth_adapter_.obj());
54 std::string BluetoothAdapterAndroid::GetAddress() const {
55 return ConvertJavaStringToUTF8(Java_BluetoothAdapter_getAddress(
56 AttachCurrentThread(), j_bluetooth_adapter_.obj()));
59 std::string BluetoothAdapterAndroid::GetName() const {
60 return ConvertJavaStringToUTF8(Java_BluetoothAdapter_getName(
61 AttachCurrentThread(), j_bluetooth_adapter_.obj()));
64 void BluetoothAdapterAndroid::SetName(const std::string& name,
65 const base::Closure& callback,
66 const ErrorCallback& error_callback) {
67 NOTIMPLEMENTED();
70 bool BluetoothAdapterAndroid::IsInitialized() const {
71 NOTIMPLEMENTED();
72 return false;
75 bool BluetoothAdapterAndroid::IsPresent() const {
76 return Java_BluetoothAdapter_isPresent(AttachCurrentThread(),
77 j_bluetooth_adapter_.obj());
80 bool BluetoothAdapterAndroid::IsPowered() const {
81 return Java_BluetoothAdapter_isPowered(AttachCurrentThread(),
82 j_bluetooth_adapter_.obj());
85 void BluetoothAdapterAndroid::SetPowered(bool powered,
86 const base::Closure& callback,
87 const ErrorCallback& error_callback) {
88 NOTIMPLEMENTED();
91 bool BluetoothAdapterAndroid::IsDiscoverable() const {
92 return Java_BluetoothAdapter_isDiscoverable(AttachCurrentThread(),
93 j_bluetooth_adapter_.obj());
96 void BluetoothAdapterAndroid::SetDiscoverable(
97 bool discoverable,
98 const base::Closure& callback,
99 const ErrorCallback& error_callback) {
100 NOTIMPLEMENTED();
103 bool BluetoothAdapterAndroid::IsDiscovering() const {
104 return Java_BluetoothAdapter_isDiscovering(AttachCurrentThread(),
105 j_bluetooth_adapter_.obj());
108 void BluetoothAdapterAndroid::CreateRfcommService(
109 const BluetoothUUID& uuid,
110 const ServiceOptions& options,
111 const CreateServiceCallback& callback,
112 const CreateServiceErrorCallback& error_callback) {
113 NOTIMPLEMENTED();
114 error_callback.Run("Not Implemented");
117 void BluetoothAdapterAndroid::CreateL2capService(
118 const BluetoothUUID& uuid,
119 const ServiceOptions& options,
120 const CreateServiceCallback& callback,
121 const CreateServiceErrorCallback& error_callback) {
122 NOTIMPLEMENTED();
123 error_callback.Run("Not Implemented");
126 void BluetoothAdapterAndroid::RegisterAudioSink(
127 const BluetoothAudioSink::Options& options,
128 const AcquiredCallback& callback,
129 const BluetoothAudioSink::ErrorCallback& error_callback) {
130 error_callback.Run(BluetoothAudioSink::ERROR_UNSUPPORTED_PLATFORM);
133 void BluetoothAdapterAndroid::RegisterAdvertisement(
134 scoped_ptr<BluetoothAdvertisement::Data> advertisement_data,
135 const CreateAdvertisementCallback& callback,
136 const CreateAdvertisementErrorCallback& error_callback) {
137 error_callback.Run(BluetoothAdvertisement::ERROR_UNSUPPORTED_PLATFORM);
140 BluetoothAdapterAndroid::BluetoothAdapterAndroid() : weak_ptr_factory_(this) {
143 BluetoothAdapterAndroid::~BluetoothAdapterAndroid() {
146 void BluetoothAdapterAndroid::AddDiscoverySession(
147 BluetoothDiscoveryFilter* discovery_filter,
148 const base::Closure& callback,
149 const ErrorCallback& error_callback) {
152 void BluetoothAdapterAndroid::RemoveDiscoverySession(
153 BluetoothDiscoveryFilter* discovery_filter,
154 const base::Closure& callback,
155 const ErrorCallback& error_callback) {
158 void BluetoothAdapterAndroid::SetDiscoveryFilter(
159 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter,
160 const base::Closure& callback,
161 const ErrorCallback& error_callback) {
164 void BluetoothAdapterAndroid::RemovePairingDelegateInternal(
165 device::BluetoothDevice::PairingDelegate* pairing_delegate) {
168 } // namespace device