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

Commit 5551a2dc authored by George Lin's avatar George Lin
Browse files

Log color snapshot (1/2)

Test: Manually tested the log is correct
Bug: 290848448
Flag: None
Change-Id: Ic7ea9c4ea383f733675eca84c8d405794c6e9bfe
parent 6946513a
Loading
Loading
Loading
Loading
+39 −0
Original line number Diff line number Diff line
@@ -15,6 +15,11 @@
 */
package com.android.customization.model.color;

import static android.stats.style.StyleEnums.COLOR_SOURCE_HOME_SCREEN_WALLPAPER;
import static android.stats.style.StyleEnums.COLOR_SOURCE_LOCK_SCREEN_WALLPAPER;
import static android.stats.style.StyleEnums.COLOR_SOURCE_PRESET_COLOR;
import static android.stats.style.StyleEnums.COLOR_SOURCE_UNSPECIFIED;

import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_COLOR;
import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_SYSTEM_PALETTE;
import static com.android.customization.model.color.ColorOptionsProvider.COLOR_SOURCE_PRESET;
@@ -27,6 +32,7 @@ import android.app.WallpaperColors;
import android.content.ContentResolver;
import android.content.Context;
import android.database.ContentObserver;
import android.graphics.Color;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
@@ -41,6 +47,7 @@ import com.android.customization.model.CustomizationManager;
import com.android.customization.model.ResourceConstants;
import com.android.customization.model.color.ColorOptionsProvider.ColorSource;
import com.android.customization.model.theme.OverlayManagerCompat;
import com.android.customization.module.logging.ThemesUserEventLogger;
import com.android.wallpaper.R;

import org.json.JSONArray;
@@ -205,6 +212,38 @@ public class ColorCustomizationManager implements CustomizationManager<ColorOpti
        return mCurrentOverlays;
    }

    /** */
    public int getCurrentColorSourceForLogging() {
        String colorSource = getCurrentColorSource();
        if (colorSource == null) {
            return COLOR_SOURCE_UNSPECIFIED;
        }
        return switch (colorSource) {
            case ColorOptionsProvider.COLOR_SOURCE_PRESET -> COLOR_SOURCE_PRESET_COLOR;
            case ColorOptionsProvider.COLOR_SOURCE_HOME -> COLOR_SOURCE_HOME_SCREEN_WALLPAPER;
            case ColorOptionsProvider.COLOR_SOURCE_LOCK -> COLOR_SOURCE_LOCK_SCREEN_WALLPAPER;
            default -> COLOR_SOURCE_UNSPECIFIED;
        };
    }

    /** */
    public int getCurrentStyleForLogging() {
        String style = getCurrentStyle();
        return style != null ? style.hashCode() : 0;
    }

    /** */
    public int getCurrentSeedColorForLogging() {
        String seedColor = getCurrentOverlays().get(OVERLAY_CATEGORY_SYSTEM_PALETTE);
        if (seedColor == null || seedColor.isEmpty()) {
            return ThemesUserEventLogger.NULL_SEED_COLOR;
        }
        if (!seedColor.startsWith("#")) {
            seedColor = "#" + seedColor;
        }
        return Color.parseColor(seedColor);
    }

    /**
     * @return The source of the currently applied color. One of
     * {@link ColorOptionsProvider#COLOR_SOURCE_HOME},{@link ColorOptionsProvider#COLOR_SOURCE_LOCK}
+5 −0
Original line number Diff line number Diff line
@@ -239,6 +239,11 @@ public abstract class ColorOption implements CustomizationOption<ColorOption> {
        return mStyle;
    }

    /**
     * @return the style of this color option for logging
     */
    public abstract int getStyleForLogging();

    /**
     * @return the index of this color option
     */
+2 −0
Original line number Diff line number Diff line
@@ -78,6 +78,8 @@ class ColorOptionImpl(
        }
    }

    override fun getStyleForLogging(): Int = style.toString().hashCode()

    class Builder {
        var title: String? = null

+7 −4
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ import kotlinx.coroutines.withContext

/**
 * Default implementation of {@link ColorOptionsProvider} that reads preset colors from a stub APK.
 * TODO (b/311212666): Make [ColorProvider] and [ColorCustomizationManager] injectable
 */
class ColorProvider(private val context: Context, stubPackageName: String) :
    ResourcesApkProvider(context, stubPackageName), ColorOptionsProvider {
@@ -68,8 +69,6 @@ class ColorProvider(private val context: Context, stubPackageName: String) :
            arrayOf(Style.TONAL_SPOT, Style.SPRITZ, Style.VIBRANT, Style.EXPRESSIVE)
        else arrayOf(Style.TONAL_SPOT)

    private val monochromeEnabled =
        InjectorProvider.getInjector().getFlags().isMonochromaticThemeEnabled(mContext)
    private var monochromeBundleName: String? = null

    private val scope =
@@ -177,7 +176,7 @@ class ColorProvider(private val context: Context, stubPackageName: String) :

        // Insert monochrome in the second position if it is enabled and included in preset
        // colors
        if (monochromeEnabled) {
        if (InjectorProvider.getInjector().getFlags().isMonochromaticThemeEnabled(mContext)) {
            monochromeBundleName?.let {
                bundles.add(1, buildPreset(it, -1, Style.MONOCHROMATIC, ColorType.WALLPAPER_COLOR))
            }
@@ -361,7 +360,11 @@ class ColorProvider(private val context: Context, stubPackageName: String) :
                        }

                    if (style == Style.MONOCHROMATIC) {
                        if (!monochromeEnabled) {
                        if (
                            !InjectorProvider.getInjector()
                                .getFlags()
                                .isMonochromaticThemeEnabled(mContext)
                        ) {
                            continue
                        }
                        hasMonochrome = true
+1 −1
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ import com.android.wallpaper.module.logging.UserEventLogger
/** Extension of [UserEventLogger] that adds ThemePicker specific events. */
interface ThemesUserEventLogger : UserEventLogger {

    fun logThemeColorApplied(@ColorSource source: Int, variant: Int, seedColor: Int)
    fun logThemeColorApplied(@ColorSource source: Int, style: Int, seedColor: Int)

    fun logGridApplied(grid: GridOption)

Loading