How to make android device always in wake mode?
Asked Answered
B

8

19

After successful root of device. Now, I need to make device always in wake state i.e. always visibility of UI and no black screen or any daydream screens. To do so I think I've to accomplish following :

  1. No lock screen - turned off
  2. Sleep set to “never”
  3. Daydream set to “off”

What I found is all about application layer i.e. there are some applications which can do above tasks. But since my mobile is rooted I want to achieve with system files so that even if some other applications try to change above functionalities then they should not be able to do so.

Bluegreen answered 6/1, 2016 at 7:30 Comment(5)
you could write a background service that does it ?Claudelle
Since my device is rooted, what if when another app try to lock or sleep mode on to device.Bluegreen
don't think it even matters if it is rooted or not... yeah, i'm not sure that even a persistent service could continually override everythingClaudelle
do you need a manual solution (then @Andrew's answer could work) or some code that would achieve this effect as an app?Require
@Require I need some code to achieve this.Bluegreen
A
10
  1. Activate developer mode
  2. go to Developer options
  3. turn on "Stay awake"
Aluminate answered 14/1, 2016 at 6:41 Comment(3)
@Abdrew ..Please understand question properly.Bluegreen
What about preventing other application from gaining root access so that they can't change your settings?Aluminate
Yes that's one of the reason, and for that I've mention that I need to do it with System files not any manual solution.Bluegreen
M
6

Your main use case appears to be as follows (from your question)

Even if some other applications try to change above functionalities then they should not be able to do so

You can write a system service to trigger the PowerManager.WakeLock at regular intervals. (Source)

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag");
wl.acquire();

// screen and CPU will stay awake during this section

wl.release();

To optimize the service you can also try setting the screen timeout the the maximum possible again at regular intervals so that even if changed manually it gets reset. (not sure how much max is allowed, you'll need to check with trial and error)

  /**
   * set screen off timeout
   * @param screenOffTimeout int 0~6
   */
private void setTimeout(int screenOffTimeout) {
    int time;
    switch (screenOffTimeout) {
    case 0:
        time = 15000;
        break;
    case 1:
        time = 30000;
        break;
    case 2:
        time = 60000;
        break;
    case 3:
        time = 120000;
        break;
    case 4:
        time = 600000;
        break;
    case 5:
        time = 1800000;
        break;
    default:
        time = -1;
    }
    android.provider.Settings.System.putInt(getContentResolver(),
            Settings.System.SCREEN_OFF_TIMEOUT, time);
}

(Source)

Mozzetta answered 14/1, 2016 at 6:23 Comment(3)
Q1- How to write "System Service"? Q2 - Your link to answer says thia method is depicted, will it work with Lollipop os?Bluegreen
System service: #6650310Mozzetta
For deprecated method just fine the latest alternatives.Mozzetta
H
2

I think you will need to modify the framework...Build framework.jar and push it to the device.

You can refer this link to know how to modify framework code-Modify java code in framework.jar and https://devmaze.wordpress.com/2011/01/18/using-com-android-internal-part-2-hacking-around/

Other alternative I can think of is using some MDM(Mobile device management) solution from Airwatch/SOTI/SAP Afaria which have privilege APIs to control the device.

Hygrothermograph answered 15/1, 2016 at 18:0 Comment(2)
framework.jar is a java file used by the android operating system. An app will NOT be able to modify this, ever.Watthour
@apmartin1991 yup but since it s a rooted phone we can modify the code and push the changes to the device..we can flash our own firmware...Hygrothermograph
F
2

Ok So after reading your question carefully, I found that you are not looking for any programmatic solution. You don't want to install an app to do that what you want is to modify the system file to achieve this functionality automatically.

Basically you want to modify the file who is exposing its methods to other apps by PowerManager class to control the sleep time and wake lock. Two things you need to know here:

  1. The system file you are looking for is available in jar format not in text or any other form.
  2. If somehow you will locate that file and start playing with that then you would end up breaking the compiled version of Android framework and your phone may misbehave after that.

Conclusion I understand you want to do something tricky by doing this but unfortunately it can't be done this way and even if you do so by playing with that file then all operations of your phone handled by PowerManager class will start playing with you. :)

Fibrosis answered 15/1, 2016 at 22:26 Comment(1)
You understand it completely, and yes I want to do something tricky but obviously without any strange behaviour then after.Bluegreen
A
1

To prevent the sleep mode on a specific View, just call setKeepScreenOn(true) on that View or set the keepScreenOn property to true.

In turns it will prevent the screen from going off while the View is on the screen. It works without requiring the WAKE_LOCK permission (or any special permission) , which is a better practice here.

Also this will not force the phone to stay awake outside the life span of the application. You can run into that problem with WakeLock

You can integrate the above method with another approach to get the full solution (outside an application layer):

From the root shell (e.g. adb shell), you can lock with:

echo mylockname >/sys/power/wake_lock 

After which the device will stay awake, until you do:

echo mylockname >/sys/power/wake_unlock    

With the same string for 'mylockname'.

Note that this will not prevent the screen from going black, but it will prevent the CPU from sleeping.

Note that /sys/power/wake_lock is read-write for user radio (1001) and group system (1000), and, of course, root.

Source: https://lwn.net/Articles/479841/

Source: https://mcmap.net/q/142750/-how-do-i-prevent-an-android-device-from-going-to-sleep-programmatically

Apologia answered 14/1, 2016 at 8:8 Comment(0)
M
1

If you want to increase screen timeout via adb shell command follow below steps:

Steps

  1. Turn on USB debugging
  2. Connect android device through usb cable
  3. Change directory to android-sdk/platform-tools/
  4. In terminal check device is connected by using below command: $ adb devices
  5. Issue screen timeout command: $ adb shell settings put system screen_off_timeout 60000

Note

60000 = 1 minute

Mouthpart answered 27/8, 2017 at 8:31 Comment(0)
E
0

adb shell "settings put system screen_off_timeout -1"

Eremite answered 16/6, 2022 at 3:31 Comment(0)
A
-2

So from Developer Options the best you could get is 30 minutes or so of "Wake" ...

According to this, there are a few good applications that can override the functionality and keep your screen on indefinitely:

  1. Keep Screen On
  2. Stay Alive
  3. Wakey

UPDATE

You will need to do research into how Android's file system is structured and how it works, then go and modify its core files. There is no easy way to do what you require. The only way is to create an Android App, that will never have an onDestroy(), and will continuously run in the background. You can use a WakeLock to achieve that.

Look here for how to use the WakeLock

Alverta answered 6/1, 2016 at 7:37 Comment(1)
Thanks for answer, but I've rooted my device and I need to make change in system files so that device is always in wake mode. Otherwise if there will be another app which may try to lock or put device in sleep mode.Bluegreen

© 2022 - 2024 — McMap. All rights reserved.