In my project, another thread will be launched in the service. To avoid this thread be paused when device suspend, I acquired the WakeLock before launch this thread and release this WakeLock after this thread is finished. Sometimes, This API call (WakeLock.acquire) takes too long time, over 4 minutes on Samsung Galaxy SII LTE.
Below is my code: In service onStartCommand, acquire wake lock:
if (mWakeLock == null) {
final PowerManager pm = (PowerManager)getSystemService(Context.POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Eca Engine");
mWakeLock.setReferenceCounted(false);
}
if (!mWakeLock.isHeld()) {
Log.d(TAG, "Before acquire");
mWakeLock.acquire();
Log.d(TAG, "After acquire");
}
......
In thread, release wake lock:
if (mWakeLock != null && mWakeLock.isHeld()) {
mWakeLock.release();
}
the log: "After acquire" printed after "Before acquire" over 4 minutes.
The test device information is: Model number: Sc-03d Android version: 2.3.6 Based version: 3c03domlb9 Kernel version: 2.6.35.11 - 3c03domlb9 980106 se.infra@sep-53#2 Build number: gingerbread omlb9
Did any one meet this issue before? Or any suggest for me is appreciated.