Automatically boot-up MTK devices (non-samsung) when docked

6.8k views Asked by At

I'm developing a standalone kiosk using an android tablet(iBall running on 4.2.2).Its has the chinese MTK in it.

Suppose when there is no power,then eventually the tab's battery will drain out and have no juice left in it.When the power comes back I want the tab to automatically bootup without any manual intervention.I read online that if we modify the code present in the battery animation file we can achieve this.For the same,I replaced the original code of the battery charging animation file called 'ipod' located at '/system/bin' with :

    #!/system/bin/sh
    /system/bin/reboot

However,when my tab was shutdown and docked it didnt boot-up,instead it was just stuck at the charging logo.When I replaced the above code with:

    /system/bin/reboot

my tab did boot-up when it was shutdown and docked.This means my code was getting stuck at '#!/system/bin/sh' . What could be the reason?

Also,while booting up the tab using the above process I want to boot it up after a delay,for which I used

    sleep 20
    /system/bin/reboot

but there was no delay in the bootup process(irrespective of the value of sleep that I give) How do I create this delay ?

PS: I gave 777 permission to the file; owner-root; group-shell. Kindly assist.Many thanks !

3

There are 3 answers

5
Basher51 On

Found the reason my commands were not executing. The reason was because,I was editing on my notepad++ on windows,until I came across this answer on SO - " Make sure your text editor is not putting a /r /n and only a /n for every new line. This is typical if you are writing the script on windows.Use notepad++ (windows) and go to edit|EOL convention|UNIX then save it. " So I changed my convention as per the above answer and ran my code and got the desired result.

0
user246100 On

I also had the need to make a device (alcatel9002x) autoboot on charger plugged, and come up with a solution replacing the ipod file. It runs the original ipod binary and at the same time, simulate pressing on the power button. I see the charging animation, but after, it does a "normal" power up.

You probably can do this with a script but I did with with a .c binary. Solution:

move /sbin/ipod to /sbin/ipod.backup

And use this code as the new binary /sbin/ipod

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>
#include <unistd.h>

void run_cmd(char *s)
{
    FILE *handle;
        char buf[64];
        size_t readn;

    handle = popen(s, "r");

    if (handle == NULL) {
        return;
    }

    while ((readn = fread(buf, 1, sizeof(buf), handle)) > 0) {
        fwrite(buf, 1, readn, stdout);
    }

    pclose(handle);

}

int main(void)
{
    FILE *handle;
        char buf[64];
        size_t readn;

    pid_t pid = fork();


    if (pid == 0)
    {
        for(int i=0;i<10;i++)
        {
            run_cmd("/system/bin/sendevent /dev/input/event0 0001 116 1");
            run_cmd("/system/bin/sendevent /dev/input/event0 0000 0000 00000000");
            run_cmd("/system/bin/sleep 2");
            run_cmd("/system/bin/sendevent /dev/input/event0 0001 116 00000000");
            run_cmd("/system/bin/sendevent /dev/input/event0 0000 0000 00000000");
            sleep(1);
        }
    }
    else
    {   
        run_cmd("/system/bin/sleep 2");
        run_cmd("/system/bin/ipod.backup");
    }

    return 0;
}

I've compiled it with arm-linux-androideabi-gcc. As I said, you probably can do this in a bash script, but this is how it worked for me.

Don't forget to chmod 667 and chown root:shell the binaries.

0
Peyman Mahdavi On

In Sony Xperia GO, the file name is "chargemon" and only by renaming it, the task is done (smartphone will be restart after plug in). (maybe other Sony brand smartphones be the same or similar)