public class

InstrumentationParameterUtil

extends java.lang.Object

 java.lang.Object

↳androidx.test.internal.platform.util.InstrumentationParameterUtil

Gradle dependencies

compile group: 'androidx.test', name: 'orchestrator', version: '1.5.0'

  • groupId: androidx.test
  • artifactId: orchestrator
  • version: 1.5.0

Artifact androidx.test:orchestrator:1.5.0 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.test:orchestrator com.android.support.test:orchestrator

Overview

Provides utility functions to retrieve and parse data from instrumentation parameter.

Summary

Constructors
publicInstrumentationParameterUtil()

Methods
public static longgetTimeoutMillis(java.lang.String key, long defaultValue)

Gets a timeout value with a given key to the instrumentation argument bundle.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public InstrumentationParameterUtil()

Methods

public static long getTimeoutMillis(java.lang.String key, long defaultValue)

Gets a timeout value with a given key to the instrumentation argument bundle.

Parameters:

key: a key for the timeout to be retrieved from the instrumentation argument.
defaultValue: a default timeout to be returned if the timeout is not specified or zero in the instrumentation argument. You can pass negative value as a defaultValue and it will be interpreted as infinite timeout. You cannot use zero as a defaultValue.

Returns:

the timeout in milliseconds for the given key. The value is always greater than zero.

Source

package androidx.test.internal.platform.util;

import androidx.test.internal.util.Checks;
import androidx.test.platform.app.InstrumentationRegistry;
import java.util.concurrent.TimeUnit;

/**
 * Provides utility functions to retrieve and parse data from instrumentation parameter.
 *
 * @hide
 */
public class InstrumentationParameterUtil {

  /**
   * Gets a timeout value with a given key to the instrumentation argument bundle.
   *
   * @param key a key for the timeout to be retrieved from the instrumentation argument.
   * @param defaultValue a default timeout to be returned if the timeout is not specified or zero in
   *     the instrumentation argument. You can pass negative value as a defaultValue and it will be
   *     interpreted as infinite timeout. You cannot use zero as a defaultValue.
   * @return the timeout in milliseconds for the given key. The value is always greater than zero.
   */
  public static long getTimeoutMillis(String key, long defaultValue) {
    Checks.checkArgument(defaultValue != 0, "default timeout value cannot be zero");

    long value = Long.parseLong(InstrumentationRegistry.getArguments().getString(key, "0"));
    if (value == 0) {
      value = defaultValue;
    }

    if (value < 0) {
      return TimeUnit.DAYS.toMillis(1);
    } else {
      return value;
    }
  }
}