| Index: device/bluetooth/bluetooth_adapter_android.cc
|
| diff --git a/device/bluetooth/bluetooth_adapter_android.cc b/device/bluetooth/bluetooth_adapter_android.cc
|
| index 0d4f1408f5bddf7bdd1db90218a2c122b35f9edc..0b8bea30de428369c8bd34823eaa8acef26e85bd 100644
|
| --- a/device/bluetooth/bluetooth_adapter_android.cc
|
| +++ b/device/bluetooth/bluetooth_adapter_android.cc
|
| @@ -5,6 +5,7 @@
|
| #include "device/bluetooth/bluetooth_adapter_android.h"
|
|
|
| #include "base/android/jni_android.h"
|
| +#include "base/android/jni_string.h"
|
| #include "base/sequenced_task_runner.h"
|
| #include "base/single_thread_task_runner.h"
|
| #include "base/thread_task_runner_handle.h"
|
| @@ -12,6 +13,7 @@
|
| #include "jni/BluetoothAdapter_jni.h"
|
|
|
| using base::android::AttachCurrentThread;
|
| +using base::android::ConvertJavaStringToUTF8;
|
|
|
| namespace device {
|
|
|
| @@ -25,6 +27,17 @@ base::WeakPtr<BluetoothAdapter> BluetoothAdapter::CreateAdapter(
|
| base::WeakPtr<BluetoothAdapterAndroid>
|
| BluetoothAdapterAndroid::CreateAdapter() {
|
| BluetoothAdapterAndroid* adapter = new BluetoothAdapterAndroid();
|
| + adapter->j_bluetooth_adapter_.Reset(Java_BluetoothAdapter_create(
|
| + AttachCurrentThread(), base::android::GetApplicationContext()));
|
| + return adapter->weak_ptr_factory_.GetWeakPtr();
|
| +}
|
| +
|
| +base::WeakPtr<BluetoothAdapterAndroid>
|
| +BluetoothAdapterAndroid::CreateAdapterWithoutPermissionForTesting() {
|
| + BluetoothAdapterAndroid* adapter = new BluetoothAdapterAndroid();
|
| + adapter->j_bluetooth_adapter_.Reset(
|
| + Java_BluetoothAdapter_createWithoutPermissionForTesting(
|
| + AttachCurrentThread(), base::android::GetApplicationContext()));
|
| return adapter->weak_ptr_factory_.GetWeakPtr();
|
| }
|
|
|
| @@ -39,11 +52,13 @@ bool BluetoothAdapterAndroid::HasBluetoothPermission() const {
|
| }
|
|
|
| std::string BluetoothAdapterAndroid::GetAddress() const {
|
| - return address_;
|
| + return ConvertJavaStringToUTF8(Java_BluetoothAdapter_getAddress(
|
| + AttachCurrentThread(), j_bluetooth_adapter_.obj()));
|
| }
|
|
|
| std::string BluetoothAdapterAndroid::GetName() const {
|
| - return name_;
|
| + return ConvertJavaStringToUTF8(Java_BluetoothAdapter_getName(
|
| + AttachCurrentThread(), j_bluetooth_adapter_.obj()));
|
| }
|
|
|
| void BluetoothAdapterAndroid::SetName(const std::string& name,
|
| @@ -58,13 +73,13 @@ bool BluetoothAdapterAndroid::IsInitialized() const {
|
| }
|
|
|
| bool BluetoothAdapterAndroid::IsPresent() const {
|
| - NOTIMPLEMENTED();
|
| - return false;
|
| + return Java_BluetoothAdapter_isPresent(AttachCurrentThread(),
|
| + j_bluetooth_adapter_.obj());
|
| }
|
|
|
| bool BluetoothAdapterAndroid::IsPowered() const {
|
| - NOTIMPLEMENTED();
|
| - return false;
|
| + return Java_BluetoothAdapter_isPowered(AttachCurrentThread(),
|
| + j_bluetooth_adapter_.obj());
|
| }
|
|
|
| void BluetoothAdapterAndroid::SetPowered(bool powered,
|
| @@ -74,8 +89,8 @@ void BluetoothAdapterAndroid::SetPowered(bool powered,
|
| }
|
|
|
| bool BluetoothAdapterAndroid::IsDiscoverable() const {
|
| - NOTIMPLEMENTED();
|
| - return false;
|
| + return Java_BluetoothAdapter_isDiscoverable(AttachCurrentThread(),
|
| + j_bluetooth_adapter_.obj());
|
| }
|
|
|
| void BluetoothAdapterAndroid::SetDiscoverable(
|
| @@ -86,8 +101,8 @@ void BluetoothAdapterAndroid::SetDiscoverable(
|
| }
|
|
|
| bool BluetoothAdapterAndroid::IsDiscovering() const {
|
| - NOTIMPLEMENTED();
|
| - return false;
|
| + return Java_BluetoothAdapter_isDiscovering(AttachCurrentThread(),
|
| + j_bluetooth_adapter_.obj());
|
| }
|
|
|
| void BluetoothAdapterAndroid::CreateRfcommService(
|
| @@ -123,8 +138,6 @@ void BluetoothAdapterAndroid::RegisterAdvertisement(
|
| }
|
|
|
| BluetoothAdapterAndroid::BluetoothAdapterAndroid() : weak_ptr_factory_(this) {
|
| - j_bluetooth_adapter_.Reset(Java_BluetoothAdapter_create(
|
| - AttachCurrentThread(), base::android::GetApplicationContext()));
|
| }
|
|
|
| BluetoothAdapterAndroid::~BluetoothAdapterAndroid() {
|
|
|