How to control your device when Android goes to sleep and wake-up

Good day.

I’m trying to create an embedded gadget by building and installing Android OS (Android 6.0.1) on the DragonBoard 410C.

When power is supplied to the DragonBoard 410C, Android starts and a screen with icons etc. is displayed. As everyone knows well, after the Android OS has started normally, pressing the power button once will turn off the screen display (sleep), and pressing the power button again will display the screen again ( wake-up).

I want Android to do certain things to the device when it goes to sleep and wake-up from that state. In other words, I want the callback function A to be executed when the Android OS goes to sleep and the callback function B to be executed when wake-up.

Where and how should I modify the Android source code? If anyone knows, please teach me. goes to sleep and the callback function B to be executed when wake up.

Thank you for your assistance, in advance.

You can simply register receiver for SCREEN_OFF and SCREEN_ON intent (e.g. android.intent.action.SCREEN_OFF) in a Android app and act accordingly.

AFAIR the screen off cause the release of a wakelock, when there is no more active wakelock, the platform enters sleep.