Android system shutdown process

Source: Internet
Author: User

The Android system has a shutdown button. If you press this button long, the system will shut down. The specific implementation process is as follows:

On the android layer, call reboot (ARG) to call sys_reboot in the kernel. The procedure is as follows:
Reboot --> sys_reboot () --> kernel_power_off () --> machine_power_off () --> pm_power_off ();
Pm_power_off is a function pointer pointing to the shutdown operation function related to a specific hardware platform.

 

System calls related to sys_reboot are implemented in source/kernel/sys. C.

Add the system call number in source/ASM-arm/unistd. h.

Then in the source/ARCH/ARM/kernel/entry-common.S for sys_call_table (system call table)

The specific table is implemented in source/ARCH/ARM/kernel/call. S.

 

Android system shutdown and restart
1. Shut down the Android system, and the restart code is located in frameworks/base/CORE/JNI/android_ 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 );......

 

 

From: http://blog.csdn.net/yanzheng1113/article/details/7178067

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.