From cc9a4c4a1481e93d54f80b333c9120bf8087be2c Mon Sep 17 00:00:00 2001 From: Oli Lan Date: Mon, 15 Mar 2021 16:33:49 +0000 Subject: Use a DeviceConfig property for the default value of the clipboard notification setting. This adds a DeviceConfig property to hold the default of the new setting to control whether notifications are shown when an app accesses clipboard. Bug: 182349993 Test: manual, "adb shell device_config put clipboard show_access_notifications false" and observe setting changes when not set manually; also check notifications shown when expected. Change-Id: I8c812793db405f0a55aa5ecbc20d893fc4a52bee --- core/java/android/content/ClipboardManager.java | 19 +++++++++++++++++++ .../android/server/clipboard/ClipboardService.java | 18 +++++++++--------- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/core/java/android/content/ClipboardManager.java b/core/java/android/content/ClipboardManager.java index cadbd609ff0b..11adfa3cecc0 100644 --- a/core/java/android/content/ClipboardManager.java +++ b/core/java/android/content/ClipboardManager.java @@ -51,6 +51,25 @@ import java.util.Objects; */ @SystemService(Context.CLIPBOARD_SERVICE) public class ClipboardManager extends android.text.ClipboardManager { + + /** + * DeviceConfig property, within the clipboard namespace, that determines whether notifications + * are shown when an app accesses clipboard. This may be overridden by a user-controlled + * setting. + * + * @hide + */ + public static final String DEVICE_CONFIG_SHOW_ACCESS_NOTIFICATIONS = + "show_access_notifications"; + + /** + * Default value for the DeviceConfig property that determines whether notifications are shown + * when an app accesses clipboard. + * + * @hide + */ + public static final boolean DEVICE_CONFIG_DEFAULT_SHOW_ACCESS_NOTIFICATIONS = true; + private final Context mContext; private final Handler mHandler; private final IClipboard mService; diff --git a/services/core/java/com/android/server/clipboard/ClipboardService.java b/services/core/java/com/android/server/clipboard/ClipboardService.java index 5bf15dc70ff9..b23830b1e9f8 100644 --- a/services/core/java/com/android/server/clipboard/ClipboardService.java +++ b/services/core/java/com/android/server/clipboard/ClipboardService.java @@ -31,6 +31,7 @@ import android.app.KeyguardManager; import android.app.UriGrantsManager; import android.content.ClipData; import android.content.ClipDescription; +import android.content.ClipboardManager; import android.content.ComponentName; import android.content.ContentProvider; import android.content.ContentResolver; @@ -176,8 +177,6 @@ public class ClipboardService extends SystemService { SystemProperties.getBoolean("ro.kernel.qemu", false); // DeviceConfig properties - private static final String PROPERTY_SHOW_ACCESS_NOTIFICATIONS = "show_access_notifications"; - private static final boolean DEFAULT_SHOW_ACCESS_NOTIFICATIONS = true; private static final String PROPERTY_MAX_CLASSIFICATION_LENGTH = "max_classification_length"; private static final int DEFAULT_MAX_CLASSIFICATION_LENGTH = 400; @@ -199,7 +198,8 @@ public class ClipboardService extends SystemService { private final SparseArray mClipboards = new SparseArray<>(); @GuardedBy("mLock") - private boolean mShowAccessNotifications = DEFAULT_SHOW_ACCESS_NOTIFICATIONS; + private boolean mShowAccessNotifications = + ClipboardManager.DEVICE_CONFIG_DEFAULT_SHOW_ACCESS_NOTIFICATIONS; @GuardedBy("mLock") private int mMaxClassificationLength = DEFAULT_MAX_CLASSIFICATION_LENGTH; @@ -269,8 +269,10 @@ public class ClipboardService extends SystemService { private void updateConfig() { synchronized (mLock) { - mShowAccessNotifications = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_CLIPBOARD, - PROPERTY_SHOW_ACCESS_NOTIFICATIONS, DEFAULT_SHOW_ACCESS_NOTIFICATIONS); + mShowAccessNotifications = DeviceConfig.getBoolean( + DeviceConfig.NAMESPACE_CLIPBOARD, + ClipboardManager.DEVICE_CONFIG_SHOW_ACCESS_NOTIFICATIONS, + ClipboardManager.DEVICE_CONFIG_DEFAULT_SHOW_ACCESS_NOTIFICATIONS); mMaxClassificationLength = DeviceConfig.getInt(DeviceConfig.NAMESPACE_CLIPBOARD, PROPERTY_MAX_CLASSIFICATION_LENGTH, DEFAULT_MAX_CLASSIFICATION_LENGTH); } @@ -1008,11 +1010,9 @@ public class ClipboardService extends SystemService { if (clipboard.primaryClip == null) { return; } - if (!mShowAccessNotifications) { - return; - } if (Settings.Secure.getInt(getContext().getContentResolver(), - Settings.Secure.CLIPBOARD_SHOW_ACCESS_NOTIFICATIONS, 1) == 0) { + Settings.Secure.CLIPBOARD_SHOW_ACCESS_NOTIFICATIONS, + (mShowAccessNotifications ? 1 : 0)) == 0) { return; } // Don't notify if the app accessing the clipboard is the same as the current owner. -- cgit v1.2.3-59-g8ed1b