Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cc9a4c4a authored by Oli Lan's avatar Oli Lan
Browse files

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
parent 6681a152
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -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;
+9 −9
Original line number Diff line number Diff line
@@ -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<PerUserClipboard> 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.