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

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

(DO NOT MERGE) 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.

Integrated from master.

Change-Id: I05e1f76ffd486439535631fe4062dabe94bd2ccf
parent 38d4cfd4
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.app;

import android.R;
import com.android.internal.app.IUsageStats;
import com.android.internal.os.PkgUsageStats;
import com.android.internal.util.MemInfoReader;
+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);
            }
        }
    }