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 package org.chromium.device.bluetooth; | 5 package org.chromium.device.bluetooth; |
6 | 6 |
7 import android.annotation.TargetApi; | 7 import android.annotation.TargetApi; |
8 import android.bluetooth.BluetoothAdapter; | 8 import android.bluetooth.BluetoothAdapter; |
9 import android.bluetooth.le.ScanSettings; | 9 import android.bluetooth.le.ScanSettings; |
10 import android.content.BroadcastReceiver; | 10 import android.content.BroadcastReceiver; |
11 import android.content.Context; | 11 import android.content.Context; |
12 import android.content.Intent; | 12 import android.content.Intent; |
13 import android.content.IntentFilter; | 13 import android.content.IntentFilter; |
14 import android.os.Build; | 14 import android.os.Build; |
15 import android.os.ParcelUuid; | 15 import android.os.ParcelUuid; |
16 | 16 |
17 import org.chromium.base.Log; | 17 import org.chromium.base.Log; |
18 import org.chromium.base.annotations.CalledByNative; | 18 import org.chromium.base.annotations.CalledByNative; |
19 import org.chromium.base.annotations.JNINamespace; | 19 import org.chromium.base.annotations.JNINamespace; |
| 20 import org.chromium.components.location.LocationUtils; |
20 | 21 |
21 import java.util.List; | 22 import java.util.List; |
22 | 23 |
23 /** | 24 /** |
24 * Exposes android.bluetooth.BluetoothAdapter as necessary for C++ | 25 * Exposes android.bluetooth.BluetoothAdapter as necessary for C++ |
25 * device::BluetoothAdapterAndroid, which implements the cross platform | 26 * device::BluetoothAdapterAndroid, which implements the cross platform |
26 * device::BluetoothAdapter. | 27 * device::BluetoothAdapter. |
27 * | 28 * |
28 * Lifetime is controlled by device::BluetoothAdapterAndroid. | 29 * Lifetime is controlled by device::BluetoothAdapterAndroid. |
29 */ | 30 */ |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 return true; | 201 return true; |
201 } | 202 } |
202 | 203 |
203 // -------------------------------------------------------------------------
-------------------- | 204 // -------------------------------------------------------------------------
-------------------- |
204 // Implementation details: | 205 // Implementation details: |
205 | 206 |
206 /** | 207 /** |
207 * @return true if Chromium has permission to scan for Bluetooth devices. | 208 * @return true if Chromium has permission to scan for Bluetooth devices. |
208 */ | 209 */ |
209 private boolean canScan() { | 210 private boolean canScan() { |
210 Wrappers.ContextWrapper context = mAdapter.getContext(); | 211 Context context = mAdapter.getContext(); |
211 | 212 |
212 return context.hasAndroidLocationPermission(); | 213 return LocationUtils.getInstance().hasAndroidLocationPermission(context)
; |
213 } | 214 } |
214 | 215 |
215 private void registerBroadcastReceiver() { | 216 private void registerBroadcastReceiver() { |
216 if (mAdapter != null) { | 217 if (mAdapter != null) { |
217 mAdapter.getContext().registerReceiver( | 218 mAdapter.getContext().registerReceiver( |
218 this, new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED
)); | 219 this, new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED
)); |
219 } | 220 } |
220 } | 221 } |
221 | 222 |
222 private void unregisterBroadcastReceiver() { | 223 private void unregisterBroadcastReceiver() { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 // 'Object' type must be used for |bluetoothDeviceWrapper| because inner cla
ss | 303 // 'Object' type must be used for |bluetoothDeviceWrapper| because inner cla
ss |
303 // Wrappers.BluetoothDeviceWrapper reference is not handled by jni_generator
.py JavaToJni. | 304 // Wrappers.BluetoothDeviceWrapper reference is not handled by jni_generator
.py JavaToJni. |
304 // http://crbug.com/505554 | 305 // http://crbug.com/505554 |
305 private native void nativeCreateOrUpdateDeviceOnScan(long nativeBluetoothAda
pterAndroid, | 306 private native void nativeCreateOrUpdateDeviceOnScan(long nativeBluetoothAda
pterAndroid, |
306 String address, Object bluetoothDeviceWrapper, List<ParcelUuid> adve
rtisedUuids); | 307 String address, Object bluetoothDeviceWrapper, List<ParcelUuid> adve
rtisedUuids); |
307 | 308 |
308 // Binds to BluetoothAdapterAndroid::nativeOnAdapterStateChanged | 309 // Binds to BluetoothAdapterAndroid::nativeOnAdapterStateChanged |
309 private native void nativeOnAdapterStateChanged( | 310 private native void nativeOnAdapterStateChanged( |
310 long nativeBluetoothAdapterAndroid, boolean powered); | 311 long nativeBluetoothAdapterAndroid, boolean powered); |
311 } | 312 } |
OLD | NEW |