falconeta / capacitor-wifi-connect

15 stars 5 forks source link

Implementation of prefixConnect on Android #10

Closed Oidlichtnwoada closed 1 year ago

Oidlichtnwoada commented 1 year ago

/**

Oidlichtnwoada commented 1 year ago

I also noticed that the method CapacitorWifiConnect.getSSIDs() leads to app crashes sometimes, even though all AndroidManifest entries are set, do you have an idea why @falconeta?

Oidlichtnwoada commented 1 year ago

@falconeta It happens on Android 11, 12 and 13

Here are the stacktraces:

Exception java.lang.RuntimeException: java.lang.reflect.InvocationTargetException at com.getcapacitor.Bridge.lambda$callPluginMethod$0 (Bridge.java:783) at com.getcapacitor.Bridge.$r8$lambda$ehFTi5f4HhVNFKTbCKAYDkpQYRA at com.getcapacitor.Bridge$$ExternalSyntheticLambda3.run at android.os.Handler.handleCallback (Handler.java:938) at android.os.Handler.dispatchMessage (Handler.java:99) at android.os.Looper.loop (Looper.java:246) at android.os.HandlerThread.run (HandlerThread.java:67) Caused by java.lang.reflect.InvocationTargetException: at java.lang.reflect.Method.invoke at com.getcapacitor.PluginHandle.invoke (PluginHandle.java:138) at com.getcapacitor.Bridge.lambda$callPluginMethod$0 (Bridge.java:774) Caused by java.lang.IllegalArgumentException: at android.app.LoadedApk.forgetReceiverDispatcher (LoadedApk.java:1523) at android.app.ContextImpl.unregisterReceiver (ContextImpl.java:1712) at android.content.ContextWrapper.unregisterReceiver (ContextWrapper.java:733) at android.content.ContextWrapper.unregisterReceiver (ContextWrapper.java:733) at com.falconeta.capacitor_wifi_connect.CapacitorWifiConnect.getSSIDs (CapacitorWifiConnect.kt:340) at com.falconeta.capacitor_wifi_connect.CapacitorWifiConnectPlugin.getSSIDs (CapacitorWifiConnectPlugin.kt:237)

Exception java.lang.RuntimeException: at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0$android-app-LoadedApk$ReceiverDispatcher$Args (LoadedApk.java:1822) at android.app.LoadedApk$ReceiverDispatcher$Args$$ExternalSyntheticLambda0.run at android.os.Handler.handleCallback (Handler.java:942) at android.os.Handler.dispatchMessage (Handler.java:99) at android.os.Looper.loopOnce (Looper.java:210) at android.os.Looper.loop (Looper.java:299) at android.app.ActivityThread.main (ActivityThread.java:8116) at java.lang.reflect.Method.invoke at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:559) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:950) Caused by java.lang.IllegalArgumentException: at android.app.LoadedApk.forgetReceiverDispatcher (LoadedApk.java:1678) at android.app.ContextImpl.unregisterReceiver (ContextImpl.java:1846) at android.content.ContextWrapper.unregisterReceiver (ContextWrapper.java:822) at android.content.ContextWrapper.unregisterReceiver (ContextWrapper.java:822) at com.falconeta.capacitor_wifi_connect.CapacitorWifiConnect$getSSIDs$wifiScanReceiver$1.onReceive (CapacitorWifiConnect.kt:328) at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0$android-app-LoadedApk$ReceiverDispatcher$Args (LoadedApk.java:1808)

Do you have an idea what is causing the problems? There are two different problems regarding getSSIDs

Oidlichtnwoada commented 1 year ago

@falconeta our company https://www.efficientio.com/ would pay if you fix this bug, please contact me hannes.brantner@efficientio.com

falconeta commented 1 year ago

Hi @Oidlichtnwoada, thank you for segnalation, i don't know why this happens, i will try this evening to investigate

falconeta commented 1 year ago

@Oidlichtnwoada I've just fixed the getSSIDs issue (version 5.1.5), now in the response payload is present a new property called status that inform a possible error (0 success, -2 KO due temporary wifi limit or generic error, -4 wifi disabled).

In the next days I'll check the securePrefixConnect method on android...

Oidlichtnwoada commented 1 year ago

Thanks so much @falconeta ... does that mean whenever the method throwed an exception before, the method now returns either -2 or -4? Or were the exceptions also sometimes blocking executions where everything should have worked and now they work too?

falconeta commented 1 year ago

All exceptions are replaced with status in the response payload (i uniformed the response method with the other). So if the status is 0 we received a list of Wi-Fi discovered, else returns an empty array

Oidlichtnwoada commented 1 year ago

Ok thanks, that means that my proposed method cannot be used to implement the securePrefixConnect on Android as this rate limit would kick in ... but it seems to be doable in Android: https://developer.android.com/guide/topics/connectivity/wifi-bootstrap We would really appreciate if securePrefixConnect functionality drops to this plugin for Android ... you have developed the best WiFi-Plugin in the Capacitor ecosystem and in my opinion it is a shame that there is no native plugin from the Capacitor core team 😄

If you need help or if I can assist in any form during tests or implementation, let me know please 👍

falconeta commented 1 year ago

Hi @Oidlichtnwoada, I just released a new version of the plugin (5.1.6) that introduces securePrefixConnect for Android as well. This way you will no longer need to call getSSIDs and can unify the flow for both platforms.

Thank you very much for the feedback!

Oidlichtnwoada commented 1 year ago

@falconeta I just tested the new implementation and it works fine ... thank you so much 👍