Take the 2-minute tour ×
Android Enthusiasts Stack Exchange is a question and answer site for enthusiasts and power users of the Android operating system. It's 100% free, no registration required.

I tried juicedefender and it does exactly what I want, but since I already have tasker running all the time I am looking for a tasker recipe.

I would like the accomplish the following behaviour:

  • Disable mobile data when screen locked and there is no transfer. If there is an ongoing transfer, allow it to complete before disabling mobile data. Enable mobile data only in periodic intervals of 15 minutes.
share|improve this question
add comment

1 Answer

A quite close profile is described at Tasker-Profile (Google-Translate English variant here). I will try to give an abstract here:

Basic Data On/Off

Tasks

You will need two tasks for this:

  1. enable mobile data:
    • Net -> Auto Sync (set ON)
    • Net -> Mobile Data (set ON)
  2. disable mobile data:
    • Net -> Auto Sync (set ON)
    • Net -> Mobile Data (set ON)

You may probably skip the "Auto Sync" part (especially if Wifi comes into play), I mentioned it just for completeness. Also, the Tasker -> PSAFE variable can be utilized to check whether the device is in power-safe mode (~ 1) or not (!~ 1).

Conditions

These are the harder part. As for screen on/off, it's easy: Event -> Display -> Display unlocked for active display, Event -> Display -> Display off for display being switched off. The harder part is to check for still running transfers -- I don't know how to do this explicitly, but it probably can be done implicitly via above mentioned %PSAFE Tasker variable: With a running transfer, the device is less likely to be in power-safe mode. You probably need to experiment with this. Connect these conditions with the appropriate tasks to create profiles.

Periodical Checks

For these you need to add a variable to above tasks: %LCD, giving us the state of the display. So in Variable -> Variable Set Name=%LCD -- in 1. set to 1 (on), in 2. to 0 (off). Now create an additional profile:

  • Time: Repeat 15min
  • State -> Variable Value %LCD ~ 0
  • State -> Variable Value %PSAFE ~ 1

So it runs all 15min, but only when the display is turned off and power-safe active. We also need an additional Task:

  • Net -> Mobile Data: ON
  • Net -> Auto Sync: ON
  • Tasker -> Wait: 1min
  • Net -> Auto Sync: OFF
  • Net -> Mobile Data: OFF

Adjust to your needs.

Checking for possible transfers in progress

Again, I'm not sure how to check whether there's an ongoing transfer. A possible solution can be found in Google Groups, but I couldn't verify this. Though, as you might want to try it out, this is the basic extract:

It's a Profile I created on my Droid to experiment with the concept of watching 3G traffic levels.

Profile: Net Traf 3G (62)
Priority: 2 CoolDown: 0
Time:  Every 10m
State: Mobile Network [ 2G:On 3G:On 3G - HSPA:On 4G:On ]
Enter: Read3gTraf (63)
A1: Test [Type:File Name Data:/sys/class/net/ppp0 Store Result In:%tg_exists Continue     Task After Error:On] 
A2: Read Line [File:/sys/class/net/ppp0/statistics/rx_bytes Line:1 To Var:%TG_RX] Read Line [ %tg_exists Is Set ]
A3: Variable Set [Name:%TG_RX_CHG To:%TG_RX-%TG_RX_OLD Do Maths:On Append:Off] 
A4: Variable Set [Name:%TG_RX_OLD To:%TG_RX Do Maths:Off Append:Off] 
A5: Stop [With Error:Off] Stop [ %SCREEN ~ off ]
A6: Variable Set [Name:%TG_RX_RATE To:ceil(%TG_RX_CHG/1024) Do Maths:On Append:Off] 
A7: Notify [Title:3g traffic active Text:%TG_RX_RATE kb since last check Icon:<icon> Number:0 Permanent:Off] 

%TG_RX_RATE will contain the kb received in the last 10 minutes, and can be used in a Context condition.
If my phone is just sitting around, the background level network traffic is less than 20 kb per minute. Surfing the web, it's 100 kb or way more per minute. Your mileage may vary.
Since /sys is really a virtual folder, the /sys/class/net/ppp0 folder only exists when the 3G interface is turned on. When I turn on wifi, the dir /sys/class/net/tiwlan0 is created instead.
(So by changing the dir path, I can also watch wifi traffic too.)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.