OSDN Git Service

Fix issue #35813031: API Review: RemoteCallbackList
authorDianne Hackborn <hackbod@google.com>
Sat, 4 Mar 2017 00:03:01 +0000 (16:03 -0800)
committerDianne Hackborn <hackbod@google.com>
Sat, 4 Mar 2017 00:13:25 +0000 (16:13 -0800)
Review comments addressed:

- Docs fixed.
- getRegisteredCallbackItem() added.

Test: booted system

Change-Id: Ib5228c566eedc5dcf72933bb375eba4257293cfc

api/current.txt
api/system-current.txt
api/test-current.txt
core/java/android/os/RemoteCallbackList.java

index 9c443f8..8639ae2 100644 (file)
@@ -31104,6 +31104,7 @@ package android.os {
     method public E getBroadcastItem(int);
     method public java.lang.Object getRegisteredCallbackCookie(int);
     method public int getRegisteredCallbackCount();
+    method public E getRegisteredCallbackItem(int);
     method public void kill();
     method public void onCallbackDied(E);
     method public void onCallbackDied(E, java.lang.Object);
index eb237fa..f2055d9 100644 (file)
@@ -33755,6 +33755,7 @@ package android.os {
     method public E getBroadcastItem(int);
     method public java.lang.Object getRegisteredCallbackCookie(int);
     method public int getRegisteredCallbackCount();
+    method public E getRegisteredCallbackItem(int);
     method public void kill();
     method public void onCallbackDied(E);
     method public void onCallbackDied(E, java.lang.Object);
index ccf688c..3ded1fb 100644 (file)
@@ -31222,6 +31222,7 @@ package android.os {
     method public E getBroadcastItem(int);
     method public java.lang.Object getRegisteredCallbackCookie(int);
     method public int getRegisteredCallbackCount();
+    method public E getRegisteredCallbackItem(int);
     method public void kill();
     method public void onCallbackDied(E);
     method public void onCallbackDied(E, java.lang.Object);
index 819afb4..9db58ee 100644 (file)
@@ -329,15 +329,38 @@ public class RemoteCallbackList<E extends IInterface> {
     }
 
     /**
-     * Return the cookies associated with a currently registered callback.  Note that this is
+     * Return a currently registered callback.  Note that this is
+     * <em>not</em> the same as {@link #getBroadcastItem} and should not be used
+     * interchangeably with it.  This method returns the registered callback at the given
+     * index, not the current broadcast state.  This means that it is not itself thread-safe:
+     * any call to {@link #register} or {@link #unregister} will change these indices, so you
+     * must do your own thread safety between these to protect from such changes.
+     *
+     * @param index Index of which callback registration to return, from 0 to
+     * {@link #getRegisteredCallbackCount()} - 1.
+     *
+     * @return Returns whatever callback is associated with this index, or null if
+     * {@link #kill()} has been called.
+     */
+    public E getRegisteredCallbackItem(int index) {
+        synchronized (mCallbacks) {
+            if (mKilled) {
+                return null;
+            }
+            return mCallbacks.valueAt(index).mCallback;
+        }
+    }
+
+    /**
+     * Return any cookie associated with a currently registered callback.  Note that this is
      * <em>not</em> the same as {@link #getBroadcastCookie} and should not be used
-     * interchangeably with it.  This method returns the current cookied registered at the given
+     * interchangeably with it.  This method returns the current cookie registered at the given
      * index, not the current broadcast state.  This means that it is not itself thread-safe:
      * any call to {@link #register} or {@link #unregister} will change these indices, so you
      * must do your own thread safety between these to protect from such changes.
      *
-     * @param index Index of which registration cookie to return from 0 to
-     * {@link #getRegisteredCallbackCount()}.
+     * @param index Index of which registration cookie to return, from 0 to
+     * {@link #getRegisteredCallbackCount()} - 1.
      *
      * @return Returns whatever cookie object is associated with this index, or null if
      * {@link #kill()} has been called.