Can I automatically turn off WIFI completely whenever not connected to a network on Android 10+ Here's my problem:
I used to run Lineage 16 on my Pixel3a, which still had the &quot;profile&quot; option where I could do things like &quot;When my home network is not within reach, switch to another profile&quot;. I used this to turn off wifi when leaving the house and it worked very well. Important: This did not need my location services to be on to work.
Now I've upgraded to Lineage 17.1 (Android 10) and this option is gone. I am now looking into how to rebuild that functionality.
My phone is rooted (via Magisk), and as a software developer I am ready to use all tools I have available.
What I've tried: I've built an app that periodically checks if I am connected to one specific SSID (since that is all I can see on Android 10 anymore - &quot;Am I connected to &quot;my-ssid&quot;?) and then turns of wifi using the shell and sulike this:  sudo(&quot;svc wifi disable&quot;). sudo() is my function that opens a process and talks to the shell.
The problem is I don't think there is a way I can guarantee my app always runs, and I'd like this to also work when the app is off? It doesn't even need to be a specific SSID, I'd be happy if my result is: &quot;If we're not connected to a wifi network for more than 3min, turn wifi off.
so what other options do I have? Tasker, just like my own attempt, kind of works but only with location services on, which I'd like to avoid. What else can I do. Can I run some kind of script or a job just on the shell or so?
Is there anything I can do with Magisk or Xposed?
Happy for any help here - the internet is full of links and tips, but they all target older OS versions. Btw the source for my (extremely rough draft) app is here if anyone is curious.
With methods described below, when the phone disconnect from your wifi network, wifi will be immediately switched off. Also they don't require the Location Services to be on.
A. Xposed Edge
Open Xposed Edge, go to More triggers &gt; Wifi Disconncted &gt; Wifi &gt; Turn off.
B. Macrodroid

Open Macrodroid, click Add Macro.
Click the + on the right of Trigger. Click Connectivity &gt; Wifi State Change &gt; Disconnected from network. Click OK. Select your network(s).
Click the + on the right of Actions. Click Connectivity &gt; Wifi Configure &gt; Disable Wifi. Click Ok
Give your macro a name. Press back, save the macro. The macro will look like this:


C. Automate

Open Automate, click the + at the bottom of the screen to add a new flow.
Click +, Connectivity &gt; Wifi enable?. Click the Wifi enable? block, set Options to Immediately. Click Save.
Click +, Connectivity &gt; Wifi network connected?. Click Wifi network connected? block, Don't click on pick the network, but enter the network name (SSID) manually. Set Options to Immediately. Click Save.
Click +, Date &amp; time &gt; Delay. Click on the Delay block, set the duration to 3s. Click Save.
Click +, Connectivity &gt; Wifi set state. Click on the Wifi set state block, select Off. Note that this block is not officially supported for Android 10+ and might not work.
Link the block has shown on the image below. Press back. Give your flow a name. Press Start to start the flow.


D. Ping your home router
You can use a script in combination with the app mentioned to ping your home router. When the pings are successful, the phone wifi stays on. When they are unsuccessful, disable you phone wifi.