Commit 611ecb2e authored by James Hollyer's avatar James Hollyer Committed by Commit Bot

Request Fine Location for bluetooth access

There is an android bug where Bluetooth low energy scans do not return
results unless the app has fine location permission.  Coarse location
permission should be sufficient to that is what we requested previously.
This is transparent to the user therefore it seems appropriate to simply
request fine permission every time.

Bug: 1025420
Change-Id: I0cec63857aa2c553f3ccf59c2f62db67fd07a93d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1941200
Commit-Queue: James Hollyer <jameshollyer@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarOvidio de Jesús Ruiz-Henríquez <odejesush@chromium.org>
Cr-Commit-Position: refs/heads/master@{#721249}
parent 3f93e51c
......@@ -258,7 +258,7 @@ public class BluetoothChooserDialog
if (mNativeBluetoothChooserDialogPtr == 0) return;
for (int i = 0; i < permissions.length; i++) {
if (permissions[i].equals(Manifest.permission.ACCESS_COARSE_LOCATION)) {
if (permissions[i].equals(Manifest.permission.ACCESS_FINE_LOCATION)) {
if (checkLocationServicesAndPermission()) {
mItemChooserDialog.clear();
Natives jni = BluetoothChooserDialogJni.get();
......@@ -272,13 +272,13 @@ public class BluetoothChooserDialog
// Returns true if Location Services is on and Chrome has permission to see the user's location.
private boolean checkLocationServicesAndPermission() {
final boolean havePermission = LocationUtils.getInstance().hasAndroidLocationPermission();
final boolean havePermission =
mWindowAndroid.hasPermission(Manifest.permission.ACCESS_FINE_LOCATION);
final boolean locationServicesOn =
LocationUtils.getInstance().isSystemLocationSettingEnabled();
if (!havePermission
&& !mWindowAndroid.canRequestPermission(
Manifest.permission.ACCESS_COARSE_LOCATION)) {
&& !mWindowAndroid.canRequestPermission(Manifest.permission.ACCESS_FINE_LOCATION)) {
// Immediately close the dialog because the user has asked Chrome not to request the
// location permission.
finishDialog(DialogFinished.DENIED_PERMISSION, "");
......@@ -353,7 +353,7 @@ public class BluetoothChooserDialog
case LinkType.REQUEST_LOCATION_PERMISSION:
mItemChooserDialog.setIgnorePendingWindowFocusChangeForClose(true);
mWindowAndroid.requestPermissions(
new String[] {Manifest.permission.ACCESS_COARSE_LOCATION},
new String[] {Manifest.permission.ACCESS_FINE_LOCATION},
BluetoothChooserDialog.this);
break;
case LinkType.REQUEST_LOCATION_SERVICES:
......@@ -379,9 +379,8 @@ public class BluetoothChooserDialog
@CalledByNative
private static BluetoothChooserDialog create(WindowAndroid windowAndroid, String origin,
int securityLevel, long nativeBluetoothChooserDialogPtr) {
if (!LocationUtils.getInstance().hasAndroidLocationPermission()
&& !windowAndroid.canRequestPermission(
Manifest.permission.ACCESS_COARSE_LOCATION)) {
if (!windowAndroid.hasPermission(Manifest.permission.ACCESS_FINE_LOCATION)
&& !windowAndroid.canRequestPermission(Manifest.permission.ACCESS_FINE_LOCATION)) {
// If we can't even ask for enough permission to scan for Bluetooth devices, don't open
// the dialog.
return null;
......
......@@ -316,13 +316,14 @@ public class BluetoothChooserDialogTest {
// Permission was requested.
Assert.assertArrayEquals(permissionDelegate.mPermissionsRequested,
new String[] {Manifest.permission.ACCESS_COARSE_LOCATION});
new String[] {Manifest.permission.ACCESS_FINE_LOCATION});
Assert.assertNotNull(permissionDelegate.mCallback);
// Grant permission.
mLocationUtils.mLocationGranted = true;
permissionDelegate.mLocationGranted = true;
TestThreadUtils.runOnUiThreadBlocking(
() -> permissionDelegate.mCallback.onRequestPermissionsResult(
new String[] {Manifest.permission.ACCESS_COARSE_LOCATION},
()
-> permissionDelegate.mCallback.onRequestPermissionsResult(
new String[] {Manifest.permission.ACCESS_FINE_LOCATION},
new int[] {PackageManager.PERMISSION_GRANTED}));
Assert.assertEquals(1, mRestartSearchCount);
......@@ -352,7 +353,7 @@ public class BluetoothChooserDialogTest {
mWindowAndroid.setAndroidPermissionDelegate(permissionDelegate);
// Grant permissions, and turn off location services.
mLocationUtils.mLocationGranted = true;
permissionDelegate.mLocationGranted = true;
mLocationUtils.mSystemLocationSettingsEnabled = false;
TestThreadUtils.runOnUiThreadBlocking(
......@@ -430,14 +431,16 @@ public class BluetoothChooserDialogTest {
Dialog mDialog;
PermissionCallback mCallback;
String[] mPermissionsRequested;
public boolean mLocationGranted;
public TestAndroidPermissionDelegate(Dialog dialog) {
mLocationGranted = false;
mDialog = dialog;
}
@Override
public boolean hasPermission(String permission) {
return false;
return mLocationGranted;
}
@Override
......@@ -456,7 +459,7 @@ public class BluetoothChooserDialogTest {
mDialog.onWindowFocusChanged(false /* hasFocus */);
mPermissionsRequested = permissions;
if (permissions.length == 1
&& permissions[0].equals(Manifest.permission.ACCESS_COARSE_LOCATION)) {
&& permissions[0].equals(Manifest.permission.ACCESS_FINE_LOCATION)) {
mCallback = callback;
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment