D
Deleted member 267841
Guest
Hi,
Execution of (user/rom) scripts in boot time is supported by the kernels (storing scripts in /system/etc/init.d).
UNIX provide a via for execute scripts on shutdown time, but i don't known any (android) kernel with this feature developed.
For this reason, I have developed a hack in order to execute scripts in shutdown time (just before the services are stopped and unmount partitions).
In order to include this feature in a ROM, you need to make a changes:
EDIT
Finally, I've decided to make this mod as a standard APK.
The framework edition is not easy and causing troubles to any users.
In the attachments of this post you have a installer that contains:
- apk that executes the binary
- binary that executes the scripts (with root permissions)
you can copy your executable scripts to /system/etc/initialization (scripts
executed in boot time) and/or in /system/etc/shutdown (scripts executed in
shutdown time).
in general, you don't need to copy any script in the initialization folder if your
kernel supports the init.d scripts folder.
Enjoy!
EDIT-END
1) Include this portion of code in the framework.jar
a) Decompile framework.jar
b) Edit com/android/internal/app/ShutdownThread.smali and include this procedure
c) In the com/android/internal/app/ShutdownThread.smali, search the function "run"
and next, search the code
(in some versions of framework.jar, the number 8 after the ShutdownThread$ differs. No problem)
d) Just after the previously searched code, include the "execute_shutdown_scripts_executor" function call
e) Recompile framework.jar
2) The "execute_shutdown_scripts_executor" has the only function to execute the
file "/system/bin/shutdownd".
You need to include this file (I attach) in this path and set permissions to 06755
(the scripts are executed has root)
3) Place your scripts in /system/etc/shut.d folder
Execution of (user/rom) scripts in boot time is supported by the kernels (storing scripts in /system/etc/init.d).
UNIX provide a via for execute scripts on shutdown time, but i don't known any (android) kernel with this feature developed.
For this reason, I have developed a hack in order to execute scripts in shutdown time (just before the services are stopped and unmount partitions).
In order to include this feature in a ROM, you need to make a changes:
EDIT
Finally, I've decided to make this mod as a standard APK.
The framework edition is not easy and causing troubles to any users.
In the attachments of this post you have a installer that contains:
- apk that executes the binary
- binary that executes the scripts (with root permissions)
you can copy your executable scripts to /system/etc/initialization (scripts
executed in boot time) and/or in /system/etc/shutdown (scripts executed in
shutdown time).
in general, you don't need to copy any script in the initialization folder if your
kernel supports the init.d scripts folder.
Enjoy!
EDIT-END
1) Include this portion of code in the framework.jar
a) Decompile framework.jar
b) Edit com/android/internal/app/ShutdownThread.smali and include this procedure
.method static execute_shutdown_scripts_executor()V
.locals 5
.prologue
.line 14
const-string v2, "ShutdownScript"
.line 17
.local v2, title:Ljava/lang/String;
:try_start_0
new-instance v1, Ljava/io/File;
const-string v3, "/system/bin/shutdownd"
invoke-direct {v1, v3}, Ljava/io/File;-><init>(Ljava/lang/StringV
.line 18
.local v1, file:Ljava/io/File;
invoke-virtual {v1}, Ljava/io/File;->exists()Z
move-result v3
if-eqz v3, :cond_0
.line 20
const-string v3, "Trying to execute \'/system/bin/shutdownd\' script."
invoke-static {v2, v3}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/StringI
.line 21
invoke-static {}, Ljava/lang/Runtime;->getRuntime()Ljava/lang/Runtime;
move-result-object v3
const-string v4, "/system/bin/shutdownd"
invoke-virtual {v3, v4}, Ljava/lang/Runtime;->exec(Ljava/lang/StringLjava/lang/Process;
move-result-object v3
invoke-virtual {v3}, Ljava/lang/Process;->waitFor()I
.line 22
const-string v3, "Script execution finished."
invoke-static {v2, v3}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/StringI
.line 33
.end local v1 #file:Ljava/io/File;
:goto_0
return-void
.line 26
.restart local v1 #file:Ljava/io/File;
:cond_0
const-string v3, "Shutdown script not found."
invoke-static {v2, v3}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/StringI
:try_end_0
.catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0
goto :goto_0
.line 29
.end local v1 #file:Ljava/io/File;
:catch_0
move-exception v0
.line 31
.local v0, e:Ljava/lang/Exception;
new-instance v3, Ljava/lang/StringBuilder;
const-string v4, "Error executing script: "
invoke-direct {v3, v4}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/StringV
invoke-virtual {v0}, Ljava/lang/Exception;->getMessage()Ljava/lang/String;
move-result-object v4
invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/StringLjava/lang/StringBuilder;
move-result-object v3
invoke-virtual {v3}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
move-result-object v3
invoke-static {v2, v3}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/StringI
goto :goto_0
.end method
c) In the com/android/internal/app/ShutdownThread.smali, search the function "run"
and next, search the code
invoke-direct {v0, v1}, Lcom/android/internal/app/ShutdownThread$8;-><init>(Lcom/android/internal/app/ShutdownThreadV
(in some versions of framework.jar, the number 8 after the ShutdownThread$ differs. No problem)
d) Just after the previously searched code, include the "execute_shutdown_scripts_executor" function call
invoke-static {}, Lcom/android/internal/app/ShutdownThread;->execute_shutdown_scripts_executor()V
e) Recompile framework.jar
2) The "execute_shutdown_scripts_executor" has the only function to execute the
file "/system/bin/shutdownd".
You need to include this file (I attach) in this path and set permissions to 06755
(the scripts are executed has root)
3) Place your scripts in /system/etc/shut.d folder
Attachments
Last edited by a moderator: