Fields Summary |
---|
private static final boolean | DEBUG |
private static final String | TAG |
private static IUpdateLock | sService |
IBinder | mToken |
int | mCount |
boolean | mRefCounted |
boolean | mHeld |
final String | mTag |
public static final String | UPDATE_LOCK_CHANGEDBroadcast Intent action sent when the global update lock state changes,
i.e. when the first locker acquires an update lock, or when the last
locker releases theirs. The broadcast is sticky but is sent only to
registered receivers. |
public static final String | NOW_IS_CONVENIENTBoolean Intent extra on the UPDATE_LOCK_CHANGED sticky broadcast, indicating
whether now is an appropriate time to interrupt device activity with an
update operation. True means that updates are okay right now; false indicates
that perhaps later would be a better time. |
public static final String | TIMESTAMPLong Intent extra on the UPDATE_LOCK_CHANGED sticky broadcast, marking the
wall-clock time [in UTC] at which the broadcast was sent. Note that this is
in the System.currentTimeMillis() time base, which may be non-monotonic especially
around reboots. |
Methods Summary |
---|
public void | acquire()Acquire an update lock.
if (DEBUG) {
Log.v(TAG, "acquire() : " + this, new RuntimeException("here"));
}
checkService();
synchronized (mToken) {
acquireLocked();
}
|
private void | acquireLocked()
if (!mRefCounted || mCount++ == 0) {
if (sService != null) {
try {
sService.acquireUpdateLock(mToken, mTag);
} catch (RemoteException e) {
Log.e(TAG, "Unable to contact service to acquire");
}
}
mHeld = true;
}
|
private static void | checkService()
if (sService == null) {
sService = IUpdateLock.Stub.asInterface(
ServiceManager.getService(Context.UPDATE_LOCK_SERVICE));
}
|
protected void | finalize()
synchronized (mToken) {
// if mHeld is true, sService must be non-null
if (mHeld) {
Log.wtf(TAG, "UpdateLock finalized while still held");
try {
sService.releaseUpdateLock(mToken);
} catch (RemoteException e) {
Log.e(TAG, "Unable to contact service to release");
}
}
}
|
public boolean | isHeld()Is this lock currently held?
synchronized (mToken) {
return mHeld;
}
|
public void | release()Release this update lock.
if (DEBUG) Log.v(TAG, "release() : " + this, new RuntimeException("here"));
checkService();
synchronized (mToken) {
releaseLocked();
}
|
private void | releaseLocked()
if (!mRefCounted || --mCount == 0) {
if (sService != null) {
try {
sService.releaseUpdateLock(mToken);
} catch (RemoteException e) {
Log.e(TAG, "Unable to contact service to release");
}
}
mHeld = false;
}
if (mCount < 0) {
throw new RuntimeException("UpdateLock under-locked");
}
|
public void | setReferenceCounted(boolean isRefCounted)Change the refcount behavior of this update lock.
if (DEBUG) {
Log.v(TAG, "setting refcounted=" + isRefCounted + " : " + this);
}
mRefCounted = isRefCounted;
|