summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChad Brubaker <cbrubaker@google.com>2018-10-01 10:38:54 -0700
committerChad Brubaker <cbrubaker@google.com>2018-10-01 16:11:20 -0700
commitbd175fe89132d5dbde1bf92d683eea22236c51fb (patch)
tree208972f534321a439f07dcff60faaf1fa8971102
parent1ec3af056e0d993bcb869cf10635d527a692593b (diff)
Allow Shell to access the clipboard
A lot of CTS tests involve the clipboard and making all of them input focus is somewhat wasteful and invasive, instead we will adopt the shell's permissions when relevant. Test: atest ClipboardManagerTest Bug: 6229949 Change-Id: I10f07e89b0baead625464c2afd5da1e229a45473
-rw-r--r--core/res/AndroidManifest.xml5
-rw-r--r--packages/Shell/AndroidManifest.xml1
-rw-r--r--services/core/java/com/android/server/clipboard/ClipboardService.java5
3 files changed, 11 insertions, 0 deletions
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index 9acb08b25db2..73c9ea86cd34 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -4147,6 +4147,11 @@
<permission android:name="android.permission.BIND_SMS_APP_SERVICE"
android:protectionLevel="signature" />
+ <!-- @hide Permission that allows background clipboard access.
+ <p>Not for use by third-party applications. -->
+ <permission android:name="android.permission.READ_CLIPBOARD_IN_BACKGROUND"
+ android:protectionLevel="signature" />
+
<application android:process="system"
android:persistent="true"
android:hasCode="false"
diff --git a/packages/Shell/AndroidManifest.xml b/packages/Shell/AndroidManifest.xml
index da870bd134bf..5c654b44d1dc 100644
--- a/packages/Shell/AndroidManifest.xml
+++ b/packages/Shell/AndroidManifest.xml
@@ -151,6 +151,7 @@
<uses-permission android:name="android.permission.CONTROL_KEYGUARD" />
<uses-permission android:name="android.permission.SUSPEND_APPS" />
+ <uses-permission android:name="android.permission.READ_CLIPBOARD_IN_BACKGROUND" />
<application android:label="@string/app_label"
android:defaultToDeviceProtectedStorage="true"
diff --git a/services/core/java/com/android/server/clipboard/ClipboardService.java b/services/core/java/com/android/server/clipboard/ClipboardService.java
index 873a8e314bb1..a769590447ab 100644
--- a/services/core/java/com/android/server/clipboard/ClipboardService.java
+++ b/services/core/java/com/android/server/clipboard/ClipboardService.java
@@ -629,6 +629,11 @@ public class ClipboardService extends SystemService {
if (mAppOps.noteOp(op, callingUid, callingPackage) != AppOpsManager.MODE_ALLOWED) {
return false;
}
+ // Shell can access the clipboard for testing purposes.
+ if (mPm.checkPermission(android.Manifest.permission.READ_CLIPBOARD_IN_BACKGROUND,
+ callingPackage) == PackageManager.PERMISSION_GRANTED) {
+ return true;
+ }
// The default IME is always allowed to access the clipboard.
String defaultIme = Settings.Secure.getStringForUser(getContext().getContentResolver(),
Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.getUserId(callingUid));