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

Commit 33227a1a authored by Lucas Dupin's avatar Lucas Dupin Committed by android-build-merger
Browse files

Merge "Fix race condition in binder thread" into oc-dr1-dev am: 33e014b9

am: 45121454

Change-Id: I7046c488618436d74de6ddfb245801cefec191e3
parents 584a6c2a 45121454
Loading
Loading
Loading
Loading
+26 −26
Original line number Diff line number Diff line
@@ -115,6 +115,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
@@ -376,41 +377,40 @@ public class WallpaperManagerService extends IWallpaperManager.Stub {
    private void notifyColorListeners(@NonNull WallpaperColors wallpaperColors, int which,
            int userId) {
        final IWallpaperManagerCallback keyguardListener;
        final RemoteCallbackList<IWallpaperManagerCallback> currentUserColorListeners;
        final RemoteCallbackList<IWallpaperManagerCallback> userAllColorListeners;
        final ArrayList<IWallpaperManagerCallback> colorListeners = new ArrayList<>();
        synchronized (mLock) {
            currentUserColorListeners = mColorsChangedListeners.get(userId);
            userAllColorListeners = mColorsChangedListeners.get(UserHandle.USER_ALL);
            final RemoteCallbackList<IWallpaperManagerCallback> currentUserColorListeners =
                    mColorsChangedListeners.get(userId);
            final RemoteCallbackList<IWallpaperManagerCallback> userAllColorListeners =
                    mColorsChangedListeners.get(UserHandle.USER_ALL);
            keyguardListener = mKeyguardListener;
        }

            if (currentUserColorListeners != null) {
            int count = currentUserColorListeners.beginBroadcast();
                final int count = currentUserColorListeners.beginBroadcast();
                for (int i = 0; i < count; i++) {
                try {
                    currentUserColorListeners.getBroadcastItem(i)
                            .onWallpaperColorsChanged(wallpaperColors, which, userId);
                } catch (RemoteException e) {
                    // Callback is gone, it's not necessary to unregister it since
                    // RemoteCallbackList#getBroadcastItem will take care of it.
                }
                    colorListeners.add(currentUserColorListeners.getBroadcastItem(i));
                }
                currentUserColorListeners.finishBroadcast();
            }

            if (userAllColorListeners != null) {
            int count = userAllColorListeners.beginBroadcast();
                final int count = userAllColorListeners.beginBroadcast();
                for (int i = 0; i < count; i++) {
                    colorListeners.add(userAllColorListeners.getBroadcastItem(i));
                }
                userAllColorListeners.finishBroadcast();
            }
        }

        final int count = colorListeners.size();
        for (int i = 0; i < count; i++) {
            try {
                    userAllColorListeners.getBroadcastItem(i)
                            .onWallpaperColorsChanged(wallpaperColors, which, userId);
                colorListeners.get(i).onWallpaperColorsChanged(wallpaperColors, which, userId);
            } catch (RemoteException e) {
                // Callback is gone, it's not necessary to unregister it since
                // RemoteCallbackList#getBroadcastItem will take care of it.
            }
        }
            userAllColorListeners.finishBroadcast();
        }

        if (keyguardListener != null) {
            try {