| 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/sequenced_task_runner.h" | 8 #include "base/sequenced_task_runner.h" |
| 8 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 9 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| 10 #include "device/bluetooth/bluetooth_advertisement.h" | 11 #include "device/bluetooth/bluetooth_advertisement.h" |
| 12 #include "jni/BluetoothAdapter_jni.h" |
| 13 |
| 14 using base::android::AttachCurrentThread; |
| 11 | 15 |
| 12 namespace device { | 16 namespace device { |
| 13 | 17 |
| 14 // static | 18 // static |
| 15 base::WeakPtr<BluetoothAdapter> BluetoothAdapter::CreateAdapter( | 19 base::WeakPtr<BluetoothAdapter> BluetoothAdapter::CreateAdapter( |
| 16 const InitCallback& init_callback) { | 20 const InitCallback& init_callback) { |
| 17 return BluetoothAdapterAndroid::CreateAdapter(); | 21 return BluetoothAdapterAndroid::CreateAdapter(); |
| 18 } | 22 } |
| 19 | 23 |
| 20 // static | 24 // static |
| 21 base::WeakPtr<BluetoothAdapter> BluetoothAdapterAndroid::CreateAdapter() { | 25 base::WeakPtr<BluetoothAdapterAndroid> |
| 26 BluetoothAdapterAndroid::CreateAdapter() { |
| 22 BluetoothAdapterAndroid* adapter = new BluetoothAdapterAndroid(); | 27 BluetoothAdapterAndroid* adapter = new BluetoothAdapterAndroid(); |
| 23 return adapter->weak_ptr_factory_.GetWeakPtr(); | 28 return adapter->weak_ptr_factory_.GetWeakPtr(); |
| 24 } | 29 } |
| 25 | 30 |
| 31 // static |
| 32 bool BluetoothAdapterAndroid::RegisterJNI(JNIEnv* env) { |
| 33 return RegisterNativesImpl(env); // Generated in BluetoothAdapter_jni.h |
| 34 } |
| 35 |
| 26 std::string BluetoothAdapterAndroid::GetAddress() const { | 36 std::string BluetoothAdapterAndroid::GetAddress() const { |
| 27 return address_; | 37 return address_; |
| 28 } | 38 } |
| 29 | 39 |
| 30 std::string BluetoothAdapterAndroid::GetName() const { | 40 std::string BluetoothAdapterAndroid::GetName() const { |
| 31 return name_; | 41 return name_; |
| 32 } | 42 } |
| 33 | 43 |
| 34 void BluetoothAdapterAndroid::SetName(const std::string& name, | 44 void BluetoothAdapterAndroid::SetName(const std::string& name, |
| 35 const base::Closure& callback, | 45 const base::Closure& callback, |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 } | 111 } |
| 102 | 112 |
| 103 void BluetoothAdapterAndroid::RegisterAdvertisement( | 113 void BluetoothAdapterAndroid::RegisterAdvertisement( |
| 104 scoped_ptr<BluetoothAdvertisement::Data> advertisement_data, | 114 scoped_ptr<BluetoothAdvertisement::Data> advertisement_data, |
| 105 const CreateAdvertisementCallback& callback, | 115 const CreateAdvertisementCallback& callback, |
| 106 const CreateAdvertisementErrorCallback& error_callback) { | 116 const CreateAdvertisementErrorCallback& error_callback) { |
| 107 error_callback.Run(BluetoothAdvertisement::ERROR_UNSUPPORTED_PLATFORM); | 117 error_callback.Run(BluetoothAdvertisement::ERROR_UNSUPPORTED_PLATFORM); |
| 108 } | 118 } |
| 109 | 119 |
| 110 BluetoothAdapterAndroid::BluetoothAdapterAndroid() : weak_ptr_factory_(this) { | 120 BluetoothAdapterAndroid::BluetoothAdapterAndroid() : weak_ptr_factory_(this) { |
| 121 j_bluetooth_adapter_.Reset(Java_BluetoothAdapter_create( |
| 122 AttachCurrentThread(), base::android::GetApplicationContext())); |
| 123 has_bluetooth_permission_ = Java_BluetoothAdapter_hasBluetoothPermission( |
| 124 AttachCurrentThread(), j_bluetooth_adapter_.obj()); |
| 111 } | 125 } |
| 112 | 126 |
| 113 BluetoothAdapterAndroid::~BluetoothAdapterAndroid() { | 127 BluetoothAdapterAndroid::~BluetoothAdapterAndroid() { |
| 114 } | 128 } |
| 115 | 129 |
| 116 void BluetoothAdapterAndroid::AddDiscoverySession( | 130 void BluetoothAdapterAndroid::AddDiscoverySession( |
| 117 BluetoothDiscoveryFilter* discovery_filter, | 131 BluetoothDiscoveryFilter* discovery_filter, |
| 118 const base::Closure& callback, | 132 const base::Closure& callback, |
| 119 const ErrorCallback& error_callback) { | 133 const ErrorCallback& error_callback) { |
| 120 } | 134 } |
| 121 | 135 |
| 122 void BluetoothAdapterAndroid::RemoveDiscoverySession( | 136 void BluetoothAdapterAndroid::RemoveDiscoverySession( |
| 123 BluetoothDiscoveryFilter* discovery_filter, | 137 BluetoothDiscoveryFilter* discovery_filter, |
| 124 const base::Closure& callback, | 138 const base::Closure& callback, |
| 125 const ErrorCallback& error_callback) { | 139 const ErrorCallback& error_callback) { |
| 126 } | 140 } |
| 127 | 141 |
| 128 void BluetoothAdapterAndroid::SetDiscoveryFilter( | 142 void BluetoothAdapterAndroid::SetDiscoveryFilter( |
| 129 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter, | 143 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter, |
| 130 const base::Closure& callback, | 144 const base::Closure& callback, |
| 131 const ErrorCallback& error_callback) { | 145 const ErrorCallback& error_callback) { |
| 132 } | 146 } |
| 133 | 147 |
| 134 void BluetoothAdapterAndroid::RemovePairingDelegateInternal( | 148 void BluetoothAdapterAndroid::RemovePairingDelegateInternal( |
| 135 device::BluetoothDevice::PairingDelegate* pairing_delegate) { | 149 device::BluetoothDevice::PairingDelegate* pairing_delegate) { |
| 136 } | 150 } |
| 137 | 151 |
| 138 } // namespace device | 152 } // namespace device |
| OLD | NEW |