Class ShadowProcess

java.lang.Object
org.robolectric.shadows.ShadowProcess

@Implements(android.os.Process.class) public class ShadowProcess extends Object
  • Constructor Details

    • ShadowProcess

      public ShadowProcess()
  • Method Details

    • killProcess

      @Implementation protected static void killProcess(int pid)
      Stores requests for killing processes. Processe that were requested to be killed can be retrieved by calling wasKilled(int). Use clearKilledProcesses() to clear the list.
    • myPid

      @Implementation protected static int myPid()
    • myUid

      @Implementation protected static int myUid()
      Returns the identifier of this process's uid. Unlike Android UIDs are randomly initialized to prevent tests from depending on any given value. Tests should access the current process UID via Process.myUid(). You can override this value by calling setUid(int).
    • myTid

      @Implementation protected static int myTid()
      Returns the identifier (Thread.getId()) of the current thread (Thread.currentThread()).
    • setThreadPriority

      @Implementation protected static void setThreadPriority(int priority)
      Stores priority for the current thread, but doesn't actually change it to not mess up with test runner. Unlike real implementation does not throw any exceptions.
    • setThreadPriority

      @Implementation protected static void setThreadPriority(int tid, int priority)
      Stores priority for the given thread, but doesn't actually change it to not mess up with test runner. Unlike real implementation does not throw any exceptions.
      Parameters:
      tid - The identifier of the thread. If equals zero, the identifier of the calling thread will be used.
      priority - The priority to be set for the thread. The range of values accepted is specified by Process.setThreadPriority(int, int), which is [-20,19].
    • getThreadPriority

      @Implementation protected static int getThreadPriority(int tid)
      Returns priority stored for the given thread.
      Parameters:
      tid - The identifier of the thread. If equals zero, the identifier of the calling thread will be used.
    • clearKilledProcesses

      public static void clearKilledProcesses()
    • setUid

      public static void setUid(int uid)
      Sets the identifier of this process.
    • setPid

      public static void setPid(int pid)
      Sets the identifier of this process.
    • reset

      @Resetter public static void reset()
    • wasKilled

      public static boolean wasKilled(int pid)
      Gets an indication of whether or not a process was killed (using killProcess(int)).
    • myProcessName

      @Implementation(minSdk=33) protected static String myProcessName()
      Returns the name of the process. You can override this value by calling setProcessName(String).
      Returns:
      process name.
    • setProcessName

      public static void setProcessName(String processName)
      Sets the process name returned by myProcessName().
      Parameters:
      processName - New process name to set. Cannot be null.