summaryrefslogtreecommitdiffstats
path: root/core/java/android/os
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2009-07-14 12:51:00 -0700
committerDianne Hackborn <hackbod@google.com>2009-07-14 12:51:00 -0700
commitdace230043314d6fab1c5ced4b031eaccd814c25 (patch)
tree0c2fbb477f5d94641cee6aa892600b6d34bc96d3 /core/java/android/os
parentae4f31706fa0589ede00dfce344779a1570cd2f3 (diff)
parentb06ea706530e6d19eb2a1a9a7ae6c5dd77d80af0 (diff)
downloadframeworks_base-dace230043314d6fab1c5ced4b031eaccd814c25.zip
frameworks_base-dace230043314d6fab1c5ced4b031eaccd814c25.tar.gz
frameworks_base-dace230043314d6fab1c5ced4b031eaccd814c25.tar.bz2
resolved conflicts for merge of b06ea706 to master
Diffstat (limited to 'core/java/android/os')
-rw-r--r--core/java/android/os/RemoteCallbackList.java24
1 files changed, 19 insertions, 5 deletions
diff --git a/core/java/android/os/RemoteCallbackList.java b/core/java/android/os/RemoteCallbackList.java
index 5ab305e..b74af16 100644
--- a/core/java/android/os/RemoteCallbackList.java
+++ b/core/java/android/os/RemoteCallbackList.java
@@ -50,6 +50,7 @@ public class RemoteCallbackList<E extends IInterface> {
/*package*/ HashMap<IBinder, Callback> mCallbacks
= new HashMap<IBinder, Callback>();
private Object[] mActiveBroadcast;
+ private int mBroadcastCount = -1;
private boolean mKilled = false;
private final class Callback implements IBinder.DeathRecipient {
@@ -196,15 +197,16 @@ public class RemoteCallbackList<E extends IInterface> {
* This creates a copy of the callback list, which you can retrieve items
* from using {@link #getBroadcastItem}. Note that only one broadcast can
* be active at a time, so you must be sure to always call this from the
- * same thread (usually by scheduling with {@link Handler} or
+ * same thread (usually by scheduling with {@link Handler}) or
* do your own synchronization. You must call {@link #finishBroadcast}
* when done.
*
* <p>A typical loop delivering a broadcast looks like this:
*
* <pre>
- * final int N = callbacks.beginBroadcast();
- * for (int i=0; i&lt;N; i++) {
+ * int i = callbacks.beginBroadcast();
+ * while (i &gt; 0) {
+ * i--;
* try {
* callbacks.getBroadcastItem(i).somethingHappened();
* } catch (RemoteException e) {
@@ -223,7 +225,12 @@ public class RemoteCallbackList<E extends IInterface> {
*/
public int beginBroadcast() {
synchronized (mCallbacks) {
- final int N = mCallbacks.size();
+ if (mBroadcastCount > 0) {
+ throw new IllegalStateException(
+ "beginBroadcast() called while already in a broadcast");
+ }
+
+ final int N = mBroadcastCount = mCallbacks.size();
if (N <= 0) {
return 0;
}
@@ -282,12 +289,19 @@ public class RemoteCallbackList<E extends IInterface> {
* @see #beginBroadcast
*/
public void finishBroadcast() {
+ if (mBroadcastCount < 0) {
+ throw new IllegalStateException(
+ "finishBroadcast() called outside of a broadcast");
+ }
+
Object[] active = mActiveBroadcast;
if (active != null) {
- final int N = active.length;
+ final int N = mBroadcastCount;
for (int i=0; i<N; i++) {
active[i] = null;
}
}
+
+ mBroadcastCount = -1;
}
}