By Machado


2015-05-11 12:53:17 8 Comments

I'm working with a chinese tablet which needs to be initialized every time after it's connected to a power source.

I'm using Tasker to do so. Problem is: this condition makes tasker execute the reboot command over and over, and it becomes a bootloop.

What should I do in order to initialize the tablet when a power source is attached, but avoid it from entering the bootloop?

Edit: TaskerProfile

<TaskerData sr="" dvi="1" tv="4.6u3">
<Profile sr="prof2" ve="2">
<cdate>1431370575080</cdate>
<edate>1431372456863</edate>
<id>2</id>
<mid0>4</mid0>
<State sr="con0" ve="2">
<code>10</code>
<pin>true</pin>
<Int sr="arg0" val="1"/>
</State>
</Profile>
<Profile sr="prof5" ve="2">
<cdate>1431370730220</cdate>
<edate>1431371684461</edate>
<flags>2</flags>
<id>5</id>
<mid0>6</mid0>
<State sr="con0" ve="2">
<code>10</code>
<Int sr="arg0" val="1"/>
</State>
</Profile>
<Project sr="proj0" ve="2">
<cdate>1431027887676</cdate>
<mdate>1431371133517</mdate>
<name>Base</name>
<pids>2,5</pids>
<tids>4,6,7</tids>
<Img sr="icon" ve="2">
<nme>hl_aaa_ext_home</nme>
</Img>
</Project>
<Task sr="task4">
<cdate>1431370589904</cdate>
<edate>1431372085383</edate>
<id>4</id>
<nme>Task1</nme>
<pri>10</pri>
<Action sr="act0" ve="7">
<code>410</code>
<Str sr="arg0" ve="3">Documents/sdcard.txt</Str>
<Str sr="arg1" ve="3">0</Str>
<Int sr="arg2" val="0"/>
<Int sr="arg3" val="0"/>
</Action>
</Task>
<Task sr="task6">
<cdate>1431370741046</cdate>
<edate>1431372415674</edate>
<id>6</id>
<nme>Task2</nme>
<pri>10</pri>
<Action sr="act0" ve="7">
<code>417</code>
<Str sr="arg0" ve="3">Documents/sdcard.txt</Str>
<Str sr="arg1" ve="3">%True</Str>
</Action>
<Action sr="act1" ve="7">
<code>410</code>
<Str sr="arg0" ve="3">Documents/sdcard.txt</Str>
<Str sr="arg1" ve="3">1</Str>
<Int sr="arg2" val="0"/>
<Int sr="arg3" val="0"/>
<ConditionList sr="if">
<Condition sr="c0" ve="3">
<lhs>%True</lhs>
<op>2</op>
<rhs>0</rhs>
</Condition>
</ConditionList>
</Action>
</Task>
<Task sr="task7">
<cdate>1431371028431</cdate>
<edate>1431372348654</edate>
<id>7</id>
<nme>runshell</nme>
<pri>10</pri>
<Action sr="act0" ve="7">
<code>123</code>
<Str sr="arg0" ve="3">reboot</Str>
<Int sr="arg1" val="0"/>
<Int sr="arg2" val="1"/>
<Str sr="arg3" ve="3"/>
<Str sr="arg4" ve="3"/>
<Str sr="arg5" ve="3"/>
<ConditionList sr="if">
<Condition sr="c0" ve="3">
<lhs>%True</lhs>
<op>2</op>
<rhs>0</rhs>
</Condition>
</ConditionList>
</Action>
</Task>
</TaskerData>

1 comments

@Firelord 2015-05-11 18:44:52

If I understood the question correctly, you want to connect the device to a power source which triggers Tasker to reboot the device (for initialization). But when the device reboots itself Tasker finds that the power source is connected so it repeats the task again. Your goal is to make Tasker reboot only once while power source remains connected. If the source is to be removed and re-inserted again, then Tasker should do the reboot again only for once.


Based on this understanding, I proposed the following solution:

The solution is very trivial. I'm using two profiles in Tasker, namely:

  1. Not power USB
  2. Power USB

These two profiles, as obvious, will be triggered by connecting/disconnecting the power source to the Android device. I'm using a file's content as a condition here to restrict boot-loop.

Note: For this answer, I chose my power source as USB only.

Instructions:

Regarding the file content:

  1. Create an empty file in your default storage. (I created a file named sdcard.txt in /sdcard. The location of this file is /sdcard/sdcard.txt.)
  2. Open this file in a text editor in Android and add 0 in it. (I used 920 Text Editor).
  3. Note that there is no logical reasoning in using 0 only. It will be used in a conditional statement only. You're at liberty to try an another number.

