| 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; |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 Log.e(TAG, "Adapter is off. Cannot stop scan: " + e); | 198 Log.e(TAG, "Adapter is off. Cannot stop scan: " + e); |
| 199 } | 199 } |
| 200 mScanCallback = null; | 200 mScanCallback = null; |
| 201 return true; | 201 return true; |
| 202 } | 202 } |
| 203 | 203 |
| 204 // -------------------------------------------------------------------------
-------------------- | 204 // -------------------------------------------------------------------------
-------------------- |
| 205 // Implementation details: | 205 // Implementation details: |
| 206 | 206 |
| 207 /** | 207 /** |
| 208 * @return true if Chromium has permission to scan for Bluetooth devices. | 208 * @return true if Chromium has permission to scan for Bluetooth devices and
location services |
| 209 * are on. |
| 209 */ | 210 */ |
| 210 private boolean canScan() { | 211 private boolean canScan() { |
| 211 Context context = mAdapter.getContext(); | 212 Context context = mAdapter.getContext(); |
| 212 | 213 |
| 213 return LocationUtils.getInstance().hasAndroidLocationPermission(context)
; | 214 boolean havePermission = LocationUtils.getInstance().hasAndroidLocationP
ermission(context); |
| 215 boolean locationServicesOn = |
| 216 LocationUtils.getInstance().isSystemLocationSettingEnabled(conte
xt); |
| 217 |
| 218 return havePermission && locationServicesOn; |
| 214 } | 219 } |
| 215 | 220 |
| 216 private void registerBroadcastReceiver() { | 221 private void registerBroadcastReceiver() { |
| 217 if (mAdapter != null) { | 222 if (mAdapter != null) { |
| 218 mAdapter.getContext().registerReceiver( | 223 mAdapter.getContext().registerReceiver( |
| 219 this, new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED
)); | 224 this, new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED
)); |
| 220 } | 225 } |
| 221 } | 226 } |
| 222 | 227 |
| 223 private void unregisterBroadcastReceiver() { | 228 private void unregisterBroadcastReceiver() { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 // 'Object' type must be used for |bluetoothDeviceWrapper| because inner cla
ss | 308 // 'Object' type must be used for |bluetoothDeviceWrapper| because inner cla
ss |
| 304 // Wrappers.BluetoothDeviceWrapper reference is not handled by jni_generator
.py JavaToJni. | 309 // Wrappers.BluetoothDeviceWrapper reference is not handled by jni_generator
.py JavaToJni. |
| 305 // http://crbug.com/505554 | 310 // http://crbug.com/505554 |
| 306 private native void nativeCreateOrUpdateDeviceOnScan(long nativeBluetoothAda
pterAndroid, | 311 private native void nativeCreateOrUpdateDeviceOnScan(long nativeBluetoothAda
pterAndroid, |
| 307 String address, Object bluetoothDeviceWrapper, List<ParcelUuid> adve
rtisedUuids); | 312 String address, Object bluetoothDeviceWrapper, List<ParcelUuid> adve
rtisedUuids); |
| 308 | 313 |
| 309 // Binds to BluetoothAdapterAndroid::nativeOnAdapterStateChanged | 314 // Binds to BluetoothAdapterAndroid::nativeOnAdapterStateChanged |
| 310 private native void nativeOnAdapterStateChanged( | 315 private native void nativeOnAdapterStateChanged( |
| 311 long nativeBluetoothAdapterAndroid, boolean powered); | 316 long nativeBluetoothAdapterAndroid, boolean powered); |
| 312 } | 317 } |
| OLD | NEW |