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

Commit f0989840 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Fix pub issue #58043: Copy crash in Android 4.3...

...when clipboard listener attached

We need to clear the calling identity before dispatching change
notifications.  Also make this more robust, so that in the face
of any failure we will clean up the broadcast state.

Change-Id: I305a8a62738595f1fe5643a063099de5ed7cb062
parent 6077115d
Loading
Loading
Loading
Loading
+20 −15
Original line number Diff line number Diff line
@@ -154,15 +154,18 @@ public class ClipboardService extends IClipboard.Stub {
            if (clip != null && clip.getItemCount() <= 0) {
                throw new IllegalArgumentException("No items");
            }
            if (mAppOps.noteOp(AppOpsManager.OP_WRITE_CLIPBOARD, Binder.getCallingUid(),
            final int callingUid = Binder.getCallingUid();
            if (mAppOps.noteOp(AppOpsManager.OP_WRITE_CLIPBOARD, callingUid,
                    callingPackage) != AppOpsManager.MODE_ALLOWED) {
                return;
            }
            checkDataOwnerLocked(clip, Binder.getCallingUid());
            checkDataOwnerLocked(clip, callingUid);
            clearActiveOwnersLocked();
            PerUserClipboard clipboard = getClipboard();
            clipboard.primaryClip = clip;
            final long ident = Binder.clearCallingIdentity();
            final int n = clipboard.primaryClipListeners.beginBroadcast();
            try {
                for (int i = 0; i < n; i++) {
                    try {
                        ListenerInfo li = (ListenerInfo)
@@ -173,12 +176,14 @@ public class ClipboardService extends IClipboard.Stub {
                                    .dispatchPrimaryClipChanged();
                        }
                    } catch (RemoteException e) {

                        // The RemoteCallbackList will take care of removing
                        // the dead object for us.
                    }
                }
            } finally {
                clipboard.primaryClipListeners.finishBroadcast();
                Binder.restoreCallingIdentity(ident);
            }
        }
    }