Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 59359d06 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Fix issue #35813031: API Review: RemoteCallbackList

Review comments addressed:

- Docs fixed.
- getRegisteredCallbackItem() added.

Test: booted system

Change-Id: Ib5228c566eedc5dcf72933bb375eba4257293cfc
parent 5603a16e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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);
+1 −0
Original line number Diff line number Diff line
@@ -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);
+1 −0
Original line number Diff line number Diff line
@@ -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);
+27 −4
Original line number Diff line number Diff line
@@ -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.