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

Commit e2745a3b authored by Rubin Xu's avatar Rubin Xu Committed by android-build-merger
Browse files

Merge "Disallow copy & paste from personal to profile under policy" into pi-dev

am: 22d10bc5

Change-Id: Ie4cec95ab77024d92f0923600c341c6baa7707c1
parents 6568eec3 22d10bc5
Loading
Loading
Loading
Loading
+20 −8
Original line number Original line Diff line number Diff line
@@ -368,6 +368,19 @@ public class ClipboardService extends SystemService {
        return related;
        return related;
    }
    }


    /** Check if the user has the given restriction set. Default to true if error occured during
     * calling UserManager, so it fails safe.
     */
    private boolean hasRestriction(String restriction, int userId) {
        try {
            return mUm.hasUserRestriction(restriction, userId);
        } catch (RemoteException e) {
            Slog.e(TAG, "Remote Exception calling UserManager.getUserRestrictions: ", e);
            // Fails safe
            return true;
        }
    }

    void setPrimaryClipInternal(@Nullable ClipData clip, int callingUid) {
    void setPrimaryClipInternal(@Nullable ClipData clip, int callingUid) {
        // Push clipboard to host, if any
        // Push clipboard to host, if any
        if (mHostClipboardMonitor != null) {
        if (mHostClipboardMonitor != null) {
@@ -391,13 +404,8 @@ public class ClipboardService extends SystemService {
        if (related != null) {
        if (related != null) {
            int size = related.size();
            int size = related.size();
            if (size > 1) { // Related profiles list include the current profile.
            if (size > 1) { // Related profiles list include the current profile.
                boolean canCopy = false;
                final boolean canCopy = !hasRestriction(
                try {
                        UserManager.DISALLOW_CROSS_PROFILE_COPY_PASTE, userId);
                    canCopy = !mUm.getUserRestrictions(userId).getBoolean(
                            UserManager.DISALLOW_CROSS_PROFILE_COPY_PASTE);
                } catch (RemoteException e) {
                    Slog.e(TAG, "Remote Exception calling UserManager: " + e);
                }
                // Copy clip data to related users if allowed. If disallowed, then remove
                // Copy clip data to related users if allowed. If disallowed, then remove
                // primary clip in related users to prevent pasting stale content.
                // primary clip in related users to prevent pasting stale content.
                if (!canCopy) {
                if (!canCopy) {
@@ -416,12 +424,16 @@ public class ClipboardService extends SystemService {
                for (int i = 0; i < size; i++) {
                for (int i = 0; i < size; i++) {
                    int id = related.get(i).id;
                    int id = related.get(i).id;
                    if (id != userId) {
                    if (id != userId) {
                        final boolean canCopyIntoProfile = !hasRestriction(
                                UserManager.DISALLOW_SHARE_INTO_MANAGED_PROFILE, id);
                        if (canCopyIntoProfile) {
                            setPrimaryClipInternal(getClipboard(id), clip, callingUid);
                            setPrimaryClipInternal(getClipboard(id), clip, callingUid);
                        }
                        }
                    }
                    }
                }
                }
            }
            }
        }
        }
    }


    void setPrimaryClipInternal(PerUserClipboard clipboard, @Nullable ClipData clip,
    void setPrimaryClipInternal(PerUserClipboard clipboard, @Nullable ClipData clip,
            int callingUid) {
            int callingUid) {