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

Commit 99ef6d25 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Revert "Convert clipboard access to use new APIs"" into main

parents b09c5aea 3dc6a7f6
Loading
Loading
Loading
Loading
+17 −7
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.settings.privacy;
import android.content.ClipboardManager;
import android.content.Context;
import android.provider.DeviceConfig;
import android.provider.Settings;

import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
@@ -37,25 +38,26 @@ public class ShowClipAccessNotificationPreferenceController

    private static final String KEY_SHOW_CLIP_ACCESS_NOTIFICATION = "show_clip_access_notification";

    private Preference mPreference;
    private final ClipboardManager mClipboardManager;
    private final DeviceConfig.OnPropertiesChangedListener mDeviceConfigListener =
            properties -> updateState(mPreference);
            properties -> updateConfig();
    private boolean mDefault;
    private Preference mPreference;

    public ShowClipAccessNotificationPreferenceController(Context context) {
        super(context, KEY_SHOW_CLIP_ACCESS_NOTIFICATION);
        mClipboardManager = context.getSystemService(ClipboardManager.class);
        updateState(mPreference);
        updateConfig();
    }

    @Override
    public boolean isChecked() {
        return mClipboardManager.areClipboardAccessNotificationsEnabled();
        return Settings.Secure.getInt(mContext.getContentResolver(),
                Settings.Secure.CLIPBOARD_SHOW_ACCESS_NOTIFICATIONS, (mDefault ? 1 : 0)) != 0;
    }

    @Override
    public boolean setChecked(boolean isChecked) {
        mClipboardManager.setClipboardAccessNotificationsEnabled(isChecked);
        Settings.Secure.putInt(mContext.getContentResolver(),
                Settings.Secure.CLIPBOARD_SHOW_ACCESS_NOTIFICATIONS, (isChecked ? 1 : 0));
        return true;
    }

@@ -92,4 +94,12 @@ public class ShowClipAccessNotificationPreferenceController
    public void onStop() {
        DeviceConfig.removeOnPropertiesChangedListener(mDeviceConfigListener);
    }

    private void updateConfig() {
        mDefault = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_CLIPBOARD,
                ClipboardManager.DEVICE_CONFIG_SHOW_ACCESS_NOTIFICATIONS,
                ClipboardManager.DEVICE_CONFIG_DEFAULT_SHOW_ACCESS_NOTIFICATIONS);
        updateState(mPreference);
    }

}