Store package name instead of label in clipboard.

This stores the source package of a clip rather than the app
label (as added in a recent change). This is so that if the
device locale is changed, the label shown in the clipboard
access is correctly localised.

Bug: 180579171
Test: manual test, copy from Settings and from share sheet and observe
toast when pasting

Change-Id: Ib54ce8ae99fa714c5d767c260e0629dc000ea7d1
This commit is contained in:
Oli Lan
2021-02-26 11:47:56 +00:00
parent 40321b70da
commit 54369d2029

View File

@@ -246,8 +246,8 @@ public class ClipboardService extends SystemService {
ClipData primaryClip;
/** UID that set {@link #primaryClip}. */
int primaryClipUid = android.os.Process.NOBODY_UID;
/** Application label of the app that set {@link #primaryClip}. */
CharSequence mPrimaryClipAppLabel;
/** Package of the app that set {@link #primaryClip}. */
String mPrimaryClipPackage;
final HashSet<String> activePermissionOwners
= new HashSet<String>();
@@ -528,20 +528,9 @@ public class ClipboardService extends SystemService {
}
}
// Retrieve the app label of the source of the clip data
CharSequence sourceAppLabel = null;
if (clip != null && sourcePackage != null) {
try {
sourceAppLabel =
mPm.getApplicationLabel(mPm.getApplicationInfo(sourcePackage, 0));
} catch (PackageManager.NameNotFoundException e) {
// leave label as null
}
}
// Update this user
final int userId = UserHandle.getUserId(uid);
setPrimaryClipInternal(getClipboard(userId), clip, uid, sourceAppLabel);
setPrimaryClipInternal(getClipboard(userId), clip, uid, sourcePackage);
// Update related users
List<UserInfo> related = getRelatedProfiles(userId);
@@ -576,7 +565,7 @@ public class ClipboardService extends SystemService {
UserManager.DISALLOW_SHARE_INTO_MANAGED_PROFILE, id);
if (canCopyIntoProfile) {
setPrimaryClipInternal(
getClipboard(id), clip, uid, sourceAppLabel);
getClipboard(id), clip, uid, sourcePackage);
}
}
}
@@ -590,7 +579,7 @@ public class ClipboardService extends SystemService {
}
private void setPrimaryClipInternal(PerUserClipboard clipboard, @Nullable ClipData clip,
int uid, @Nullable CharSequence sourceAppLabel) {
int uid, @Nullable String sourcePackage) {
revokeUris(clipboard);
clipboard.activePermissionOwners.clear();
if (clip == null && clipboard.primaryClip == null) {
@@ -599,10 +588,10 @@ public class ClipboardService extends SystemService {
clipboard.primaryClip = clip;
if (clip != null) {
clipboard.primaryClipUid = uid;
clipboard.mPrimaryClipAppLabel = sourceAppLabel;
clipboard.mPrimaryClipPackage = sourcePackage;
} else {
clipboard.primaryClipUid = android.os.Process.NOBODY_UID;
clipboard.mPrimaryClipAppLabel = null;
clipboard.mPrimaryClipPackage = null;
}
if (clip != null) {
final ClipDescription description = clip.getDescription();
@@ -887,12 +876,23 @@ public class ClipboardService extends SystemService {
return;
}
// Retrieve the app label of the source of the clip data
CharSequence sourceAppLabel = null;
if (clipboard.mPrimaryClipPackage != null) {
try {
sourceAppLabel = mPm.getApplicationLabel(
mPm.getApplicationInfo(clipboard.mPrimaryClipPackage, 0));
} catch (PackageManager.NameNotFoundException e) {
// leave label as null
}
}
try {
CharSequence callingAppLabel = mPm.getApplicationLabel(
mPm.getApplicationInfo(callingPackage, 0));
String message;
if (clipboard.mPrimaryClipAppLabel != null) {
message = callingAppLabel + " pasted from " + clipboard.mPrimaryClipAppLabel;
if (sourceAppLabel != null) {
message = callingAppLabel + " pasted from " + sourceAppLabel;
} else {
message = callingAppLabel + " pasted from clipboard";
}