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/sequenced_task_runner.h" | 9 #include "base/sequenced_task_runner.h" |
9 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
10 #include "base/thread_task_runner_handle.h" | 11 #include "base/thread_task_runner_handle.h" |
11 #include "device/bluetooth/bluetooth_advertisement.h" | 12 #include "device/bluetooth/bluetooth_advertisement.h" |
12 #include "jni/BluetoothAdapter_jni.h" | 13 #include "jni/BluetoothAdapter_jni.h" |
13 | 14 |
14 using base::android::AttachCurrentThread; | 15 using base::android::AttachCurrentThread; |
| 16 using base::android::ConvertJavaStringToUTF8; |
15 | 17 |
16 namespace device { | 18 namespace device { |
17 | 19 |
18 // static | 20 // static |
19 base::WeakPtr<BluetoothAdapter> BluetoothAdapter::CreateAdapter( | 21 base::WeakPtr<BluetoothAdapter> BluetoothAdapter::CreateAdapter( |
20 const InitCallback& init_callback) { | 22 const InitCallback& init_callback) { |
21 return BluetoothAdapterAndroid::CreateAdapter(); | 23 return BluetoothAdapterAndroid::CreateAdapter(); |
22 } | 24 } |
23 | 25 |
24 // static | 26 // static |
25 base::WeakPtr<BluetoothAdapterAndroid> | 27 base::WeakPtr<BluetoothAdapterAndroid> |
26 BluetoothAdapterAndroid::CreateAdapter() { | 28 BluetoothAdapterAndroid::CreateAdapter() { |
27 BluetoothAdapterAndroid* adapter = new BluetoothAdapterAndroid(); | 29 BluetoothAdapterAndroid* adapter = new BluetoothAdapterAndroid(); |
| 30 adapter->j_bluetooth_adapter_.Reset(Java_BluetoothAdapter_create( |
| 31 AttachCurrentThread(), base::android::GetApplicationContext())); |
28 return adapter->weak_ptr_factory_.GetWeakPtr(); | 32 return adapter->weak_ptr_factory_.GetWeakPtr(); |
29 } | 33 } |
30 | 34 |
| 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(); |
| 42 } |
| 43 |
31 // static | 44 // static |
32 bool BluetoothAdapterAndroid::RegisterJNI(JNIEnv* env) { | 45 bool BluetoothAdapterAndroid::RegisterJNI(JNIEnv* env) { |
33 return RegisterNativesImpl(env); // Generated in BluetoothAdapter_jni.h | 46 return RegisterNativesImpl(env); // Generated in BluetoothAdapter_jni.h |
34 } | 47 } |
35 | 48 |
36 bool BluetoothAdapterAndroid::HasBluetoothPermission() const { | 49 bool BluetoothAdapterAndroid::HasBluetoothPermission() const { |
37 return Java_BluetoothAdapter_hasBluetoothPermission( | 50 return Java_BluetoothAdapter_hasBluetoothPermission( |
38 AttachCurrentThread(), j_bluetooth_adapter_.obj()); | 51 AttachCurrentThread(), j_bluetooth_adapter_.obj()); |
39 } | 52 } |
40 | 53 |
41 std::string BluetoothAdapterAndroid::GetAddress() const { | 54 std::string BluetoothAdapterAndroid::GetAddress() const { |
42 return address_; | 55 return ConvertJavaStringToUTF8(Java_BluetoothAdapter_getAddress( |
| 56 AttachCurrentThread(), j_bluetooth_adapter_.obj())); |
43 } | 57 } |
44 | 58 |
45 std::string BluetoothAdapterAndroid::GetName() const { | 59 std::string BluetoothAdapterAndroid::GetName() const { |
46 return name_; | 60 return ConvertJavaStringToUTF8(Java_BluetoothAdapter_getName( |
| 61 AttachCurrentThread(), j_bluetooth_adapter_.obj())); |
47 } | 62 } |
48 | 63 |
49 void BluetoothAdapterAndroid::SetName(const std::string& name, | 64 void BluetoothAdapterAndroid::SetName(const std::string& name, |
50 const base::Closure& callback, | 65 const base::Closure& callback, |
51 const ErrorCallback& error_callback) { | 66 const ErrorCallback& error_callback) { |
52 NOTIMPLEMENTED(); | 67 NOTIMPLEMENTED(); |
53 } | 68 } |
54 | 69 |
55 bool BluetoothAdapterAndroid::IsInitialized() const { | 70 bool BluetoothAdapterAndroid::IsInitialized() const { |
56 NOTIMPLEMENTED(); | 71 NOTIMPLEMENTED(); |
57 return false; | 72 return false; |
58 } | 73 } |
59 | 74 |
60 bool BluetoothAdapterAndroid::IsPresent() const { | 75 bool BluetoothAdapterAndroid::IsPresent() const { |
61 NOTIMPLEMENTED(); | 76 return Java_BluetoothAdapter_isPresent(AttachCurrentThread(), |
62 return false; | 77 j_bluetooth_adapter_.obj()); |
63 } | 78 } |
64 | 79 |
65 bool BluetoothAdapterAndroid::IsPowered() const { | 80 bool BluetoothAdapterAndroid::IsPowered() const { |
66 NOTIMPLEMENTED(); | 81 return Java_BluetoothAdapter_isPowered(AttachCurrentThread(), |
67 return false; | 82 j_bluetooth_adapter_.obj()); |
68 } | 83 } |
69 | 84 |
70 void BluetoothAdapterAndroid::SetPowered(bool powered, | 85 void BluetoothAdapterAndroid::SetPowered(bool powered, |
71 const base::Closure& callback, | 86 const base::Closure& callback, |
72 const ErrorCallback& error_callback) { | 87 const ErrorCallback& error_callback) { |
73 NOTIMPLEMENTED(); | 88 NOTIMPLEMENTED(); |
74 } | 89 } |
75 | 90 |
76 bool BluetoothAdapterAndroid::IsDiscoverable() const { | 91 bool BluetoothAdapterAndroid::IsDiscoverable() const { |
77 NOTIMPLEMENTED(); | 92 return Java_BluetoothAdapter_isDiscoverable(AttachCurrentThread(), |
78 return false; | 93 j_bluetooth_adapter_.obj()); |
79 } | 94 } |
80 | 95 |
81 void BluetoothAdapterAndroid::SetDiscoverable( | 96 void BluetoothAdapterAndroid::SetDiscoverable( |
82 bool discoverable, | 97 bool discoverable, |
83 const base::Closure& callback, | 98 const base::Closure& callback, |
84 const ErrorCallback& error_callback) { | 99 const ErrorCallback& error_callback) { |
85 NOTIMPLEMENTED(); | 100 NOTIMPLEMENTED(); |
86 } | 101 } |
87 | 102 |
88 bool BluetoothAdapterAndroid::IsDiscovering() const { | 103 bool BluetoothAdapterAndroid::IsDiscovering() const { |
89 NOTIMPLEMENTED(); | 104 return Java_BluetoothAdapter_isDiscovering(AttachCurrentThread(), |
90 return false; | 105 j_bluetooth_adapter_.obj()); |
91 } | 106 } |
92 | 107 |
93 void BluetoothAdapterAndroid::CreateRfcommService( | 108 void BluetoothAdapterAndroid::CreateRfcommService( |
94 const BluetoothUUID& uuid, | 109 const BluetoothUUID& uuid, |
95 const ServiceOptions& options, | 110 const ServiceOptions& options, |
96 const CreateServiceCallback& callback, | 111 const CreateServiceCallback& callback, |
97 const CreateServiceErrorCallback& error_callback) { | 112 const CreateServiceErrorCallback& error_callback) { |
98 NOTIMPLEMENTED(); | 113 NOTIMPLEMENTED(); |
99 error_callback.Run("Not Implemented"); | 114 error_callback.Run("Not Implemented"); |
100 } | 115 } |
(...skipping 15 matching lines...) Expand all Loading... |
116 } | 131 } |
117 | 132 |
118 void BluetoothAdapterAndroid::RegisterAdvertisement( | 133 void BluetoothAdapterAndroid::RegisterAdvertisement( |
119 scoped_ptr<BluetoothAdvertisement::Data> advertisement_data, | 134 scoped_ptr<BluetoothAdvertisement::Data> advertisement_data, |
120 const CreateAdvertisementCallback& callback, | 135 const CreateAdvertisementCallback& callback, |
121 const CreateAdvertisementErrorCallback& error_callback) { | 136 const CreateAdvertisementErrorCallback& error_callback) { |
122 error_callback.Run(BluetoothAdvertisement::ERROR_UNSUPPORTED_PLATFORM); | 137 error_callback.Run(BluetoothAdvertisement::ERROR_UNSUPPORTED_PLATFORM); |
123 } | 138 } |
124 | 139 |
125 BluetoothAdapterAndroid::BluetoothAdapterAndroid() : weak_ptr_factory_(this) { | 140 BluetoothAdapterAndroid::BluetoothAdapterAndroid() : weak_ptr_factory_(this) { |
126 j_bluetooth_adapter_.Reset(Java_BluetoothAdapter_create( | |
127 AttachCurrentThread(), base::android::GetApplicationContext())); | |
128 } | 141 } |
129 | 142 |
130 BluetoothAdapterAndroid::~BluetoothAdapterAndroid() { | 143 BluetoothAdapterAndroid::~BluetoothAdapterAndroid() { |
131 } | 144 } |
132 | 145 |
133 void BluetoothAdapterAndroid::AddDiscoverySession( | 146 void BluetoothAdapterAndroid::AddDiscoverySession( |
134 BluetoothDiscoveryFilter* discovery_filter, | 147 BluetoothDiscoveryFilter* discovery_filter, |
135 const base::Closure& callback, | 148 const base::Closure& callback, |
136 const ErrorCallback& error_callback) { | 149 const ErrorCallback& error_callback) { |
137 } | 150 } |
138 | 151 |
139 void BluetoothAdapterAndroid::RemoveDiscoverySession( | 152 void BluetoothAdapterAndroid::RemoveDiscoverySession( |
140 BluetoothDiscoveryFilter* discovery_filter, | 153 BluetoothDiscoveryFilter* discovery_filter, |
141 const base::Closure& callback, | 154 const base::Closure& callback, |
142 const ErrorCallback& error_callback) { | 155 const ErrorCallback& error_callback) { |
143 } | 156 } |
144 | 157 |
145 void BluetoothAdapterAndroid::SetDiscoveryFilter( | 158 void BluetoothAdapterAndroid::SetDiscoveryFilter( |
146 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter, | 159 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter, |
147 const base::Closure& callback, | 160 const base::Closure& callback, |
148 const ErrorCallback& error_callback) { | 161 const ErrorCallback& error_callback) { |
149 } | 162 } |
150 | 163 |
151 void BluetoothAdapterAndroid::RemovePairingDelegateInternal( | 164 void BluetoothAdapterAndroid::RemovePairingDelegateInternal( |
152 device::BluetoothDevice::PairingDelegate* pairing_delegate) { | 165 device::BluetoothDevice::PairingDelegate* pairing_delegate) { |
153 } | 166 } |
154 | 167 |
155 } // namespace device | 168 } // namespace device |
OLD | NEW |