Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting strange ACCESS_FINE_LOCATION denial on Android 12, targeting API 31 #947

Open
QuentinFarizon opened this issue Dec 7, 2022 · 6 comments

Comments

@QuentinFarizon
Copy link

I am on the latest version of this plugin (1.6.1-cli) and latest cordova-android (11.0.0), so targeting API 31

On some devices (including my personal phone, a Sony Xperia 1 II on Android 12), scanning doesn't work at all. It pormpts for permissions (I even use cordova.plugins.diagnostic to premptively prompt them), but scanning returns no results.

I have tried looking at logcat for some ideas, and I see a strange log about permissions :
BluetoothUtils: Permission denial: Need ACCESS_FINE_LOCATION permission to get scan results
From my understanding, on a Android 12 phone targeting API 31, this permission should not be needed at all.

@peitschie
Copy link
Collaborator

Hi @QuentinFarizon ... it sounds like you've root-caused it correctly there! That's a bit unideal.

As a quick test, can you try asking for the ACCESS_FINE_LOCATION permission via the diagnostic plugin for this specific phone and see if that allows the scan results to be reported?

It does sound like the Sony Android 12 variant there is non-compliant with Android (as you've already noted)

@tigohenryschultz
Copy link

This plugin is breaking my Android app. If I don't use this plugin then my @capacitor/geolocation works fine. With this plugin installed my ACCESS_FINE_LOCATION / ACCESS_COARSE_LOCATION issues arise. I can't use this plugin right now.

@tigohenryschultz
Copy link

Something like this may fix for Android 31/32

    if (targetSdkVersion >= 31) {
        // Strip out Android 12+ changes
        androidManifest = stripPermission(androidManifest, 'ACCESS_FINE_LOCATION');
        androidManifest = stripPermission(androidManifest, 'ACCESS_COARSE_LOCATION');
        androidManifest = stripPermission(androidManifest, 'ACCESS_BACKGROUND_LOCATION');
        manifestChanged = true;
    }

@peitschie
Copy link
Collaborator

hi @tigohenryschultz , it sounds like you're hitting #932

The fix here is to switch to the slim variant of this plugin, and manually control those permissions yourself, as per #932 (comment)

If that doesn't work, please feel free to raise a new issue.

@tigohenryschultz
Copy link

Okay I will try that on Monday for now I built my app on a fork with my changes:

https://github.com/tigohenryschultz/cordova-plugin-ble-central

@peitschie
Copy link
Collaborator

The specific issue you're facing there @tigohenryschultz is that this plugin now specifies a maxSdk version for coarse & fine location, which messes up Cordova's somewhat naive XML merge logic. What your workaround there is doing is simply removing one of the offending permission entries... but it's unfortunately non-deterministic in my experience, so was not suitable to build into the plugin itself 😩 .

The only solution in the end is to remove those permission entries completely, as that is the only way to ensure no conflicts with other plugins.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants