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

Commit 6e3f3545 authored by Chris Tate's avatar Chris Tate Committed by Android (Google) Code Review
Browse files

Merge "Expanded wallpaper APIs for keyguard and change detection"

parents c20ba757 ad3c2592
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -5686,10 +5686,13 @@ package android.app {
    method public android.graphics.drawable.Drawable peekFastDrawable();
    method public void sendWallpaperCommand(android.os.IBinder, java.lang.String, int, int, int, android.os.Bundle);
    method public void setBitmap(android.graphics.Bitmap) throws java.io.IOException;
    method public void setBitmap(android.graphics.Bitmap, android.graphics.Rect, boolean) throws java.io.IOException;
    method public int setBitmap(android.graphics.Bitmap, android.graphics.Rect, boolean) throws java.io.IOException;
    method public int setBitmap(android.graphics.Bitmap, android.graphics.Rect, boolean, int) throws java.io.IOException;
    method public void setResource(int) throws java.io.IOException;
    method public int setResource(int, int) throws java.io.IOException;
    method public void setStream(java.io.InputStream) throws java.io.IOException;
    method public void setStream(java.io.InputStream, android.graphics.Rect, boolean) throws java.io.IOException;
    method public int setStream(java.io.InputStream, android.graphics.Rect, boolean) throws java.io.IOException;
    method public int setStream(java.io.InputStream, android.graphics.Rect, boolean, int) throws java.io.IOException;
    method public void setWallpaperOffsetSteps(float, float);
    method public void setWallpaperOffsets(android.os.IBinder, float, float);
    method public void suggestDesiredDimensions(int, int);
@@ -5700,6 +5703,8 @@ package android.app {
    field public static final java.lang.String COMMAND_SECONDARY_TAP = "android.wallpaper.secondaryTap";
    field public static final java.lang.String COMMAND_TAP = "android.wallpaper.tap";
    field public static final java.lang.String EXTRA_LIVE_WALLPAPER_COMPONENT = "android.service.wallpaper.extra.LIVE_WALLPAPER_COMPONENT";
    field public static final int FLAG_SET_LOCK = 2; // 0x2
    field public static final int FLAG_SET_SYSTEM = 1; // 0x1
    field public static final java.lang.String WALLPAPER_PREVIEW_META_DATA = "android.wallpaper.preview";
  }
+7 −2
Original line number Diff line number Diff line
@@ -5818,12 +5818,15 @@ package android.app {
    method public android.graphics.drawable.Drawable peekFastDrawable();
    method public void sendWallpaperCommand(android.os.IBinder, java.lang.String, int, int, int, android.os.Bundle);
    method public void setBitmap(android.graphics.Bitmap) throws java.io.IOException;
    method public void setBitmap(android.graphics.Bitmap, android.graphics.Rect, boolean) throws java.io.IOException;
    method public int setBitmap(android.graphics.Bitmap, android.graphics.Rect, boolean) throws java.io.IOException;
    method public int setBitmap(android.graphics.Bitmap, android.graphics.Rect, boolean, int) throws java.io.IOException;
    method public void setDisplayOffset(android.os.IBinder, int, int);
    method public void setDisplayPadding(android.graphics.Rect);
    method public void setResource(int) throws java.io.IOException;
    method public int setResource(int, int) throws java.io.IOException;
    method public void setStream(java.io.InputStream) throws java.io.IOException;
    method public void setStream(java.io.InputStream, android.graphics.Rect, boolean) throws java.io.IOException;
    method public int setStream(java.io.InputStream, android.graphics.Rect, boolean) throws java.io.IOException;
    method public int setStream(java.io.InputStream, android.graphics.Rect, boolean, int) throws java.io.IOException;
    method public boolean setWallpaperComponent(android.content.ComponentName);
    method public void setWallpaperOffsetSteps(float, float);
    method public void setWallpaperOffsets(android.os.IBinder, float, float);
@@ -5835,6 +5838,8 @@ package android.app {
    field public static final java.lang.String COMMAND_SECONDARY_TAP = "android.wallpaper.secondaryTap";
    field public static final java.lang.String COMMAND_TAP = "android.wallpaper.tap";
    field public static final java.lang.String EXTRA_LIVE_WALLPAPER_COMPONENT = "android.service.wallpaper.extra.LIVE_WALLPAPER_COMPONENT";
    field public static final int FLAG_SET_LOCK = 2; // 0x2
    field public static final int FLAG_SET_SYSTEM = 1; // 0x1
    field public static final java.lang.String WALLPAPER_PREVIEW_META_DATA = "android.wallpaper.preview";
  }
+7 −2
Original line number Diff line number Diff line
@@ -5688,10 +5688,13 @@ package android.app {
    method public android.graphics.drawable.Drawable peekFastDrawable();
    method public void sendWallpaperCommand(android.os.IBinder, java.lang.String, int, int, int, android.os.Bundle);
    method public void setBitmap(android.graphics.Bitmap) throws java.io.IOException;
    method public void setBitmap(android.graphics.Bitmap, android.graphics.Rect, boolean) throws java.io.IOException;
    method public int setBitmap(android.graphics.Bitmap, android.graphics.Rect, boolean) throws java.io.IOException;
    method public int setBitmap(android.graphics.Bitmap, android.graphics.Rect, boolean, int) throws java.io.IOException;
    method public void setResource(int) throws java.io.IOException;
    method public int setResource(int, int) throws java.io.IOException;
    method public void setStream(java.io.InputStream) throws java.io.IOException;
    method public void setStream(java.io.InputStream, android.graphics.Rect, boolean) throws java.io.IOException;
    method public int setStream(java.io.InputStream, android.graphics.Rect, boolean) throws java.io.IOException;
    method public int setStream(java.io.InputStream, android.graphics.Rect, boolean, int) throws java.io.IOException;
    method public void setWallpaperOffsetSteps(float, float);
    method public void setWallpaperOffsets(android.os.IBinder, float, float);
    method public void suggestDesiredDimensions(int, int);
@@ -5702,6 +5705,8 @@ package android.app {
    field public static final java.lang.String COMMAND_SECONDARY_TAP = "android.wallpaper.secondaryTap";
    field public static final java.lang.String COMMAND_TAP = "android.wallpaper.tap";
    field public static final java.lang.String EXTRA_LIVE_WALLPAPER_COMPONENT = "android.service.wallpaper.extra.LIVE_WALLPAPER_COMPONENT";
    field public static final int FLAG_SET_LOCK = 2; // 0x2
    field public static final int FLAG_SET_SYSTEM = 1; // 0x1
    field public static final java.lang.String WALLPAPER_PREVIEW_META_DATA = "android.wallpaper.preview";
  }
+17 −7
Original line number Diff line number Diff line
@@ -28,37 +28,47 @@ interface IWallpaperManager {

    /**
     * Set the wallpaper.
     *
     * If 'extras' is non-null, on successful return it will contain:
     *   EXTRA_SET_WALLPAPER_ID : integer ID that the new wallpaper will have
     *
     * 'which' is some combination of:
     *   FLAG_SET_SYSTEM
     *   FLAG_SET_LOCK
     */
    ParcelFileDescriptor setWallpaper(String name, in String callingPackage);
    ParcelFileDescriptor setWallpaper(String name, in String callingPackage,
            out Bundle extras, int which);
    
    /**
     * Set the live wallpaper.
     * Set the live wallpaper. This only affects the system wallpaper.
     */
    void setWallpaperComponentChecked(in ComponentName name, in String callingPackage);

    /**
     * Set the live wallpaper.
     * Set the live wallpaper. This only affects the system wallpaper.
     */
    void setWallpaperComponent(in ComponentName name);

    /**
     * Get the wallpaper.
     * Get the system wallpaper.
     */
    ParcelFileDescriptor getWallpaper(IWallpaperManagerCallback cb,
            out Bundle outParams);
    
    /**
     * Get information about a live wallpaper.
     * If the current system wallpaper is a live wallpaper component, return the
     * information about that wallpaper.  Otherwise, if it is a static image,
     * simply return null.
     */
    WallpaperInfo getWallpaperInfo();
    
    /**
     * Clear the wallpaper.
     * Clear the system wallpaper.
     */
    void clearWallpaper(in String callingPackage);

    /**
     * Return whether there is a wallpaper set with the given name.
     * Return whether the current system wallpaper has the given name.
     */
    boolean hasNamedWallpaper(String name);

+139 −32
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.app;

import android.annotation.IntDef;
import android.annotation.RawRes;
import android.annotation.SystemApi;
import android.content.ComponentName;
@@ -60,6 +61,8 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.List;

/**
@@ -145,6 +148,32 @@ public class WallpaperManager {
     */
    public static final String COMMAND_DROP = "android.home.drop";

    /**
     * Extra passed back from setWallpaper() giving the new wallpaper's assigned ID.
     * @hide
     */
    public static final String EXTRA_NEW_WALLPAPER_ID = "android.service.wallpaper.extra.ID";

    // flags for which kind of wallpaper to set

    /** @hide */
    @IntDef(flag = true, value = {
            FLAG_SET_SYSTEM,
            FLAG_SET_LOCK
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface SetWallpaperFlags {}

    /**
     * Flag: use the supplied imagery as the general system wallpaper.
     */
    public static final int FLAG_SET_SYSTEM = 1 << 0;

    /**
     * Flag: use the supplied imagery as the lock-screen wallpaper.
     */
    public static final int FLAG_SET_LOCK = 1 << 1;

    private final Context mContext;
    
    /**
@@ -717,20 +746,41 @@ public class WallpaperManager {
     * wallpaper.
     */
    public void setResource(@RawRes int resid) throws IOException {
        setResource(resid, FLAG_SET_SYSTEM);
    }

    /**
     * Version of {@link #setResource(int)} that takes an optional Bundle for returning
     * metadata about the operation to the caller.
     *
     * @param resid
     * @param which Flags indicating which wallpaper(s) to configure with the new imagery.
     *
     * @see #FLAG_SET_LOCK
     * @see #FLAG_SET_SYSTEM
     *
     * @return An integer ID assigned to the newly active wallpaper; or zero on failure.
     *
     * @throws IOException
     */
    public int setResource(@RawRes int resid, @SetWallpaperFlags int which)
            throws IOException {
        if (sGlobals.mService == null) {
            Log.w(TAG, "WallpaperService not running");
            return;
            return 0;
        }
        final Bundle result = new Bundle();
        try {
            Resources resources = mContext.getResources();
            /* Set the wallpaper to the default values */
            ParcelFileDescriptor fd = sGlobals.mService.setWallpaper(
                    "res:" + resources.getResourceName(resid), mContext.getOpPackageName());
                    "res:" + resources.getResourceName(resid),
                    mContext.getOpPackageName(), result, which);
            if (fd != null) {
                FileOutputStream fos = null;
                try {
                    fos = new ParcelFileDescriptor.AutoCloseOutputStream(fd);
                    setWallpaper(resources.openRawResource(resid), fos);
                    copyStreamToWallpaperFile(resources.openRawResource(resid), fos);
                } finally {
                    IoUtils.closeQuietly(fos);
                }
@@ -738,6 +788,7 @@ public class WallpaperManager {
        } catch (RemoteException e) {
            // Ignore
        }
        return result.getInt(EXTRA_NEW_WALLPAPER_ID, 0);
    }

    /**
@@ -753,7 +804,7 @@ public class WallpaperManager {
     * <p>This method requires the caller to hold the permission
     * {@link android.Manifest.permission#SET_WALLPAPER}.
     *
     * @param bitmap The bitmap to save.
     * @param bitmap The bitmap to be used as the new system wallpaper.
     *
     * @throws IOException If an error occurs when attempting to set the wallpaper
     *     to the provided image.
@@ -783,24 +834,52 @@ public class WallpaperManager {
     * @param allowBackup {@code true} if the OS is permitted to back up this wallpaper
     *     image for restore to a future device; {@code false} otherwise.
     *
     * @return An integer ID assigned to the newly active wallpaper; or zero on failure.
     *
     * @throws IOException If an error occurs when attempting to set the wallpaper
     *     to the provided image.
     * @throws IllegalArgumentException If the {@code visibleCropHint} rectangle is
     *     empty or invalid.
     */
    public void setBitmap(Bitmap fullImage, Rect visibleCropHint, boolean allowBackup)
    public int setBitmap(Bitmap fullImage, Rect visibleCropHint, boolean allowBackup)
            throws IOException {
        return setBitmap(fullImage, visibleCropHint, allowBackup, FLAG_SET_SYSTEM);
    }

    /**
    /**
     * Version of {@link #setBitmap(Bitmap, Rect, boolean)} that allows the caller
     * to specify which of the supported wallpaper categories to set.
     *
     * @param fullImage A bitmap that will supply the wallpaper imagery.
     * @param visibleCropHint The rectangular subregion of {@code fullImage} that should be
     *     displayed as wallpaper.  Passing {@code null} for this parameter means that
     *     the full image should be displayed if possible given the image's and device's
     *     aspect ratios, etc.
     * @param allowBackup {@code true} if the OS is permitted to back up this wallpaper
     *     image for restore to a future device; {@code false} otherwise.
     * @param which Flags indicating which wallpaper(s) to configure with the new imagery.
     *
     * @see #FLAG_SET_LOCK_WALLPAPER
     * @see #FLAG_SET_SYSTEM_WALLPAPER
     *
     * @return An integer ID assigned to the newly active wallpaper; or zero on failure.
     *
     * @throws IOException
     */
    public int setBitmap(Bitmap fullImage, Rect visibleCropHint,
            boolean allowBackup, @SetWallpaperFlags int which)
            throws IOException {
        validateRect(visibleCropHint);
        if (sGlobals.mService == null) {
            Log.w(TAG, "WallpaperService not running");
            return;
            return 0;
        }
        final Bundle result = new Bundle();
        try {
            ParcelFileDescriptor fd = sGlobals.mService.setWallpaper(null,
                    mContext.getOpPackageName());
            if (fd == null) {
                return;
            }
                    mContext.getOpPackageName(), result, which);
            if (fd != null) {
                FileOutputStream fos = null;
                try {
                    fos = new ParcelFileDescriptor.AutoCloseOutputStream(fd);
@@ -808,9 +887,11 @@ public class WallpaperManager {
                } finally {
                    IoUtils.closeQuietly(fos);
                }
            }
        } catch (RemoteException e) {
            // Ignore
        }
        return result.getInt(EXTRA_NEW_WALLPAPER_ID, 0);
    }

    private final void validateRect(Rect rect) {
@@ -843,7 +924,7 @@ public class WallpaperManager {
        setStream(bitmapData, null, true);
    }

    private void setWallpaper(InputStream data, FileOutputStream fos)
    private void copyStreamToWallpaperFile(InputStream data, FileOutputStream fos)
            throws IOException {
        byte[] buffer = new byte[32768];
        int amt;
@@ -877,29 +958,55 @@ public class WallpaperManager {
     * @throws IllegalArgumentException If the {@code visibleCropHint} rectangle is
     *     empty or invalid.
     */
    public void setStream(InputStream bitmapData, Rect visibleCropHint, boolean allowBackup)
    public int setStream(InputStream bitmapData, Rect visibleCropHint, boolean allowBackup)
            throws IOException {
        return setStream(bitmapData, visibleCropHint, allowBackup, FLAG_SET_SYSTEM);
    }

    /**
     * Version of {@link #setStream(InputStream, Rect, boolean)} that allows the caller
     * to specify which of the supported wallpaper categories to set.
     *
     * @param bitmapData A stream containing the raw data to install as a wallpaper.
     * @param visibleCropHint The rectangular subregion of the streamed image that should be
     *     displayed as wallpaper.  Passing {@code null} for this parameter means that
     *     the full image should be displayed if possible given the image's and device's
     *     aspect ratios, etc.
     * @param allowBackup {@code true} if the OS is permitted to back up this wallpaper
     *     image for restore to a future device; {@code false} otherwise.
     * @param which Flags indicating which wallpaper(s) to configure with the new imagery.
     *
     * @see #FLAG_SET_LOCK_WALLPAPER
     * @see #FLAG_SET_SYSTEM_WALLPAPER
     *
     * @throws IOException
     */
    public int setStream(InputStream bitmapData, Rect visibleCropHint,
            boolean allowBackup, @SetWallpaperFlags int which)
                    throws IOException {
        validateRect(visibleCropHint);
        if (sGlobals.mService == null) {
            Log.w(TAG, "WallpaperService not running");
            return;
            return 0;
        }
        final Bundle result = new Bundle();
        try {
            ParcelFileDescriptor fd = sGlobals.mService.setWallpaper(null,
                    mContext.getOpPackageName());
            if (fd == null) {
                return;
            }
                    mContext.getOpPackageName(), result, which);
            if (fd != null) {
                FileOutputStream fos = null;
                try {
                    fos = new ParcelFileDescriptor.AutoCloseOutputStream(fd);
                setWallpaper(bitmapData, fos);
                    copyStreamToWallpaperFile(bitmapData, fos);
                } finally {
                    IoUtils.closeQuietly(fos);
                }
            }
        } catch (RemoteException e) {
            // Ignore
        }

        return result.getInt(EXTRA_NEW_WALLPAPER_ID, 0);
    }

    /**
Loading