henrichg / PhoneProfilesPlus

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

fix: trigger outside mobile cell event when connected cell is not any… #131

Closed KarolBedkowski closed 5 months ago

KarolBedkowski commented 5 months ago

… list

When current connected mobile cell is not on any defined list, "Mobile cell sensor" with enabled "start when outside..." stay inactive. Adding this cell to any other list make this sensor work ok. In this form this feature has very limited usability.

Problem is result of getting list of cells filtered by current connected cell (db.addMobileCellsToList(_cellsList, registeredCell)) and do next checks only when this list is not empty. If we are connected to unknown cell (list is empty), no more check are performed even when we check "outside".

Now, when cells list is empty, default result depend on _whenOutside, so empty list and "outside" enabled trigger event. When "outside" is false, there is no change in behaviour.

henrichg commented 5 months ago

But "Start when outside mobile cells" is ony for CONFIGURED mobile cells. Not configured are ignored.

This is the same also for:

Not exists parameter similar to "Not configured..." and is not planed to implement it.

henrichg commented 5 months ago

Sorry, will not be merged.

KarolBedkowski commented 5 months ago

Hi, sorry, i couldn't answer earlier.

Ok, but imho this behavior is at least confusing. Maybe this should be more highlighted. When I set some cells list and set "outside" I assume all cells that don't bellow to this list trigger this sensor, no matter its known/configured or not.

My usecase is quite simple - I have "home" cells list and want to set some profiles when I outside this area. I don't want to configure all cells in the world. (this is simplified - due to other rules I need to add many more rules to handle it; my change simplify it a lot).

From other side - I not sure what is purpose to this switch - if I need to specify all "outside" cells in any list I guess I can simple select this "other" list and don't use "outside" switch at all.

I don't use other sensors from list above, maybe there is different situation. However years ago (other soft) I have rule "when I have not connected to one of may trusted wifi network - start vpn". If I need add all "temporary" wifi networks to some list to get if work - imho something is wrong.

Regards, K.

henrichg commented 5 months ago

Example: in event are configured all cells at home. This is 5-6 cells in my home. I want to start event, when mobile is outside of home = outside of ALL configured home cells. And for this is good to use "start when outside".

KarolBedkowski commented 5 months ago

Yes, i try it already. But it not work. Cell must be added to any other list to trigger home + outside. So seems to be bug.

Maybe I'm wrong, but looking into code you get db.addMobileCellsToList(_cellsList, registeredCell) when registeredCell is not know in PPP, cellsList is empty so in loop is skipped and no other action taken.

henrichg commented 5 months ago

Sorry, I do not understand. If "Start when outside mobile cell" si checked, "Mobile cells sensor" sets pass status to true (green) when ALL cells in this sensor are outside of mobile (= mobile is not connected to any cell configured in this sensor).

But: sensor uses only saved mobile cells, saved to db by mobile cells scanner.

"db.addMobileCellsToList(_cellsList, registeredCell)" adds cells from DB to _cellsList. And if registeredCell is not 0, then adds only this cell. registeredCell is cell from system, to this cell is mobile currently connected.

Mobile cells scanner is running in background and saves connected cells to db. Detected mobile cells by scanner are not automatically added. Are added only by user interaction. User must allow to add it.

And yes, if registeredCell is not in saved cells, then returned is empty list. Then yes, if mobile is connected to cell, which is not saved to DB by scanner this cell is then ignored. If mobile cells scanner add it latter, then will be used by sensor.

henrichg commented 5 months ago

Important: registeredCell is not cell saved to db by scanner or configured in sensor. It is cell returned by system. To this cell is mobile actually connected.

henrichg commented 5 months ago

Example: Mobile is connected to cell, which is not in sensor and in db. Then how to check it? If you are at home and mobile is connected to new, not saved, not configured cell, then is not possible to mark it as "inside" of home. It is unknown cell. It must be saved by scanner and added to configured cells in sensor. By me, better is ignoring this cell.

KarolBedkowski commented 5 months ago

I understand.

There is no problem with ignoring cell when "Start when outside..." is off. But for rules with enable "outside", connection to unknown cell should not be ignored, and imo PPP should take it into consideration. After all we are "outside" given list (all lists to be precise).

My patch change behavior only when "Start when outside..." is on - if current connected cell is not registered in PPP - result of sensor is positive. So rules are property activated. If "Start when outside.." is off - nothing changed and cell is ignored.

Anyway - this patch solve this problem for me, but if there is other idea for this - no problem. I thought this was a some kind of bug...

regards, Karol

henrichg commented 5 months ago

Hm, but. When mobile IS outside of home, then is better to set pass status to true. :-) Hm, Hm. Problem is only when mobile is in home. In this situation, unknown cell will be checked as outside even when mobile is in home. :-) Then: I will implemnet it as in your patch.

henrichg commented 5 months ago

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

KarolBedkowski commented 5 months ago

Thank you.