| 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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 } | 178 } |
| 179 | 179 |
| 180 Log.d(TAG, "removeDiscoverySession: Now %d sessions.", mNumDiscoverySess
ions); | 180 Log.d(TAG, "removeDiscoverySession: Now %d sessions.", mNumDiscoverySess
ions); |
| 181 return true; | 181 return true; |
| 182 } | 182 } |
| 183 | 183 |
| 184 // -------------------------------------------------------------------------
-------------------- | 184 // -------------------------------------------------------------------------
-------------------- |
| 185 // Implementation details: | 185 // Implementation details: |
| 186 | 186 |
| 187 /** | 187 /** |
| 188 * @return true if Chromium has permission to scan for Bluetooth devices. | 188 * @return true if Chromium has permission to scan for Bluetooth devices and
location services |
| 189 * are on. |
| 189 */ | 190 */ |
| 190 private boolean canScan() { | 191 private boolean canScan() { |
| 191 Wrappers.ContextWrapper context = mAdapter.getContext(); | 192 Wrappers.ContextWrapper context = mAdapter.getContext(); |
| 193 boolean havePermission = context.hasAndroidLocationPermission(); |
| 194 boolean locationServicesOn = context.isSystemLocationSettingEnabled(); |
| 192 | 195 |
| 193 return context.hasAndroidLocationPermission(); | 196 return havePermission && locationServicesOn; |
| 194 } | 197 } |
| 195 | 198 |
| 196 private void registerBroadcastReceiver() { | 199 private void registerBroadcastReceiver() { |
| 197 if (mAdapter != null) { | 200 if (mAdapter != null) { |
| 198 mAdapter.getContext().registerReceiver( | 201 mAdapter.getContext().registerReceiver( |
| 199 this, new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED
)); | 202 this, new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED
)); |
| 200 } | 203 } |
| 201 } | 204 } |
| 202 | 205 |
| 203 private void unregisterBroadcastReceiver() { | 206 private void unregisterBroadcastReceiver() { |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 // 'Object' type must be used for |bluetoothDeviceWrapper| because inner cla
ss | 346 // 'Object' type must be used for |bluetoothDeviceWrapper| because inner cla
ss |
| 344 // Wrappers.BluetoothDeviceWrapper reference is not handled by jni_generator
.py JavaToJni. | 347 // Wrappers.BluetoothDeviceWrapper reference is not handled by jni_generator
.py JavaToJni. |
| 345 // http://crbug.com/505554 | 348 // http://crbug.com/505554 |
| 346 private native void nativeCreateOrUpdateDeviceOnScan(long nativeBluetoothAda
pterAndroid, | 349 private native void nativeCreateOrUpdateDeviceOnScan(long nativeBluetoothAda
pterAndroid, |
| 347 String address, Object bluetoothDeviceWrapper, List<ParcelUuid> adve
rtisedUuids); | 350 String address, Object bluetoothDeviceWrapper, List<ParcelUuid> adve
rtisedUuids); |
| 348 | 351 |
| 349 // Binds to BluetoothAdapterAndroid::nativeOnAdapterStateChanged | 352 // Binds to BluetoothAdapterAndroid::nativeOnAdapterStateChanged |
| 350 private native void nativeOnAdapterStateChanged( | 353 private native void nativeOnAdapterStateChanged( |
| 351 long nativeBluetoothAdapterAndroid, boolean powered); | 354 long nativeBluetoothAdapterAndroid, boolean powered); |
| 352 } | 355 } |
| OLD | NEW |