particle-iot / particle-android

Particle Open Source for Android
Apache License 2.0
37 stars 38 forks source link

DeviceSetup: Android 9 wifi scan throttling #68

Open rduriancik opened 5 years ago

rduriancik commented 5 years ago

Hey! We're using your device setup library and we have one user whose device wifi doesn't show up in the setup. I did notice neither fatal nor non-fatal crash in Crashlytics so I assume there was no error thrown. Therefore I think the cause is that getScanResults() method in WifiFacade returned an empty list. He has Pixel 3 XL with Android 9. I have a bad feeling that it has something to do with how they started throttling the frequency of wifi scans in this version (https://developer.android.com/guide/topics/connectivity/wifi-scan#wifi-scan-throttling). I don't have Android 9 to test it so I'm giving it to your attention. Do you think my suspicion is right? If so is there a way how to fix that?

jensck commented 5 years ago

Your theory is a good one. I haven't run into this on my Pixel 2 w/Android 9, but this is the sort of issue which might not be triggered depending on the circumstances.

One way to confirm this would be to ask the user to wait two minutes from their last attempt, make sure that the device they're trying to connect to is powered on and in setup mode, and then try setup. The device ought to be there in the first four scans (scanning happens every 10 seconds).

rduriancik commented 5 years ago

I let him try it. The device network showed up in first 3 seconds (probably first wifi scan). So it supports the theory.

I'm thinking how to take this UX wise. Even if we optimize it that the app scans wifi only until the device is found and then the other APs are sent to the next screen so that we don't need to scan again, there is no guarantee that the device network will be found in the first four scans. My concern is that they are planning to completely remove wifi scan option from the Wi-FiManager (https://developer.android.com/reference/android/net/wifi/WifiManager.html#startScan()). In that case we would have to move towards iOS approach - let user select network manually in the wifi settings. For now, if you don't find a better solution, besides optimization I mentioned before I'd store timestamp of the first scan and count them. Then if user exhausts the scan attempts I'd let him select the network manually and pass the scanresult of the last scan to the next screen. Maybe? I don't know how I would solve back button press yet, though.

jensck commented 5 years ago

I doubt they will remove Wi-FI scanning entirely. That would break a major API, and completely break the setup process for many IOT/smart devices, not just Particle-powered stuff.

Regardless, this scanning change could be an issue for some. I'm not sure what you mean about "let him select the network manually" though. Do you mean manually typing in the Wi-Fi SSID?

rduriancik commented 5 years ago

To select particle device network I meant to go to system wifi settings (out of the app), choose particle network and get back to the app. The app would somehow detect that the phone is connected to the right network.

jensck commented 5 years ago

I'm not convinced we should be giving up on Wi-Fi scanning just yet. Asking the user to exit your app to accomplish something is far from ideal UX.

What if scanning behavior was changed to only perform only two scans (one up front and a second one X seconds later just in case a device isn't plugged in yet/isn't in setup mode/etc), and the results shown to the user would be the union of both scans.

Another option: only perform one scan and then give the user a "Scan again" button (which, unfortunately, would silently fail on the 5th scan in 2 minutes, but will that be an issue?)

Any thoughts on these approaches?

rduriancik commented 5 years ago

Yeah, I agree. I was counting on the worst case scenario.

:thinking: Both approaches sound good. Maybe I'd show to the user that some scanning is happening, like progress circle or something so that he won't think the app is not doing anything.

I think I like the second approach more. Maybe when that screen is shown, wait 1-2 seconds then start wifi scan, if a network of the device is not found, show scan again button. If the user tries 5th scan show some dialog or something that he needs to wait, maybe? Uh, UI/UX is hard. :expressionless:

jensck commented 5 years ago

UI/UX is hard.

No easy answers to stuff like this, that's for sure.

I'm going to bring this to the attention of the product folks at Particle to get their take on the situation. I'll update here once I've talked w/them.

MozilaIP commented 5 years ago

Let's upvote and comment https://issuetracker.google.com/issues/112688545

jensck commented 4 years ago

internal ref: ch41794