I use the Blokada+ VPN on my phone for privacy reasons. However, some websites I use regularly (most notably https://archive.today/) won’t load through Blokada+ is active. I want to be able to turn Blokada+ off quickly when I need to use a website that doesn’t work through it, and turn it back on quickly afterward.
If all the websites in question were just picky about VPN traffic to the websites themselves, this would be easy… The Blokada+ app comes with a quick setting tile for toggling the VPN, so I could just use that tile to goggle it off before accessing any of the picky websites. However, some of the websites, including archive.today, have DNS servers for their domains which also reject Blokada+ traffic. So that means I need to turn off both the VPN and Blokada’s private DNS setting before trying to access archive.today, and turn both of them back on afterward.
But wait, it gets worse. My home WiFi network uses a local DNS server, and that server also routes DNS query traffic through Blokada+, so I also need to turn off WiFi, in addition to turning off the VPN and the private DNS setting.
But wait, there’s more. The Blokada+ app notices when the Blokada private DNS setting is off and displays a pop-up forcing you to go to your system settings to turn it back on before it will let you turn on the VPN. Unfortunately, sometimes “notices” has a lag, i.e., if you turn the private DNS setting back on and then immediately open the Blokada app, it may make you go to the system settings to turn back on something you’ve already turned back on. That makes automating a solution to this problem annoyingly more complicated.
More complicated, but not impossible! Here’s the Tasker task I came up with, using the AutoInput app for the parts involving automating the Blokada+ app. This is attached to the first Tasker quick setting tile, which is then added to the quick setting tiles visible when I drag down from the top of the screen.
Task: Blokada Tile
A1: Close System Dialogs
A2: App Info [ ]
A3: Custom Setting [Name: private_dns_mode, Read Setting To: %dnsmode ]
A4: If [ %dnsmode ~ hostname ]
A5: AutoInput Actions v2 [
Configuration: Actions To Perform: openApp(org.blokada.sex)
wait(1000)
click(point,540\,949)
click(text,Turn Off All Protection) ]
A6: Custom Setting [ Name: private_dns_mode, Value: off ]
A7: If [ %WIFII ~ *my-home-wifi-SSID* ]
A8: WiFi [ Set: Off ]
A9: End If
A10: Set up Quick Setting Tile [ Task: Blokada Tile, Status: Inactive ]
A11: Else
A12: Custom Setting [ Name: private_dns_mode, Value: hostname ]
A13: AutoInput Actions v2 [
Configuration: Actions To Perform: openApp(org.blokada.sex)
click(text,Open Settings)
wait(500)
click(text,Open Settings)
wait(500)
Timeout (Seconds): 5
Continue Task After Error:On ]
A14: If [ %err = 0 ]
A15: Launch App [ Package/App Name: Blokada 6 ]
A16: Wait [ MS: 500 ]
A17: End If
A18: AutoInput Actions v2 [
Configuration: Actions To Perform: click(point,540\,949)
Timeout (Seconds): 5
Continue Task After Error:On ]
A19: WiFi [ Set: On ]
A20: Set up Quick Setting Tile [ Task: Blokada Tile, Status: Active ]
A21: End If
A22: Launch App [ Package/App Name: %app_name, Continue Task After Error:On ]
A23: If [ %err > 0 ]
A24: Go Home
A25: End If
In other words, “Close the quick setting tile menu. If private DNS is enabled, then disable the Blokada+ VPN, then disable private DNS, disable WiFi if I’m at home, and dim the quick setting tile. Otherwise, enable private DNS, enable the Blokada+ VPN, enable WiFi, and light up the quick setting tile. Finally, go back to the app that was running before we opened the Blokada+ app, or to the home screen if no app was running.
Three additional wrinkles you may have noticed in the Tasker description above:
- The button in the Blokada+ app to turn the VPN on/off doesn’t have any text associated with it, so AutoInput can’t find it by text, so I had to use a point position.
- The Blokada+ app doesn’t always display the pop-up requiring you to go to settings to turn private DNS back on, so I had to check if AutoInput was able to click on the “Open Settings” button and otherwise assume the pop-up didn’t happen and go straight to clicking the button to enable the VPN.
- At least in the current version of the Blokada+ VPN, at least on my phone, the first time I click on “Open Settings” instead of opening settings it scrolls down slightly, then I have to click “Open Settings” a second time.
One more wrinkle that isn’t obvious from anything written above is that the “WiFi” action I used doesn’t work unless the current release of Tasker Settings is installed on your phone (some of the links in the README file there are to older versions of Tasker Settings; I recommend you ignore those links and install the latest version.