Do not throw SecurityException from getPrimaryClip.
Currently getPrimaryClip throws a SecurityException if a Uri in clipboard has become invalid and permission to it can no longer be granted. This is unexpected and can crash apps that are trying to paste. This change catches the exception and clears clipboard if this case occurs. Bug: 187942504 Test: atest android.appsecurity.cts.AppSecurityTests#testPermissionDiffCert Test: build & flash, create invalid Uri by uninstalling and reinstalling Chrome Change-Id: I9994bb03f1aed47e32a500bba8886eea3f2cd905
This commit is contained in:
@@ -379,7 +379,15 @@ public class ClipboardService extends SystemService {
|
||||
return null;
|
||||
}
|
||||
synchronized (mLock) {
|
||||
addActiveOwnerLocked(intendingUid, pkg);
|
||||
try {
|
||||
addActiveOwnerLocked(intendingUid, pkg);
|
||||
} catch (SecurityException e) {
|
||||
// Permission could not be granted - URI may be invalid
|
||||
Slog.i(TAG, "Could not grant permission to primary clip. Clearing clipboard.");
|
||||
setPrimaryClipInternalLocked(null, intendingUid, pkg);
|
||||
return null;
|
||||
}
|
||||
|
||||
PerUserClipboard clipboard = getClipboardLocked(intendingUserId);
|
||||
showAccessNotificationLocked(pkg, intendingUid, intendingUserId, clipboard);
|
||||
notifyTextClassifierLocked(clipboard, pkg, intendingUid);
|
||||
|
||||
Reference in New Issue
Block a user