From 380687e41d8a2db5d5a5ed6a9e8cf78916e93378 Mon Sep 17 00:00:00 2001 From: Nate Myren Date: Tue, 3 Jan 2023 16:52:29 -0800 Subject: [PATCH] Add clipboard access APIs to ClipboardManager Add @SystemApis in ClipboardManager that allow the getting and setting of the Clipboard Access Notification enable state. Bug: 263305143 Test: manual Change-Id: Ief0fb902af89be19e2b67f40c1cfbe82f0cab6e0 --- core/api/system-current.txt | 3 ++ .../android/content/ClipboardManager.java | 33 ++++++++++++++ core/java/android/content/IClipboard.aidl | 4 ++ core/res/AndroidManifest.xml | 7 +++ .../server/clipboard/ClipboardService.java | 45 +++++++++++++++++++ 5 files changed, 92 insertions(+) diff --git a/core/api/system-current.txt b/core/api/system-current.txt index 95e331e98ee9f..7f4b7b50e758f 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -173,6 +173,7 @@ package android { field public static final String MANAGE_BLUETOOTH_WHEN_WIRELESS_CONSENT_REQUIRED = "android.permission.MANAGE_BLUETOOTH_WHEN_WIRELESS_CONSENT_REQUIRED"; field public static final String MANAGE_CARRIER_OEM_UNLOCK_STATE = "android.permission.MANAGE_CARRIER_OEM_UNLOCK_STATE"; field public static final String MANAGE_CA_CERTIFICATES = "android.permission.MANAGE_CA_CERTIFICATES"; + field public static final String MANAGE_CLIPBOARD_ACCESS_NOTIFICATION = "android.permission.MANAGE_CLIPBOARD_ACCESS_NOTIFICATION"; field public static final String MANAGE_CLOUDSEARCH = "android.permission.MANAGE_CLOUDSEARCH"; field public static final String MANAGE_CONTENT_CAPTURE = "android.permission.MANAGE_CONTENT_CAPTURE"; field public static final String MANAGE_CONTENT_SUGGESTIONS = "android.permission.MANAGE_CONTENT_SUGGESTIONS"; @@ -3399,6 +3400,8 @@ package android.content { } public class ClipboardManager extends android.text.ClipboardManager { + method @RequiresPermission(android.Manifest.permission.MANAGE_CLIPBOARD_ACCESS_NOTIFICATION) public boolean areClipboardAccessNotificationsEnabled(); + method @RequiresPermission(android.Manifest.permission.MANAGE_CLIPBOARD_ACCESS_NOTIFICATION) public void setClipboardAccessNotificationsEnabled(boolean); method @RequiresPermission(android.Manifest.permission.SET_CLIP_SOURCE) public void setPrimaryClipAsPackage(@NonNull android.content.ClipData, @NonNull String); } diff --git a/core/java/android/content/ClipboardManager.java b/core/java/android/content/ClipboardManager.java index 06a3b1e1cc667..8a22ce3a75f87 100644 --- a/core/java/android/content/ClipboardManager.java +++ b/core/java/android/content/ClipboardManager.java @@ -134,6 +134,39 @@ public class ClipboardManager extends android.text.ClipboardManager { ServiceManager.getServiceOrThrow(Context.CLIPBOARD_SERVICE)); } + /** + * Determine if the Clipboard Access Notifications are enabled + * + * @return true if notifications are enabled, false otherwise. + * + * @hide + */ + @SystemApi + @RequiresPermission(Manifest.permission.MANAGE_CLIPBOARD_ACCESS_NOTIFICATION) + public boolean areClipboardAccessNotificationsEnabled() { + try { + return mService.areClipboardAccessNotificationsEnabledForUser(mContext.getUserId()); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + + /** + * + * Set the enable state of the Clipboard Access Notifications + * @param enable Whether to enable notifications + * @hide + */ + @SystemApi + @RequiresPermission(Manifest.permission.MANAGE_CLIPBOARD_ACCESS_NOTIFICATION) + public void setClipboardAccessNotificationsEnabled(boolean enable) { + try { + mService.setClipboardAccessNotificationsEnabledForUser(enable, mContext.getUserId()); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + /** * Sets the current primary clip on the clipboard. This is the clip that * is involved in normal cut and paste operations. diff --git a/core/java/android/content/IClipboard.aidl b/core/java/android/content/IClipboard.aidl index b2216d4953e6c..fe7798fb24a11 100644 --- a/core/java/android/content/IClipboard.aidl +++ b/core/java/android/content/IClipboard.aidl @@ -48,4 +48,8 @@ interface IClipboard { String getPrimaryClipSource(String callingPackage, String attributionTag, int userId, int deviceId); + + boolean areClipboardAccessNotificationsEnabledForUser(int userId); + + void setClipboardAccessNotificationsEnabledForUser(boolean enable, int userId); } diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml index e9771a9dcb7fb..4da978bf4c990 100644 --- a/core/res/AndroidManifest.xml +++ b/core/res/AndroidManifest.xml @@ -7107,6 +7107,13 @@ @hide Not for use by third-party applications. --> + + + +