The following is the call-related code with the idea permission:
Any system-level application will go to the Linux system call. For reboot, it will call int reboot (INT mode) or directly use _ reboot, we only need to change the mode Value to OK,
Mode contains:
# Define rb_autoboot linux_reboot_assist_restart
# Define rb_halt_system linux_reboot_assist_halt
# Define rb_enable_cad linux_reboot_cmd_cad_on
# Define rb_disable_cad linux_reboot_cmd_cad_off
# Define rb_power_off linux_reboot_assist_power_off
The options are power off and autoboot. Of course, you need the root or system permissions, or the shell does not seem to be a problem.
Shutdown:
In frameworks/base/services/Java/COM/Android/Server/batteryservice. Java
Intent intent = new intent (intent. action_request_shutdown );
Intent. putextra (intent. extra_key_confirm, false );
Intent. setflags (intent. flag_activity_new_task );
Mcontext. startactivity (intent );
Restart:
Intent I = new intent (intent. action_reboot );
I. putextra ("Nowait", 1 );
I. putextra ("interval", 1 );
I. putextra ("window", 0 );
Sendbroadcast (I );
The following is the idea:
Android system shutdown and restart
1. Shut down the Android system, and the restart code is located in frameworks asecorejniandroid_ OS _power.cpp, which contains
Static void android_ OS _power_shutdown (jnienv * ENV, jobject clazz)
{/* Shut down */
Sync ();
# Ifdef have_android_ OS
Reboot (rb_power_off );
# Endif
}
Static void android_ OS _power_reboot (jnienv * ENV, jobject clazz, jstring reason)
{/* Restart */
Sync ();
# Ifdef have_android_ OS
If (reason = NULL ){
Reboot (rb_autoboot );
} Else {
Const char * chars = env-> getstringutfchars (reason, null );
_ Reboot (linux_reboot_magic1, linux_reboot_magic2,
Linux_reboot_cmd_restart2, (char *) chars );
Env-> releasestringutfchars (reason, chars); // in case it fails.
}
Jnithrowioexception (ENV, errno );
# Endif
}
2. sys_reboot will be called in Linux, so we can add the restart function to Android;
Which functions are implemented by shutdown and restart in Linux kernel.
The final implementation of reboot is implemented in the arch_reset () function, which is usually defined in arch/ARM/Mach-xxx/include/Mach/system. h. System. H is applied by the Public Code of ARM kernel. Therefore, you need to define this header file and implement it.
The function prototype of arch_reset is
Void arch_reset (char Mode)
Void arch_reset (char Mode)
To shut down, point the pm_power_off function pointer to your own implementation function. The function pointer is defined in this way.
Void (* pm_power_off) (void );......
Http://yueguc.iteye.com/blog/1030305
Android system shutdown and restart
1. Shut down the Android system, and the restart code is located in frameworksasecorejniandroid_ OS _power.cpp, which contains
Static void android_ OS _power_shutdown (jnienv * ENV, jobject clazz)
{/* Shut down */
Sync ();
# Ifdef have_android_ OS
Reboot (rb_power_off );
# Endif
}
Static void android_ OS _power_reboot (jnienv * ENV, jobject clazz, jstring reason)
{/* Restart */
Sync ();
# Ifdef have_android_ OS
If (reason = NULL ){
Reboot (rb_autoboot );
} Else {
Const char * chars = env-> getstringutfchars (reason, null );
_ Reboot (linux_reboot_magic1, linux_reboot_magic2,
Linux_reboot_cmd_restart2, (char *) chars );
Env-> releasestringutfchars (reason, chars); // in case it fails.
}
Jnithrowioexception (ENV, errno );
# Endif
}
2. sys_reboot will be called in Linux, so we can add the restart function to Android;
Which functions are implemented by shutdown and restart in Linux kernel.
The final implementation of reboot is implemented in the arch_reset () function, which is usually defined in arch/ARM/Mach-xxx/include/Mach/system. h. System. H is applied by the Public Code of ARM kernel. Therefore, you need to define this header file and implement it.
The function prototype of arch_reset is
Void arch_reset (char Mode)
Void arch_reset (char Mode)
To shut down, point the pm_power_off function pointer to your own implementation function. The function pointer is defined in this way.
Void (* pm_power_off) (void );......