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

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

Snap for 12426030 from 0200754b to 25Q1-release

Change-Id: I96bc264c30b46d8338c59150168a9cc915bc0d3f
parents ef94fc6d 0200754b
Loading
Loading
Loading
Loading
+34 −7
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ import android.text.TextUtils;
import android.util.Log;
import android.util.SparseArray;

import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
@@ -66,6 +67,8 @@ import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.FlagOp;
import com.android.launcher3.util.SQLiteCacheHelper;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.nio.ByteBuffer;
import java.util.AbstractMap;
import java.util.Arrays;
@@ -88,6 +91,31 @@ public abstract class BaseIconCache {
    // Empty class name is used for storing package default entry.
    public static final String EMPTY_CLASS_NAME = ".";

    @Retention(RetentionPolicy.SOURCE)
    @IntDef(value = {
            LookupFlag.DEFAULT,
            LookupFlag.USE_LOW_RES,
            LookupFlag.USE_PACKAGE_ICON,
    }, flag = true)
    /** Various options to control cache lookup */
    public @interface LookupFlag {
        /**
         * Default behavior of cache lookup is to load high-res icon with no fallback
         */
        int DEFAULT = 0;

        /**
         * When specified, the cache tries to load the low res version of the entry unless a
         * high-res is already in memory
         */
        int USE_LOW_RES = 1 << 0;
        /**
         * When specified, the cache tries to lookup the package entry for the item, if the object
         * entry fails
         */
        int USE_PACKAGE_ICON = 1 << 1;
    }

    public static class CacheEntry {

        @NonNull
@@ -441,26 +469,25 @@ public abstract class BaseIconCache {
    protected <T> CacheEntry cacheLocked(
            @NonNull final ComponentName componentName, @NonNull final UserHandle user,
            @NonNull final Supplier<T> infoProvider, @NonNull final CachingLogic<T> cachingLogic,
            final boolean usePackageIcon, final boolean useLowResIcon) {
            @LookupFlag int lookupFlags) {
        return cacheLocked(
                componentName,
                user,
                infoProvider,
                cachingLogic,
                null,
                usePackageIcon,
                useLowResIcon);
                lookupFlags,
                null);
    }

    @NonNull
    protected <T> CacheEntry cacheLocked(
            @NonNull final ComponentName componentName, @NonNull final UserHandle user,
            @NonNull final Supplier<T> infoProvider, @NonNull final CachingLogic<T> cachingLogic,
            @Nullable final Cursor cursor, final boolean usePackageIcon,
            final boolean useLowResIcon) {
            @LookupFlag int lookupFlags, @Nullable final Cursor cursor) {
        assertWorkerThread();
        ComponentKey cacheKey = new ComponentKey(componentName, user);
        CacheEntry entry = mCache.get(cacheKey);
        final boolean useLowResIcon = (lookupFlags & LookupFlag.USE_LOW_RES) != 0;
        if (entry == null || (entry.bitmap.isLowRes() && !useLowResIcon)) {
            entry = new CacheEntry();
            if (cachingLogic.addToMemCache()) {
@@ -481,7 +508,7 @@ public abstract class BaseIconCache {
                        object,
                        entry,
                        cachingLogic,
                        usePackageIcon,
                        (lookupFlags & LookupFlag.USE_PACKAGE_ICON) != 0,
                        /* usePackageTitle= */ true,
                        componentName,
                        user);
+59 −62
Original line number Diff line number Diff line
@@ -36,11 +36,11 @@ import com.google.android.torus.core.wallpaper.listener.LiveWallpaperKeyguardEve
import java.lang.ref.WeakReference

/**
 * Implements [WallpaperService] using Filament to render the wallpaper.
 * An instance of this class should only implement [getWallpaperEngine]
 * Implements [WallpaperService] using Filament to render the wallpaper. An instance of this class
 * should only implement [getWallpaperEngine]
 *
 * Note: [LiveWallpaper] subclasses must include the following attribute/s
 * in the AndroidManifest.xml:
 * Note: [LiveWallpaper] subclasses must include the following attribute/s in the
 * AndroidManifest.xml:
 * - android:configChanges="uiMode"
 */
abstract class LiveWallpaper : WallpaperService() {
@@ -77,18 +77,19 @@ abstract class LiveWallpaper : WallpaperService() {
         * through WallpaperService.Engine.onCommand events that should be more accurate.
         */
        if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.R) {
            wakeStateReceiver = object : BroadcastReceiver() {
            wakeStateReceiver =
                object : BroadcastReceiver() {
                    override fun onReceive(context: Context, intent: Intent) {
                        val positionExtras = Bundle()
                        when (intent.action) {
                            Intent.ACTION_SCREEN_ON -> {
                                positionExtras.putInt(
                                    LiveWallpaperEventListener.WAKE_ACTION_LOCATION_X,
                                -1
                                    -1,
                                )
                                positionExtras.putInt(
                                    LiveWallpaperEventListener.WAKE_ACTION_LOCATION_Y,
                                -1
                                    -1,
                                )
                                wakeStateChangeListeners.forEach {
                                    it.get()?.onWake(positionExtras)
@@ -98,11 +99,11 @@ abstract class LiveWallpaper : WallpaperService() {
                            Intent.ACTION_SCREEN_OFF -> {
                                positionExtras.putInt(
                                    LiveWallpaperEventListener.SLEEP_ACTION_LOCATION_X,
                                -1
                                    -1,
                                )
                                positionExtras.putInt(
                                    LiveWallpaperEventListener.SLEEP_ACTION_LOCATION_Y,
                                -1
                                    -1,
                                )
                                wakeStateChangeListeners.forEach {
                                    it.get()?.onSleep(positionExtras)
@@ -121,22 +122,21 @@ abstract class LiveWallpaper : WallpaperService() {
    }

    /**
     * Must be implemented to return a new instance of [TorusEngine].
     * If you want it to subscribe to wallpaper interactions (offset, preview, zoom...) the engine
     * should also implement [LiveWallpaperEventListener]. If you want it to subscribe to touch
     * events, it should implement [TorusTouchListener].
     * Must be implemented to return a new instance of [TorusEngine]. If you want it to subscribe to
     * wallpaper interactions (offset, preview, zoom...) the engine should also implement
     * [LiveWallpaperEventListener]. If you want it to subscribe to touch events, it should
     * implement [TorusTouchListener].
     *
     * Note: You might have multiple Engines running at the same time (when the wallpaper is set as
     * the active wallpaper and the user is in the wallpaper picker viewing a preview of it
     * as well). You can track the lifecycle when *any* Engine is active using the
     * the active wallpaper and the user is in the wallpaper picker viewing a preview of it as
     * well). You can track the lifecycle when *any* Engine is active using the
     * is{First/Last}ActiveInstance parameters of the create/destroy methods.
     *
     */
    abstract fun getWallpaperEngine(context: Context, surfaceHolder: SurfaceHolder): TorusEngine

    /**
     * returns a new instance of [LiveWallpaperEngineWrapper].
     * Caution: This function should not be override when extending [LiveWallpaper] class.
     * returns a new instance of [LiveWallpaperEngineWrapper]. Caution: This function should not be
     * override when extending [LiveWallpaper] class.
     */
    override fun onCreateEngine(): Engine {
        val wrapper = LiveWallpaperEngineWrapper()
@@ -196,9 +196,7 @@ abstract class LiveWallpaper : WallpaperService() {
            return false
        }

        /**
         * Triggers the [WallpaperService] to recompute the Wallpaper Colors.
         */
        /** Triggers the [WallpaperService] to recompute the Wallpaper Colors. */
        fun notifyWallpaperColorsChanged() {
            this.wallpaperServiceEngine?.notifyColorsChanged()
        }
@@ -227,11 +225,11 @@ abstract class LiveWallpaper : WallpaperService() {

    /**
     * Implementation of [WallpaperService.Engine] that works as a wrapper. If we used a
     * [WallpaperService.Engine] instance as the framework engine, we would find the problem
     * that the engine will be created for preview, then destroyed and recreated again when the
     * wallpaper is set. This behavior may cause to load assets multiple time for every time the
     * Rendering engine is created. Also, wrapping our [TorusEngine] inside
     * [WallpaperService.Engine] allow us to reuse [TorusEngine] in other places, like Activities.
     * [WallpaperService.Engine] instance as the framework engine, we would find the problem that
     * the engine will be created for preview, then destroyed and recreated again when the wallpaper
     * is set. This behavior may cause to load assets multiple time for every time the Rendering
     * engine is created. Also, wrapping our [TorusEngine] inside [WallpaperService.Engine] allow us
     * to reuse [TorusEngine] in other places, like Activities.
     */
    private inner class LiveWallpaperEngineWrapper : WallpaperService.Engine() {
        private lateinit var wallpaperEngine: TorusEngine
@@ -245,7 +243,8 @@ abstract class LiveWallpaper : WallpaperService() {
             * For Android 10 (SDK 29).
             * This is needed for Foldables and multiple display devices.
             */
            val context = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
            val context =
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
                    displayContext ?: this@LiveWallpaper
                } else {
                    this@LiveWallpaper
@@ -298,7 +297,7 @@ abstract class LiveWallpaper : WallpaperService() {
            holder: SurfaceHolder?,
            format: Int,
            width: Int,
            height: Int
            height: Int,
        ) {
            super.onSurfaceChanged(holder, format, width, height)
            wallpaperEngine.resize(width, height)
@@ -310,7 +309,7 @@ abstract class LiveWallpaper : WallpaperService() {
            xOffsetStep: Float,
            yOffsetStep: Float,
            xPixelOffset: Int,
            yPixelOffset: Int
            yPixelOffset: Int,
        ) {
            super.onOffsetsChanged(
                xOffset,
@@ -318,7 +317,7 @@ abstract class LiveWallpaper : WallpaperService() {
                xOffsetStep,
                yOffsetStep,
                xPixelOffset,
                yPixelOffset
                yPixelOffset,
            )

            if (wallpaperEngine is LiveWallpaperEventListener) {
@@ -328,7 +327,7 @@ abstract class LiveWallpaper : WallpaperService() {
                        1.0f
                    } else {
                        xOffsetStep
                    }
                    },
                )
            }
        }
@@ -368,7 +367,7 @@ abstract class LiveWallpaper : WallpaperService() {
            y: Int,
            z: Int,
            extras: Bundle?,
            resultRequested: Boolean
            resultRequested: Boolean,
        ): Bundle? {
            when (action) {
                COMMAND_REAPPLY -> onWallpaperReapplied()
@@ -406,9 +405,7 @@ abstract class LiveWallpaper : WallpaperService() {
            wallpaperEngine.onWallpaperFlagsChanged(which)
        }

        /**
         * This is overriding a hidden API [WallpaperService.shouldZoomOutWallpaper].
         */
        /** This is overriding a hidden API [WallpaperService.shouldZoomOutWallpaper]. */
        override fun shouldZoomOutWallpaper(): Boolean {
            if (wallpaperEngine is LiveWallpaperEventListener) {
                return (wallpaperEngine as LiveWallpaperEventListener).shouldZoomOutWallpaper()
+20 −19
Original line number Diff line number Diff line
@@ -36,8 +36,8 @@ interface LiveWallpaperEventListener {
     * the home of the launcher). This only tracts the horizontal scroll.
     *
     * @param xOffset The current offset of the scroll. The value is normalize between [0,1].
     * @param xOffsetStep How is stepped the scroll. If you invert [xOffsetStep] you get the
     * number of pages in the scrolling area.
     * @param xOffsetStep How is stepped the scroll. If you invert [xOffsetStep] you get the number
     *   of pages in the scrolling area.
     */
    fun onOffsetChanged(xOffset: Float, xOffsetStep: Float)

@@ -45,27 +45,28 @@ interface LiveWallpaperEventListener {
     * Called when the zoom level of the wallpaper is changing.
     *
     * @param zoomLevel A value between 0 and 1 that tells how much the wallpaper should be zoomed
     * out: if 0, the wallpaper should be in normal state; if 1 the wallpaper should be zoomed out.
     *   out: if 0, the wallpaper should be in normal state; if 1 the wallpaper should be zoomed
     *   out.
     */
    fun onZoomChanged(zoomLevel: Float)

    /**
     * Call when the wallpaper was set, and then is reapplied. This means that the wallpaper was
     * set and is being set again. This is useful to know if the wallpaper settings have to be
     * reapplied again (i.e. if the user enters the wallpaper picker and picks the same wallpaper,
     * changes the settings and sets the wallpaper again).
     * Call when the wallpaper was set, and then is reapplied. This means that the wallpaper was set
     * and is being set again. This is useful to know if the wallpaper settings have to be reapplied
     * again (i.e. if the user enters the wallpaper picker and picks the same wallpaper, changes the
     * settings and sets the wallpaper again).
     */
    fun onWallpaperReapplied()

    /**
     * Called when the Wallpaper colors need to be computed you can create a [WallpaperColors]
     * instance using the [WallpaperColors.fromBitmap] function and passing a bitmap that
     * represents the wallpaper (i.e. the gallery thumbnail) or use the [WallpaperColors]
     * constructor and pass the primary, secondary and tertiary colors. This method is specially
     * important since the UI will change their colors based on what is returned here.
     * instance using the [WallpaperColors.fromBitmap] function and passing a bitmap that represents
     * the wallpaper (i.e. the gallery thumbnail) or use the [WallpaperColors] constructor and pass
     * the primary, secondary and tertiary colors. This method is specially important since the UI
     * will change their colors based on what is returned here.
     *
     * @return The colors that represent the wallpaper; null if you want the System to take
     * care of the colors.
     * @return The colors that represent the wallpaper; null if you want the System to take care of
     *   the colors.
     */
    fun computeWallpaperColors(): WallpaperColors?

@@ -73,8 +74,8 @@ interface LiveWallpaperEventListener {
     * Called when the wallpaper receives the preview information (asynchronous call).
     *
     * @param extras the bundle of the preview information. The key "which_preview" can be used to
     * retrieve a string value (ex. main_preview_home) that specifies which preview the engine
     * is referring to.
     *   retrieve a string value (ex. main_preview_home) that specifies which preview the engine is
     *   referring to.
     */
    fun onPreviewInfoReceived(extras: Bundle?) {}

+1 −6
Original line number Diff line number Diff line
@@ -15,9 +15,4 @@
     limitations under the License.
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.android.app.viewcapture">
    <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"
        tools:ignore="ProtectedPermissions" />
</manifest>
<manifest package="com.android.app.viewcapture"/>
 No newline at end of file
+5 −0
Original line number Diff line number Diff line
@@ -15,7 +15,12 @@
  -->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.android.app.viewcapture.test">

    <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"
        tools:ignore="ProtectedPermissions" />

    <application
        android:debuggable="true"
        android:theme="@android:style/Theme.NoTitleBar">
Loading