| 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 |
| 36 bool BluetoothAdapterAndroid::HasBluetoothPermission() const { |
| 37 return Java_BluetoothAdapter_hasBluetoothPermission( |
| 38 AttachCurrentThread(), j_bluetooth_adapter_.obj()); |
| 39 } |
| 40 |
| 26 std::string BluetoothAdapterAndroid::GetAddress() const { | 41 std::string BluetoothAdapterAndroid::GetAddress() const { |
| 27 return address_; | 42 return address_; |
| 28 } | 43 } |
| 29 | 44 |
| 30 std::string BluetoothAdapterAndroid::GetName() const { | 45 std::string BluetoothAdapterAndroid::GetName() const { |
| 31 return name_; | 46 return name_; |
| 32 } | 47 } |
| 33 | 48 |
| 34 void BluetoothAdapterAndroid::SetName(const std::string& name, | 49 void BluetoothAdapterAndroid::SetName(const std::string& name, |
| 35 const base::Closure& callback, | 50 const base::Closure& callback, |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 } | 116 } |
| 102 | 117 |
| 103 void BluetoothAdapterAndroid::RegisterAdvertisement( | 118 void BluetoothAdapterAndroid::RegisterAdvertisement( |
| 104 scoped_ptr<BluetoothAdvertisement::Data> advertisement_data, | 119 scoped_ptr<BluetoothAdvertisement::Data> advertisement_data, |
| 105 const CreateAdvertisementCallback& callback, | 120 const CreateAdvertisementCallback& callback, |
| 106 const CreateAdvertisementErrorCallback& error_callback) { | 121 const CreateAdvertisementErrorCallback& error_callback) { |
| 107 error_callback.Run(BluetoothAdvertisement::ERROR_UNSUPPORTED_PLATFORM); | 122 error_callback.Run(BluetoothAdvertisement::ERROR_UNSUPPORTED_PLATFORM); |
| 108 } | 123 } |
| 109 | 124 |
| 110 BluetoothAdapterAndroid::BluetoothAdapterAndroid() : weak_ptr_factory_(this) { | 125 BluetoothAdapterAndroid::BluetoothAdapterAndroid() : weak_ptr_factory_(this) { |
| 126 j_bluetooth_adapter_.Reset(Java_BluetoothAdapter_create( |
| 127 AttachCurrentThread(), base::android::GetApplicationContext())); |
| 111 } | 128 } |
| 112 | 129 |
| 113 BluetoothAdapterAndroid::~BluetoothAdapterAndroid() { | 130 BluetoothAdapterAndroid::~BluetoothAdapterAndroid() { |
| 114 } | 131 } |
| 115 | 132 |
| 116 void BluetoothAdapterAndroid::AddDiscoverySession( | 133 void BluetoothAdapterAndroid::AddDiscoverySession( |
| 117 BluetoothDiscoveryFilter* discovery_filter, | 134 BluetoothDiscoveryFilter* discovery_filter, |
| 118 const base::Closure& callback, | 135 const base::Closure& callback, |
| 119 const ErrorCallback& error_callback) { | 136 const ErrorCallback& error_callback) { |
| 120 } | 137 } |
| 121 | 138 |
| 122 void BluetoothAdapterAndroid::RemoveDiscoverySession( | 139 void BluetoothAdapterAndroid::RemoveDiscoverySession( |
| 123 BluetoothDiscoveryFilter* discovery_filter, | 140 BluetoothDiscoveryFilter* discovery_filter, |
| 124 const base::Closure& callback, | 141 const base::Closure& callback, |
| 125 const ErrorCallback& error_callback) { | 142 const ErrorCallback& error_callback) { |
| 126 } | 143 } |
| 127 | 144 |
| 128 void BluetoothAdapterAndroid::SetDiscoveryFilter( | 145 void BluetoothAdapterAndroid::SetDiscoveryFilter( |
| 129 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter, | 146 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter, |
| 130 const base::Closure& callback, | 147 const base::Closure& callback, |
| 131 const ErrorCallback& error_callback) { | 148 const ErrorCallback& error_callback) { |
| 132 } | 149 } |
| 133 | 150 |
| 134 void BluetoothAdapterAndroid::RemovePairingDelegateInternal( | 151 void BluetoothAdapterAndroid::RemovePairingDelegateInternal( |
| 135 device::BluetoothDevice::PairingDelegate* pairing_delegate) { | 152 device::BluetoothDevice::PairingDelegate* pairing_delegate) { |
| 136 } | 153 } |
| 137 | 154 |
| 138 } // namespace device | 155 } // namespace device |
| OLD | NEW |