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

Commit 8bf5250c authored by Robert Snoeberger's avatar Robert Snoeberger
Browse files

Add timestamp when applying a clock face

Bug: 134687399
Test: Applied clock and checked settings with `adb shell settings get
secure lock_screen_custom_clock_face`.
Test: Changed clock face, quit picker, and checked that correct current
clock face was shown when I reopened.

Change-Id: Ib995f6bb60378a8c13e8107c5ed5167447d5ae79
parent b6fec564
Loading
Loading
Loading
Loading
+21 −2
Original line number Diff line number Diff line
@@ -20,6 +20,9 @@ import android.provider.Settings.Secure;

import com.android.customization.module.ThemesUserEventLogger;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * {@link CustomizationManager} for clock faces that implements apply by writing to secure settings.
 */
@@ -27,6 +30,8 @@ public class ClockManager extends BaseClockManager {

    // TODO: use constant from Settings.Secure
    static final String CLOCK_FACE_SETTING = "lock_screen_custom_clock_face";
    private static final String CLOCK_FIELD = "clock";
    private static final String TIMESTAMP_FIELD = "_applied_timestamp";
    private final ContentResolver mContentResolver;
    private final ThemesUserEventLogger mEventLogger;

@@ -39,7 +44,15 @@ public class ClockManager extends BaseClockManager {

    @Override
    protected void handleApply(Clockface option, Callback callback) {
        boolean stored = Secure.putString(mContentResolver, CLOCK_FACE_SETTING, option.getId());
        boolean stored;
        try {
            final JSONObject json = new JSONObject();
            json.put(CLOCK_FIELD, option.getId());
            json.put(TIMESTAMP_FIELD, System.currentTimeMillis());
            stored = Secure.putString(mContentResolver, CLOCK_FACE_SETTING, json.toString());
        } catch (JSONException ex) {
            stored = false;
        }
        if (stored) {
            mEventLogger.logClockApplied(option);
            callback.onSuccess();
@@ -50,6 +63,12 @@ public class ClockManager extends BaseClockManager {

    @Override
    protected String lookUpCurrentClock() {
        return Secure.getString(mContentResolver, CLOCK_FACE_SETTING);
        final String value = Secure.getString(mContentResolver, CLOCK_FACE_SETTING);
        try {
            final JSONObject json = new JSONObject(value);
            return json.getString(CLOCK_FIELD);
        } catch (JSONException ex) {
            return value;
        }
    }
}