优化wakelock处理

serial
Matthew 2 years ago
parent cb3100c528
commit 94968a676a

@ -443,7 +443,7 @@ unsigned long CPhoneDevice::RequestWakelock(unsigned long timeout)
std::string name = WAKELOCK_NAME;
name += to_string(wakelockId);
ALOGI("RequestWakelock=%lld",wakelockId);
// ALOGI("RequestWakelock=%lld",wakelockId);
jboolean ret = JNI_FALSE;
JNIEnv* env = NULL;
@ -471,7 +471,7 @@ unsigned long CPhoneDevice::RequestWakelock(unsigned long timeout)
bool CPhoneDevice::ReleaseWakelock(unsigned long wakelock)
{
ALOGI("ReleaseWakelock=%lld", wakelock);
// ALOGI("ReleaseWakelock=%lld", wakelock);
std::string name = WAKELOCK_NAME;
name += to_string(wakelock);

@ -437,7 +437,6 @@ public class MicroPhotoService extends Service {
registerReceiver(screenactionreceiver, screenactionreceiver.getFilter());
// File path = getApplicationContext().getFilesDir();
String appPath = buildAppDir(this.getApplicationContext());
@ -482,14 +481,17 @@ public class MicroPhotoService extends Service {
public void requestWakelock(String name, long timeout) {
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
PowerManager.WakeLock wl = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, name);
PowerManager.WakeLock wl = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK/* | PowerManager.ON_AFTER_RELEASE*/, name);
PowerManager.WakeLock wl2 = null;
synchronized (mWakeLocks) {
wl2 = mWakeLocks.replace(name, wl);
wl2 = mWakeLocks.get(name);
mWakeLocks.put(name, wl);
}
if (wl2 != null) {
Log.i(TAG, "Release same name wakelock:" + name);
wl2.release();
}
Log.i(TAG, "Request wakelock:" + name);
if (timeout == 0) wl.acquire();
else wl.acquire(timeout);
}
@ -501,6 +503,7 @@ public class MicroPhotoService extends Service {
mWakeLocks.remove(name);
}
if (wl != null) {
Log.i(TAG, "Release wakelock:" + name);
wl.release();
}
}

Loading…
Cancel
Save