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

Commit d3a582a9 authored by Santiago Etchebehere's avatar Santiago Etchebehere
Browse files

Add timestamp to serialized ThemeBundle json

Add timestamp when applying a theme

Bug: 134686741
Change-Id: Ib516f5ceb71d812522baaf1ee862427bbadac75d
parent edb5d71b
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -349,7 +349,7 @@ public class DefaultThemeProvider extends ResourcesApkProvider implements ThemeB
    }

    private void addThemeBundleToArray(JSONArray themesArray, ThemeBundle themeBundle) {
        JSONObject jsonPackages = themeBundle.getJsonPackages();
        JSONObject jsonPackages = themeBundle.getJsonPackages(false);
        try {
            jsonPackages.put(THEME_TITLE_FIELD, themeBundle.getTitle());
            if (themeBundle instanceof CustomTheme) {
+23 −7
Original line number Diff line number Diff line
@@ -31,7 +31,9 @@ import android.graphics.drawable.AdaptiveIconDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.PathShape;
import android.icu.text.SimpleDateFormat;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
@@ -52,14 +54,17 @@ import com.android.wallpaper.asset.BitmapCachingAsset;
import com.android.wallpaper.model.LiveWallpaperInfo;
import com.android.wallpaper.model.WallpaperInfo;

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

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;

@@ -70,7 +75,10 @@ import java.util.Set;
 */
public class ThemeBundle implements CustomizationOption<ThemeBundle> {

    private static final String TAG = "ThemeBundle";
    private final static String EMPTY_JSON = "{}";
    private final static String TIMESTAMP_FIELD = "_applied_timestamp";

    private final String mTitle;
    private final PreviewInfo mPreviewInfo;
    private final boolean mIsDefault;
@@ -121,10 +129,10 @@ public class ThemeBundle implements CustomizationOption<ThemeBundle> {
    @Override
    public boolean isActive(CustomizationManager<ThemeBundle> manager) {
        ThemeManager themeManager = (ThemeManager) manager;
        String serializedOverlays = themeManager.getStoredOverlays();

        if (mIsDefault) {
            return TextUtils.isEmpty(serializedOverlays);
            String serializedOverlays = themeManager.getStoredOverlays();
            return TextUtils.isEmpty(serializedOverlays) || EMPTY_JSON.equals(serializedOverlays);
        } else {
            Map<String, String> currentOverlays = themeManager.getCurrentOverlays();
            return mPackagesByCategory.equals(currentOverlays);
@@ -197,19 +205,27 @@ public class ThemeBundle implements CustomizationOption<ThemeBundle> {
    }

    public String getSerializedPackages() {
        if (isDefault()) {
            return "";
        return getJsonPackages(false).toString();
    }
        return getJsonPackages().toString();

    public String getSerializedPackagesWithTimestamp() {
        return getJsonPackages(true).toString();
    }

    JSONObject getJsonPackages() {
    JSONObject getJsonPackages(boolean insertTimestamp) {
        if (isDefault()) {
            return new JSONObject();
        }
        JSONObject json = new JSONObject(mPackagesByCategory);
        // Remove items with null values to avoid deserialization issues.
        removeNullValues(json);
        if (insertTimestamp) {
            try {
                json.put(TIMESTAMP_FIELD, System.currentTimeMillis());
            } catch (JSONException e) {
                Log.e(TAG, "Couldn't add timestamp to serialized themebundle");
            }
        }
        return json;
    }

+1 −1
Original line number Diff line number Diff line
@@ -153,7 +153,7 @@ public class ThemeManager implements CustomizationManager<ThemeBundle> {

    private void applyOverlays(ThemeBundle theme, Callback callback) {
        boolean allApplied = Settings.Secure.putString(mActivity.getContentResolver(),
                ResourceConstants.THEME_SETTING, theme.getSerializedPackages());
                ResourceConstants.THEME_SETTING, theme.getSerializedPackagesWithTimestamp());
        if (theme instanceof CustomTheme) {
            storeCustomTheme((CustomTheme) theme);
        }