MacrobenchmarkScope

public final class MacrobenchmarkScope


Provides access to common operations in app automation, such as killing the app, or navigating home.

Summary

Public constructors

MacrobenchmarkScope(
    @NonNull String packageName,
    boolean launchWithClearTask
)

Public methods

final void

Drop Kernel's in-memory cache of disk pages.

final void

Force-stop the process being measured.

final void
pressHome(long delayDurationMs)

Perform a home button click.

final void

Start an activity, by default the default launch of the package, and wait until its launch completes.

final void

Start an activity with the provided intent, and wait until its launch completes.

Public constructors

MacrobenchmarkScope

public final MacrobenchmarkScope(
    @NonNull String packageName,
    boolean launchWithClearTask
)

Public methods

dropKernelPageCache

@NonNull
public final void dropKernelPageCache()

Drop Kernel's in-memory cache of disk pages.

Enables measuring disk-based startup cost, without simply accessing cache of disk data held in memory, such as during cold startup.

killProcess

@NonNull
public final void killProcess()

Force-stop the process being measured.

pressHome

@NonNull
public final void pressHome(long delayDurationMs)

Perform a home button click.

Useful for resetting the test to a base condition in cases where the app isn't killed in each iteration.

startActivityAndWait

@NonNull
public final void startActivityAndWait(@NonNull Function1<@NonNull IntentUnit> block)

Start an activity, by default the default launch of the package, and wait until its launch completes.

This call will ignore any parcelable extras on the intent, as the start is performed by converting the Intent to a URI, and starting via am start shell command.

Parameters
@NonNull Function1<@NonNull IntentUnit> block

Allows customization of the intent used to launch the activity.

Throws
kotlin.IllegalStateException

if unable to acquire intent for package.

startActivityAndWait

@NonNull
public final void startActivityAndWait(@NonNull Intent intent)

Start an activity with the provided intent, and wait until its launch completes.

This call will ignore any parcelable extras on the intent, as the start is performed by converting the Intent to a URI, and starting via am start shell command.

Parameters
@NonNull Intent intent

Specifies which app/Activity should be launched.