tripflex / WifiWizard2

A Cordova plugin for managing Wifi networks (new version of WiFiWizard) - Latest is version 3+

Home Page:https://www.npmjs.com/package/cordova-plugin-wifiwizard2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Main thread blocked while connecting to a network

Pietfro opened this issue · comments

I have been testing the plugin for the past 3 days and I must say - it is a huge step up in comparison to the previous version:) Good job @tripflex !
However, I am experiencing main thread blockage whenever I run connect() method. After connect() completes everything goes back to normal.
I am not able to debug the app as everything hangs and CPU goes crazy.

Did anybody notice that as well?

HTC 10
Android 8.0
Cordova 7.0

Same thing happens on Android emulator.

@Pietfro thanks for reporting this, I have seen this happen a few times I just have not had time to figure out why and come up with a solution ... pretty sure it's just because of the original forked code pieces that are not running in a Runnable ... do you only experience this on connect or are there others?

If this doesn't happen on scan then I should be able to resolve this by doing the same as in that method that creates a new Runnable instance

For reference, here's what the notifications plugin did on change from 0.7 to 0.8:
https://github.com/katzer/cordova-plugin-local-notifications/blob/0.8/src/android/LocalNotification.java#L130

@tripflex thanks for the response.
I was testing it mostly on connect as the app that I am building does not require scan. Let me do more thorough testing on other methods and get back to you afterwards.

I am experiencing the same problem on my Android project. I tested it on an Moto g and Moto g5s plus. The former (kind of old) freezes while the latter hang for a couple of seconds and then keeps on working.

I had a look on the plugin code and the problem doesn't seem to be on the connect() method itself but on the waitForConnection() one. Maybe the Thread.sleep shouldn't be used there?

But anyway, the temporary FIX for me was to simply comment out line 696 of WifiWizard2.java:

696 //return waitForConnection(callbackContext, networkIdToConnect);
697 callbackContext.error("CONNECTION_MECHANISM_DONE");
698 return true;

The downside is that I won't have a callback for successful or failed connection.

@AndreFWeber , @tripflex , in that case maybe be it is worth to consider creating a separate worker thread to handle the connection, for instance:

new Thread(new Runnable() {
        public void run() {
            // connection stuff
        }
}).start();

or use AsyncTask.

Hey all. I've fixed this in my PR #43 - @tripflex please could you review and merge if happy 😄

@jack828 thank you for submitting the PR, i'll respond on the PR

Still happenning on version 3.0.0 in an Ionic app :/

I'm using an Motorola X Play with Android 7.1.1. Main UI thread keep blocked until the promisse has been returned.