Tasker: Wifi switch and Mobile Data toggle problem - Tasker Tips & Tricks

Android Marshmellow + rooted.
I'm using (like so many) a few profiles/taks to switch from Mobile Data to Wifi when i get home and back when i leave home. Works pretty nice but... not all the time.
The reason behind this is the difference on how Wifi and Mobile Data are activated.
If changed both manually (via the drop down menu) both act as a toggle.
But within tasker this behaviour changes. Wifi has an On / Off option, Mobile Data has to but that doesn't work anymore since Google changed the activation for Mobile Data which means that you can only set it with the help of Active Input and that turns it into a toggle.
And this creates a syncronisation problem between Wifi and Mobile Data.
I'll explain the difference:
If i set Wifi to ON Wifi goes ON.
If i set Wifi again to ON, Wifi stays ON. It will only go OFF when i set it to OFF.
It behaves as a physical switch.
Mobile Data however does not.
If i activate Mobile Data through Active Input and it's OFF, it will go ON. And when it's ON it will go OFF.
It behaves a toggle.
Now this works OK as long as everything is in sync.
If Mobile Data is ON and i reach home, Wifi is turned ON, i get the connected signal and Mobile Data is turned OFF. Same goes the other way, if i leave home, Wifi connection is lost and Wifi is turned Off. When the connection is lost Mobile Data is turned On again. Works nice.
But this can get out of sync because of the switch/toggle behaviour.
Example:
If i'm home, Wifi is ON and Mobile Data is OFF. If i turn Wifi OFF manually , the connection is lost and Mobile Data comes ON. If i turn Wifi back ON, Mobile Data goes OFF again.
But the other way there is a problem. If i'm not home and turn Mobile Data OFF somewhere and reach at home, tasker sees this, turns on Wifi and "toggles" Mobile Data to be OFF but since it's a toggle action, Mobile Data will come ON instead and both are then ON. And from then on the nice syncronisation between Wifi and Mobile Data is gone.
This manual override (like i like to call it) also doesn't update the variable i use which is logical since the Mobile Data wasn't "toggled" through Tasker.
I tried to solve this with a double variable check together with a variable i set when Mobile Data is connected (2G,3G,or 4G) and then toggle Mobile Data according to this and set/reset the variables but while this should work better in theory, it still doesn't work all the time because indoors, Mobile Data connection can be lost and then the Mobile Data toggles again to a state i don't want again setting a desyncronisation between Wifi and Mobile Data. In fact, due to this the syncronisation has become more unstable. So i removed the Mobile Data connected part again.
Questions:
- Is there a way to make Mobile Data work as a switch instead of a toggle?
- If not, is there a way to detect is the Mobile Data button has been touched (which i could then use in a variable)?

I'm using shell commands to switch mobile data on/off.
If your selinux is permissive, simply run a shell command with this:
Code:
svc data enable;
or
Code:
svc data disable;
If your selinux is enforcing, you need to add two lines, so it looks like this:
Code:
setenforce permissive;
svc data enable;
setenforce enforcing;
and respectively
Code:
setenforce permissive;
svc data disable;
setenforce enforcing;
Needless to say, you need root access for this.

I'm afraid that's currently above my head...

To add a shell command:
Code > Run Shell
Tick "root"
Put the codes from above in "Command"

Sukarn said:
To add a shell command:
Code > Run Shell
Tick "root"
Put the codes from above in "Command"
Click to expand...
Click to collapse
Exactly. [emoji106]

If i do that, can you then explain at least what it does exactly?
I guess it will turn on/off mobile data but on what basis?
How do these commands know when to turn it on or off depending on my wifi state?
What does " if your selinix is enforcing" means?
Edit: Got it partly working with the shell commands. Mobile data doesn't always turn off when wifi comes back on and is connected. It still can get out of sync.
It does not check the state of the mobile data if i interact and turn it on/off manually because it doesn't seem to know in what state is after playing around with it manually.
Also, tasker sometimes seems to get stuck somewhere in the middle of the code for disabling the mobile data.
Need to look a bit more into why tommorow...

