Only notify about clipboard access once per clip per app.

This limits the toast notification "<app> pasted from <source>"
to be shown only once per clip per app/user.

Bug: 171640049
Test: Manual, copy from one app then paste multiple times in another.
Check that other apps still display message the first time when pasting.

Change-Id: Ida66bce0301116e0236e0acced6550cafa13ac39
This commit is contained in:
Oli Lan
2021-03-05 18:17:13 +00:00
parent a644b68892
commit f1a34e47c0

View File

@@ -57,6 +57,7 @@ import android.provider.Settings;
import android.text.TextUtils;
import android.util.Slog;
import android.util.SparseArray;
import android.util.SparseBooleanArray;
import android.view.autofill.AutofillManagerInternal;
import android.widget.Toast;
@@ -273,6 +274,9 @@ public class ClipboardService extends SystemService {
/** Package of the app that set {@link #primaryClip}. */
String mPrimaryClipPackage;
/** Uids that have already triggered a toast notification for {@link #primaryClip} */
final SparseBooleanArray mNotifiedUids = new SparseBooleanArray();
final HashSet<String> activePermissionOwners
= new HashSet<String>();
@@ -648,6 +652,7 @@ public class ClipboardService extends SystemService {
return;
}
clipboard.primaryClip = clip;
clipboard.mNotifiedUids.clear();
if (clip != null) {
clipboard.primaryClipUid = uid;
clipboard.mPrimaryClipPackage = sourcePackage;
@@ -938,6 +943,11 @@ public class ClipboardService extends SystemService {
&& mAutofillInternal.isAugmentedAutofillServiceForUser(uid, userId)) {
return;
}
// Don't notify if already notified for this uid and clip.
if (clipboard.mNotifiedUids.get(uid)) {
return;
}
clipboard.mNotifiedUids.put(uid, true);
// Retrieve the app label of the source of the clip data
CharSequence sourceAppLabel = null;