This guide shows how to solve the screen wake lag on Samsung devices which can be almost 2 seconds from button press to actual screen-on depending on configuration and whether or not an external SD card is used. You're probably here because you've figured out that all the tricks listed in other threads (like turning off s-voice, ripple effect, and even freezing certain apps) does little to fix the problem. There are things other than wake-from-deep-sleep that can cause some lag, but the majority of the lag is caused by processor and sensor power-up cycles that cannot be improved using any method of modifying settings.
This fix should work on all incarnations of the Note II and potentially other Samsung devices as well. I'll dispense with the usual disclaimers about apktool, decompiling, and recompiling. Obviously this guide assumes some knowledge of those.
The Note II goes into deep sleep within about 1 second of screen off, so to eliminate wake lag, we need to prevent deep sleep. We do this by creating a wake lock. Yes, this means your phone will not go into deep sleep but before jumping to conclusions that this will nail your battery, see this post in my ROM thread for the gory details of what I found. Long story short, many people get better battery life by preventing deep sleep because the phone isn't constantly powering up different parts of the circuitry all the time. And from what I found, your phone is forced to wake out of deep sleep a lot, potentially hundreds of times an hour, to perform regular operations.
Devs, modders, and tweakers: feel free to use this mod in anything you develop and all I ask is that you credit me and link to this thread.
So let's get to it. We'll be making all our changes in android.policy.jar in the KeyguardViewMediator.smali file.
So open KeyguardViewMediator.smali and at the top, add the line in blue to create a ZeroWakeLag wakelock so that end users will be able to see and identify the wakelock that is keeping their phone awake:
Next, add these lines in blue in the constructor method to initialize the new wakelock:
Now our wakelock is initialized so let's add a wakelock.acquire when the screen turns OFF so there is a permanent wakelock while the screen is off. Just add the lines in blue at the top of the onScreenTurnedOff method:
Now the wakelock is acquired on screen off, so let's add the lines in blue below to release the wakelock when the screen comes on in the OnScreenTurnedOn event. Technically you could skip the release altogether and it'd do the same thing but it's just good coding practice to release a wakelock when you are done with it rather than driving the reference count up:
That's it! Recompile and enjoy the zero wake lag.
Note to devs, tweakers, and modders. This mod works best when combined with some sort of screen-off underclocking and limiting screen-off processing to a single CPU. There are plenty of scripts to do that out there and it can even be done with CPU tuners, so I'll leave that part to you. As I said though, even that is not really necessary because you'd be surprised how much has to be woken up (see the post linked above) when in deep sleep so in many cases, it's better to just let the CPU's idle at-the-ready to avoid all the waking that happens from Google services, push mails, alarms, widget updating, etc. You (or your ROM dev) can also make this mod selectable by using system properties to turn the feature on/off by just jumping around the "acquire" and "release" statements in the OnScreenTurnedOff and OnScreenTurnedOn events.
Sharing
As mentioned above, use this mod in whatever mod, tweak, or ROM you like but please just credit me and link to this thread. Thanks!
Click to Donate
Donations are greatly appreciated. If I've saved you some time and aggravation with this mod, donating a few bucks is the best way to say thanks!
This fix should work on all incarnations of the Note II and potentially other Samsung devices as well. I'll dispense with the usual disclaimers about apktool, decompiling, and recompiling. Obviously this guide assumes some knowledge of those.
The Note II goes into deep sleep within about 1 second of screen off, so to eliminate wake lag, we need to prevent deep sleep. We do this by creating a wake lock. Yes, this means your phone will not go into deep sleep but before jumping to conclusions that this will nail your battery, see this post in my ROM thread for the gory details of what I found. Long story short, many people get better battery life by preventing deep sleep because the phone isn't constantly powering up different parts of the circuitry all the time. And from what I found, your phone is forced to wake out of deep sleep a lot, potentially hundreds of times an hour, to perform regular operations.
Devs, modders, and tweakers: feel free to use this mod in anything you develop and all I ask is that you credit me and link to this thread.
So let's get to it. We'll be making all our changes in android.policy.jar in the KeyguardViewMediator.smali file.
So open KeyguardViewMediator.smali and at the top, add the line in blue to create a ZeroWakeLag wakelock so that end users will be able to see and identify the wakelock that is keeping their phone awake:
Code:
.field private mWakeLock:Landroid/os/PowerManager$WakeLock;
[COLOR="Blue"].field private mZeroWakeLag:Landroid/os/PowerManager$WakeLock;[/COLOR]
.field private mWakelockSequence:I
Code:
const-string v2, "keyguardWakeAndHandOff"
invoke-virtual {v0, v1, v2}, Landroid/os/PowerManager;->newWakeLock(ILjava/lang/String;)Landroid/os/PowerManager$WakeLock;
move-result-object v0
iput-object v0, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mWakeAndHandOff:Landroid/os/PowerManager$WakeLock;
.line 314
iget-object v0, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mWakeAndHandOff:Landroid/os/PowerManager$WakeLock;
const/4 v1, 0x0
invoke-virtual {v0, v1}, Landroid/os/PowerManager$WakeLock;->setReferenceCounted(Z)V
[COLOR="Blue"]iget-object v0, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mPM:Landroid/os/PowerManager;
const/4 v1, 0x1
const-string v2, "ZeroWakeLag"
invoke-virtual {v0, v1, v2}, Landroid/os/PowerManager;->newWakeLock(ILjava/lang/String;)Landroid/os/PowerManager$WakeLock;
move-result-object v0
iput-object v0, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mZeroWakeLag:Landroid/os/PowerManager$WakeLock;
iget-object v0, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mZeroWakeLag:Landroid/os/PowerManager$WakeLock;
const/4 v1, 0x0
invoke-virtual {v0, v1}, Landroid/os/PowerManager$WakeLock;->setReferenceCounted(Z)V[/COLOR]
.line 316
new-instance v7, Landroid/content/IntentFilter;
Code:
.method public onScreenTurnedOff(I)V
.locals 30
.parameter "why"
.prologue
.line 400
[COLOR="Blue"]move-object/from16 v0, p0
iget-object v1, v0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mZeroWakeLag:Landroid/os/PowerManager$WakeLock;
invoke-virtual {v1}, Landroid/os/PowerManager$WakeLock;->acquire()V[/COLOR]
monitor-enter p0
.line 401
const/16 v26, 0x0
:try_start_0
move/from16 v0, v26
move-object/from16 v1, p0
iput-boolean v0, v1, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mScreenOn:Z
Code:
.method public onScreenTurnedOn(Lcom/android/internal/policy/impl/KeyguardViewManager$ShowListener;)V
.locals 3
.parameter "showListener"
.prologue
.line 545
monitor-enter p0
.line 546
[COLOR="Blue"]iget-object v1, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mZeroWakeLag:Landroid/os/PowerManager$WakeLock;
invoke-virtual {v1}, Landroid/os/PowerManager$WakeLock;->release()V[/COLOR]
const/4 v0, 0x1
:try_start_0
iput-boolean v0, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mScreenOn:Z
Note to devs, tweakers, and modders. This mod works best when combined with some sort of screen-off underclocking and limiting screen-off processing to a single CPU. There are plenty of scripts to do that out there and it can even be done with CPU tuners, so I'll leave that part to you. As I said though, even that is not really necessary because you'd be surprised how much has to be woken up (see the post linked above) when in deep sleep so in many cases, it's better to just let the CPU's idle at-the-ready to avoid all the waking that happens from Google services, push mails, alarms, widget updating, etc. You (or your ROM dev) can also make this mod selectable by using system properties to turn the feature on/off by just jumping around the "acquire" and "release" statements in the OnScreenTurnedOff and OnScreenTurnedOn events.
Sharing
As mentioned above, use this mod in whatever mod, tweak, or ROM you like but please just credit me and link to this thread. Thanks!
Click to Donate
Donations are greatly appreciated. If I've saved you some time and aggravation with this mod, donating a few bucks is the best way to say thanks!
Last edited: