henrichg / PhoneProfilesPlus

Profile manager for Android - event triggered
Apache License 2.0
389 stars 32 forks source link

[bug fix] Wifi sensor fix #132

Closed Pankovea closed 2 months ago

Pankovea commented 3 months ago

The Wi-Fi connection search sensor only works if geolocation is enabled.

I have an Honor X8b Currently configured with a Wi-Fi sensor that is not connected to an access point. But when geolocation is disabled, the sensor still works. Although it should not have worked because he does not have access to this data.

henrichg commented 3 months ago

"The Wi-Fi connection search sensor only works if geolocation is enabled."

You means "Wi-Fi sensor" with "Connection type"="Nearby"? And you have dislabed Loaction in Location system settings?

PPP do not check Location setting in Wi-Fi scanning. If PPP receives broadcast for Wi-Fi scanning, then will be used.

PPP has WifiScanBroadcastReceiver with action WifiManager.SCAN_RESULTS_AVAILABLE_ACTION. And if is received this broadcast, PPP use data from it. In it PPP only check Location permission and then gets scanned ssids with: List _scanResults = WifiManager.getScanResults();

Maybe in your Honor working wi-fi scanning even when Location is disabled.

But by my tests, in some devices _scanResults list is empty when Location is disabled.

Pankovea commented 3 months ago

Hello, Henrich. I don't really understand what you mean. I'll show you how things are in more detail. I'm trying on another device and the behavior is exactly the same. App version 6.5 (7140) The sensor settings are as follows Screenshot_20240612_233332 The result of the work is as follows:

  1. Geolocation is on. And the sensor is not triggered. This is the expected behavior 01
  2. Geolocation is off. And the sensor is triggered. It shouldn't be like this. 02

When the sensor cannot receive data about connection or non-connection to the network, it should not be triggered. Now it's triggered.

henrichg commented 3 months ago

You do not using Wi-Fi scanning. In "Connection type" is configured "Not connected". This do not use wifi scanner, only check for connect/disconnect from wifi.

And this "Connection type" working only when Loaction is enabled?

EDIT: Your device is Honor? Because SSID name is "Xiaomi...". This ssid is from Xiaomi router? EDIT2: I will testing it in my Huawei P40.

Pankovea commented 3 months ago

I've tried both ways.: Connected to Wi-Fi and located nearby. It's just that in this case it's more revealing.

My device is Honor X8b (Android 13), Xiaomi_74A6 is my router. My second device in the same behaviour is Redmi 9 pro (Android 12). But my third device works correctly - Redmi Note 5 (Android 9). Moreover, it works correctly even without turning on geolocation. And even in scan mode.

What could be the problem?

henrichg commented 3 months ago

Hm yes, if Location is disabled, sensor is passed. OK I must fix it. Tested in my Huawei P40.

Pankovea commented 3 months ago

Thanks.

henrichg commented 3 months ago

Ok, problem is with security in Android.

  1. Is not possible to get connected SSID. It returns: SSID="\<unknown ssid>"
  2. Also is not possible to get configured SSID List from device Settings. It returns empty list.

Result: Location MUST be enabled to get proper connected SSID.

Pankovea commented 3 months ago

In case when location is turned off, the sensor must not be triggered.

henrichg commented 3 months ago

OK, but then configured SSID in sensor will be ignored? Because this is ugly "workaround".

henrichg commented 3 months ago

Hm "workaround" implemented. But your wifi sensor will be not passed (green), when Location is dislabled. In both Connection types: "Connected", "Not connected". Is this as you want it?

Pankovea commented 3 months ago

I think it will be correct behaviour. Because if the sensor does't know about the actual state of the Wi-Fi module, then it should not do anything by default. Perhaps this is my special case. Maybe you can add a setting for this?

henrichg commented 3 months ago

Exists parameter notAllowedWifi. If is true, sensor will do nothing, pass status is not changed. By me this not good, because if sensor is passed and you disable Location, sensor pass status do not change. Stays passed.

For this reason I'm impleneted: if Location is disabled, force set pass status to false.

Pankovea commented 3 months ago

Awesome! I see you've already made a commit. Can I get the apk and test it?

henrichg commented 3 months ago

OK. If you want, install and test this beta version: https://drive.google.com/file/d/13V2Zkb5W4VxNdMiXfsRs5iuWflt2xasY/view?usp=drivesdk

Pankovea commented 3 months ago

I have tested the behaviour and now it doesn't work correctly in this case. 03 In this case you also need to mark that you need access to geolocation like here Screenshot_20240614_093340

henrichg commented 3 months ago
  1. No, this is correct. Because if Location is disabled, sensor pass status is forced to false.

  2. Information about disabled Location will be added in next beta.

henrichg commented 3 months ago

New fixed beta: https://drive.google.com/file/d/13V2Zkb5W4VxNdMiXfsRs5iuWflt2xasY/view?usp=drivesdk

Pankovea commented 3 months ago
  1. No, this is correct. Because if Location is disabled, sensor pass status is forced to false.

I meant that the behavior is expected for us, but not for the user. There were no notes.

Now it works good. But it may be necessary to make the sensor's status red. As well as other parts where the incorrect settings. Thus, it will be clear that the sensor is inoperable.

henrichg commented 3 months ago

But if Location is disabled, is not possible to get connected SSID.

Again: Problem is with security in Android.

Result: Location MUST be enabled to get proper connected SSID.

Pankovea commented 3 months ago

I understand that. that's why I'm saying that the user needs to highlight it in red.

Upd: I'm sorry for my English. translation difficulties.

Pankovea commented 3 months ago

We have been using your application for many years. and these settings were good for turning on the profile "outdoors". and there were problems with the new device. Thank you for your efforts and for your prompt response.

henrichg commented 3 months ago

OK, added also generation of error notificaton + red color, when Location is required, but not enabled. If you want, install this beta: https://drive.google.com/file/d/13V2Zkb5W4VxNdMiXfsRs5iuWflt2xasY/view?usp=drivesdk

Pankovea commented 3 months ago

Great! Thanks. 🤝

xkonglong commented 1 month ago

This fix caused Profile to be deactivated in some cases.

Pankovea commented 1 month ago

This fix caused Profile to be deactivated in some cases.

What do you mean?