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

Commit 92e0291f authored by Chad Brubaker's avatar Chad Brubaker
Browse files

Allow apps to write to the clipboard without input focus

Blocking writes breaks common share UI flow in apps. Since common
write abuse cases rely on modifying the contents (e.g. injecting spam
links) only blocking reads still gives the intended privacy properties.

Test: atest tests/tests/content/src/android/content/cts/ClipboardManagerTest.java
Fixes: 112844309

Change-Id: I18fdba192fcf9c8d3fb4cbaeaea1468657e5131e
parent 342df6dd
Loading
Loading
Loading
Loading
+0 −6
Original line number Diff line number Diff line
@@ -95,9 +95,6 @@ public class ClipboardManager extends android.text.ClipboardManager {
     * Sets the current primary clip on the clipboard.  This is the clip that
     * is involved in normal cut and paste operations.
     *
     * <em>If the application is not the default IME or does not have input focus this will have
     * no effect.</em>
     *
     * @param clip The clipped data item to set.
     * @see #getPrimaryClip()
     * @see #clearPrimaryClip()
@@ -115,9 +112,6 @@ public class ClipboardManager extends android.text.ClipboardManager {
    /**
     * Clears any current primary clip on the clipboard.
     *
     * <em>If the application is not the default IME or does not have input focus this will have
     * no effect.</em>
     *
     * @see #setPrimaryClip(ClipData)
     */
    public void clearPrimaryClip() {
+14 −6
Original line number Diff line number Diff line
@@ -634,12 +634,20 @@ public class ClipboardService extends SystemService {
            return true;
        }

        // Otherwise only focused applications can access the clipboard.
        switch (op) {
            case AppOpsManager.OP_READ_CLIPBOARD:
                // Clipboard can only be read by applications with focus.
                boolean uidFocused = mWm.isUidFocused(callingUid);
                if (!uidFocused) {
                    Slog.e(TAG, "Denying clipboard access to " + callingPackage
                            + ", application is not in focus.");
                }
                return uidFocused;
            case AppOpsManager.OP_WRITE_CLIPBOARD:
                // Writing is allowed without focus.
                return true;
            default:
                throw new IllegalArgumentException("Unknown clipboard appop " + op);
        }
    }
}