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