flutter_background_geolocation icon indicating copy to clipboard operation
flutter_background_geolocation copied to clipboard

Android: Fatal exception - android.permission.ACCESS_WIFI_STATE required

Open viplavrawal opened this issue 2 years ago • 5 comments

Your Environment

  • Plugin version: 4.8.3
  • Platform: Android
  • OS version: 13
  • Device manufacturer / model: Samsung S22
  • Flutter info (flutter doctor):

Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.3.6, on macOS 13.2 22D49 darwin-arm (Rosetta), locale en-GB) [!] Android toolchain - develop for Android devices (Android SDK version 30.0.3) ✗ cmdline-tools component is missing Run path/to/sdkmanager --install "cmdline-tools;latest" See https://developer.android.com/studio/command-line for more details. ✗ Android license status unknown. Run flutter doctor --android-licenses to accept the SDK licenses. See https://flutter.dev/docs/get-started/install/macos#android-setup for more details. [✓] Xcode - develop for iOS and macOS (Xcode 14.2) [✓] Chrome - develop for the web [✓] Android Studio (version 2021.3) [✓] VS Code (version 1.75.0) [✓] Connected device (3 available) [✓] HTTP Host Availability

  • Plugin config:
geofenceModeHighAccuracy: true,
enableHeadless: true,
desiredAccuracy: Config.DESIRED_ACCURACY_HIGH,
distanceFilter: 0,
stopOnTerminate: false,
scheduleUseAlarmManager: true,
startOnBoot: true,
autoSync: true,
debug: false,
logLevel: Config.LOG_LEVEL_ERROR,
reset: true,
disableMotionActivityUpdates: true,
schedule: [1-7 0:01-1:00],

Expected Behavior

Should not get error in crashlytics saying android.permission.ACCESS_WIFI_STATE is required.

Actual Behavior

Receiving error in crashlytics saying android.permission.ACCESS_WIFI_STATE is not present which is causing the app to crash for some users.

Steps to Reproduce

  1. Purchased the plugin
  2. Tested on release and debug version locally, faced no such issues
  3. Crashlytics notifying crashes happening due to missing permission

Context

We are already using the following permissions from manifest:

<uses-permission android:name="android.permission.USE_BIOMETRIC"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />

Debug logs

Logs
Fatal Exception: java.lang.SecurityException: WifiService: Neither user 10028 nor current process has android.permission.ACCESS_WIFI_STATE.
       at android.os.Parcel.createExceptionOrNull(Parcel.java:3023)
       at android.os.Parcel.createException(Parcel.java:3007)
       at android.os.Parcel.readException(Parcel.java:2990)
       at android.os.Parcel.readException(Parcel.java:2932)
       at android.net.wifi.IWifiManager$Stub$Proxy.getWifiEnabledState(IWifiManager.java:2912)
       at android.net.wifi.WifiManager.getWifiState(WifiManager.java:4429)
       at android.net.wifi.WifiManager.isWifiEnabled(WifiManager.java:4441)
       at com.transistorsoft.locationmanager.event.LocationProviderChangeEvent.init(LocationProviderChangeEvent.java:122)
       at com.transistorsoft.locationmanager.event.LocationProviderChangeEvent.<init>(LocationProviderChangeEvent.java:3)
       at com.transistorsoft.locationmanager.provider.TSProviderManager.<init>(TSProviderManager.java:5)
       at com.transistorsoft.locationmanager.provider.TSProviderManager.getInstanceSynchronized(TSProviderManager.java:9)
       at com.transistorsoft.locationmanager.provider.TSProviderManager.getInstance(TSProviderManager.java:4)
       at com.transistorsoft.locationmanager.adapter.BackgroundGeolocation.$r8$lambda$oSDeWXxQl1jmikdjYQwff60damw(BackgroundGeolocation.java:28)
       at com.transistorsoft.locationmanager.adapter.BackgroundGeolocation.b(BackgroundGeolocation.java:14)
       at com.transistorsoft.locationmanager.adapter.BackgroundGeolocation.getInstance(BackgroundGeolocation.java:10)
       at com.transistorsoft.locationmanager.BootReceiver.a(BootReceiver.java:8)
       at com.transistorsoft.locationmanager.BootReceiver.a(BootReceiver.java)
       at com.transistorsoft.locationmanager.BootReceiver$a.run(BootReceiver.java:109)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)
       at java.lang.Thread.run(Thread.java:1012)

viplavrawal avatar Feb 24 '23 07:02 viplavrawal

The plugin has its own AndroidManifest, containing all its required permissions, which is automatically merged into your App's AndroidManifest. As you can see below (line 3) , one of those permissions is android.permission.ACCESS_WIFI_STATE. The plugin has been using this permission for over 8 years and this issue has never been reported.

Are you doing something in your own AndroidManifest to explicitly remove this required permission?

    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION" />
    <uses-permission android:name="com.huawei.hms.permission.ACTIVITY_RECOGNITION" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
    <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
    <!-- device-specific permissions for DeviceSettings methods -->
    <uses-permission android:name="oppo.permission.OPPO_COMPONENT_SAFE"/>
    <uses-permission android:name="com.huawei.permission.external_app_settings.USE_COMPONENT"/>

christocracy avatar Feb 24 '23 13:02 christocracy

We have a very straight forward manifest. The only different thing that we are doing is merging manifests to replace the value of com.transistorsoft.locationmanager.license across various flavors of our app. I don't suppose there's anything in there that could target this specific permission and remove it. Can you think of something else that might be causing this issue?

It's happening for a very small number of users (only 8), but is a repetitive crash for them that seems to happen as soon as they open the app.

viplavrawal avatar Feb 27 '23 07:02 viplavrawal

Can you think of something else

No. Have you searched this yourself?

christocracy avatar Feb 27 '23 12:02 christocracy

I've checked with several android experts in our team and also checked online but couldn't find anything. Found this weird solution but it doesn't make much sense. I suppose the only solution is that we launch and update in the app and add this permission in our main manifest.

If you agree with this solution, and don't think any further research is required here, please feel free to close this thread.

viplavrawal avatar Mar 02 '23 12:03 viplavrawal

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar May 08 '24 01:05 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar May 22 '24 01:05 github-actions[bot]