Chromium Code Reviews| 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.Manifest; | 7 import android.Manifest; |
| 8 import android.annotation.TargetApi; | 8 import android.annotation.TargetApi; |
| 9 import android.bluetooth.BluetoothAdapter; | 9 import android.bluetooth.BluetoothAdapter; |
| 10 import android.bluetooth.le.ScanSettings; | 10 import android.bluetooth.le.ScanSettings; |
| 11 import android.content.BroadcastReceiver; | 11 import android.content.BroadcastReceiver; |
| 12 import android.content.Context; | 12 import android.content.Context; |
| 13 import android.content.Intent; | 13 import android.content.Intent; |
| 14 import android.content.IntentFilter; | 14 import android.content.IntentFilter; |
| 15 import android.location.LocationManager; | |
| 15 import android.os.Build; | 16 import android.os.Build; |
| 16 import android.os.ParcelUuid; | 17 import android.os.ParcelUuid; |
| 17 | 18 |
| 18 import org.chromium.base.Log; | 19 import org.chromium.base.Log; |
| 19 import org.chromium.base.annotations.CalledByNative; | 20 import org.chromium.base.annotations.CalledByNative; |
| 20 import org.chromium.base.annotations.JNINamespace; | 21 import org.chromium.base.annotations.JNINamespace; |
| 21 | 22 |
| 22 import java.util.List; | 23 import java.util.List; |
| 23 | 24 |
| 24 /** | 25 /** |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 179 } | 180 } |
| 180 | 181 |
| 181 Log.d(TAG, "removeDiscoverySession: Now %d sessions.", mNumDiscoverySess ions); | 182 Log.d(TAG, "removeDiscoverySession: Now %d sessions.", mNumDiscoverySess ions); |
| 182 return true; | 183 return true; |
| 183 } | 184 } |
| 184 | 185 |
| 185 // ------------------------------------------------------------------------- -------------------- | 186 // ------------------------------------------------------------------------- -------------------- |
| 186 // Implementation details: | 187 // Implementation details: |
| 187 | 188 |
| 188 /** | 189 /** |
| 189 * @return true if Chromium has permission to scan for Bluetooth devices. | 190 * @return true if Chromium has permission to scan for Bluetooth devices and location services |
| 191 * are on. | |
| 190 */ | 192 */ |
| 191 private boolean canScan() { | 193 private boolean canScan() { |
| 192 Wrappers.ContextWrapper context = mAdapter.getContext(); | 194 Wrappers.ContextWrapper context = mAdapter.getContext(); |
| 193 return context.checkPermission(Manifest.permission.ACCESS_COARSE_LOCATIO N) | 195 boolean havePermission = context.checkPermission(Manifest.permission.ACC ESS_COARSE_LOCATION) |
| 194 || context.checkPermission(Manifest.permission.ACCESS_FINE_LOCAT ION); | 196 || context.checkPermission(Manifest.permission.ACCESS_FINE_LOCAT ION); |
| 197 | |
| 198 Wrappers.LocationManagerWrapper locationManager = context.getLocationMan ager(); | |
| 199 boolean locationServicesOn = | |
| 200 locationManager.isProviderEnabled(LocationManager.NETWORK_PROVID ER) | |
|
Jeffrey Yasskin
2016/06/03 01:52:48
https://developer.android.com/reference/android/lo
| |
| 201 || locationManager.isProviderEnabled(LocationManager.GPS_PROVIDE R); | |
| 202 | |
| 203 return havePermission && locationServicesOn; | |
| 195 } | 204 } |
| 196 | 205 |
| 197 private void registerBroadcastReceiver() { | 206 private void registerBroadcastReceiver() { |
| 198 if (mAdapter != null) { | 207 if (mAdapter != null) { |
| 199 mAdapter.getContext().registerReceiver( | 208 mAdapter.getContext().registerReceiver( |
| 200 this, new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED )); | 209 this, new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED )); |
| 201 } | 210 } |
| 202 } | 211 } |
| 203 | 212 |
| 204 private void unregisterBroadcastReceiver() { | 213 private void unregisterBroadcastReceiver() { |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 344 // 'Object' type must be used for |bluetoothDeviceWrapper| because inner cla ss | 353 // 'Object' type must be used for |bluetoothDeviceWrapper| because inner cla ss |
| 345 // Wrappers.BluetoothDeviceWrapper reference is not handled by jni_generator .py JavaToJni. | 354 // Wrappers.BluetoothDeviceWrapper reference is not handled by jni_generator .py JavaToJni. |
| 346 // http://crbug.com/505554 | 355 // http://crbug.com/505554 |
| 347 private native void nativeCreateOrUpdateDeviceOnScan(long nativeBluetoothAda pterAndroid, | 356 private native void nativeCreateOrUpdateDeviceOnScan(long nativeBluetoothAda pterAndroid, |
| 348 String address, Object bluetoothDeviceWrapper, List<ParcelUuid> adve rtisedUuids); | 357 String address, Object bluetoothDeviceWrapper, List<ParcelUuid> adve rtisedUuids); |
| 349 | 358 |
| 350 // Binds to BluetoothAdapterAndroid::nativeOnAdapterStateChanged | 359 // Binds to BluetoothAdapterAndroid::nativeOnAdapterStateChanged |
| 351 private native void nativeOnAdapterStateChanged( | 360 private native void nativeOnAdapterStateChanged( |
| 352 long nativeBluetoothAdapterAndroid, boolean powered); | 361 long nativeBluetoothAdapterAndroid, boolean powered); |
| 353 } | 362 } |
| OLD | NEW |