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 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://stackoverflow.com/a/18968753/3125120
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:
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
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:
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. :)
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)
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.