flutternetwork / WiFiFlutter

Flutter plugin suite for various WiFi services.
https://wifi.flutternetwork.dev
285 stars 176 forks source link

[wifi_iot] Crash at WifiManager.getScanResults #264

Open DarkDancers opened 2 years ago

DarkDancers commented 2 years ago

Hi WiFiFlutter Team, We found multiple crashes on firebase. Please check the Stack Trace as following:

Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.List android.net.wifi.WifiManager.getScanResults()' on a null object reference
       at com.alternadom.wifiiot.WifiIotPlugin.handleNetworkScanResult(WifiIotPlugin.java:649)
       at com.alternadom.wifiiot.WifiIotPlugin$4.onReceive(WifiIotPlugin.java:643)
       at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0$LoadedApk$ReceiverDispatcher$Args(LoadedApk.java:1573)
       at android.app.-$$Lambda$LoadedApk$ReceiverDispatcher$Args$_BumDX2UKsnxLVrE6UJsJZkotuA.run(-.java:2)
       at android.os.Handler.handleCallback(Handler.java:883)
       at android.os.Handler.dispatchMessage(Handler.java:100)
       at android.os.Looper.loop(Looper.java:214)
       at android.app.ActivityThread.main(ActivityThread.java:7438)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:989)
daadu commented 2 years ago

Ok, looks like the Flutter engine was detached and attached back - in between the scan event received might have caused this crash. Is it a one time crash? or happening in specific conditions? are you able to reproduce it?

DarkDancers commented 2 years ago

just discovered this crash. still look into it not able to reproduce atm. from firebase report: 20933 crash events affecting 8104 users seem its not one time crash

Ok, looks like the Flutter engine was detached and attached back - in between the scan event received might have caused this crash. Is it a one time crash? or happening in specific conditions? are you able to reproduce it?

daadu commented 2 years ago

Seems like a tricky bug, let me know if you find more info.

I have following ideas:

  1. not resetting "context" and "wifiManger" in cleanup
  2. unregister Broadcast receiver in cleanup
  3. always get WiFiManger "in-line" instead of getting-and-caching instance in "init"

Check the code if you can get some hint, what is wrong.