Java Code Examples for android.os.RemoteCallbackList#finishBroadcast()

The following examples show how to use android.os.RemoteCallbackList#finishBroadcast() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WallpaperVisibilityListeners.java    From android_9.0.0_r45 with Apache License 2.0 7 votes vote down vote up
void notifyWallpaperVisibilityChanged(DisplayContent displayContent) {
    final int displayId = displayContent.getDisplayId();
    final boolean visible = displayContent.mWallpaperController.isWallpaperVisible();
    RemoteCallbackList<IWallpaperVisibilityListener> displayListeners =
            mDisplayListeners.get(displayId);

    // No listeners for this display.
    if (displayListeners == null) {
        return;
    }

    int i = displayListeners.beginBroadcast();
    while (i > 0) {
        i--;
        IWallpaperVisibilityListener listener = displayListeners.getBroadcastItem(i);
        try {
            listener.onWallpaperVisibilityChanged(visible, displayId);
        } catch (RemoteException e) {
            // Nothing to do in here, RemoteCallbackListener will clean it up.
        }
    }
    displayListeners.finishBroadcast();
}
 
Example 2
Source File: NetworkScoreService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void sendCacheUpdateCallback(BiConsumer<INetworkScoreCache, Object> consumer,
        Collection<RemoteCallbackList<INetworkScoreCache>> remoteCallbackLists) {
    for (RemoteCallbackList<INetworkScoreCache> callbackList : remoteCallbackLists) {
        synchronized (callbackList) { // Ensure only one active broadcast per RemoteCallbackList
            final int count = callbackList.beginBroadcast();
            try {
                for (int i = 0; i < count; i++) {
                    consumer.accept(callbackList.getBroadcastItem(i),
                            callbackList.getBroadcastCookie(i));
                }
            } finally {
                callbackList.finishBroadcast();
            }
        }
    }
}
 
Example 3
Source File: ExternalOpenVPNService.java    From android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void handleMessage(Message msg) {

    RemoteCallbackList<IOpenVPNStatusCallback> callbacks;
    switch (msg.what) {
        case SEND_TOALL:
            if (service == null || service.get() == null)
                return;

            callbacks = service.get().mCallbacks;


            // Broadcast to all clients the new value.
            final int N = callbacks.beginBroadcast();
            for (int i = 0; i < N; i++) {
                try {
                    sendUpdate(callbacks.getBroadcastItem(i), (UpdateMessage) msg.obj);
                } catch (RemoteException e) {
                    // The RemoteCallbackList will take care of removing
                    // the dead object for us.
                }
            }
            callbacks.finishBroadcast();
            break;
    }
}
 
Example 4
Source File: OpenVPNStatusService.java    From bitmask_android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void handleMessage(Message msg) {

    RemoteCallbackList<IStatusCallbacks> callbacks;
    if (service == null || service.get() == null)
        return;
    callbacks = service.get().mCallbacks;
    // Broadcast to all clients the new value.
    final int N = callbacks.beginBroadcast();
    for (int i = 0; i < N; i++) {

        try {
            IStatusCallbacks broadcastItem = callbacks.getBroadcastItem(i);

            switch (msg.what) {
                case SEND_NEW_LOGITEM:
                    broadcastItem.newLogItem((LogItem) msg.obj);
                    break;
                case SEND_NEW_BYTECOUNT:
                    Pair<Long, Long> inout = (Pair<Long, Long>) msg.obj;
                    broadcastItem.updateByteCount(inout.first, inout.second);
                    break;
                case SEND_NEW_STATE:
                    sendUpdate(broadcastItem, (UpdateMessage) msg.obj);
                    break;

                case SEND_NEW_CONNECTED_VPN:
                    broadcastItem.connectedVPN((String) msg.obj);
                    break;
            }
        } catch (RemoteException e) {
            // The RemoteCallbackList will take care of removing
            // the dead object for us.
        }
    }
    callbacks.finishBroadcast();
}