* {@link #PROXIMITY_SCREEN_OFF_WAKE_LOCK} wake lock until the proximity sensor
* indicates that an object is not in close proximity.
*/
- public static final int RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY = 1;
+ public static final int RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY = 1 << 0;
+
+ /**
+ * Flag for {@link WakeLock#release(int)} when called due to timeout.
+ * @hide
+ */
+ public static final int RELEASE_FLAG_TIMEOUT = 1 << 16;
/**
* Brightness value for fully on.
private String mTag;
private final String mPackageName;
private final IBinder mToken;
- private int mCount;
+ private int mInternalCount;
+ private int mExternalCount;
private boolean mRefCounted = true;
private boolean mHeld;
private WorkSource mWorkSource;
private final Runnable mReleaser = new Runnable() {
public void run() {
- release();
+ release(RELEASE_FLAG_TIMEOUT);
}
};
}
private void acquireLocked() {
- if (!mRefCounted || mCount++ == 0) {
+ mInternalCount++;
+ mExternalCount++;
+ if (!mRefCounted || mInternalCount == 1) {
// Do this even if the wake lock is already thought to be held (mHeld == true)
// because non-reference counted wake locks are not always properly released.
// For example, the keyguard's wake lock might be forcibly released by the
*/
public void release(int flags) {
synchronized (mToken) {
- if (!mRefCounted || --mCount == 0) {
+ mInternalCount--;
+ if ((flags & RELEASE_FLAG_TIMEOUT) == 0) {
+ mExternalCount--;
+ }
+ if (!mRefCounted || mInternalCount == 0) {
mHandler.removeCallbacks(mReleaser);
if (mHeld) {
Trace.asyncTraceEnd(Trace.TRACE_TAG_POWER, mTraceName, 0);
mHeld = false;
}
}
- if (mCount < 0) {
+ if (mRefCounted && mExternalCount < 0) {
throw new RuntimeException("WakeLock under-locked " + mTag);
}
}
synchronized (mToken) {
return "WakeLock{"
+ Integer.toHexString(System.identityHashCode(this))
- + " held=" + mHeld + ", refCount=" + mCount + "}";
+ + " held=" + mHeld + ", refCount=" + mInternalCount + "}";
}
}