diff options
10 files changed, 78 insertions, 14 deletions
diff --git a/src/com/android/customization/model/color/ColorCustomizationManager.java b/src/com/android/customization/model/color/ColorCustomizationManager.java index 0f87a7b4..a09efd26 100644 --- a/src/com/android/customization/model/color/ColorCustomizationManager.java +++ b/src/com/android/customization/model/color/ColorCustomizationManager.java @@ -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} diff --git a/src/com/android/customization/model/color/ColorOption.java b/src/com/android/customization/model/color/ColorOption.java index 77fe4044..f57aa860 100644 --- a/src/com/android/customization/model/color/ColorOption.java +++ b/src/com/android/customization/model/color/ColorOption.java @@ -240,6 +240,11 @@ public abstract class ColorOption implements CustomizationOption<ColorOption> { } /** + * @return the style of this color option for logging + */ + public abstract int getStyleForLogging(); + + /** * @return the index of this color option */ public int getIndex() { diff --git a/src/com/android/customization/model/color/ColorOptionImpl.kt b/src/com/android/customization/model/color/ColorOptionImpl.kt index 461d2a3a..f0905283 100644 --- a/src/com/android/customization/model/color/ColorOptionImpl.kt +++ b/src/com/android/customization/model/color/ColorOptionImpl.kt @@ -78,6 +78,8 @@ class ColorOptionImpl( } } + override fun getStyleForLogging(): Int = style.toString().hashCode() + class Builder { var title: String? = null diff --git a/src/com/android/customization/model/color/ColorProvider.kt b/src/com/android/customization/model/color/ColorProvider.kt index 339e558e..6fdfd2ca 100644 --- a/src/com/android/customization/model/color/ColorProvider.kt +++ b/src/com/android/customization/model/color/ColorProvider.kt @@ -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 diff --git a/src/com/android/customization/module/logging/ThemesUserEventLogger.kt b/src/com/android/customization/module/logging/ThemesUserEventLogger.kt index 66dea5a5..60fd062a 100644 --- a/src/com/android/customization/module/logging/ThemesUserEventLogger.kt +++ b/src/com/android/customization/module/logging/ThemesUserEventLogger.kt @@ -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) diff --git a/src/com/android/customization/module/logging/ThemesUserEventLoggerImpl.kt b/src/com/android/customization/module/logging/ThemesUserEventLoggerImpl.kt index 1cbda983..1441c717 100644 --- a/src/com/android/customization/module/logging/ThemesUserEventLoggerImpl.kt +++ b/src/com/android/customization/module/logging/ThemesUserEventLoggerImpl.kt @@ -47,6 +47,7 @@ import android.stats.style.StyleEnums.WALLPAPER_EFFECT_FG_DOWNLOAD import android.stats.style.StyleEnums.WALLPAPER_EFFECT_PROBE import android.stats.style.StyleEnums.WALLPAPER_EXPLORE import android.text.TextUtils +import com.android.customization.model.color.ColorCustomizationManager import com.android.customization.model.grid.GridOption import com.android.customization.module.logging.ThemesUserEventLogger.ClockSize import com.android.customization.module.logging.ThemesUserEventLogger.ColorSource @@ -64,6 +65,7 @@ class ThemesUserEventLoggerImpl @Inject constructor( private val preferences: WallpaperPreferences, + private val colorManager: ColorCustomizationManager, private val appSessionId: AppSessionId, ) : ThemesUserEventLogger { @@ -74,6 +76,9 @@ constructor( .setLockWallpaperCategoryHash(preferences.getLockCategoryHash()) .setLockWallpaperIdHash(preferences.getLockWallpaperIdHash()) .setEffectIdHash(preferences.getHomeWallpaperEffectsIdHash()) + .setColorSource(colorManager.currentColorSourceForLogging) + .setColorVariant(colorManager.currentStyleForLogging) + .setSeedColor(colorManager.currentSeedColorForLogging) .log() } @@ -157,13 +162,13 @@ constructor( override fun logThemeColorApplied( @ColorSource source: Int, - variant: Int, + style: Int, seedColor: Int, ) { SysUiStatsLogger(THEME_COLOR_APPLIED) .setAppSessionId(appSessionId.getId()) .setColorSource(source) - .setColorVariant(variant) + .setColorVariant(style) .setSeedColor(seedColor) .log() } diff --git a/src/com/android/customization/picker/color/ui/viewmodel/ColorPickerViewModel.kt b/src/com/android/customization/picker/color/ui/viewmodel/ColorPickerViewModel.kt index 3c3d1143..ed83136e 100644 --- a/src/com/android/customization/picker/color/ui/viewmodel/ColorPickerViewModel.kt +++ b/src/com/android/customization/picker/color/ui/viewmodel/ColorPickerViewModel.kt @@ -147,8 +147,8 @@ private constructor( logger.logThemeColorApplied( colorOptionModel.colorOption .sourceForLogging, - colorOptionModel.colorOption.style - .ordinal + 1, + colorOptionModel.colorOption + .styleForLogging, colorOptionModel.colorOption .seedColorForLogging, ) diff --git a/src_override/com/android/wallpaper/module/AppModule.kt b/src_override/com/android/wallpaper/module/AppModule.kt index f07c2b4a..16e5a885 100644 --- a/src_override/com/android/wallpaper/module/AppModule.kt +++ b/src_override/com/android/wallpaper/module/AppModule.kt @@ -16,6 +16,8 @@ package com.android.wallpaper.module import android.content.Context +import com.android.customization.model.color.ColorCustomizationManager +import com.android.customization.model.theme.OverlayManagerCompat import com.android.customization.module.CustomizationInjector import com.android.customization.module.DefaultCustomizationPreferences import com.android.customization.module.ThemePickerInjector @@ -58,5 +60,13 @@ abstract class AppModule { fun provideDefaultWallpaperModelFactory(): DefaultWallpaperModelFactory { return DefaultWallpaperModelFactory() } + + @Provides + @Singleton + fun provideColorCustomizationManager( + @ApplicationContext context: Context + ): ColorCustomizationManager { + return ColorCustomizationManager.getInstance(context, OverlayManagerCompat(context)) + } } } diff --git a/tests/common/src/com/android/customization/module/logging/TestThemesUserEventLogger.kt b/tests/common/src/com/android/customization/module/logging/TestThemesUserEventLogger.kt index bb49ff09..8e9dacdb 100644 --- a/tests/common/src/com/android/customization/module/logging/TestThemesUserEventLogger.kt +++ b/tests/common/src/com/android/customization/module/logging/TestThemesUserEventLogger.kt @@ -31,14 +31,14 @@ class TestThemesUserEventLogger @Inject constructor() : @ColorSource var themeColorSource: Int = StyleEnums.COLOR_SOURCE_UNSPECIFIED private set - var themeColorVariant: Int = -1 + var themeColorStyle: Int = -1 private set var themeSeedColor: Int = -1 private set - override fun logThemeColorApplied(@ColorSource source: Int, variant: Int, seedColor: Int) { + override fun logThemeColorApplied(@ColorSource source: Int, style: Int, seedColor: Int) { this.themeColorSource = source - this.themeColorVariant = variant + this.themeColorStyle = style this.themeSeedColor = seedColor } diff --git a/tests/robotests/src/com/android/customization/model/picker/color/ui/viewmodel/ColorPickerViewModelTest.kt b/tests/robotests/src/com/android/customization/model/picker/color/ui/viewmodel/ColorPickerViewModelTest.kt index 66175828..889720e4 100644 --- a/tests/robotests/src/com/android/customization/model/picker/color/ui/viewmodel/ColorPickerViewModelTest.kt +++ b/tests/robotests/src/com/android/customization/model/picker/color/ui/viewmodel/ColorPickerViewModelTest.kt @@ -149,7 +149,7 @@ class ColorPickerViewModelTest { assertThat(logger.themeColorSource) .isEqualTo(StyleEnums.COLOR_SOURCE_LOCK_SCREEN_WALLPAPER) - assertThat(logger.themeColorVariant).isEqualTo(Style.EXPRESSIVE.ordinal + 1) + assertThat(logger.themeColorStyle).isEqualTo(Style.EXPRESSIVE.toString().hashCode()) assertThat(logger.themeSeedColor).isEqualTo(Color.parseColor("#121212")) } @@ -179,7 +179,7 @@ class ColorPickerViewModelTest { advanceUntilIdle() assertThat(logger.themeColorSource).isEqualTo(StyleEnums.COLOR_SOURCE_PRESET_COLOR) - assertThat(logger.themeColorVariant).isEqualTo(Style.FRUIT_SALAD.ordinal + 1) + assertThat(logger.themeColorStyle).isEqualTo(Style.FRUIT_SALAD.toString().hashCode()) assertThat(logger.themeSeedColor).isEqualTo(Color.parseColor("#ABCDEF")) } |