Don't append userIds for the current user's clipData uris.
If the primary user has a managed profile:
When setting the clipboard in the primary user:
The uris of the primary user's clipboard must not have an
embedded userId.
BUG:28572936
Change-Id: I1eb505c4518cc16a6513b950f6c2b1232a22426d
diff --git a/core/java/android/content/ClipData.java b/core/java/android/content/ClipData.java
index c365e9e..d9816a6 100644
--- a/core/java/android/content/ClipData.java
+++ b/core/java/android/content/ClipData.java
@@ -191,6 +191,14 @@
final Intent mIntent;
Uri mUri;
+ /** @hide */
+ public Item(Item other) {
+ mText = other.mText;
+ mHtmlText = other.mHtmlText;
+ mIntent = other.mIntent;
+ mUri = other.mUri;
+ }
+
/**
* Create an Item consisting of a single block of (possibly styled) text.
*/
@@ -816,6 +824,11 @@
return mItems.get(index);
}
+ /** @hide */
+ public void setItemAt(int index, Item item) {
+ mItems.set(index, item);
+ }
+
/**
* Prepare this {@link ClipData} to leave an app process.
*
diff --git a/services/core/java/com/android/server/clipboard/ClipboardService.java b/services/core/java/com/android/server/clipboard/ClipboardService.java
index 1c26846..66aa403 100644
--- a/services/core/java/com/android/server/clipboard/ClipboardService.java
+++ b/services/core/java/com/android/server/clipboard/ClipboardService.java
@@ -188,6 +188,14 @@
if (!canCopy) {
clip = null;
} else {
+ // We want to fix the uris of the related user's clip without changing the
+ // uris of the current user's clip.
+ // So, copy the ClipData, and then copy all the items, so that nothing
+ // is shared in memmory.
+ clip = new ClipData(clip);
+ for (int i = clip.getItemCount() - 1; i >= 0; i--) {
+ clip.setItemAt(i, new ClipData.Item(clip.getItemAt(i)));
+ }
clip.fixUrisLight(userId);
}
for (int i = 0; i < size; i++) {