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

Commit 70973b7b authored by Dianne Hackborn's avatar Dianne Hackborn Committed by The Android Automerger
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 a34a64d2
Loading
Loading
Loading
Loading
+3 −2
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@


package android.app;
package android.app;


import android.R;
import com.android.internal.app.IUsageStats;
import com.android.internal.app.IUsageStats;
import com.android.internal.os.PkgUsageStats;
import com.android.internal.os.PkgUsageStats;
import com.android.internal.util.MemInfoReader;
import com.android.internal.util.MemInfoReader;
+20 −15
Original line number Original line Diff line number Diff line
@@ -154,15 +154,18 @@ public class ClipboardService extends IClipboard.Stub {
            if (clip != null && clip.getItemCount() <= 0) {
            if (clip != null && clip.getItemCount() <= 0) {
                throw new IllegalArgumentException("No items");
                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) {
                    callingPackage) != AppOpsManager.MODE_ALLOWED) {
                return;
                return;
            }
            }
            checkDataOwnerLocked(clip, Binder.getCallingUid());
            checkDataOwnerLocked(clip, callingUid);
            clearActiveOwnersLocked();
            clearActiveOwnersLocked();
            PerUserClipboard clipboard = getClipboard();
            PerUserClipboard clipboard = getClipboard();
            clipboard.primaryClip = clip;
            clipboard.primaryClip = clip;
            final long ident = Binder.clearCallingIdentity();
            final int n = clipboard.primaryClipListeners.beginBroadcast();
            final int n = clipboard.primaryClipListeners.beginBroadcast();
            try {
                for (int i = 0; i < n; i++) {
                for (int i = 0; i < n; i++) {
                    try {
                    try {
                        ListenerInfo li = (ListenerInfo)
                        ListenerInfo li = (ListenerInfo)
@@ -173,12 +176,14 @@ public class ClipboardService extends IClipboard.Stub {
                                    .dispatchPrimaryClipChanged();
                                    .dispatchPrimaryClipChanged();
                        }
                        }
                    } catch (RemoteException e) {
                    } catch (RemoteException e) {

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