Package org.robolectric
Class RuntimeEnvironment
- java.lang.Object
-
- org.robolectric.RuntimeEnvironment
-
public class RuntimeEnvironment extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static ApplicationapplicationDeprecated.Please migrate toandroidx.test.core.app.ApplicationProvider#getApplicationContextstatic PathcompileTimeSystemResourcesFilestatic ContextsystemContext
-
Constructor Summary
Constructors Constructor Description RuntimeEnvironment()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static NumbercastNativePtr(long ptr)static ObjectgetActivityThread()static PathgetAndroidFrameworkJarPath()static intgetApiLevel()static org.robolectric.res.ResourceTablegetAppResourceTable()static org.robolectric.res.ResourceTablegetCompileTimeResourceTable()static ThreadgetMainThread()Retrieves the main thread.static org.robolectric.util.SchedulergetMasterScheduler()Retrieves the current master scheduler.static StringgetQualifiers()Returns a qualifier string describing the currentConfigurationof the system resources.static StringgetQualifiers(Configuration configuration, DisplayMetrics displayMetrics)Returns a qualifier string describing the given configuration and display metrics.static org.robolectric.res.ResourceTablegetSystemResourceTable()static org.robolectric.util.TempDirectorygetTempDirectory()static booleanisMainThread()Tests if the current thread is currently set as the main thread.static booleanisMainThread(Thread thread)Tests if the given thread is currently set as the main thread.static voidsetActivityThread(Object newActivityThread)static voidsetAndroidFrameworkJarPath(Path localArtifactPath)static voidsetAppResourceTable(org.robolectric.res.ResourceTable appResourceTable)static voidsetCompileTimeResourceTable(org.robolectric.res.ResourceTable compileTimeResourceTable)static voidsetMainThread(Thread newMainThread)Sets the main thread.static voidsetMasterScheduler(org.robolectric.util.Scheduler masterScheduler)Sets the current master scheduler.static voidsetQualifiers(String newQualifiers)Overrides the current device configuration.static voidsetSystemResourceTable(org.robolectric.res.ResourceTable systemResourceTable)static voidsetTempDirectory(org.robolectric.util.TempDirectory tempDirectory)static voidsetUseLegacyResources(boolean useLegacyResources)Deprecated.Do not use.static booleanuseLegacyResources()Deprecated.Do not use.
-
-
-
Field Detail
-
systemContext
public static Context systemContext
-
application
@Deprecated public static Application application
Deprecated.Please migrate toandroidx.test.core.app.ApplicationProvider#getApplicationContext
-
compileTimeSystemResourcesFile
public static Path compileTimeSystemResourcesFile
-
-
Method Detail
-
isMainThread
public static boolean isMainThread(Thread thread)
Tests if the given thread is currently set as the main thread.- Parameters:
thread- the thread to test.- Returns:
- true if the specified thread is the main thread, false otherwise.
- See Also:
isMainThread()
-
isMainThread
public static boolean isMainThread()
Tests if the current thread is currently set as the main thread.Not supported in realistic looper mode.
- Returns:
- true if the current thread is the main thread, false otherwise.
-
getMainThread
public static Thread getMainThread()
Retrieves the main thread. The main thread is the thread to which the main looper is attached. Defaults to the thread that initialises theRuntimeEnvironmentclass.Not supported in realistic looper mode.
- Returns:
- The main thread.
- See Also:
setMainThread(Thread),isMainThread()
-
setMainThread
public static void setMainThread(Thread newMainThread)
Sets the main thread. The main thread is the thread to which the main looper is attached. Defaults to the thread that initialises theRuntimeEnvironmentclass.Not supported in realistic looper mode.
- Parameters:
newMainThread- the new main thread.- See Also:
setMainThread(Thread),isMainThread()
-
getActivityThread
public static Object getActivityThread()
-
setActivityThread
public static void setActivityThread(Object newActivityThread)
-
getQualifiers
public static String getQualifiers()
Returns a qualifier string describing the currentConfigurationof the system resources.- Returns:
- a qualifier string as described (https://developer.android.com/guide/topics/resources/providing-resources.html#QualifierRules)[here].
-
getQualifiers
public static String getQualifiers(Configuration configuration, DisplayMetrics displayMetrics)
Returns a qualifier string describing the given configuration and display metrics.- Parameters:
configuration- the configuration.displayMetrics- the display metrics.- Returns:
- a qualifier string as described (https://developer.android.com/guide/topics/resources/providing-resources.html#QualifierRules)[here].
-
setQualifiers
public static void setQualifiers(String newQualifiers)
Overrides the current device configuration.If {@param newQualifiers} starts with a plus ('+'), the prior configuration is used as the base configuration, with the given changes applied additively. Otherwise, default values are used for unspecified properties, as described here.
- Parameters:
newQualifiers- the qualifiers to apply
-
getApiLevel
public static int getApiLevel()
-
castNativePtr
public static Number castNativePtr(long ptr)
-
getMasterScheduler
public static org.robolectric.util.Scheduler getMasterScheduler()
Retrieves the current master scheduler. This scheduler is always used by the mainLooper, and if the global scheduler option is set it is also used for the background scheduler and for all otherLoopers- Returns:
- The current master scheduler.
- See Also:
see org.robolectric.Robolectric#getForegroundThreadScheduler() see org.robolectric.Robolectric#getBackgroundThreadScheduler()
-
setMasterScheduler
public static void setMasterScheduler(org.robolectric.util.Scheduler masterScheduler)
Sets the current master scheduler. SeegetMasterScheduler()for details. Note that this method is primarily intended to be called by the Robolectric core setup code. Changing the master scheduler during a test will have unpredictable results.- Parameters:
masterScheduler- the new master scheduler.- See Also:
see org.robolectric.Robolectric#getForegroundThreadScheduler() see org.robolectric.Robolectric#getBackgroundThreadScheduler()
-
setSystemResourceTable
public static void setSystemResourceTable(org.robolectric.res.ResourceTable systemResourceTable)
-
setAppResourceTable
public static void setAppResourceTable(org.robolectric.res.ResourceTable appResourceTable)
-
getSystemResourceTable
public static org.robolectric.res.ResourceTable getSystemResourceTable()
-
getAppResourceTable
public static org.robolectric.res.ResourceTable getAppResourceTable()
-
setCompileTimeResourceTable
public static void setCompileTimeResourceTable(org.robolectric.res.ResourceTable compileTimeResourceTable)
-
getCompileTimeResourceTable
public static org.robolectric.res.ResourceTable getCompileTimeResourceTable()
-
setTempDirectory
public static void setTempDirectory(org.robolectric.util.TempDirectory tempDirectory)
-
getTempDirectory
public static org.robolectric.util.TempDirectory getTempDirectory()
-
setAndroidFrameworkJarPath
public static void setAndroidFrameworkJarPath(Path localArtifactPath)
-
getAndroidFrameworkJarPath
public static Path getAndroidFrameworkJarPath()
-
useLegacyResources
@Deprecated public static boolean useLegacyResources()
Deprecated.Do not use.Internal only.
-
setUseLegacyResources
@Deprecated public static void setUseLegacyResources(boolean useLegacyResources)
Deprecated.Do not use.Internal only.
-
-