Android suspend/resume flow (Part 1: User Mode)

Source: Internet
Author: User

When the user presses the power button:

0) Android/frameworks/base/services/Java/COM/Android/Server/windowmanagerservice. Java
Boolean screenisoff =! Mpowermanager. isscreenon ();
Boolean screenisdim =! Mpowermanager. isscreenbright ();
Int actions = mpolicy. interceptkeytq (event ,! Screenisoff); ==> Step 1
If (Actions & windowmanagerpolicy. action_go_to_sleep )! = 0 ){
Mpowermanager. Gotosleep (event. When); ==> Step 2
}

 

1) Android/frameworks/policies/base/phone/COM/Android/Internal/policy/impl/phonewindowmanager. Java

Interceptkeytq Function

 

If (type = rawinputevent. ev_key ){
If (code = keyevent. keycode_endcall
| Code = keyevent. keycode_power ){

If (down ){

...................

// Only try to turn off the screen if we didn't already hang up
Mshouldturnoffonkeyup = true;
Mhandler. postdelayed (mpowerlongpress,
Viewconfiguration. getglobalactionkeytimeout (); ==> over Ms pop-up dialog box
Result & = ~ Action_pass_to_user;

}

Else {

Log. D (TAG, "power button up/R/N ");
Mhandler. removecallbacks (mpowerlongpress); ==> if the power up key exists within ms, cancel the dialog box

.................

Result | = action_go_to_sleep;
}

 

2) Android/framework/base/services/Java/COM/Android/Server/powermanagerservice. Java
Public void Gotosleep (long time)
{
Gotosleepwithreason (time, windowmanagerpolicy. off_because_of_user );
}

3) Jave Native Interface:
Android/frameworks/base/CORE/JNI/android_ OS _power.cpp

Static int
Setscreenstate (jnienv * ENV, jobject clazz, jboolean on)
{
Return set_screen_state (on );
}

4) Android/hardware/libhardware_legacy/power. c
Int
Set_screen_state (INT on)
{
Qemu_fallback (set_screen_state (on ));

Initialize_fds () ;==> open ("/sys/power/State", o_rdwr );

If (g_error) return g_error;

Char Buf [32];
Int Len;
If (on)
Len = sprintf (BUF, on_state );
Else
Len = sprintf (BUF, off_state );
Len = write (g_fds [request_state], Buf, Len) ;==> echo mem>/sys/power/State
If (LEN <0 ){
LogE ("failed setting last user activity: g_error = % d/N", g_error );
}
Return 0;
}

5) system will enter suspend mode and it will start normal Linux suspend Flow

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.