Windows precompiled header support in GN.
[chromium-blink-merge.git] / device / bluetooth / bluetooth_adapter_android.cc
blob8dbd56f0b2a7d44fc2ec7e6e7ffa49f65c930962
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/android/bluetooth_adapter_wrapper.h"
13 #include "device/bluetooth/bluetooth_advertisement.h"
14 #include "jni/ChromeBluetoothAdapter_jni.h"
16 using base::android::AttachCurrentThread;
17 using base::android::ConvertJavaStringToUTF8;
19 namespace device {
21 // static
22 base::WeakPtr<BluetoothAdapter> BluetoothAdapter::CreateAdapter(
23 const InitCallback& init_callback) {
24 return BluetoothAdapterAndroid::Create(
25 BluetoothAdapterWrapper::CreateWithDefaultAdapter().obj());
28 // static
29 base::WeakPtr<BluetoothAdapterAndroid> BluetoothAdapterAndroid::Create(
30 jobject java_bluetooth_adapter_wrapper) {
31 BluetoothAdapterAndroid* adapter = new BluetoothAdapterAndroid();
33 adapter->j_bluetooth_adapter_.Reset(Java_ChromeBluetoothAdapter_create(
34 AttachCurrentThread(), java_bluetooth_adapter_wrapper));
36 return adapter->weak_ptr_factory_.GetWeakPtr();
39 // static
40 bool BluetoothAdapterAndroid::RegisterJNI(JNIEnv* env) {
41 return RegisterNativesImpl(env); // Generated in BluetoothAdapter_jni.h
44 std::string BluetoothAdapterAndroid::GetAddress() const {
45 return ConvertJavaStringToUTF8(Java_ChromeBluetoothAdapter_getAddress(
46 AttachCurrentThread(), j_bluetooth_adapter_.obj()));
49 std::string BluetoothAdapterAndroid::GetName() const {
50 return ConvertJavaStringToUTF8(Java_ChromeBluetoothAdapter_getName(
51 AttachCurrentThread(), j_bluetooth_adapter_.obj()));
54 void BluetoothAdapterAndroid::SetName(const std::string& name,
55 const base::Closure& callback,
56 const ErrorCallback& error_callback) {
57 NOTIMPLEMENTED();
60 bool BluetoothAdapterAndroid::IsInitialized() const {
61 return true;
64 bool BluetoothAdapterAndroid::IsPresent() const {
65 return Java_ChromeBluetoothAdapter_isPresent(AttachCurrentThread(),
66 j_bluetooth_adapter_.obj());
69 bool BluetoothAdapterAndroid::IsPowered() const {
70 return Java_ChromeBluetoothAdapter_isPowered(AttachCurrentThread(),
71 j_bluetooth_adapter_.obj());
74 void BluetoothAdapterAndroid::SetPowered(bool powered,
75 const base::Closure& callback,
76 const ErrorCallback& error_callback) {
77 NOTIMPLEMENTED();
80 bool BluetoothAdapterAndroid::IsDiscoverable() const {
81 return Java_ChromeBluetoothAdapter_isDiscoverable(AttachCurrentThread(),
82 j_bluetooth_adapter_.obj());
85 void BluetoothAdapterAndroid::SetDiscoverable(
86 bool discoverable,
87 const base::Closure& callback,
88 const ErrorCallback& error_callback) {
89 NOTIMPLEMENTED();
92 bool BluetoothAdapterAndroid::IsDiscovering() const {
93 return Java_ChromeBluetoothAdapter_isDiscovering(AttachCurrentThread(),
94 j_bluetooth_adapter_.obj());
97 void BluetoothAdapterAndroid::CreateRfcommService(
98 const BluetoothUUID& uuid,
99 const ServiceOptions& options,
100 const CreateServiceCallback& callback,
101 const CreateServiceErrorCallback& error_callback) {
102 NOTIMPLEMENTED();
103 error_callback.Run("Not Implemented");
106 void BluetoothAdapterAndroid::CreateL2capService(
107 const BluetoothUUID& uuid,
108 const ServiceOptions& options,
109 const CreateServiceCallback& callback,
110 const CreateServiceErrorCallback& error_callback) {
111 NOTIMPLEMENTED();
112 error_callback.Run("Not Implemented");
115 void BluetoothAdapterAndroid::RegisterAudioSink(
116 const BluetoothAudioSink::Options& options,
117 const AcquiredCallback& callback,
118 const BluetoothAudioSink::ErrorCallback& error_callback) {
119 error_callback.Run(BluetoothAudioSink::ERROR_UNSUPPORTED_PLATFORM);
122 void BluetoothAdapterAndroid::RegisterAdvertisement(
123 scoped_ptr<BluetoothAdvertisement::Data> advertisement_data,
124 const CreateAdvertisementCallback& callback,
125 const CreateAdvertisementErrorCallback& error_callback) {
126 error_callback.Run(BluetoothAdvertisement::ERROR_UNSUPPORTED_PLATFORM);
129 BluetoothAdapterAndroid::BluetoothAdapterAndroid() : weak_ptr_factory_(this) {
132 BluetoothAdapterAndroid::~BluetoothAdapterAndroid() {
135 void BluetoothAdapterAndroid::AddDiscoverySession(
136 BluetoothDiscoveryFilter* discovery_filter,
137 const base::Closure& callback,
138 const ErrorCallback& error_callback) {
139 error_callback.Run();
142 void BluetoothAdapterAndroid::RemoveDiscoverySession(
143 BluetoothDiscoveryFilter* discovery_filter,
144 const base::Closure& callback,
145 const ErrorCallback& error_callback) {
146 error_callback.Run();
149 void BluetoothAdapterAndroid::SetDiscoveryFilter(
150 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter,
151 const base::Closure& callback,
152 const ErrorCallback& error_callback) {
153 error_callback.Run();
156 void BluetoothAdapterAndroid::RemovePairingDelegateInternal(
157 device::BluetoothDevice::PairingDelegate* pairing_delegate) {
160 } // namespace device