Class ShadowEnvironment

java.lang.Object
org.robolectric.shadows.ShadowEnvironment

@Implements(android.os.Environment.class) public class ShadowEnvironment extends Object
  • Constructor Details

    • ShadowEnvironment

      public ShadowEnvironment()
  • Method Details

    • getExternalStorageState

      @Implementation protected static String getExternalStorageState()
    • setExternalStorageState

      public static void setExternalStorageState(String externalStorageState)
      Sets the return value of getExternalStorageState().
      Parameters:
      externalStorageState - Value to return from getExternalStorageState().
    • setIsExternalStorageEmulated

      public static void setIsExternalStorageEmulated(boolean emulated)
      Sets the return value of isExternalStorageEmulated().
      Parameters:
      emulated - Value to return from isExternalStorageEmulated().
    • setIsExternalStorageLegacy

      public static void setIsExternalStorageLegacy(boolean legacy)
      Sets the return value of isExternalStorageLegacy() ()}.
      Parameters:
      legacy - Value to return from isExternalStorageLegacy().
    • setStorageDirectory

      public static void setStorageDirectory(Path directory)
      Sets the return value of getStorageDirectory(). This can be used for example, when testing code paths that need to perform regex matching on this directory.

      Note that the default value provides a directory that is usable in the test environment. If the test app uses this method to override that default directory, please clean up any files written to that directory, as the Robolectric environment will not purge that directory when the test ends.

      Parameters:
      directory - Path to return from getStorageDirectory().
    • getStorageDirectory

      @Implementation(minSdk=30) protected static File getStorageDirectory()
    • setExternalStorageDirectory

      public static void setExternalStorageDirectory(Path directory)
      Sets the return value of getExternalStorageDirectory(). Note that the default value provides a directory that is usable in the test environment. If the test app uses this method to override that default directory, please clean up any files written to that directory, as the Robolectric environment will not purge that directory when the test ends.
      Parameters:
      directory - Path to return from getExternalStorageDirectory().
    • getExternalStorageDirectory

      @Implementation protected static File getExternalStorageDirectory()
    • buildExternalStorageAppCacheDirs

      @Implementation protected static File[] buildExternalStorageAppCacheDirs(String packageName)
    • getExternalStorageAppCacheDirectory

      @Implementation(maxSdk=18) protected static File getExternalStorageAppCacheDirectory(String packageName)
    • setExternalStoragePublicDirectory

      public static void setExternalStoragePublicDirectory(Path directory)
      Sets the return value of getExternalStoragePublicDirectory(java.lang.String). Note that the default value provides a directory that is usable in the test environment. If the test app uses this method to override that default directory, please clean up any files written to that directory, as the Robolectric environment will not purge that directory when the test ends.
      Parameters:
      directory - Path to return from getExternalStoragePublicDirectory(java.lang.String).
    • getExternalStoragePublicDirectory

      @Implementation protected static File getExternalStoragePublicDirectory(String type)
    • reset

      @Resetter public static void reset()
    • isExternalStorageRemovable

      @Implementation protected static boolean isExternalStorageRemovable()
    • getStorageState

      @Implementation protected static String getStorageState(File directory)
    • getExternalStorageState

      @Implementation(minSdk=21) protected static String getExternalStorageState(File directory)
    • isExternalStorageRemovable

      @Implementation(minSdk=21) protected static boolean isExternalStorageRemovable(File path)
    • isExternalStorageEmulated

      @Implementation(minSdk=21) protected static boolean isExternalStorageEmulated(File path)
    • isExternalStorageEmulated

      @Implementation protected static boolean isExternalStorageEmulated()
    • isExternalStorageLegacy

      @Implementation(minSdk=29) protected static boolean isExternalStorageLegacy(File path)
    • isExternalStorageLegacy

      @Implementation(minSdk=29) protected static boolean isExternalStorageLegacy()
    • setExternalStorageRemovable

      public static void setExternalStorageRemovable(File file, boolean isRemovable)
      Sets the "isRemovable" flag of a particular file.
      Parameters:
      file - Target file.
      isRemovable - True if the filesystem is removable.
    • setExternalStorageEmulated

      public static void setExternalStorageEmulated(File file, boolean isEmulated)
      Sets the "isEmulated" flag of a particular file.
      Parameters:
      file - Target file.
      isEmulated - True if the filesystem is emulated.
    • addExternalDir

      public static File addExternalDir(String path)
      Adds a directory to list returned by ShadowEnvironment.ShadowUserEnvironment.getExternalDirs().
      Parameters:
      path - the external dir to add
    • setExternalStorageState

      public static void setExternalStorageState(File directory, String state)
      Sets the getExternalStorageState(File) for given directory.
      Parameters:
      externalStorageState - Value to return from getExternalStorageState(File).