diff options
| author | Santiago Etchebehere <santie@google.com> | 2020-01-14 15:27:11 -0800 |
|---|---|---|
| committer | Santiago Etchebehere <santie@google.com> | 2020-01-22 10:51:04 -0800 |
| commit | 44a2831560cad519f0caa38cf218c7ec92d4f708 (patch) | |
| tree | 950e4b8483150fddef463b646717a98109985d85 /core/java/android | |
| parent | 1ea91ab30b45fad354c3bb30d58711f8a8542b97 (diff) | |
[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
Diffstat (limited to 'core/java/android')
4 files changed, 92 insertions, 0 deletions
diff --git a/core/java/android/app/IWallpaperManager.aidl b/core/java/android/app/IWallpaperManager.aidl index 4cb8d936aa9c..34684c4c4228 100644 --- a/core/java/android/app/IWallpaperManager.aidl +++ b/core/java/android/app/IWallpaperManager.aidl @@ -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); } diff --git a/core/java/android/app/WallpaperManager.java b/core/java/android/app/WallpaperManager.java index 2507991362a5..c1800fbf00fa 100644 --- a/core/java/android/app/WallpaperManager.java +++ b/core/java/android/app/WallpaperManager.java @@ -1833,6 +1833,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, * and any attempt to obtain of the wallpaper will return {@code null}. diff --git a/core/java/android/service/wallpaper/IWallpaperEngine.aidl b/core/java/android/service/wallpaper/IWallpaperEngine.aidl index 00e0b7c170be..84b6869bf620 100644 --- a/core/java/android/service/wallpaper/IWallpaperEngine.aidl +++ b/core/java/android/service/wallpaper/IWallpaperEngine.aidl @@ -37,4 +37,5 @@ oneway interface IWallpaperEngine { void requestWallpaperColors(); @UnsupportedAppUsage void destroy(); + void setZoomOut(float scale); } diff --git a/core/java/android/service/wallpaper/WallpaperService.java b/core/java/android/service/wallpaper/WallpaperService.java index 9a76a1b4eb79..f0d2263e797a 100644 --- a/core/java/android/service/wallpaper/WallpaperService.java +++ b/core/java/android/service/wallpaper/WallpaperService.java @@ -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; @@ -494,6 +499,15 @@ public abstract class WallpaperService extends Service { } /** + * 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. */ @@ -621,6 +635,16 @@ public abstract class WallpaperService extends Service { } /** + * 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); |