Update:
Got it fully working with the shell commands and sync between Wifi and Mobile Data seems OK (for now at least).
I'm using the settings get global mobile_date command to put the status into a variable and then work with this and the wifi status variable to toggle Mobile Data on and off.
One thing i haven't found yet is what the settings get mobile_data exactly returns, the state of the toggle button in the notification screen or the state of the mobile data being connected?

Related

Help!! Wifi vs Mobile Data priority

By default, I keep my mobile data on. When I switch Wifi on, it would override the mobile data, and when I switch Wifi off, it would resume mobile data, and this is working perfectly without needing me to manually switch mobile data on/off. I guess this is the general behavior of Android device.
However, recently I tried some apps to switch mobile data on/off, and it must be one of these apps which changed the network connectivity priority. What happen now is that when my mobile data is on, I cannot turn on Wifi (well, wifi is on, but it won't connect to any ssid, and just show Disabled), so i must manually switch the mobile data off that I can use Wifi.
This so annoying, and I have been searching for solutions but can't find any.
Since those apps I tried do not require root access, I guess i could revert to originally settings without root, but I couldn't find any options in system settings about network connectivity priority.
Experts please help!
After some more search, I found that one of these apps must have used "setNetworkPreference" to change the preference from TYPE_WIFI to TYPE_MOBILE.
Ref.
http://developer.android.com/refere...ctivityManager.html#setNetworkPreference(int)
But i'm not android programmer, i have no idea how I can reset it to default.
Any help would be much appreciated.

Test Net variables acting up when wifi is enabled... bug in Tasker?

New to tasker, after reading around a bit, I created a profile for switch Wifi to Mobile Data and back depending on the place i'm at.
To make sure both Wifi and Mobile Data are not on at the same time (if one of them should be a bit flacky), i work with a few wait statements and some variables which tell me if i went through either toggling wifi or mobile data on or off. This works rather nice as long as tasker does the job.
But when i toggle either of them manually (to try something out), things can act up and the according variables are not set/reset then because tasker didn't run through the task for toggling either wifi or mobile data.
Then when fooling around with Tasker, i came accross the Test Net command which can return a yes or no text depending on what state mobile data is on with one nice touch, it also switches the state when mobile data is toggled manually. This text can be stored in whatever variable i want and then used to determine the state of mobile data being on or off which i can then use in my tasks to decide if tasker i has to run through them when everything is running automatic.
Thinking i found the holy grail for the manual toggle not updating the variables problem, i changed all my tasks and replaced my previous variables in which the mobile state was stored to with the one i got from the Test Net command.
This seemed to work nice at first but then at a given point i discovered that the state of variable made with the Test Net command didn't match the true state of the Mobile Data toggle switch.
After lots of trial and error i found out that if Wifi is on (either manually set or set by Tasker), the mobile data variable retrieved from Test Net isn't updated anymore and therefore can give a wrong state if toggled manually and that my tasks don't work anymore when i toggle mobile data manually. If i turn Wifi off and then toggle mobile data, the variable is updated again (but i have to toggle it first) and everything works again.
First i thought i had somewhere some double set/reset of the variable but that was not the case.
To cut a long story short:
The mobile data variable retrieved from the Test Net command to see if mobile data is enabled yes/no isn't updated when wifi is enabled. Bug or not?

Auto Turn Off Mobile Data When Connected to WiFi

Does anyone know of an app that will automatically turn off mobile data when i'm successfully connected to a WiFi connection have have internet access through it.
The app should do something like this...
1. Check for WiFi connection
2. If WiFi = connected, then test WiFi connection
3. If connection = Good, then turn off Mobile Data, else leave Data connection ON
If you suggest Tasker, then you better follow it up with a full write-up on how to set it up on Tasker.
I believe (someone will correct me if I'm wrong) that Android is programmed to use wifi when it's available, even though your data connection looks as if it's on.
If you're not happy with that, Automate It should be able to do something for you. I have Automate It Pro set to turn off wifi & data at midnight, for example, to avoid the nuisance of emails pinging me in the middle of the night. And it switches wifi & sync on at 09:00 each day. Very useful tool, simpler than Tasker, so no tutorial from me...
There are a few Automate apps in the Play Store - it's this one:
https://play.google.com/store/apps/details?id=AutomateIt.mainPackage
This free version allows you 3 (as I recall) triggers - if you need more it's not too expensive to buy Pro.
I use RadioControl to handle that for me.
https://play.google.com/store/apps/details?id=com.nikhilparanjape.radiocontrol&hl=en
It requires root, and it's not perfect. But it works well enough for me.
[NG]Owner
Try smart radio xposed module.
pr0ndigy said:
Does anyone know of an app that will automatically turn off mobile data when i'm successfully connected to a WiFi connection have have internet access through it.
The app should do something like this...
1. Check for WiFi connection
2. If WiFi = connected, then test WiFi connection
3. If connection = Good, then turn off Mobile Data, else leave Data connection ON
If you suggest Tasker, then you better follow it up with a full write-up on how to set it up on Tasker.
Click to expand...
Click to collapse
Tasker does it pretty simply, but it needs root access..
Set up (2) tasks - I called mine Data Off & Data On. You will need to select "Net/Mobile Data" and then set "On" or "Off" respectively. Next set up your profile. Select "State/Net/Wifi Connected", and leave everything empty and save. This will trigger the profile when any wifi is connected. (Optionally, you could set it to your home or work wifi, etc). Your "task" will be "Data Off", then add an "exit task" for "Data On" (by long pressing the Data On and selecting "exit task").
dahawthorne said:
I believe (someone will correct me if I'm wrong) that Android is programmed to use wifi when it's available, even though your data connection looks as if it's on.
Click to expand...
Click to collapse
^^^^ This. Android has done this for years. Some devices have the ability to keep mobile data on with wifi, but those usually default to OFF.
Note in the screenshot below that my Cellular network state (mobile data) is "Disconnected"
Pkt_Lnt said:
^^^^ This. Android has done this for years. Some devices have the ability to keep mobile data on with wifi, but those usually default to OFF.
Note in the screenshot below that my Cellular network state (mobile data) is "Disconnected"
Click to expand...
Click to collapse
Interestingly, I bring up the same screen on my phone (when connected to wifi) and it shows cellular is still connected??
jbaumert said:
Interestingly, I bring up the same screen on my phone (when connected to wifi) and it shows cellular is still connected??
Click to expand...
Click to collapse
Do you have a ROM that has that option and it is enabled?
Pkt_Lnt said:
Do you have a ROM that has that option and it is enabled?
Click to expand...
Click to collapse
Running SIX ROM - Just checked, that option is disabled in the Dev Settings / connected to good wifi / and cellular is active...
¯\_(ツ)_/¯
Now it is a question for that rom dev.

How to toggle off Mobile Data automatically ?

How can i toggle off Mobile Data automatically at night (11pm - 6am).
Tasker doesnt allow toggling mobile data with my OP 3T (Android 7)?
I tried AutoInput but it doesnt work.
Any ideas ?
i also tried an app called "sound profile" and IFTTT
I use AUTOMATE by Llamalab to do just that and other tasks. I have 5 main flows running,
1- Airplane mode 11pm to 7am.
2- Turn mobile data ON or OFF according if WiFi connected or not
3- If mobile data enabled switch to 2g when screen OFF and back to 3g/4g when screen unlocked
4- Only enable NFC when phone unlocked
5- Turn OFF bluetooth if no device connected
Its easy to learn its modular flow system and plenty of user flows shared through the app.
Download app from playstore called leandroid
it makes you able to do exactly that but not only for mobile data but for gps, wifi, bt, etc
Is this also available with a non root device?

Mobile network state includes WIFI

Hey..
I have setup a project to system lock phone (deactivate fingerprint login etc.) if it looses connection to mobile networks. This is extra safety for my in the event someone gets hold of it.
To accomplish this I've setup a profile with the state 'Mobile Network', selected all network modes and used the 'any' trigger and inverted to make trigger whenever the state have no mobile networks. This is tested and works but..
.. whenever WIFI is on it doesn't trigger. If you disable WIFI or it looses WIFI connection it triggers.
Is this bad behavior or am I missing something?
The project in whole still works since an active WIFI connection would give me access to my phone and therefore a system lock is only needed in the event I cant reach it, ie. no WIFI and mobile data.
Thank you.

Categories

Resources