Regarding Profiles and Tasks in Tasker app:

  1. Launch Tasker.
  2. Under Profiles tab create a Profile by tapping +State → Power → Power.
  3. Under Source choose USB.
  4. Check Invert -- this will make Not power USB profile.
  5. Press Back key/button once and select New Task.
  6. Add a name for your task (persistent) or leave it blank (deleting profile will delete it as well).
  7. Under Tasks tab tap +FileWrite File.
  8. Under File field mention the location of your text file. In this case, it is /sdcard/sdcard.txt.
  9. Write 0 under Text field.
  10. Uncheck Append and Add Newline. -- we want to replace the content, so no appending should be done.
  11. Tap Back key/button twice to save this task.
  12. In order to create Power USB profile, repeat step 2,3,5 and 6, respectively.
  13. Under Tasks tab tap +FileRead File.
  14. Repeat step 8.
  15. Under To Var type %True -- You can change %True to any other name. Make sure that you capitalize at least one letter of your variable to make it non-local. See this to know more.
  16. Repeat step 11, 7 and 8.
  17. Type 1 under Text field.
  18. Repeat step 10.
  19. Tap + corresponding to If. Add %True and 0 in fields respectively. It should look like %True ~ 0.
  20. Repeat step 11.
  21. Under Tasks tab tap +CodeRun Shell.
  22. Type reboot under Command. (My device is rooted, so I provided root permissions to this step to avoid any hassle.) As a soft-reboot option, you can use killall zygote instead of reboot.
  23. Check Use Root if your device is rooted.
  24. Leave Store Output In and Store Errors In blank.
  25. Repeat step 19 and 20.
  26. Go to Profiles and enable both profiles. To save yourself from unnecessary trouble, disable any other power related profile other than the ones mentioned above.
  27. Tasker must be Enabled. You can check this by tapping Menu key/button once and amongst the options, Disable tasker would be visible. Also, if this app is running and you happen to minimize it, then as a default setting you would see its icon in the Status bar with the profile mentioned there (if activated).

We're good to go.

  • Go to Home Screen of your device.
  • Connect power source (we used USB only here).
  • Your device will reboot. Do not disconnect power source to verify that boot-loop vanished.
  • When the device comes back to Home Screen after reboot, you can see that Power USB profile is activated in tasker yet there is no boot-loop, not to mention that your initialization is also done. :)
  • Disconnect power source and the profile will switch to No power USB.
  • Connect power source again and device will reboot again for once.

Status: Objective Completed. Done!

@Machado 2015-05-11 19:15:43

It is switching between both profiles, but it doesn't execute the RunShell "reboot" task

@Firelord 2015-05-11 19:22:23

@Tardo I traced this issue. If I uncheck root option in this task, then the device doesn't reboot at all. Guess what, no error in logs of Tasker as well. I checked root option and it worked fine. I'm having this feeling that your device is un-rooted.

@Machado 2015-05-11 19:23:43

I'm using SuperSU from Chainfire to root the device

@Machado 2015-05-11 19:24:13

If I execute (manually) the reboot task, it will reboot

@Firelord 2015-05-11 19:26:25

Can you send me the screen shots of all the profiles and tasks that you made using this answer in details? IDK how to export and restore tasker data.

@Machado 2015-05-11 19:28:00

I will edit the post with the Profiles and Tasks.

@Firelord 2015-05-11 19:28:08

@Machado 2015-05-11 19:33:08

Go to the ActionBar Settings (in the right corner) -> Data -> Share . Then you'll be able to get into a TextEditor a file similar to the one I've just posted as an edit.

@Machado 2015-05-11 19:38:58

Sorry but I don't have enough reputation to use the chat. :(

@Firelord 2015-05-11 19:42:11

No issue with chat, the system asked me so I tried moving it. Anyway, I tried viewing the stuff in text editor and I also have another option. If you hold down a profile you get the option to "Export" it. I've exported both profiles and I think you should be able to import them. I'm sending you now.

@Machado 2015-05-11 19:44:31

Aight. Please check the chat again.

Related Questions

Sponsored Content

1 Answered Questions

Execute task if tasker profile has been active for some time

  • 2016-02-10 22:17:34
  • HugoRune
  • 2520 View
  • 1 Score
  • 1 Answer
  • Tags:   tasker automation

1 Answered Questions

How to execute “reboot recovery” in recovery mode?

2 Answered Questions

[SOLVED] Tasker - read the ping time

  • 2018-08-05 18:01:16
  • Hamed
  • 814 View
  • 0 Score
  • 2 Answer
  • Tags:   tasker

1 Answered Questions

[SOLVED] Configure Tasker as alarm for date and time

  • 2016-06-02 08:05:38
  • Jack Maddington
  • 1834 View
  • 1 Score
  • 1 Answer
  • Tags:   tasker

1 Answered Questions

[SOLVED] Tasker: How can I randomize a wait action?

  • 2015-09-19 02:47:13
  • Nutshell
  • 219 View
  • 0 Score
  • 1 Answer
  • Tags:   tasker

1 Answered Questions

[SOLVED] Tasker: How can I delete a file after a month

  • 2014-05-08 13:54:45
  • kyriesent
  • 1544 View
  • 1 Score
  • 1 Answer
  • Tags:   tasker

1 Answered Questions

Sponsored Content