This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

power script on Android ICS


I am writing a script which will play the video then go to suspend and resume will be happened after 60 seconds followed by holding wake_lock.On next loop video is playing but display is not turning on and rest of functionality is working fine.


Please share your thought on this and main concern is how to turn on the display on next loop.

Below is my script:


Script:
rand_test_loop(){
    while [ 1 ]
    do
 input keyevent 82  // unlock home screen
 input keyevent 3 // home screen

am start -a android.intent.action.VIEW -d   "file:///mnt/sdcard/AV_1080p.mp4" -t "video/*"

sleep 30
 echo "calling suspend"
 echo 60 >/d/pm_debug/wakeup_timer_seconds
 #echo mem > /sys/power/state
echo test>/sys/power/wake_unlock
echo "call power button"
input keyevent 26 //power button
sleep 7
echo "test" >/sys/power/wake_lock
input keyevent 82
input keyevent 3
echo "home came***"
 off_count=`cat /d/pm_debug/count | grep DEVICE-OFF`

 echo "OFF Mode count $off_count ************!!!!!!!!!!!!!!!"
    done
}
 rand_test_loop 

Regards

Chinmoy

  • It is similar to what is mentioned in

    http://omapedia.org/wiki/Android_How-tos#Disabling_screen_lock_forever

    are you setting "Stay Awake" configuration?

    http://omapedia.org/wiki/Android_How-tos#Booting_with_Unlocked_Screen

    It is the phone window manager and that has a rule to discard the inputs from internal keyboard or mouse-pads when the device goes to sleep after timeout. It is the Keyguard that takes care to unlock the screen but if the dispatched input events are discarded then screen will not turn on and Keyguard will not receive any input to unlock the screen.

  • In order to turn on the screen it is needed to press Power button or in tablet or depending on some configuration pressing Home button.

  • That is the issue .Device is will go to system wide suspend then i am able to hold the wake lock in resume path but display is not ON.

    Regards

    Chinmoy

  • By the script and what is in next link

    http://developer.android.com/reference/android/os/PowerManager.WakeLock.html

    public void acquire ()
    Since: API Level 1
    Makes sure the device is on at the level you asked when you created the wake lock.

    you are calling wake lock after sending the device to suspend that makes wake lock invalid.

    If you set "stay Awake" at preferences it must keep the device on but then the command you are sending is turning the system down,

    echo 60 >/d/pm_debug/wakeup_timer_seconds

    but the keyguard timeout is reached.

    A link to Power Manager,

    http://developer.android.com/reference/android/os/PowerManager.html

    from the same link

    PowerManager.WakeLock
    Class lets you say that you need to have the device on.
    Call release when you are done and don't need the lock anymore.
    Any application using a WakeLock must request the android.permission.WAKE_LOCK permission in an <uses-permission> element of the application's manifest.

    it has the "acquire(long timeout)" function that seems similar to the one you use.

    but then you are waiting 30 seconds before setting this commands, and the keyguard is enabled after 30 seconds of inactivity.

    if you want to keep the device up while playing the video you need to set the wakelock before or while playing the video, Android interface is

    http://developer.android.com/guide/topics/media/mediaplayer.html#manifest

    one time KeyGuard is called it will turn off the screen base in actual state, for ICS

    /mydroid/frameworks/base/policy/src/com/android/internal/policy/impl/KeyguardViewMediator.java
        /**
         * Called to let us know the screen was turned off.
         * @param why either {@link WindowManagerPolicy#OFF_BECAUSE_OF_USER},
         *   {@link WindowManagerPolicy#OFF_BECAUSE_OF_TIMEOUT} or
         *   {@link WindowManagerPolicy#OFF_BECAUSE_OF_PROX_SENSOR}.
         */
        public void onScreenTurnedOff(int why) {

    the timeout is defined in

    ./mydroid/frameworks/base/policy/src/com/android/internal/policy/impl/KeyguardViewMediator.java
        private static final int KEYGUARD_DISPLAY_TIMEOUT_DELAY_DEFAULT = 30000;

    the issue is that when it is enabled all input keyboard or touch screen events are discarded and then those cannot be used like wakeup events, for tablets I have seen that home button wakes up the screen there is a code in inputreader or inputdispatcher that checks for power keys and home keys to wakeup the device, I was not using a Blaze at this time but that means there is code to allow use of home key as wake up key.

    the next to mention should be that by using " stay awake" from preferences makes system to stay on and the input keyevent 26 must turn on the screen,

    internally Android can unlock the screen when receiving a incoming call or alarm is activated,

    /mydroid/frameworks/base/policy/src/com/android/internal/policy/impl/KeyguardViewMediator.java
        /**
         * Same semantics as {@link WindowManagerPolicy#enableKeyguard}; provide
         * a way for external stuff to override normal keyguard behavior.  For instance
         * the phone app disables the keyguard when it receives incoming calls.
         */
        public void setKeyguardEnabled(boolean enabled) {
            synchronized (this) {
                if (DEBUG) Log.d(TAG, "setKeyguardEnabled(" + enabled + ")");
                mExternallyEnabled = enabled;

    in your script depending in what you meant to do changing the order of the command could make the device to be awake all the time by setting the wake lock, but if your script means to test the wakeup capabilities then it will be blocked by the keyguard and window policy manager rules to discard input events from internal devices.

    Probably if you call wake lock before or instead of 30 seconds call? in other case it will depend on what is your test case, if it is to test keyguard (turn on the screen) then it could require some other commands or code.

    A comment apart, there could be some issues with the used user by sending the commands directly from a script when there is a interface for it and using correct permissions, from previous link and next link, I remember there is the "service" command to send values to a service but I cannot find a reference to a command line that uses it.

    /mydroid/frameworks/base/cmds/service

    for service command it should be something like

    service call SERVICE CODE [i32 INT | s16 STR]

    this comment is base in a comment that I found for a system service that it mentions that it is needed to call a service function from its binder client not directly from the service, this because some code needed to be executed from this part before in order to do proper state change or command, if someone has some information about this it could be great that it to be shared.

  • By disabling the lock screen it make screen ti run on again.

    This is setting [none] in "Settings/Security/Screen lock".