renyuneyun / Easer

User-defined explicit automation for Android
https://renyuneyun.github.io/Easer/
GNU General Public License v3.0
805 stars 92 forks source link

"reverse" for wifi condition not working #377

Open renyuneyun opened 3 years ago

renyuneyun commented 3 years ago

@renyuneyun thank you for adding this feature.

i installed the beta release to test this out. in order to toggle a VPN on when wireguard is in the background, you must set wireguard to "not optimize" for battery usage. with this set, i can trigger wireguard enable when eg. "WiFi enabled" is false.

one problem i ran into: i'd like to enable VPN only when not on home WiFi. however, the "reverse scenario" for WiFi connectivity appears broken. the condition never triggers, though the positive condition does.

i see you tried to address this in a previous PR https://github.com/renyuneyun/Easer/commit/3331d91331efe32cabdaa73c8d51b6e0e2e2508e

Originally posted by @khimaros in https://github.com/renyuneyun/Easer/issues/361#issuecomment-838582344

renyuneyun commented 3 years ago

@khimaros just to check: are you using Condition or Event for the wifi connection?

khimaros commented 3 years ago

@renyuneyun hello! i am using condition for this script.

renyuneyun commented 3 years ago

That's strange... My test works as expected... Would you mind sharing your relevant settings (scripts, conditions, etc)? Maybe something can be found from there.

May 15, 2021 00:10:12 khimaros @.***>:

