Git Product home page Git Product logo

Comments (11)

itamardo avatar itamardo commented on August 17, 2024 2

I prefer not to ask my users for fine location on android 12 so as long as this is forced in 1.5.2, I forked and
changed AndroidManifest.xml to:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  package="com.boskokg.flutter_blue_plus">
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" />
    <uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" android:maxSdkVersion="30" />
    <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
    <uses-permission android:name="android.permission.BLUETOOTH_SCAN" android:usesPermissionFlags="neverForLocation"
        tools:targetApi="s" />
</manifest>

and changed FlutterBluePlusPlugin.java in the scan code to omit the check of fine location for type "s" like this:

case "startScan":
      {
        ensurePermissionBeforeAction(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ? Manifest.permission.BLUETOOTH_SCAN : Manifest.permission.ACCESS_FINE_LOCATION, (grantedScan, permissionScan) -> {
          if (grantedScan) {
            ensurePermissionBeforeAction(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ? Manifest.permission.BLUETOOTH_CONNECT : null, (grantedConnect, permissionConnect) -> {
              if (grantedConnect)
                startScan(call, result);
              else
                result.error(
                        "no_permissions", String.format("flutter_blue plugin requires %s for scanning", permissionConnect), null);
            });
          }
          else
            result.error(
                    "no_permissions", String.format("flutter_blue plugin requires %s for scanning", permissionScan), null);
        });
        break;
      }

The changelog for 1.5.0 states that the fine location requirement was added on purpose on Android12. I never encountered the need myself on an Android12 phone and the documentation clearly states that fine location isn't needed for scanning.
Can anyone share a phone model that needs fine location with Android 12?

from flutter_blue_plus.

virshe00 avatar virshe00 commented on August 17, 2024

I prefer not to ask my users for fine location on android 12 so as long as this is forced in 1.5.2, I forked and changed AndroidManifest.xml to:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  package="com.boskokg.flutter_blue_plus">
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" />
    <uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" android:maxSdkVersion="30" />
    <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
    <uses-permission android:name="android.permission.BLUETOOTH_SCAN" android:usesPermissionFlags="neverForLocation"
        tools:targetApi="s" />
</manifest>

and changed FlutterBluePlusPlugin.java in the scan code to omit the check of fine location for type "s" like this:

case "startScan":
      {
        ensurePermissionBeforeAction(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ? Manifest.permission.BLUETOOTH_SCAN : Manifest.permission.ACCESS_FINE_LOCATION, (grantedScan, permissionScan) -> {
          if (grantedScan) {
            ensurePermissionBeforeAction(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ? Manifest.permission.BLUETOOTH_CONNECT : null, (grantedConnect, permissionConnect) -> {
              if (grantedConnect)
                startScan(call, result);
              else
                result.error(
                        "no_permissions", String.format("flutter_blue plugin requires %s for scanning", permissionConnect), null);
            });
          }
          else
            result.error(
                    "no_permissions", String.format("flutter_blue plugin requires %s for scanning", permissionScan), null);
        });
        break;
      }

The changelog for 1.5.0 states that the fine location requirement was added on purpose on Android12. I never encountered the need myself on an Android12 phone and the documentation clearly states that fine location isn't needed for scanning. Can anyone share a phone model that needs fine location with Android 12?

If phones are using Android 12, you'd expect them all to have the same permission requirements wouldn't you?

from flutter_blue_plus.

itamardo avatar itamardo commented on August 17, 2024

@virshe00 I would, yes, which is why I don't understand the decision made in 1.5.0 and why I feel ok with the fork I made. Still - the changelog hints that some people faced Android 12 phones that failed to work with the documented requirements, so maybe some manufacturer did something wrong? idk. Myself, I never encountered an Android 12 phone that needed fine location for BLE, but I didn't test more than a few manufacturers

from flutter_blue_plus.

virshe00 avatar virshe00 commented on August 17, 2024

@itamardo Yeah, that makes sense. I can't find any reference to anyone having issues and if some phone manufacturer isn't following the Android specification then idk what else they're doing and they sound like a bad brand.

Regardless, I think the core of the issue comes from requiring fine location permissions, but only if you don't specify neverForLocation.

@chipweinberger Could you please make a decision as to what you think the course of action should be? I can understand why you might want to enforce precise location. If there's no way to detect whether the manifest specifies neverForLocation, it might be safer to simply enforce fine location. However, I think reverting the commit and having a note/section in the README around the permissions section might be sufficient. If we were really pedantic, we could spit out a warning message if we don't have fine location.

from flutter_blue_plus.

xbug42 avatar xbug42 commented on August 17, 2024

Can anyone share a phone model that needs fine location with Android 12?

I would be interested too... This new location permission request is very annoying and against the Android specs (as long as BT is not used for location, obviously)

from flutter_blue_plus.

chipweinberger avatar chipweinberger commented on August 17, 2024

please open a PR.

This change was made because I pulled a fork. I'm not sure if the fork was for 11 or 12, but FBP should target the most recent version.

from flutter_blue_plus.

GorIvanov avatar GorIvanov commented on August 17, 2024

Thank you @itamardo !
I have spend 2 days to make ap works again...
Google is already annoying all the time to change and come up with new rules and mechanisms ...

from flutter_blue_plus.

GorIvanov avatar GorIvanov commented on August 17, 2024

I would like to contact flutter developers. I hope you read github.
You are creating a cross-platform framework that should behave the same on all platforms and have common interaction mechanisms. Now there are more than 10 options for plugins for working with bluetooth on pub.dev. I believe that you, as developers of a cross-platform framework, are obliged to develop and make part of the framework all the basic mechanisms for working with such things as bluetooth, cameras, wifi, and the like, as is done for example in QT.

from flutter_blue_plus.

itamardo avatar itamardo commented on August 17, 2024

My manifest above had a missing line (fine location for sdk <= 30) that was apparently needed for an Android 11 phone so I updated it like this:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  package="com.boskokg.flutter_blue_plus">
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" />
    <uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" android:maxSdkVersion="30" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" android:maxSdkVersion="30" />
    <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
    <uses-permission android:name="android.permission.BLUETOOTH_SCAN" android:usesPermissionFlags="neverForLocation"
        tools:targetApi="s" />
</manifest>

from flutter_blue_plus.

virshe00 avatar virshe00 commented on August 17, 2024

My manifest above had a missing line (fine location for sdk <= 30) that was apparently needed for an Android 11 phone so I updated it like this:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  package="com.boskokg.flutter_blue_plus">
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" />
    <uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" android:maxSdkVersion="30" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" android:maxSdkVersion="30" />
    <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
    <uses-permission android:name="android.permission.BLUETOOTH_SCAN" android:usesPermissionFlags="neverForLocation"
        tools:targetApi="s" />
</manifest>

I wondered about this, thanks for pointing it out.
I'll try and get this thing done over the weekend.

from flutter_blue_plus.

chipweinberger avatar chipweinberger commented on August 17, 2024

a lot of this changed in 1.7.0+

please try 1.7.6+, reopen a new issue if you still have problems.

from flutter_blue_plus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.