Clearing app data when creating base line profiles

303 Views Asked by At

I'm trying to create some baseline profiles for my Android app that are a bit more meaningful than simply startActivityAndWait()

My app starts off in an uninitialised state but once the user has chosen a destination this is stored in DataStore Preferences and you then no longer see the initial screens.

This means that running the BaselineProfileRule for the subsequent iterations fail because the initial buttons etc. are no longer applicable.

Is there a way to clear the app data between test runs with the BaselineProfile tests? I've tried adding InstrumentationRegistry.getInstrumentation().uiAutomation.executeShellCommand("adb shell pm clear *packageName*") in the test but it doesn't seem to have any effect.

I also tried adding testInstrumentationRunnerArguments clearPackageData: 'true' to the benchmark build.gradle but this was also ineffective.

1

There are 1 best solutions below

2
On

A workaround I've been using to handling this is

fun MacrobenchmarkScope.isFirstIteration() = iteration == 0

And then, inside setup block:

if (isFirstIteration()) {
    pressHome()
    startActivityAndWait()
    //Login
    killProcess()
}