summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Oli Lan <olilan@google.com> 2021-03-10 11:19:55 +0000
committer Oli Lan <olilan@google.com> 2021-03-11 12:39:57 +0000
commitfddbb49c013f00b3f2d368179b7144ac7b06d10c (patch)
tree1abbb7430fa2866320435ffb20736f4513e44e34
parentbc80405a5e8c4d8e1d7d4873889c4fe2b216ef7d (diff)
Clear calling identity before retrieving app label for clipboard toast.
This fixes an issue where the source app in the clipboard access toast was not displayed for apps targeting API 30+. This is because the calling identity of the copying app was being used, resulting in package visibility limitations being applied. Bug: 182349975 Test: Manual, install app targeting API 30 and paste from another app. Test: atest ClipboardManagerTest Test: atest ManagedProfileCrossProfileTest#testCrossProfileCopyPaste Change-Id: Icdd2d07a3e2855dba749dbbb3427fd3a8b217671
-rw-r--r--services/core/java/com/android/server/clipboard/ClipboardService.java54
1 files changed, 28 insertions, 26 deletions
diff --git a/services/core/java/com/android/server/clipboard/ClipboardService.java b/services/core/java/com/android/server/clipboard/ClipboardService.java
index e0d1375b4069..6712c5474921 100644
--- a/services/core/java/com/android/server/clipboard/ClipboardService.java
+++ b/services/core/java/com/android/server/clipboard/ClipboardService.java
@@ -950,34 +950,36 @@ public class ClipboardService extends SystemService {
}
clipboard.mNotifiedUids.put(uid, true);
- // 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
+ 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) {
- message = getContext().getString(
- R.string.pasted_from_app, callingAppLabel, sourceAppLabel);
- } else {
- message = getContext().getString(R.string.pasted_from_clipboard, callingAppLabel);
+ try {
+ CharSequence callingAppLabel = mPm.getApplicationLabel(
+ mPm.getApplicationInfoAsUser(callingPackage, 0, userId));
+ String message;
+ if (sourceAppLabel != null) {
+ message = getContext().getString(
+ R.string.pasted_from_app, callingAppLabel, sourceAppLabel);
+ } else {
+ message = getContext().getString(
+ R.string.pasted_from_clipboard, callingAppLabel);
+ }
+ Slog.i(TAG, message);
+ Toast.makeText(
+ getContext(), UiThread.get().getLooper(), message, Toast.LENGTH_SHORT)
+ .show();
+ } catch (PackageManager.NameNotFoundException e) {
+ // do nothing
}
- Slog.i(TAG, message);
- Binder.withCleanCallingIdentity(() ->
- Toast.makeText(getContext(), UiThread.get().getLooper(), message,
- Toast.LENGTH_SHORT)
- .show());
- } catch (PackageManager.NameNotFoundException e) {
- // do nothing
- }
+ });
}
}