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

Commit 44a28315 authored by Santiago Etchebehere's avatar Santiago Etchebehere
Browse files

[Zoom-out 1/N] Add API in WallpaperManager

Add an API in WallpaperManager (client and server) and
WallpaperService to pass a wallpaper zoom value to the
wallpaper service and engine.

Bug: 146387434
Test: (added testDeliversZoomChanged)
Test: atest WallpaperServiceTest
Change-Id: Idd9ea2aefb845ad1d330cbdd6e088b926bcfece7
parent 1ea91ab3
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -43033,6 +43033,7 @@ package android.service.wallpaper {
    method public void onSurfaceRedrawNeeded(android.view.SurfaceHolder);
    method public void onTouchEvent(android.view.MotionEvent);
    method public void onVisibilityChanged(boolean);
    method public void onZoomChanged(@FloatRange(from=0.0f, to=1.0f) float);
    method public void setOffsetNotificationsEnabled(boolean);
    method public void setTouchEventsEnabled(boolean);
  }
+7 −0
Original line number Diff line number Diff line
@@ -175,4 +175,11 @@ interface IWallpaperManager {
     * Called from SystemUI when it shows the AoD UI.
     */
    oneway void setInAmbientMode(boolean inAmbientMode, long animationDuration);

    /**
     * Called when the wallpaper needs to zoom out.
     * The zoom value goes from 0 to 1 (inclusive) where 1 means fully zoomed out,
     * 0 means fully zoomed in
     */
    oneway void setWallpaperZoomOut(float zoom, String callingPackage, int displayId);
}
+18 −0
Original line number Diff line number Diff line
@@ -1832,6 +1832,24 @@ public class WallpaperManager {
        }
    }

    /**
     * Set the current zoom out level of the wallpaper
     * @param zoom from 0 to 1 (inclusive) where 1 means fully zoomed out, 0 means fully zoomed in
     *
     * @hide
     */
    public void setWallpaperZoomOut(float zoom) {
        if (zoom < 0 || zoom > 1f) {
            throw new IllegalArgumentException("zoom must be between 0 and one: " + zoom);
        }
        try {
            sGlobals.mService.setWallpaperZoomOut(zoom, mContext.getOpPackageName(),
                    mContext.getDisplayId());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Returns whether wallpapers are supported for the calling user. If this function returns
     * {@code false}, any attempts to changing the wallpaper will have no effect,
+1 −0
Original line number Diff line number Diff line
@@ -37,4 +37,5 @@ oneway interface IWallpaperEngine {
    void requestWallpaperColors();
    @UnsupportedAppUsage
    void destroy();
    void setZoomOut(float scale);
}
+66 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.service.wallpaper;

import android.annotation.FloatRange;
import android.annotation.Nullable;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
@@ -121,6 +122,9 @@ public abstract class WallpaperService extends Service {
    private static final int MSG_WINDOW_MOVED = 10035;
    private static final int MSG_TOUCH_EVENT = 10040;
    private static final int MSG_REQUEST_WALLPAPER_COLORS = 10050;
    private static final int MSG_SCALE = 10100;

    private static final float MAX_SCALE = 1.15f;

    private static final int NOTIFY_COLORS_RATE_LIMIT_MS = 1000;

@@ -169,6 +173,7 @@ public abstract class WallpaperService extends Service {
        int mType;
        int mCurWidth;
        int mCurHeight;
        float mZoom = 0f;
        int mWindowFlags = WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
        int mWindowPrivateFlags =
                WindowManager.LayoutParams.PRIVATE_FLAG_WANTS_OFFSET_NOTIFICATIONS;
@@ -493,6 +498,15 @@ public abstract class WallpaperService extends Service {
            mFixedSizeAllowed = allowed;
        }

        /**
         * Returns the current scale of the surface
         * @hide
         */
        @VisibleForTesting
        public float getZoom() {
            return mZoom;
        }

        /**
         * Called once to initialize the engine.  After returning, the
         * engine's surface will be created by the framework.
@@ -620,6 +634,16 @@ public abstract class WallpaperService extends Service {
        public void onSurfaceDestroyed(SurfaceHolder holder) {
        }

        /**
         * Called when the zoom level of the wallpaper changed.
         * This method will be called with the initial zoom level when the surface is created.
         *
         * @param zoom the zoom level, between 0 indicating fully zoomed in and 1 indicating fully
         *             zoomed out.
         */
        public void onZoomChanged(@FloatRange(from = 0f, to = 1f) float zoom) {
        }

        /**
         * Notifies the engine that wallpaper colors changed significantly.
         * This will trigger a {@link #onComputeColors()} call.
@@ -704,6 +728,7 @@ public abstract class WallpaperService extends Service {
            out.print(prefix); out.print("mConfiguration=");
                    out.println(mMergedConfiguration.getMergedConfiguration());
            out.print(prefix); out.print("mLayout="); out.println(mLayout);
            out.print(prefix); out.print("mZoom="); out.println(mZoom);
            synchronized (mLock) {
                out.print(prefix); out.print("mPendingXOffset="); out.print(mPendingXOffset);
                        out.print(" mPendingXOffset="); out.println(mPendingXOffset);
@@ -719,6 +744,37 @@ public abstract class WallpaperService extends Service {
            }
        }

        /**
         * Set the wallpaper zoom to the given value. This value will be ignored when in ambient
         * mode (and zoom will be reset to 0).
         * @hide
         * @param zoom between 0 and 1 (inclusive) indicating fully zoomed in to fully zoomed out
         *              respectively.
         */
        @VisibleForTesting
        public void setZoom(float zoom) {
            if (DEBUG) {
                Log.v(TAG, "set zoom received: " + zoom);
            }
            boolean updated = false;
            synchronized (mLock) {
                if (DEBUG) {
                    Log.v(TAG, "mZoom: " + mZoom + " updated: " + zoom);
                }
                if (mIsInAmbientMode) {
                    mZoom = 0;
                }
                if (Float.compare(zoom, mZoom) != 0) {
                    mZoom = zoom;
                    updated = true;
                }
            }
            if (DEBUG) Log.v(TAG, "setZoom updated? " + updated);
            if (updated && !mDestroyed) {
                onZoomChanged(mZoom);
            }
        }

        private void dispatchPointer(MotionEvent event) {
            if (event.isTouchEvent()) {
                synchronized (mLock) {
@@ -917,6 +973,7 @@ public abstract class WallpaperService extends Service {
                                    c.surfaceCreated(mSurfaceHolder);
                                }
                            }
                            onZoomChanged(0f);
                        }

                        redrawNeeded |= creating || (relayoutResult
@@ -1077,6 +1134,7 @@ public abstract class WallpaperService extends Service {
                mIsInAmbientMode = inAmbientMode;
                if (mCreated) {
                    onAmbientModeChanged(inAmbientMode, animationDuration);
                    setZoom(0);
                }
            }
        }
@@ -1351,6 +1409,11 @@ public abstract class WallpaperService extends Service {
            }
        }

        public void setZoomOut(float scale) {
            Message msg = mCaller.obtainMessageI(MSG_SCALE, Float.floatToIntBits(scale));
            mCaller.sendMessage(msg);
        }

        public void reportShown() {
            if (!mShownReported) {
                mShownReported = true;
@@ -1423,6 +1486,9 @@ public abstract class WallpaperService extends Service {
                case MSG_UPDATE_SURFACE:
                    mEngine.updateSurface(true, false, false);
                    break;
                case MSG_SCALE:
                    mEngine.setZoom(Float.intBitsToFloat(message.arg1));
                    break;
                case MSG_VISIBILITY_CHANGED:
                    if (DEBUG) Log.v(TAG, "Visibility change in " + mEngine
                            + ": " + message.arg1);
Loading