Class ShadowWallpaperManager

java.lang.Object
org.robolectric.shadows.ShadowWallpaperManager

@Implements(android.app.WallpaperManager.class) public class ShadowWallpaperManager extends Object
  • Constructor Details

    • ShadowWallpaperManager

      public ShadowWallpaperManager()
  • Method Details

    • sendWallpaperCommand

      @Implementation protected void sendWallpaperCommand(IBinder windowToken, String action, int x, int y, int z, Bundle extras)
    • setResource

      @Implementation(maxSdk=23) protected void setResource(int resid)
      Sets a resource id as the current wallpaper.

      This only caches the resource id in memory. Calling this will override any previously set resource and does not differentiate between users.

    • setResource

      @Implementation(minSdk=24) protected int setResource(int resid, int which)
    • hasResourceWallpaper

      @Implementation protected boolean hasResourceWallpaper(int resid)
      Returns whether the current wallpaper has been set through setResource(int) or setResource(int, int) with the same resource id.
    • setBitmapWithDescription

      @Implementation(minSdk=36) protected int setBitmapWithDescription(Bitmap fullImage, WallpaperDescription description, boolean allowBackup, int which) throws IOException
      Caches fullImage and description in the memory based on which.

      After a success call, any previously set live wallpaper is removed,

      Parameters:
      fullImage - the bitmap image to be cached in the memory
      description - the wallpaper description to be cached in the memory
      allowBackup - whether the wallpaper is backup eligible
      which - flag indicating which wallpaper to configure with the new bitmap, either WallpaperManager.FLAG_LOCK or WallpaperManager.FLAG_SYSTEM are valid
      Returns:
      0 if fails to cache. Otherwise, 1.
    • setStreamWithDescription

      @Implementation(minSdk=36) protected int setStreamWithDescription(InputStream bitmapData, WallpaperDescription description, boolean allowBackup, int which) throws IOException
      Caches bitmapData and description in the memory based on which.

      After a success call, any previously set live wallpaper is removed,

      Parameters:
      bitmapData - the input stream which contains a bitmap image to be cached in the memory
      description - the wallpaper description to be cached in the memory
      allowBackup - whether the wallpaper is backup eligible
      which - flag indicating which wallpaper to configure with the input stream, either WallpaperManager.FLAG_LOCK or WallpaperManager.FLAG_SYSTEM are valid
      Returns:
      0 if fails to cache. Otherwise, 1.
    • setBitmap

      @Implementation(minSdk=24) protected int setBitmap(Bitmap fullImage, Rect visibleCropHint, boolean allowBackup, int which)
      Caches fullImage in the memory based on which.

      After a success call, any previously set live wallpaper is removed,

      Parameters:
      fullImage - the bitmap image to be cached in the memory
      visibleCropHint - the visible crop hint to be cached in the memory
      allowBackup - whether the wallpaper is backup eligible
      which - either WallpaperManager.FLAG_LOCK or {WallpaperManager#FLAG_SYSTEM}
      Returns:
      0 if fails to cache. Otherwise, 1.
    • getBitmap

      @Nullable public Bitmap getBitmap(int which)
      Returns the memory cached Bitmap associated with which.
      Parameters:
      which - either WallpaperManager.FLAG_LOCK or WallpaperManager.FLAG_SYSTEM.
      Returns:
      The memory cached Bitmap associated with which. null if no bitmap was set.
    • getVisibleCropHint

      @Nullable public Rect getVisibleCropHint(int which)
      Returns the memory cached Rect associated with which.
      Parameters:
      which - either WallpaperManager.FLAG_LOCK or WallpaperManager.FLAG_SYSTEM.
      Returns:
      The memory cached Rect associated with which. null if no rect was set.
    • getCropHints

      @Nullable public SparseArray<Rect> getCropHints(int which)
      Returns the memory cached SparseArray<Rect> associated with which.
      Parameters:
      which - either WallpaperManager.FLAG_LOCK or {WallpaperManager#FLAG_SYSTEM}.
      Returns:
      The memory cached SparseArray<Rect> associated with which. null if no sparse array was set.
    • getDescription

      @Nullable public WallpaperDescription getDescription(int which)
      Returns the memory cached WallpaperDescription associated with which.
      Parameters:
      which - either WallpaperManager.FLAG_LOCK or WallpaperManager.FLAG_SYSTEM.
      Returns:
      The memory cached WallpaperDescription associated with which. null if no wallpaper description was set.
    • getWallpaperDescription

      @Nullable public WallpaperDescription getWallpaperDescription(int which)
      Returns the memory cached WallpaperDescription associated with which.
      Parameters:
      which - either WallpaperManager.FLAG_LOCK or WallpaperManager.FLAG_SYSTEM.
      Returns:
      The memory cached WallpaperDescription associated with which. null if no wallpaper description was set.
    • getWallpaperFile

      @Implementation(minSdk=24) @Nullable protected ParcelFileDescriptor getWallpaperFile(int which)
      Gets a wallpaper file associated with which.
      Parameters:
      which - either WallpaperManager.FLAG_LOCK or {WallpaperManager#FLAG_SYSTEM}
      Returns:
      An open, readable file descriptor to the requested wallpaper image file; null if no such wallpaper is configured.
    • getWallpaperFile

      @Implementation(minSdk=36) protected ParcelFileDescriptor getWallpaperFile(int which, boolean getCropped)
      Gets a wallpaper file associated with which.
      Parameters:
      which - either WallpaperManager.FLAG_LOCK or {WallpaperManager#FLAG_SYSTEM}
      getCropped - not used.
      Returns:
      An open, readable file descriptor to the requested wallpaper image file; null if no such wallpaper is configured.
    • isWallpaperBackupEligible

      @Implementation(minSdk=36) protected boolean isWallpaperBackupEligible(int which)
      Returns whether the current wallpaper is backup eligible.
    • getWallpaperId

      @Implementation(minSdk=24) protected int getWallpaperId(int which)
      Returns the id of the current wallpaper associated with which. If there is no such wallpaper configured, returns a negative number.
    • isSetWallpaperAllowed

      @Implementation(minSdk=24) protected boolean isSetWallpaperAllowed()
    • setIsSetWallpaperAllowed

      public void setIsSetWallpaperAllowed(boolean allowed)
    • isWallpaperSupported

      @Implementation(minSdk=23) protected boolean isWallpaperSupported()
    • setIsWallpaperSupported

      public void setIsWallpaperSupported(boolean supported)
    • setStream

      @Implementation(minSdk=24) protected int setStream(InputStream bitmapData, Rect visibleCropHint, boolean allowBackup, int which)
      Caches bitmapData in the memory based on which.
      Parameters:
      bitmapData - the input stream which contains a bitmap image to be cached in the memory
      visibleCropHint - not used
      allowBackup - whether the wallpaper is backup eligible
      which - either WallpaperManager.FLAG_LOCK or {WallpaperManager#FLAG_SYSTEM}
      Returns:
      0 if fails to cache. Otherwise, 1.
    • setWallpaperComponent

      @Implementation(minSdk=23) protected boolean setWallpaperComponent(ComponentName wallpaperService) throws IOException, XmlPullParserException
      Sets a live wallpaper, wallpaperService, as the current wallpaper.

      This only caches the live wallpaper info in the memory. Calling this will remove any previously set static wallpaper.

      Throws:
      IOException
      XmlPullParserException
    • getWallpaperInfo

      @Implementation protected WallpaperInfo getWallpaperInfo()
      Returns the information about the wallpaper if the current wallpaper is a live wallpaper component. Otherwise, if the wallpaper is a static image, this returns null.
    • setWallpaperDimAmount

      @Implementation(minSdk=33) protected void setWallpaperDimAmount(float dimAmount)
    • getAllWallpaperDimAmounts

      public List<Float> getAllWallpaperDimAmounts()
      Returns a list of all dim amounts set from calls to setWallpaperDimAmount. This can be used to verify that repeated calls to setWallpaperDimAmount are not done which can cause issues.
    • getWallpaperDimAmount

      @Implementation(minSdk=33) protected float getWallpaperDimAmount()
    • getWallpaperCommandRecords

      public List<ShadowWallpaperManager.WallpaperCommandRecord> getWallpaperCommandRecords()
    • reset

      @Resetter public static void reset()