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 | |
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
7 files changed, 161 insertions, 0 deletions
diff --git a/api/current.txt b/api/current.txt index ba14b4e6987a..70202e77ede7 100644 --- a/api/current.txt +++ b/api/current.txt @@ -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); } 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); diff --git a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java index 03139d2e5e03..36e97755ab8a 100644 --- a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java +++ b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java @@ -2180,6 +2180,47 @@ public class WallpaperManagerService extends IWallpaperManager.Stub } } + /** + * Called when the wallpaper needs to zoom out. + * + * @param zoom from 0 to 1 (inclusive) where 1 means fully zoomed out, 0 means fully zoomed in. + * @param callingPackage package name calling this API. + * @param displayId id of the display whose zoom is updating. + */ + public void setWallpaperZoomOut(float zoom, String callingPackage, int displayId) { + if (!isWallpaperSupported(callingPackage)) { + return; + } + synchronized (mLock) { + if (!isValidDisplay(displayId)) { + throw new IllegalArgumentException("Cannot find display with id=" + displayId); + } + int userId = UserHandle.getCallingUserId(); + if (mCurrentUserId != userId) { + return; // Don't change the properties now + } + WallpaperData wallpaper = getWallpaperSafeLocked(userId, FLAG_SYSTEM); + if (zoom < 0 || zoom > 1f) { + throw new IllegalArgumentException("zoom must be between 0 and one: " + zoom); + } + + if (wallpaper.connection != null) { + final WallpaperConnection.DisplayConnector connector = wallpaper.connection + .getDisplayConnectorOrCreate(displayId); + final IWallpaperEngine engine = connector != null ? connector.mEngine : null; + if (engine != null) { + try { + engine.setZoomOut(zoom); + } catch (RemoteException e) { + if (DEBUG) { + Slog.w(TAG, "Couldn't set wallpaper zoom", e); + } + } + } + } + } + } + @Deprecated @Override public ParcelFileDescriptor getWallpaper(String callingPkg, IWallpaperManagerCallback cb, diff --git a/tests/Internal/src/android/service/wallpaper/WallpaperServiceTest.java b/tests/Internal/src/android/service/wallpaper/WallpaperServiceTest.java index 592aa3ac4a6b..153ca79e346b 100644 --- a/tests/Internal/src/android/service/wallpaper/WallpaperServiceTest.java +++ b/tests/Internal/src/android/service/wallpaper/WallpaperServiceTest.java @@ -58,4 +58,31 @@ public class WallpaperServiceTest { ambientModeChangedCount[0], 2); } + @Test + public void testDeliversZoomChanged() { + int[] zoomChangedCount = {0}; + WallpaperService service = new WallpaperService() { + @Override + public Engine onCreateEngine() { + return new Engine() { + @Override + public void onZoomChanged(float zoom) { + super.onZoomChanged(zoom); + zoomChangedCount[0]++; + } + }; + } + }; + WallpaperService.Engine engine = service.onCreateEngine(); + engine.setCreated(true); + + engine.setZoom(.5f); + assertEquals("engine scale was not updated", .5f, engine.getZoom(), .001f); + assertEquals("onZoomChanged should have been called", 1, zoomChangedCount[0]); + + engine.setZoom(0); + assertEquals("engine scale was not updated", 0, engine.getZoom(), .001f); + assertEquals("onAmbientModeChanged should have been called", 2, zoomChangedCount[0]); + } + } |