@Implements(android.os.Environment.class) public class ShadowEnvironment extends Object
Modifier and Type | Class | Description |
---|---|---|
static class |
ShadowEnvironment.ShadowUserEnvironment |
Constructor | Description |
---|---|
ShadowEnvironment() |
Modifier and Type | Method | Description |
---|---|---|
static File |
addExternalDir(String path) |
Adds a directory to list returned by
ShadowEnvironment.ShadowUserEnvironment.getExternalDirs() . |
protected static File[] |
buildExternalStorageAppCacheDirs(String packageName) |
|
protected static File |
getExternalStorageAppCacheDirectory(String packageName) |
|
protected static File |
getExternalStorageDirectory() |
|
protected static File |
getExternalStoragePublicDirectory(String type) |
|
protected static String |
getExternalStorageState() |
|
protected static String |
getExternalStorageState(File directory) |
|
protected static String |
getStorageState(File directory) |
|
protected static boolean |
isExternalStorageEmulated() |
|
protected static boolean |
isExternalStorageEmulated(File path) |
|
protected static boolean |
isExternalStorageLegacy() |
|
protected static boolean |
isExternalStorageLegacy(File path) |
|
protected static boolean |
isExternalStorageRemovable() |
|
protected static boolean |
isExternalStorageRemovable(File path) |
|
static void |
reset() |
|
static void |
setExternalStorageDirectory(Path directory) |
Sets the return value of
getExternalStorageDirectory() . |
static void |
setExternalStorageEmulated(File file,
boolean isEmulated) |
Sets the "isEmulated" flag of a particular file.
|
static void |
setExternalStorageRemovable(File file,
boolean isRemovable) |
Sets the "isRemovable" flag of a particular file.
|
static void |
setExternalStorageState(File directory,
String state) |
Sets the
getExternalStorageState(File) for given directory. |
static void |
setExternalStorageState(String externalStorageState) |
Sets the return value of
getExternalStorageState() . |
static void |
setIsExternalStorageEmulated(boolean emulated) |
Sets the return value of
isExternalStorageEmulated() . |
static void |
setIsExternalStorageLegacy(boolean legacy) |
Sets the return value of
isExternalStorageLegacy() ()}. |
@Implementation protected static String getExternalStorageState()
public static void setExternalStorageState(String externalStorageState)
getExternalStorageState()
.externalStorageState
- Value to return from getExternalStorageState()
.public static void setIsExternalStorageEmulated(boolean emulated)
isExternalStorageEmulated()
.emulated
- Value to return from isExternalStorageEmulated()
.public static void setIsExternalStorageLegacy(boolean legacy)
isExternalStorageLegacy()
()}.legacy
- Value to return from isExternalStorageLegacy()
.public static void setExternalStorageDirectory(Path directory)
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.directory
- Path to return from getExternalStorageDirectory()
.@Implementation protected static File getExternalStorageDirectory()
@Implementation(minSdk=19) protected static File[] buildExternalStorageAppCacheDirs(String packageName)
@Implementation(maxSdk=18) protected static File getExternalStorageAppCacheDirectory(String packageName)
@Implementation protected static File getExternalStoragePublicDirectory(String type)
@Resetter public static void reset()
@Implementation protected static boolean isExternalStorageRemovable()
@Implementation(minSdk=19) protected static String getStorageState(File directory)
@Implementation(minSdk=21) protected static String getExternalStorageState(File directory)
@Implementation(minSdk=21) protected static boolean isExternalStorageRemovable(File path)
@Implementation(minSdk=21) protected static boolean isExternalStorageEmulated(File path)
@Implementation protected static boolean isExternalStorageEmulated()
@Implementation(minSdk=29) protected static boolean isExternalStorageLegacy(File path)
@Implementation(minSdk=29) protected static boolean isExternalStorageLegacy()
public static void setExternalStorageRemovable(File file, boolean isRemovable)
file
- Target file.isRemovable
- True if the filesystem is removable.public static void setExternalStorageEmulated(File file, boolean isEmulated)
file
- Target file.isEmulated
- True if the filesystem is emulated.public static File addExternalDir(String path)
ShadowEnvironment.ShadowUserEnvironment.getExternalDirs()
.path
- the external dir to addpublic static void setExternalStorageState(File directory, String state)
getExternalStorageState(File)
for given directory.externalStorageState
- Value to return from getExternalStorageState(File)
.