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

Commit 324b474b authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 9163457 from 23514122 to tm-qpr2-release

Change-Id: I7f2a7b916abe39ac1753bf209ea0130f7fa15375
parents 97bd7bd2 23514122
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
+src/
+src_override/
+tests/
-src/com/android/customization/model/color/ColorProvider.kt
-src/com/android/customization/model/color/ColorUtils.kt
-src/com/android/customization/module/SysUiStatsLogger.kt
-src/com/android/customization/picker/clock/ClockSectionView.kt
+5 −45
Original line number Diff line number Diff line
@@ -15,18 +15,11 @@
 */
package com.android.customization.model.color;

import static com.android.customization.model.ResourceConstants.PATH_SIZE;

import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.Path;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.PathShape;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

@@ -34,16 +27,13 @@ import androidx.annotation.ColorInt;
import androidx.annotation.Dimension;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import androidx.core.graphics.PathParser;

import com.android.customization.model.ResourceConstants;
import com.android.systemui.monet.Style;
import com.android.wallpaper.R;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
@@ -103,8 +93,6 @@ public class ColorBundle extends ColorOption {
        // Monet system palette and accent colors
        @ColorInt public final int primaryColorLight;
        @ColorInt public final int primaryColorDark;
        public final List<Drawable> icons;
        public final Drawable shapeDrawable;
        @Dimension
        public final int bottomSheetCornerRadius;

@@ -115,14 +103,11 @@ public class ColorBundle extends ColorOption {

        private PreviewInfo(
                int secondaryColorLight, int secondaryColorDark, int colorSystemPaletteLight,
                int primaryColorDark, List<Drawable> icons, Drawable shapeDrawable,
                @Dimension int cornerRadius) {
                int primaryColorDark, @Dimension int cornerRadius) {
            this.secondaryColorLight = secondaryColorLight;
            this.secondaryColorDark = secondaryColorDark;
            this.primaryColorLight = colorSystemPaletteLight;
            this.primaryColorDark = primaryColorDark;
            this.icons = icons;
            this.shapeDrawable = shapeDrawable;
            this.bottomSheetCornerRadius = cornerRadius;
        }

@@ -188,7 +173,6 @@ public class ColorBundle extends ColorOption {
        // System and Monet colors
        @ColorInt private int mPrimaryColorLight = Color.TRANSPARENT;
        @ColorInt private int mPrimaryColorDark = Color.TRANSPARENT;
        private List<Drawable> mIcons = new ArrayList<>();
        private boolean mIsDefault;
        private Style mStyle = Style.TONAL_SPOT;
        private int mIndex;
@@ -213,26 +197,12 @@ public class ColorBundle extends ColorOption {
         * @return the {@link PreviewInfo} object
         */
        public PreviewInfo createPreviewInfo(@NonNull Context context) {
            ShapeDrawable shapeDrawable = null;
            Resources system = context.getResources().getSystem();
            String pathString = system.getString(
                    system.getIdentifier(ResourceConstants.CONFIG_ICON_MASK,
                            "string", ResourceConstants.ANDROID_PACKAGE));
            Path path = null;
            if (!TextUtils.isEmpty(pathString)) {
                path = PathParser.createPathFromPathData(pathString);
            }
            if (path != null) {
                PathShape shape = new PathShape(path, PATH_SIZE, PATH_SIZE);
                shapeDrawable = new ShapeDrawable(shape);
                shapeDrawable.setIntrinsicHeight((int) PATH_SIZE);
                shapeDrawable.setIntrinsicWidth((int) PATH_SIZE);
            }
            return new PreviewInfo(mSecondaryColorLight,
                    mSecondaryColorDark, mPrimaryColorLight, mPrimaryColorDark, mIcons,
                    shapeDrawable, system.getDimensionPixelOffset(
                    system.getIdentifier(ResourceConstants.CONFIG_CORNERRADIUS,
                            "dimen", ResourceConstants.ANDROID_PACKAGE)));
                    mSecondaryColorDark, mPrimaryColorLight, mPrimaryColorDark,
                    system.getDimensionPixelOffset(
                            system.getIdentifier(ResourceConstants.CONFIG_CORNERRADIUS, "dimen",
                                    ResourceConstants.ANDROID_PACKAGE)));
        }

        public Map<String, String> getPackages() {
@@ -297,16 +267,6 @@ public class ColorBundle extends ColorOption {
            return this;
        }

        /**
         * Sets icon for bundle
         * @param icon icon in {@link Drawable}
         * @return this of {@link Builder}
         */
        public Builder addIcon(Drawable icon) {
            mIcons.add(icon);
            return this;
        }

        /**
         * Sets overlay package for bundle
         * @param category the category of bundle
+0 −28
Original line number Diff line number Diff line
@@ -15,18 +15,12 @@
 */
package com.android.customization.model.color;

import static com.android.customization.model.ResourceConstants.ANDROID_PACKAGE;
import static com.android.customization.model.ResourceConstants.ICONS_FOR_PREVIEW;
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.ColorUtils.toColorString;

import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.content.res.Resources.NotFoundException;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.Log;

@@ -80,26 +74,4 @@ class ColorBundlePreviewExtractor {
        }
        builder.setStyle(s);
    }

    void addAndroidIconOverlay(ColorBundle.Builder builder) throws NameNotFoundException {
        addSystemDefaultIcons(builder, ICONS_FOR_PREVIEW);
    }

    void addSystemDefaultIcons(ColorBundle.Builder builder, String... previewIcons) {
        try {
            for (String iconName : previewIcons) {
                builder.addIcon(loadIconPreviewDrawable(iconName));
            }
        } catch (NameNotFoundException | NotFoundException e) {
            Log.w(TAG, "Didn't find android package icons, will skip preview", e);
        }
    }

    Drawable loadIconPreviewDrawable(String drawableName)
            throws NameNotFoundException, NotFoundException {
        Resources packageRes = mPackageManager.getResourcesForApplication(ANDROID_PACKAGE);
        Resources res = Resources.getSystem();
        return res.getDrawable(packageRes.getIdentifier(drawableName, "drawable",
                        ANDROID_PACKAGE), null);
    }
}
+127 −107
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ import android.app.WallpaperColors
import android.content.Context
import android.content.res.ColorStateList
import android.content.res.Resources
import android.text.TextUtils
import androidx.annotation.ColorInt
import androidx.core.graphics.ColorUtils.setAlphaComponent
import androidx.lifecycle.LifecycleOwner
@@ -29,8 +28,8 @@ import com.android.customization.model.ResourceConstants.COLOR_BUNDLES_ARRAY_NAM
import com.android.customization.model.ResourceConstants.COLOR_BUNDLE_MAIN_COLOR_PREFIX
import com.android.customization.model.ResourceConstants.COLOR_BUNDLE_NAME_PREFIX
import com.android.customization.model.ResourceConstants.COLOR_BUNDLE_STYLE_PREFIX
import com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_SYSTEM_PALETTE
import com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_COLOR
import com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_SYSTEM_PALETTE
import com.android.customization.model.ResourcesApkProvider
import com.android.customization.model.color.ColorOptionsProvider.COLOR_SOURCE_HOME
import com.android.customization.model.color.ColorOptionsProvider.COLOR_SOURCE_LOCK
@@ -39,16 +38,15 @@ import com.android.systemui.monet.ColorScheme
import com.android.systemui.monet.Style
import com.android.wallpaper.compat.WallpaperManagerCompat
import com.android.wallpaper.module.InjectorProvider
import java.util.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.util.*

/**
 * Default implementation of {@link ColorOptionsProvider} that reads preset colors from
 * a stub APK.
 * Default implementation of {@link ColorOptionsProvider} that reads preset colors from a stub APK.
 */
class ColorProvider(context: Context, stubPackageName: String) :
    ResourcesApkProvider(context, stubPackageName), ColorOptionsProvider {
@@ -64,11 +62,13 @@ class ColorProvider(context: Context, stubPackageName: String) :

    private val monetEnabled = ColorUtils.isMonetEnabled(context)
    // TODO(b/202145216): Use style method to fetch the list of style.
    private var styleList = if (themeStyleEnabled) arrayOf(
        Style.TONAL_SPOT, Style.SPRITZ, Style.VIBRANT, Style.EXPRESSIVE
    ) else arrayOf(Style.TONAL_SPOT)
    private var styleList =
        if (themeStyleEnabled)
            arrayOf(Style.TONAL_SPOT, Style.SPRITZ, Style.VIBRANT, Style.EXPRESSIVE)
        else arrayOf(Style.TONAL_SPOT)

    private val scope = if (mContext is LifecycleOwner) {
    private val scope =
        if (mContext is LifecycleOwner) {
            mContext.lifecycleScope
        } else {
            CoroutineScope(Dispatchers.Default + SupervisorJob())
@@ -79,16 +79,19 @@ class ColorProvider(context: Context, stubPackageName: String) :
    private var homeWallpaperColors: WallpaperColors? = null
    private var lockWallpaperColors: WallpaperColors? = null


    override fun isAvailable(): Boolean {
        return monetEnabled && super.isAvailable() && colorsAvailable
    }

    override fun fetch(callback: OptionsFetchedListener<ColorOption>?, reload: Boolean,
    override fun fetch(
        callback: OptionsFetchedListener<ColorOption>?,
        reload: Boolean,
        homeWallpaperColors: WallpaperColors?,
                       lockWallpaperColors: WallpaperColors?) {
        val wallpaperColorsChanged = this.homeWallpaperColors != homeWallpaperColors
                || this.lockWallpaperColors != lockWallpaperColors
        lockWallpaperColors: WallpaperColors?
    ) {
        val wallpaperColorsChanged =
            this.homeWallpaperColors != homeWallpaperColors ||
                this.lockWallpaperColors != lockWallpaperColors
        if (wallpaperColorsChanged) {
            this.homeWallpaperColors = homeWallpaperColors
            this.lockWallpaperColors = lockWallpaperColors
@@ -122,12 +125,15 @@ class ColorProvider(context: Context, stubPackageName: String) :
            manager.getWallpaperId(WallpaperManagerCompat.FLAG_SYSTEM)
    }

    private fun loadSeedColors(homeWallpaperColors: WallpaperColors?,
                               lockWallpaperColors: WallpaperColors?) {
    private fun loadSeedColors(
        homeWallpaperColors: WallpaperColors?,
        lockWallpaperColors: WallpaperColors?
    ) {
        if (homeWallpaperColors == null) return

        val bundles: MutableList<ColorOption> = ArrayList()
        val colorsPerSource = if (lockWallpaperColors == null) {
        val colorsPerSource =
            if (lockWallpaperColors == null) {
                MAX_SEED_COLORS
            } else {
                MAX_SEED_COLORS / 2
@@ -141,14 +147,16 @@ class ColorProvider(context: Context, stubPackageName: String) :
                colorsPerSource,
                if (shouldLockColorsGoFirst) COLOR_SOURCE_LOCK else COLOR_SOURCE_HOME,
                true,
                    bundles)
                bundles
            )
            // Second half of the colors
            buildColorSeeds(
                if (shouldLockColorsGoFirst) homeWallpaperColors else lockWallpaperColors,
                MAX_SEED_COLORS - bundles.size / styleSize,
                if (shouldLockColorsGoFirst) COLOR_SOURCE_HOME else COLOR_SOURCE_LOCK,
                false,
                    bundles)
                bundles
            )
        } else {
            buildColorSeeds(homeWallpaperColors, colorsPerSource, COLOR_SOURCE_HOME, true, bundles)
        }
@@ -157,8 +165,13 @@ class ColorProvider(context: Context, stubPackageName: String) :
        colorBundles = bundles
    }

    private fun buildColorSeeds(wallpaperColors: WallpaperColors, maxColors: Int, source: String,
                                containsDefault: Boolean, bundles: MutableList<ColorOption>) {
    private fun buildColorSeeds(
        wallpaperColors: WallpaperColors,
        maxColors: Int,
        source: String,
        containsDefault: Boolean,
        bundles: MutableList<ColorOption>
    ) {
        val seedColors = ColorScheme.getSeedColors(wallpaperColors)
        val defaultSeed = seedColors.first()
        buildBundle(defaultSeed, 0, containsDefault, source, bundles)
@@ -167,19 +180,27 @@ class ColorProvider(context: Context, stubPackageName: String) :
        }
    }

    private fun buildBundle(colorInt: Int, i: Int, isDefault: Boolean, source: String,
                            bundles: MutableList<ColorOption>) {
    private fun buildBundle(
        colorInt: Int,
        i: Int,
        isDefault: Boolean,
        source: String,
        bundles: MutableList<ColorOption>
    ) {
        // TODO(b/202145216): Measure time cost in the loop.
        for (style in styleList) {
            val builder = ColorSeedOption.Builder()
            val lightColorScheme = ColorScheme(colorInt, /* darkTheme= */ false, style)
            val darkColorScheme = ColorScheme(colorInt, /* darkTheme= */ true, style)
            builder.setLightColors(lightColorScheme.getLightColorPreview())
            builder
                .setLightColors(lightColorScheme.getLightColorPreview())
                .setDarkColors(darkColorScheme.getDarkColorPreview())
                .addOverlayPackage(OVERLAY_CATEGORY_SYSTEM_PALETTE,
                .addOverlayPackage(
                    OVERLAY_CATEGORY_SYSTEM_PALETTE,
                    if (isDefault) "" else toColorString(colorInt)
                )
                .addOverlayPackage(OVERLAY_CATEGORY_COLOR,
                .addOverlayPackage(
                    OVERLAY_CATEGORY_COLOR,
                    if (isDefault) "" else toColorString(colorInt)
                )
                .setSource(source)
@@ -194,37 +215,31 @@ class ColorProvider(context: Context, stubPackageName: String) :
    }

    /**
     * Returns the colors for the light theme version of the preview of a ColorScheme
     * based on this order:
     * |-------|
     * | 0 | 1 |
     * |---+---|
     * | 2 | 3 |
     * |-------|
     * Returns the colors for the light theme version of the preview of a ColorScheme based on this
     * order: |-------| | 0 | 1 | |---+---| | 2 | 3 | |-------|
     */
    @ColorInt
    private fun ColorScheme.getLightColorPreview(): IntArray {
        return intArrayOf(setAlphaComponent(this.accent1[2], ALPHA_MASK),
        return intArrayOf(
            setAlphaComponent(this.accent1[2], ALPHA_MASK),
            setAlphaComponent(this.accent1[2], ALPHA_MASK),
            ColorStateList.valueOf(this.accent3[6]).withLStar(85f).colors[0],
                setAlphaComponent(this.accent1[6], ALPHA_MASK))
            setAlphaComponent(this.accent1[6], ALPHA_MASK)
        )
    }

    /**
     * Returns the color for the dark theme version of the preview of a ColorScheme
     * based on this order:
     * |-------|
     * | 0 | 1 |
     * |---+---|
     * | 2 | 3 |
     * |-------|
     * Returns the color for the dark theme version of the preview of a ColorScheme based on this
     * order: |-------| | 0 | 1 | |---+---| | 2 | 3 | |-------|
     */
    @ColorInt
    private fun ColorScheme.getDarkColorPreview(): IntArray {
        return intArrayOf(setAlphaComponent(this.accent1[2], ALPHA_MASK),
        return intArrayOf(
            setAlphaComponent(this.accent1[2], ALPHA_MASK),
            setAlphaComponent(this.accent1[2], ALPHA_MASK),
            ColorStateList.valueOf(this.accent3[6]).withLStar(85f).colors[0],
                setAlphaComponent(this.accent1[6], ALPHA_MASK))
            setAlphaComponent(this.accent1[6], ALPHA_MASK)
        )
    }

    private fun ColorScheme.getPresetColorPreview(seed: Int): IntArray {
@@ -235,7 +250,8 @@ class ColorProvider(context: Context, stubPackageName: String) :
        }
    }

    private suspend fun loadPreset() = withContext(Dispatchers.IO) {
    private suspend fun loadPreset() =
        withContext(Dispatchers.IO) {
            val extractor = ColorBundlePreviewExtractor(mContext)
            val bundles: MutableList<ColorOption> = ArrayList()

@@ -251,27 +267,31 @@ class ColorProvider(context: Context, stubPackageName: String) :
                extractor.addPrimaryColor(builder, colorFromStub)
                extractor.addSecondaryColor(builder, colorFromStub)
                if (themeStyleEnabled) {
                val styleName = try {
                    val styleName =
                        try {
                            getItemStringFromStub(COLOR_BUNDLE_STYLE_PREFIX, bundleName)
                        } catch (e: Resources.NotFoundException) {
                            null
                        }
                    extractor.addColorStyle(builder, styleName)
                val style = try {
                    val style =
                        try {
                            if (styleName != null) Style.valueOf(styleName) else Style.TONAL_SPOT
                        } catch (e: IllegalArgumentException) {
                            Style.TONAL_SPOT
                        }

                val darkColors = ColorScheme(colorFromStub, true, style)
                        .getPresetColorPreview(colorFromStub)
                val lightColors = ColorScheme(colorFromStub, false, style)
                    val darkColors =
                        ColorScheme(colorFromStub, true, style).getPresetColorPreview(colorFromStub)
                    val lightColors =
                        ColorScheme(colorFromStub, false, style)
                            .getPresetColorPreview(colorFromStub)
                    builder.setColorPrimaryDark(darkColors[0]).setColorSecondaryDark(darkColors[1])
                builder.setColorPrimaryLight(lightColors[0]).setColorSecondaryLight(lightColors[1])
                    builder
                        .setColorPrimaryLight(lightColors[0])
                        .setColorSecondaryLight(lightColors[1])
                }

            extractor.addAndroidIconOverlay(builder)
                bundles.add(builder.build(mContext))
                index++
            }
+11 −11
Original line number Diff line number Diff line
@@ -22,18 +22,14 @@ import android.os.SystemProperties
import android.util.Log
import androidx.annotation.ColorInt

/**
 * Utility to wrap Monet's color extraction
 */
/** Utility to wrap Monet's color extraction */
object ColorUtils {
    private const val TAG = "ColorUtils"
    private const val MONET_FLAG = "flag_monet"
    private var sSysuiRes: Resources? = null
    private var sFlagId = 0

    /**
     * Returns true if color extraction is enabled in systemui.
     */
    /** Returns true if color extraction is enabled in systemui. */
    @JvmStatic
    fun isMonetEnabled(context: Context): Boolean {
        var monetEnabled = SystemProperties.getBoolean("persist.systemui.flag_monet", false)
@@ -41,8 +37,11 @@ object ColorUtils {
            if (sSysuiRes == null) {
                try {
                    val pm = context.packageManager
                    val sysUIInfo = pm.getApplicationInfo("com.android.systemui",
                            PackageManager.GET_META_DATA or PackageManager.MATCH_SYSTEM_ONLY)
                    val sysUIInfo =
                        pm.getApplicationInfo(
                            "com.android.systemui",
                            PackageManager.GET_META_DATA or PackageManager.MATCH_SYSTEM_ONLY
                        )
                    if (sysUIInfo != null) {
                        sSysuiRes = pm.getResourcesForApplication(sysUIInfo)
                    }
@@ -51,8 +50,9 @@ object ColorUtils {
                }
            }
            if (sFlagId == 0) {
                sFlagId = if (sSysuiRes == null) 0 else sSysuiRes!!.getIdentifier(
                        MONET_FLAG, "bool", "com.android.systemui")
                sFlagId =
                    if (sSysuiRes == null) 0
                    else sSysuiRes!!.getIdentifier(MONET_FLAG, "bool", "com.android.systemui")
            }
            if (sFlagId > 0) {
                monetEnabled = sSysuiRes!!.getBoolean(sFlagId)
Loading