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 ...@@ -258,7 +258,7 @@ public class BluetoothChooserDialog
if (mNativeBluetoothChooserDialogPtr == 0) return; if (mNativeBluetoothChooserDialogPtr == 0) return;
for (int i = 0; i < permissions.length; i++) { 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()) { if (checkLocationServicesAndPermission()) {
mItemChooserDialog.clear(); mItemChooserDialog.clear();
Natives jni = BluetoothChooserDialogJni.get(); Natives jni = BluetoothChooserDialogJni.get();
...@@ -272,13 +272,13 @@ public class BluetoothChooserDialog ...@@ -272,13 +272,13 @@ public class BluetoothChooserDialog
// Returns true if Location Services is on and Chrome has permission to see the user's location. // Returns true if Location Services is on and Chrome has permission to see the user's location.
private boolean checkLocationServicesAndPermission() { private boolean checkLocationServicesAndPermission() {
final boolean havePermission = LocationUtils.getInstance().hasAndroidLocationPermission(); final boolean havePermission =
mWindowAndroid.hasPermission(Manifest.permission.ACCESS_FINE_LOCATION);
final boolean locationServicesOn = final boolean locationServicesOn =
LocationUtils.getInstance().isSystemLocationSettingEnabled(); LocationUtils.getInstance().isSystemLocationSettingEnabled();
if (!havePermission if (!havePermission
&& !mWindowAndroid.canRequestPermission( && !mWindowAndroid.canRequestPermission(Manifest.permission.ACCESS_FINE_LOCATION)) {
Manifest.permission.ACCESS_COARSE_LOCATION)) {
// Immediately close the dialog because the user has asked Chrome not to request the // Immediately close the dialog because the user has asked Chrome not to request the
// location permission. // location permission.
finishDialog(DialogFinished.DENIED_PERMISSION, ""); finishDialog(DialogFinished.DENIED_PERMISSION, "");
...@@ -353,7 +353,7 @@ public class BluetoothChooserDialog ...@@ -353,7 +353,7 @@ public class BluetoothChooserDialog
case LinkType.REQUEST_LOCATION_PERMISSION: case LinkType.REQUEST_LOCATION_PERMISSION:
mItemChooserDialog.setIgnorePendingWindowFocusChangeForClose(true); mItemChooserDialog.setIgnorePendingWindowFocusChangeForClose(true);
mWindowAndroid.requestPermissions( mWindowAndroid.requestPermissions(
new String[] {Manifest.permission.ACCESS_COARSE_LOCATION}, new String[] {Manifest.permission.ACCESS_FINE_LOCATION},
BluetoothChooserDialog.this); BluetoothChooserDialog.this);
break; break;
case LinkType.REQUEST_LOCATION_SERVICES: case LinkType.REQUEST_LOCATION_SERVICES:
...@@ -379,9 +379,8 @@ public class BluetoothChooserDialog ...@@ -379,9 +379,8 @@ public class BluetoothChooserDialog
@CalledByNative @CalledByNative
private static BluetoothChooserDialog create(WindowAndroid windowAndroid, String origin, private static BluetoothChooserDialog create(WindowAndroid windowAndroid, String origin,
int securityLevel, long nativeBluetoothChooserDialogPtr) { int securityLevel, long nativeBluetoothChooserDialogPtr) {
if (!LocationUtils.getInstance().hasAndroidLocationPermission() if (!windowAndroid.hasPermission(Manifest.permission.ACCESS_FINE_LOCATION)
&& !windowAndroid.canRequestPermission( && !windowAndroid.canRequestPermission(Manifest.permission.ACCESS_FINE_LOCATION)) {
Manifest.permission.ACCESS_COARSE_LOCATION)) {
// If we can't even ask for enough permission to scan for Bluetooth devices, don't open // If we can't even ask for enough permission to scan for Bluetooth devices, don't open
// the dialog. // the dialog.
return null; return null;
......
...@@ -316,13 +316,14 @@ public class BluetoothChooserDialogTest { ...@@ -316,13 +316,14 @@ public class BluetoothChooserDialogTest {
// Permission was requested. // Permission was requested.
Assert.assertArrayEquals(permissionDelegate.mPermissionsRequested, Assert.assertArrayEquals(permissionDelegate.mPermissionsRequested,
new String[] {Manifest.permission.ACCESS_COARSE_LOCATION}); new String[] {Manifest.permission.ACCESS_FINE_LOCATION});
Assert.assertNotNull(permissionDelegate.mCallback); Assert.assertNotNull(permissionDelegate.mCallback);
// Grant permission. // Grant permission.
mLocationUtils.mLocationGranted = true; permissionDelegate.mLocationGranted = true;
TestThreadUtils.runOnUiThreadBlocking( 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})); new int[] {PackageManager.PERMISSION_GRANTED}));
Assert.assertEquals(1, mRestartSearchCount); Assert.assertEquals(1, mRestartSearchCount);
...@@ -352,7 +353,7 @@ public class BluetoothChooserDialogTest { ...@@ -352,7 +353,7 @@ public class BluetoothChooserDialogTest {
mWindowAndroid.setAndroidPermissionDelegate(permissionDelegate); mWindowAndroid.setAndroidPermissionDelegate(permissionDelegate);
// Grant permissions, and turn off location services. // Grant permissions, and turn off location services.
mLocationUtils.mLocationGranted = true; permissionDelegate.mLocationGranted = true;
mLocationUtils.mSystemLocationSettingsEnabled = false; mLocationUtils.mSystemLocationSettingsEnabled = false;
TestThreadUtils.runOnUiThreadBlocking( TestThreadUtils.runOnUiThreadBlocking(
...@@ -430,14 +431,16 @@ public class BluetoothChooserDialogTest { ...@@ -430,14 +431,16 @@ public class BluetoothChooserDialogTest {
Dialog mDialog; Dialog mDialog;
PermissionCallback mCallback; PermissionCallback mCallback;
String[] mPermissionsRequested; String[] mPermissionsRequested;
public boolean mLocationGranted;
public TestAndroidPermissionDelegate(Dialog dialog) { public TestAndroidPermissionDelegate(Dialog dialog) {
mLocationGranted = false;
mDialog = dialog; mDialog = dialog;
} }
@Override @Override
public boolean hasPermission(String permission) { public boolean hasPermission(String permission) {
return false; return mLocationGranted;
} }
@Override @Override
...@@ -456,7 +459,7 @@ public class BluetoothChooserDialogTest { ...@@ -456,7 +459,7 @@ public class BluetoothChooserDialogTest {
mDialog.onWindowFocusChanged(false /* hasFocus */); mDialog.onWindowFocusChanged(false /* hasFocus */);
mPermissionsRequested = permissions; mPermissionsRequested = permissions;
if (permissions.length == 1 if (permissions.length == 1
&& permissions[0].equals(Manifest.permission.ACCESS_COARSE_LOCATION)) { && permissions[0].equals(Manifest.permission.ACCESS_FINE_LOCATION)) {
mCallback = callback; 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