From a2e7124ba9dbbe2508e2b7f6215905f78a110433 Mon Sep 17 00:00:00 2001 From: secrecyflag <96260868+secrecyflag@users.noreply.github.com> Date: Sat, 1 Apr 2023 20:05:44 -0400 Subject: [PATCH] configurable clipboard auto-clear timeout --- core/java/android/ext/settings/ClipboardConstants.java | 7 +++++++ core/java/android/ext/settings/ExtSettings.java | 4 ++++ .../com/android/server/clipboard/ClipboardService.java | 9 ++++----- 3 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 core/java/android/ext/settings/ClipboardConstants.java diff --git a/core/java/android/ext/settings/ClipboardConstants.java b/core/java/android/ext/settings/ClipboardConstants.java new file mode 100644 index 000000000000..fb9faf2cfe1e --- /dev/null +++ b/core/java/android/ext/settings/ClipboardConstants.java @@ -0,0 +1,7 @@ +package android.ext.settings; + +/** @hide */ +public class ClipboardConstants { + // From com.android.server.clipboard.ClipboardService.DEFAULT_CLIPBOARD_TIMEOUT_MILLIS + public static final int DEFAULT_CLIPBOARD_TIMEOUT_MILLIS = 3600000; +} diff --git a/core/java/android/ext/settings/ExtSettings.java b/core/java/android/ext/settings/ExtSettings.java index 95357db151ad..89b3d65b1304 100644 --- a/core/java/android/ext/settings/ExtSettings.java +++ b/core/java/android/ext/settings/ExtSettings.java @@ -3,6 +3,7 @@ import java.lang.reflect.Field; import java.util.Set; +import static android.ext.settings.ClipboardConstants.DEFAULT_CLIPBOARD_TIMEOUT_MILLIS; import static android.ext.settings.GnssConstants.SUPL_DISABLED; import static android.ext.settings.GnssConstants.SUPL_SERVER_GRAPHENEOS_PROXY; import static android.ext.settings.GnssConstants.SUPL_SERVER_STANDARD; @@ -31,6 +32,9 @@ public class ExtSettings { public static final BoolSetting SCRAMBLE_PIN_LAYOUT = new BoolSetting( Setting.Scope.PER_USER, "lockscreen_scramble_pin_layout", false); + public static final IntSetting CLIPBOARD_AUTO_CLEAR_TIMEOUT = new IntSetting( + Setting.Scope.PER_USER, "clipboard_auto_clear_timeout", DEFAULT_CLIPBOARD_TIMEOUT_MILLIS); + private ExtSettings() {} // used for making settings defined in this class unreadable by third-party apps diff --git a/services/core/java/com/android/server/clipboard/ClipboardService.java b/services/core/java/com/android/server/clipboard/ClipboardService.java index 6f9a17682dd7..48e9591136d3 100644 --- a/services/core/java/com/android/server/clipboard/ClipboardService.java +++ b/services/core/java/com/android/server/clipboard/ClipboardService.java @@ -43,6 +43,7 @@ import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.UserInfo; +import android.ext.settings.ExtSettings; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Binder; @@ -421,17 +422,15 @@ private void scheduleAutoClear(@UserIdInt int userId, int intendingUid) { intendingUid, userId); mClipboardClearHandler.sendMessageDelayed(clearMessage, - getTimeoutForAutoClear()); + getTimeoutForAutoClear(userId)); } } finally { Binder.restoreCallingIdentity(oldIdentity); } } - private long getTimeoutForAutoClear() { - return DeviceConfig.getLong(DeviceConfig.NAMESPACE_CLIPBOARD, - PROPERTY_AUTO_CLEAR_TIMEOUT, - DEFAULT_CLIPBOARD_TIMEOUT_MILLIS); + private long getTimeoutForAutoClear(int userId) { + return ExtSettings.CLIPBOARD_AUTO_CLEAR_TIMEOUT.get(getContext(), userId); } @Override