Methods Summary |
---|
public void | acquire(IBinder token, java.lang.String tag)Record that this token has been acquired. When acquire is called, and
the current count is 0, the acquired method is called on the given
handler.
synchronized (mTokens) {
// explicitly checked to avoid bogus sendNotification calls because
// of the WeakHashMap and the GC
int oldSize = mTokens.size();
Death d = new Death(token, tag);
try {
token.linkToDeath(d, 0);
} catch (RemoteException e) {
return;
}
mTokens.put(token, d);
if (oldSize == 0 && !mAcquired) {
sendNotificationLocked(true);
mAcquired = true;
}
}
|
public abstract void | acquired()Called when the number of active tokens goes from 0 to 1.
|
public void | cleanup(IBinder token, boolean unlink)
synchronized (mTokens) {
Death d = mTokens.remove(token);
if (unlink && d != null) {
d.token.unlinkToDeath(d, 0);
d.token = null;
}
if (mTokens.size() == 0 && mAcquired) {
sendNotificationLocked(false);
mAcquired = false;
}
}
|
public void | dump()
ArrayList<String> a = dumpInternal();
for (String s : a) {
Log.i(mTag, s);
}
|
public void | dump(java.io.PrintWriter pw)
ArrayList<String> a = dumpInternal();
for (String s : a) {
pw.println(s);
}
|
private java.util.ArrayList | dumpInternal()
ArrayList<String> a = new ArrayList<String>();
synchronized (mTokens) {
Set<IBinder> keys = mTokens.keySet();
a.add("Token count: " + mTokens.size());
int i = 0;
for (IBinder b: keys) {
a.add("[" + i + "] " + mTokens.get(b).tag + " - " + b);
i++;
}
}
return a;
|
public boolean | isAcquired()
synchronized (mTokens) {
return mAcquired;
}
|
public void | release(IBinder token)
cleanup(token, true);
|
public abstract void | released()Called when the number of active tokens goes from 1 to 0.
|
private void | sendNotificationLocked(boolean on)
int value = on ? 1 : 0;
if (mNotificationQueue == -1) {
// empty
mNotificationQueue = value;
mHandler.post(mNotificationTask);
}
else if (mNotificationQueue != value) {
// it's a pair, so cancel it
mNotificationQueue = -1;
mHandler.removeCallbacks(mNotificationTask);
}
// else, same so do nothing -- maybe we should warn?
|