diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml
index 7ea762c2fbbb3..4d43943d022cd 100644
--- a/core/res/res/values/strings.xml
+++ b/core/res/res/values/strings.xml
@@ -2802,6 +2802,15 @@
%1$s pasted from clipboard
+
+ %1$s pasted text you copied
+
+
+ %1$s pasted an image you copied
+
+
+ %1$s pasted content you copied
+
More
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index 1d74d85fb9db6..b7d132ec1c593 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -560,6 +560,9 @@
+
+
+
diff --git a/services/core/java/com/android/server/clipboard/ClipboardService.java b/services/core/java/com/android/server/clipboard/ClipboardService.java
index 71565301e3ed1..2fbae81ce4c96 100644
--- a/services/core/java/com/android/server/clipboard/ClipboardService.java
+++ b/services/core/java/com/android/server/clipboard/ClipboardService.java
@@ -1044,27 +1044,16 @@ public class ClipboardService extends SystemService {
clipboard.mNotifiedUids.put(uid, true);
Binder.withCleanCallingIdentity(() -> {
- // Retrieve the app label of the source of the clip data
- CharSequence sourceAppLabel = null;
- if (clipboard.mPrimaryClipPackage != null) {
- try {
- sourceAppLabel = mPm.getApplicationLabel(mPm.getApplicationInfoAsUser(
- clipboard.mPrimaryClipPackage, 0, userId));
- } catch (PackageManager.NameNotFoundException e) {
- // leave label as null
- }
- }
-
try {
CharSequence callingAppLabel = mPm.getApplicationLabel(
mPm.getApplicationInfoAsUser(callingPackage, 0, userId));
String message;
- if (sourceAppLabel != null) {
+ if (isText(clipboard.primaryClip)) {
message = getContext().getString(
- R.string.pasted_from_app, callingAppLabel, sourceAppLabel);
+ R.string.pasted_text, callingAppLabel);
} else {
message = getContext().getString(
- R.string.pasted_from_clipboard, callingAppLabel);
+ R.string.pasted_content, callingAppLabel);
}
Slog.i(TAG, message);
Toast.makeText(
@@ -1075,4 +1064,21 @@ public class ClipboardService extends SystemService {
}
});
}
+
+ /**
+ * Returns true if the provided {@link ClipData} represents a single piece of text. That is, if
+ * there is only on {@link ClipData.Item}, and that item contains a non-empty piece of text and
+ * no URI or Intent. Note that HTML may be provided along with text so the presence of
+ * HtmlText in the clip does not prevent this method returning true.
+ */
+ private static boolean isText(@NonNull ClipData data) {
+ if (data.getItemCount() > 1) {
+ return false;
+ }
+ ClipData.Item item = data.getItemAt(0);
+
+ return !TextUtils.isEmpty(item.getText()) && item.getUri() == null
+ && item.getIntent() == null;
+ }
+
}