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

Commit cc560f43 authored by Chris Poultney's avatar Chris Poultney
Browse files

Lock screen live wallpaper: adds home/lock screen flag as argument.

Bug: 253481667
Test: TreeHugger
Test: CTS tests for API changes in same topic
Change-Id: Icfe1096026569baf29bc3ffe062327c4d52b17fa
parent 9d601f12
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -7272,6 +7272,7 @@ package android.app {
    method @RequiresPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE) public android.os.ParcelFileDescriptor getWallpaperFile(int);
    method public int getWallpaperId(int);
    method public android.app.WallpaperInfo getWallpaperInfo();
    method @Nullable public android.app.WallpaperInfo getWallpaperInfo(int);
    method public boolean hasResourceWallpaper(@RawRes int);
    method public boolean isSetWallpaperAllowed();
    method public boolean isWallpaperSupported();
@@ -39986,6 +39987,7 @@ package android.service.wallpaper {
    method public int getDesiredMinimumWidth();
    method @Nullable public android.content.Context getDisplayContext();
    method public android.view.SurfaceHolder getSurfaceHolder();
    method public int getWallpaperFlags();
    method public boolean isPreview();
    method public boolean isVisible();
    method public void notifyColorsChanged();
@@ -40002,6 +40004,7 @@ package android.service.wallpaper {
    method @MainThread public void onSurfaceRedrawNeeded(android.view.SurfaceHolder);
    method @MainThread public void onTouchEvent(android.view.MotionEvent);
    method @MainThread public void onVisibilityChanged(boolean);
    method @MainThread public void onWallpaperFlagsChanged(int);
    method @MainThread public void onZoomChanged(@FloatRange(from=0.0f, to=1.0f) float);
    method public void setOffsetNotificationsEnabled(boolean);
    method public void setTouchEventsEnabled(boolean);
+1 −0
Original line number Diff line number Diff line
@@ -1082,6 +1082,7 @@ package android.app {
    method @FloatRange(from=0.0f, to=1.0f) @RequiresPermission(android.Manifest.permission.SET_WALLPAPER_DIM_AMOUNT) public float getWallpaperDimAmount();
    method public void setDisplayOffset(android.os.IBinder, int, int);
    method @RequiresPermission(android.Manifest.permission.SET_WALLPAPER_COMPONENT) public boolean setWallpaperComponent(android.content.ComponentName);
    method @RequiresPermission(android.Manifest.permission.SET_WALLPAPER_COMPONENT) public boolean setWallpaperComponentWithFlags(@NonNull android.content.ComponentName, int);
    method @RequiresPermission(android.Manifest.permission.SET_WALLPAPER_DIM_AMOUNT) public void setWallpaperDimAmount(@FloatRange(from=0.0f, to=1.0f) float);
  }
+9 −2
Original line number Diff line number Diff line
@@ -50,9 +50,10 @@ interface IWallpaperManager {
            IWallpaperManagerCallback completion, int userId);

    /**
     * Set the live wallpaper. This only affects the system wallpaper.
     * Set the live wallpaper.
     */
    void setWallpaperComponentChecked(in ComponentName name, in String callingPackage, int userId);
    void setWallpaperComponentChecked(in ComponentName name, in String callingPackage, int which,
            int userId);

    /**
     * Set the live wallpaper. This only affects the system wallpaper.
@@ -88,6 +89,12 @@ interface IWallpaperManager {
    @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
    WallpaperInfo getWallpaperInfo(int userId);

    /**
     * If the current wallpaper for destination `which` is a live wallpaper component, return the
     * information about that wallpaper.  Otherwise, if it is a static image, simply return null.
     */
    WallpaperInfo getWallpaperInfoWithFlags(int which, int userId);

    /**
     * Clear the system wallpaper.
     */
+97 −41
Original line number Diff line number Diff line
@@ -67,7 +67,6 @@ import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import android.os.StrictMode;
import android.os.SystemProperties;
import android.service.wallpaper.WallpaperService;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.ArraySet;
@@ -521,10 +520,7 @@ public class WallpaperManager {
        }

        WallpaperColors getWallpaperColors(int which, int userId, int displayId) {
            if (which != FLAG_LOCK && which != FLAG_SYSTEM) {
                throw new IllegalArgumentException(
                        "Must request colors for exactly one kind of wallpaper");
            }
            checkExactlyOneWallpaperFlagSet(which);

            try {
                return mService.getWallpaperColors(which, userId, displayId);
@@ -857,9 +853,7 @@ public class WallpaperManager {
            throw new RuntimeException(new DeadSystemException());
        }

        if (which != FLAG_SYSTEM && which != FLAG_LOCK) {
            throw new IllegalArgumentException("Must request exactly one kind of wallpaper");
        }
        checkExactlyOneWallpaperFlagSet(which);

        Resources resources = mContext.getResources();
        horizontalAlignment = Math.max(0, Math.min(1, horizontalAlignment));
@@ -1114,6 +1108,19 @@ public class WallpaperManager {
        return getBitmapAsUser(mContext.getUserId(), hardware);
    }

    /**
     * Like {@link #getDrawable()} but returns a Bitmap.
     *
     * @param hardware Asks for a hardware backed bitmap.
     * @param which Specifies home or lock screen
     * @see Bitmap.Config#HARDWARE
     * @hide
     */
    @Nullable
    public Bitmap getBitmap(boolean hardware, @SetWallpaperFlags int which) {
        return getBitmapAsUser(mContext.getUserId(), hardware, which);
    }

    /**
     * Like {@link #getDrawable()} but returns a Bitmap for the provided user.
     *
@@ -1124,6 +1131,17 @@ public class WallpaperManager {
        return sGlobals.peekWallpaperBitmap(mContext, true, FLAG_SYSTEM, userId, hardware, cmProxy);
    }

    /**
     * Like {@link #getDrawable()} but returns a Bitmap for the provided user.
     *
     * @param which Specifies home or lock screen
     * @hide
     */
    public Bitmap getBitmapAsUser(int userId, boolean hardware, @SetWallpaperFlags int which) {
        final ColorManagementProxy cmProxy = getColorManagementProxy();
        return sGlobals.peekWallpaperBitmap(mContext, true, which, userId, hardware, cmProxy);
    }

    /**
     * Peek the dimensions of system wallpaper of the user without decoding it.
     *
@@ -1281,9 +1299,7 @@ public class WallpaperManager {
     */
    @UnsupportedAppUsage
    public ParcelFileDescriptor getWallpaperFile(@SetWallpaperFlags int which, int userId) {
        if (which != FLAG_SYSTEM && which != FLAG_LOCK) {
            throw new IllegalArgumentException("Must request exactly one kind of wallpaper");
        }
        checkExactlyOneWallpaperFlagSet(which);

        if (sGlobals.mService == null) {
            Log.w(TAG, "WallpaperService not running");
@@ -1333,16 +1349,7 @@ public class WallpaperManager {
     * @hide
     */
    public WallpaperInfo getWallpaperInfoForUser(int userId) {
        try {
            if (sGlobals.mService == null) {
                Log.w(TAG, "WallpaperService not running");
                throw new RuntimeException(new DeadSystemException());
            } else {
                return sGlobals.mService.getWallpaperInfo(userId);
            }
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
        return getWallpaperInfo(FLAG_SYSTEM, userId);
    }

    /**
@@ -1353,10 +1360,10 @@ public class WallpaperManager {
     * @param which Specifies wallpaper to request (home or lock).
     * @throws IllegalArgumentException if {@code which} is not exactly one of
     * {{@link #FLAG_SYSTEM},{@link #FLAG_LOCK}}.
     * @hide
     */
    @Nullable
    public WallpaperInfo getWallpaperInfo(@SetWallpaperFlags int which) {
        return getWallpaperInfo();
        return getWallpaperInfo(which, mContext.getUserId());
    }

    /**
@@ -1371,7 +1378,17 @@ public class WallpaperManager {
     * @hide
     */
    public WallpaperInfo getWallpaperInfo(@SetWallpaperFlags int which, int userId) {
        return getWallpaperInfoForUser(userId);
        checkExactlyOneWallpaperFlagSet(which);
        try {
            if (sGlobals.mService == null) {
                Log.w(TAG, "WallpaperService not running");
                throw new RuntimeException(new DeadSystemException());
            } else {
                return sGlobals.mService.getWallpaperInfoWithFlags(which, userId);
            }
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
@@ -2012,7 +2029,10 @@ public class WallpaperManager {
    }

    /**
     * Set the live wallpaper.
     * Set the implementation of {@link android.service.wallpaper.WallpaperService} used to render
     * wallpaper, usually in order to set a live wallpaper.
     *
     * @param name Name of the component to use.
     *
     * @hide
     */
@@ -2080,43 +2100,72 @@ public class WallpaperManager {
    }

    /**
     * Set the live wallpaper.
     * Set the implementation of {@link android.service.wallpaper.WallpaperService} used to render
     * wallpaper, usually in order to set a live wallpaper.
     *
     * This can only be called by packages with android.permission.SET_WALLPAPER_COMPONENT
     * permission. The caller must hold the INTERACT_ACROSS_USERS_FULL permission to change
     * another user's wallpaper.
     *
     * @param name Name of the component to use.
     * @param userId User for whom the component should be set.
     *
     * @hide
     */
    @RequiresPermission(android.Manifest.permission.SET_WALLPAPER_COMPONENT)
    @UnsupportedAppUsage
    public boolean setWallpaperComponent(ComponentName name, int userId) {
        if (sGlobals.mService == null) {
            Log.w(TAG, "WallpaperService not running");
            throw new RuntimeException(new DeadSystemException());
        }
        try {
            sGlobals.mService.setWallpaperComponentChecked(name, mContext.getOpPackageName(),
                    userId);
            return true;
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
        return setWallpaperComponentWithFlags(name, FLAG_SYSTEM | FLAG_LOCK, userId);
    }

    /**
     * Set the live wallpaper for the given screen(s).
     * Set the implementation of {@link android.service.wallpaper.WallpaperService} used to render
     * wallpaper, usually in order to set a live wallpaper, for a given wallpaper destination.
     *
     * This can only be called by packages with android.permission.SET_WALLPAPER_COMPONENT
     * permission. The caller must hold the INTERACT_ACROSS_USERS_FULL permission to change
     * another user's wallpaper.
     *
     * @param name Name of the component to use.
     * @param which Specifies wallpaper destination (home and/or lock).
     *
     * @hide
     */
    @SystemApi
    @RequiresPermission(android.Manifest.permission.SET_WALLPAPER_COMPONENT)
    public boolean setWallpaperComponentWithFlags(@NonNull ComponentName name,
            @SetWallpaperFlags int which) {
        return setWallpaperComponent(name);
        return setWallpaperComponentWithFlags(name, which, mContext.getUserId());
    }

    /**
     * Set the implementation of {@link android.service.wallpaper.WallpaperService} used to render
     * wallpaper, usually in order to set a live wallpaper, for a given wallpaper destination.
     *
     * This can only be called by packages with android.permission.SET_WALLPAPER_COMPONENT
     * permission. The caller must hold the INTERACT_ACROSS_USERS_FULL permission to change
     * another user's wallpaper.
     *
     * @param name Name of the component to use.
     * @param which Specifies wallpaper destination (home and/or lock).
     * @param userId User for whom the component should be set.
     *
     * @hide
     */
    @RequiresPermission(android.Manifest.permission.SET_WALLPAPER_COMPONENT)
    public boolean setWallpaperComponentWithFlags(@NonNull ComponentName name,
            @SetWallpaperFlags int which, int userId) {
        if (sGlobals.mService == null) {
            Log.w(TAG, "WallpaperManagerService not running");
            throw new RuntimeException(new DeadSystemException());
        }
        try {
            sGlobals.mService.setWallpaperComponentChecked(name, mContext.getOpPackageName(),
                    which, userId);
            return true;
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
@@ -2440,6 +2489,13 @@ public class WallpaperManager {
        return mCmProxy;
    }

    private static void checkExactlyOneWallpaperFlagSet(@SetWallpaperFlags int which) {
        if (which == FLAG_SYSTEM || which == FLAG_LOCK) {
            return;
        }
        throw new IllegalArgumentException("Must specify exactly one kind of wallpaper");
    }

    /**
     * A hidden class to help {@link Globals#getCurrentWallpaperLocked} handle color management.
     * @hide
@@ -2519,7 +2575,7 @@ public class WallpaperManager {
         *
         * @param colors Wallpaper color info, {@code null} when not available.
         * @param which A combination of {@link #FLAG_LOCK} and {@link #FLAG_SYSTEM}
         * @see WallpaperService.Engine#onComputeColors()
         * @see android.service.wallpaper.WallpaperService.Engine#onComputeColors()
         */
        void onColorsChanged(@Nullable WallpaperColors colors, int which);

@@ -2531,7 +2587,7 @@ public class WallpaperManager {
         * @param colors Wallpaper color info, {@code null} when not available.
         * @param which A combination of {@link #FLAG_LOCK} and {@link #FLAG_SYSTEM}
         * @param userId Owner of the wallpaper
         * @see WallpaperService.Engine#onComputeColors()
         * @see android.service.wallpaper.WallpaperService.Engine#onComputeColors()
         * @hide
         */
        default void onColorsChanged(@Nullable WallpaperColors colors, int which, int userId) {
+1 −0
Original line number Diff line number Diff line
@@ -47,4 +47,5 @@ interface IWallpaperEngine {
    oneway void addLocalColorsAreas(in List<RectF> regions);
    SurfaceControl mirrorSurfaceControl();
    oneway void applyDimming(float dimAmount);
    oneway void setWallpaperFlags(int which);
}
Loading