@renyuneyun[https://github.com/renyuneyun] hello! i am using condition for this script.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub[https://github.com/renyuneyun/Easer/issues/377#issuecomment-841543896], or unsubscribe[https://github.com/notifications/unsubscribe-auth/AAZEEG7REVPQZVVB5SG7POTTNWUVHANCNFSM445FB6XQ]. [data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAD8AAAA/CAYAAABXXxDfAAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAAAAmSURBVGiB7cEBDQAAAMKg909tDwcUAAAAAAAAAAAAAAAAAAAAJwY+QwABivJx1AAAAABJRU5ErkJggg==###24x24:true###][跟踪图像][https://github.com/notifications/beacon/AAZEEG46IKJGIY2SE3H5DPTTNWUVHA5CNFSM445FB6X2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOGIUPBWA.gif]

khimaros commented 3 years ago

@renyuneyun -- i believe i see what's happening.

the way i was testing this was by disabling WiFi entirely (via quick toggle); in that case, the "Home WiFi" reverse scenario condition does not trigger. however, "Disconnect" in the WiFi settings or connecting to a non-matching network does trigger it.

the workaround is to add another condition of "Connectivity Type: WiFi" with another script using that as the reverse scenario to also enable the VPN. so there will be three scripts total.

i am using Easer 0.8.2-beta from F-Droid on an AOSP build (Pixel 3).

for reference, i've included the original configuration and the workaround below.

original configuration

condition

{"name":"Home WiFi","version":16,"condition":{"spec":"wifi connection","data":"{\"essid\":[\"<ELIDED>\"]}"}}

profile

{"name":"Disable VPN","version":16,"operation":[{"spec":"wireguard","data":"{\"tunnel_name\":\"<ELIDED>\",\"tunnel_state\":false}"}]}
{"name":"Enable VPN","version":16,"operation":[{"spec":"wireguard","data":"{\"tunnel_name\":\"<ELIDED>\",\"tunnel_state\":true}"}]}

script

{"name":"Disable VPN home","version":16,"active":true,"profile":"Disable VPN","trigger":{"type":"condition","condition":"Home WiFi"},"reverse":false}
{"name":"Enable VPN away","version":16,"active":true,"profile":"Enable VPN","trigger":{"type":"condition","condition":"Home WiFi"},"reverse":true}

workaround configuration

condition

{"name":"Home WiFi","version":16,"condition":{"spec":"wifi connection","data":"{\"essid\":[\"<ELIDED>\"]}"}}
{"name":"WiFi Connected","version":16,"condition":{"spec":"connectivity","data":"[10]"}}

profile

{"name":"Disable VPN","version":16,"operation":[{"spec":"wireguard","data":"{\"tunnel_name\":\"<ELIDED>\",\"tunnel_state\":false}"}]}
{"name":"Enable VPN","version":16,"operation":[{"spec":"wireguard","data":"{\"tunnel_name\":\"<ELIDED>\",\"tunnel_state\":true}"}]}

script

{"name":"Disable VPN home","version":16,"active":true,"profile":"Disable VPN","trigger":{"type":"condition","condition":"Home WiFi"},"reverse":false}
{"name":"Enable VPN away","version":16,"active":true,"profile":"Enable VPN","trigger":{"type":"condition","condition":"Home WiFi"},"reverse":true}
{"name":"Enable VPN mobile","version":16,"active":true,"profile":"Enable VPN","trigger":{"type":"condition","condition":"WiFi Connected"},"reverse":true}
huuhaa commented 3 years ago

Just douple checking... Since at begin this is marked as bug and is still open.. Is this known bug or should following work:

-Script VPN on demand > reverse for condition home wifi SSID > profile: turn on vpn -Child script of "VPN on demand" > Wifi disabled > event (not reversed) "wifi is enabled > no" > profile: turn vpn on

At profile: "turn vpn on" > wireguard ticked > Tunnel Name given > Tunnel State: Up

Does that seem ok?

Also, is location really needed for this app, would think wifi status etc doesn't require location. But on the other hand at android also BT is under location permission.. But while location enabled, it actually seems to get GPS location...

id4vip commented 3 years ago

Please somebody guide me to make a profile in easer for controlling wireguard. based on this post i am able to configure wifi conditions. everything works fine. but not able to understand th profile portion to on off wireguard app & wireguard tunnel "myhome" {"name":"Disable VPN home","version":16,"active":true,"profile":"Disable VPN","trigger":{"type":"condition","condition":"Home WiFi"},"reverse":false} {"name":"Enable VPN away","version":16,"active":true,"profile":"Enable VPN","trigger":{"type":"condition","condition":"Home WiFi"},"reverse":true}

teemue commented 3 years ago

Though I don't understand the logic, I managed to get Wireguard tunnel switching work.

However, I noticed that almost always when the tunnel is set up after wifi disconnect, the tunnel hasn't really connected and I have to do toggle it off and on manually.

Xerono commented 3 years ago

I have a problem that may be related - Easer doesn't notice when I'm on wifi. It's the same case as in the opening post here, but without the "reverse". "Reverse" works fine for me (Wireguard gets enabled), but I can't get it to disable once I'm back in my home wifi. This happens everytime.

In addition, I have the same problem as teemue, as in I sometimes have to toggle Wireguard manually before I get a connection. I can't reproduce this behaviour, it's random. I assumed the problem came from being not connected to a mobile network before setting up the tunnel, but even if I only activate wireguard once a connection exists, the problem can occur.

madpsy commented 2 years ago

@Xerono Does the VPN disconnect if you hit the refresh icon on the Outline pane? I had the same issue and ended up duplicating the script but using a Condition instead of Event and have to have both versions active.

Xerono commented 2 years ago

@madpsy Yes, refresh seems to change to the correct script. I tried using events and conditions, can you post your setup?

prontog commented 2 years ago

Hello and thanks for this very useful app. I just wanted to thank @khimaros for his comment that helped me troubleshoot the "Wireguard Tunnel State: Up" profile. I had to disable battery optimization for this to work. The weird part is that "Wireguard Tunnel State: Down" profile always worked. Thanks again.

renyuneyun commented 2 years ago

Hi. Sorry for not being able to find the cause, as I couldn't reproduce this on my phone and was busy during the period... (Happy to accept PRs if this could be automatically tested.)

There is a recent report #430, which seems to be related to this issue. Could I have a quick check from people: does the issue still exist on v0.8.2.3-beta2? And does this also still exist when you put Easer in the foreground (e.g. with screen open on, e.g., Pivot page)? (And information about your system/ROM version will be appreciated.)