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 Application
application
Deprecated.Please migrate toandroidx.test.core.app.ApplicationProvider#getApplicationContext
static Path
compileTimeSystemResourcesFile
static Context
systemContext
Deprecated.UsegetApplication()
orandroidx.test.core.app.ApplicationProvider#getApplicationContext
instead. -
Constructor Summary
Constructors Constructor Description RuntimeEnvironment()
-
Method Summary
Modifier and Type Method Description static Number
castNativePtr(long ptr)
static Object
getActivityThread()
static Path
getAndroidFrameworkJarPath()
static int
getApiLevel()
static Application
getApplication()
Get a reference to theApplication
under test.static ResourceTable
getAppResourceTable()
static ResourceTable
getCompileTimeResourceTable()
static Class<? extends Application>
getConfiguredApplicationClass()
static Thread
getMainThread()
Retrieves the main thread.static Scheduler
getMasterScheduler()
Retrieves the current master scheduler.static String
getQualifiers()
Returns a qualifier string describing the currentConfiguration
of the system resources.static String
getQualifiers(Configuration configuration, DisplayMetrics displayMetrics)
Returns a qualifier string describing the given configuration and display metrics.static ResourceTable
getSystemResourceTable()
static TempDirectory
getTempDirectory()
static boolean
isMainThread()
Tests if the current thread is currently set as the main thread.static boolean
isMainThread(Thread thread)
Tests if the given thread is currently set as the main thread.static void
setActivityThread(Object newActivityThread)
static void
setAndroidFrameworkJarPath(Path localArtifactPath)
static void
setApplicationSupplier(com.google.common.base.Supplier<Application> applicationSupplier)
internal use onlystatic void
setAppResourceTable(ResourceTable appResourceTable)
static void
setCompileTimeResourceTable(ResourceTable compileTimeResourceTable)
static void
setConfiguredApplicationClass(Class<? extends Application> clazz)
static void
setMainThread(Thread newMainThread)
Sets the main thread.static void
setMasterScheduler(Scheduler masterScheduler)
Sets the current master scheduler.static void
setQualifiers(String newQualifiers)
Overrides the current device configuration.static void
setSystemResourceTable(ResourceTable systemResourceTable)
static void
setTempDirectory(TempDirectory tempDirectory)
static void
setUseLegacyResources(boolean useLegacyResources)
Deprecated.Do not use.static boolean
useLegacyResources()
Deprecated.Do not use.
-
Field Details
-
systemContext
Deprecated.UsegetApplication()
orandroidx.test.core.app.ApplicationProvider#getApplicationContext
instead. Note that unlike the alternatives, this field is inherently incompatible withLazyApplication
. This field may be removed in a later release -
application
Deprecated.Please migrate toandroidx.test.core.app.ApplicationProvider#getApplicationContext
-
compileTimeSystemResourcesFile
-
-
Constructor Details
-
RuntimeEnvironment
public RuntimeEnvironment()
-
-
Method Details
-
getApplication
Get a reference to theApplication
under test. The Application may be created a test setup time or created lazily at call time, based on the test's {@link LazyApplication) setting. If lazy loading is enabled, this method must be called on the main/test thread. An alternate API is {@link androidx.test.core.app.ApplicationProvider#getApplicationContext()}, which is preferable if you desire cross platform tests that work on the JVM and real Android devices. -
setApplicationSupplier
public static void setApplicationSupplier(com.google.common.base.Supplier<Application> applicationSupplier)internal use only -
getConfiguredApplicationClass
-
setConfiguredApplicationClass
-
isMainThread
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
Retrieves the main thread. The main thread is the thread to which the main looper is attached. Defaults to the thread that initialises theRuntimeEnvironment
class.Not supported in realistic looper mode.
- Returns:
- The main thread.
- See Also:
setMainThread(Thread)
,isMainThread()
-
setMainThread
Sets the main thread. The main thread is the thread to which the main looper is attached. Defaults to the thread that initialises theRuntimeEnvironment
class.Not supported in realistic looper mode.
- Parameters:
newMainThread
- the new main thread.- See Also:
setMainThread(Thread)
,isMainThread()
-
getActivityThread
-
setActivityThread
-
getQualifiers
Returns a qualifier string describing the currentConfiguration
of the system resources.- Returns:
- a qualifier string as described (https://developer.android.com/guide/topics/resources/providing-resources.html#QualifierRules)[here].
-
getQualifiers
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
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
-
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 otherLooper
s- Returns:
- The current master scheduler.
- See Also:
see org.robolectric.Robolectric#getForegroundThreadScheduler() see org.robolectric.Robolectric#getBackgroundThreadScheduler()
-
setMasterScheduler
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
-
setAppResourceTable
-
getSystemResourceTable
-
getAppResourceTable
-
setCompileTimeResourceTable
-
getCompileTimeResourceTable
-
setTempDirectory
-
getTempDirectory
-
setAndroidFrameworkJarPath
-
getAndroidFrameworkJarPath
-
useLegacyResources
Deprecated.Do not use.Internal only. -
setUseLegacyResources
Deprecated.Do not use.Internal only.
-