public class

InstrumentationParameterUtil

extends java.lang.Object

 java.lang.Object

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

Gradle dependencies

compile group: 'androidx.test', name: 'monitor', version: '1.6.0-alpha03'

  • groupId: androidx.test
  • artifactId: monitor
  • version: 1.6.0-alpha03

Artifact androidx.test:monitor:1.6.0-alpha03 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.test:monitor com.android.support.test:monitor

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;
    }
  }
}