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

Commit 3c1756bb authored by Jay Aliomer's avatar Jay Aliomer Committed by Android (Google) Code Review
Browse files

Merge "Revert^2 "Wallpaper Local color sampling"" into sc-dev

parents 145b1a45 4f172bf8
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.app;

import android.app.WallpaperColors;
import android.graphics.RectF;

/**
 * @hide
 */
oneway interface ILocalWallpaperColorConsumer {
    void onColorsChanged(in RectF area, in WallpaperColors colors);
}
 No newline at end of file
+14 −0
Original line number Diff line number Diff line
@@ -17,9 +17,11 @@
package android.app;

import android.graphics.Rect;
import android.graphics.RectF;
import android.os.Bundle;
import android.os.ParcelFileDescriptor;
import android.app.IWallpaperManagerCallback;
import android.app.ILocalWallpaperColorConsumer;
import android.app.WallpaperInfo;
import android.content.ComponentName;
import android.app.WallpaperColors;
@@ -161,6 +163,18 @@ interface IWallpaperManager {
     */
    WallpaperColors getWallpaperColors(int which, int userId, int displayId);

    /**
    * @hide
    */
    void removeOnLocalColorsChangedListener(
            in ILocalWallpaperColorConsumer callback, int which, int userId, int displayId);

    /**
    * @hide
    */
    void addOnLocalColorsChangedListener(in ILocalWallpaperColorConsumer callback,
                                    in List<RectF> regions, int which, int userId, int displayId);

    /**
     * Register a callback to receive color updates from a display
     */
+76 −0
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ import android.os.RemoteException;
import android.os.StrictMode;
import android.os.SystemProperties;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.Log;
import android.util.Pair;
import android.view.Display;
@@ -107,6 +108,8 @@ public class WallpaperManager {
    private static boolean DEBUG = false;
    private float mWallpaperXStep = -1;
    private float mWallpaperYStep = -1;
    private static final @NonNull RectF LOCAL_COLOR_BOUNDS =
            new RectF(0, 0, 1, 1);

    /** {@hide} */
    private static final String PROP_WALLPAPER = "ro.config.wallpaper";
@@ -309,6 +312,8 @@ public class WallpaperManager {
        private int mCachedWallpaperUserId;
        private Bitmap mDefaultWallpaper;
        private Handler mMainLooperHandler;
        private ArrayMap<LocalWallpaperColorConsumer, ILocalWallpaperColorConsumer>
                mLocalColorCallbacks = new ArrayMap<>();

        Globals(IWallpaperManager service, Looper looper) {
            mService = service;
@@ -350,6 +355,40 @@ public class WallpaperManager {
            }
        }

        private ILocalWallpaperColorConsumer wrap(LocalWallpaperColorConsumer callback) {
            ILocalWallpaperColorConsumer callback2 = new ILocalWallpaperColorConsumer.Stub() {
                @Override
                public void onColorsChanged(RectF area, WallpaperColors colors) {
                    callback.onColorsChanged(area, colors);
                }
            };
            mLocalColorCallbacks.put(callback, callback2);
            return callback2;
        }

        public void addOnColorsChangedListener(@NonNull LocalWallpaperColorConsumer callback,
                @NonNull List<RectF> regions, int which, int userId, int displayId) {
            try {
                mService.addOnLocalColorsChangedListener(wrap(callback) , regions, which,
                                                         userId, displayId);
            } catch (RemoteException e) {
                // Can't get colors, connection lost.
            }
        }

        public void removeOnColorsChangedListener(
                @NonNull LocalWallpaperColorConsumer callback, int which, int userId,
                int displayId) {
            ILocalWallpaperColorConsumer callback2 = mLocalColorCallbacks.remove(callback);
            if (callback2 == null) return;
            try {
                mService.removeOnLocalColorsChangedListener(
                        callback2, which, userId, displayId);
            } catch (RemoteException e) {
                // Can't get colors, connection lost.
            }
        }

        /**
         * Stop listening to wallpaper color events.
         *
@@ -1056,6 +1095,29 @@ public class WallpaperManager {
        return sGlobals.getWallpaperColors(which, userId, mContext.getDisplayId());
    }

    /**
     * @hide
     */
    public void addOnColorsChangedListener(@NonNull LocalWallpaperColorConsumer callback,
            List<RectF> regions) throws IllegalArgumentException {
        for (RectF region : regions) {
            if (!LOCAL_COLOR_BOUNDS.contains(region)) {
                throw new IllegalArgumentException("Regions must be within bounds "
                        + LOCAL_COLOR_BOUNDS);
            }
        }
        sGlobals.addOnColorsChangedListener(callback, regions, FLAG_SYSTEM,
                                                 mContext.getUserId(), mContext.getDisplayId());
    }

    /**
     * @hide
     */
    public void removeOnColorsChangedListener(@NonNull LocalWallpaperColorConsumer callback) {
        sGlobals.removeOnColorsChangedListener(callback, FLAG_SYSTEM, mContext.getUserId(),
                mContext.getDisplayId());
    }

    /**
     * Version of {@link #getWallpaperFile(int)} that can access the wallpaper data
     * for a given user.  The caller must hold the INTERACT_ACROSS_USERS_FULL
@@ -2202,4 +2264,18 @@ public class WallpaperManager {
            onColorsChanged(colors, which);
        }
    }

    /**
     * Callback to update a consumer with a local color change
     * @hide
     */
    public interface LocalWallpaperColorConsumer {

        /**
         * Gets called when a color of an area gets updated
         * @param area
         * @param colors
         */
        void onColorsChanged(RectF area, WallpaperColors colors);
    }
}
+96 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.service.wallpaper;

import android.app.WallpaperColors;
import android.graphics.Bitmap;
import android.graphics.RectF;
import android.util.ArrayMap;
import android.util.ArraySet;

import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;

/**
 * This class represents a page of a launcher page used by the wallpaper
 * @hide
 */
public class EngineWindowPage {
    private Bitmap mScreenShot;
    private volatile long  mLastUpdateTime = 0;
    private Set<RectF> mCallbackAreas = new ArraySet<>();
    private Map<RectF, WallpaperColors> mRectFColors = new ArrayMap<>();

    /** should be locked extrnally */
    public void addArea(RectF area) {
        mCallbackAreas.add(area);
    }

    /** should be locked extrnally */
    public void addWallpaperColors(RectF area, WallpaperColors colors) {
        mCallbackAreas.add(area);
        mRectFColors.put(area, colors);
    }

    /** get screenshot bitmap */
    public Bitmap getBitmap() {
        if (mScreenShot == null || mScreenShot.isRecycled()) return null;
        return mScreenShot;
    }

    /** remove callbacks for an area */
    public void removeArea(RectF area) {
        mCallbackAreas.remove(area);
        mRectFColors.remove(area);
    }

    /** set the last time the screenshot was updated */
    public void setLastUpdateTime(long lastUpdateTime) {
        mLastUpdateTime = lastUpdateTime;
    }

    /** get last screenshot time */
    public long getLastUpdateTime() {
        return mLastUpdateTime;
    }

    /** get colors for an area */
    public WallpaperColors getColors(RectF rect) {
        return mRectFColors.get(rect);
    }

    /** set the new bitmap version */
    public void setBitmap(Bitmap screenShot) {
        mScreenShot = screenShot;
    }

    /** get areas of interest */
    public Set<RectF> getAreas() {
        return mCallbackAreas;
    }

    /** run operations on this page */
    public synchronized void execSync(Consumer<EngineWindowPage> run) {
        run.accept(this);
    }

    /** nullify the area color */
    public void removeColor(RectF colorArea) {
        mRectFColors.remove(colorArea);
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.service.wallpaper;

import android.graphics.RectF;
import android.os.ParcelFileDescriptor;
import android.service.wallpaper.IWallpaperEngine;
import android.app.WallpaperColors;
@@ -28,4 +29,5 @@ interface IWallpaperConnection {
    void engineShown(IWallpaperEngine engine);
    ParcelFileDescriptor setWallpaper(String name);
    void onWallpaperColorsChanged(in WallpaperColors colors, int displayId);
    void onLocalWallpaperColorsChanged(in RectF area, in WallpaperColors colors, int displayId);
}
Loading