diff --git a/MacrobenchmarkSample/macrobenchmark/src/main/kotlin/com/example/macrobenchmark/baselineprofile/Common.kt b/MacrobenchmarkSample/macrobenchmark/src/main/kotlin/com/example/macrobenchmark/baselineprofile/Common.kt index 6c2e37a..0eb564b 100644 --- a/MacrobenchmarkSample/macrobenchmark/src/main/kotlin/com/example/macrobenchmark/baselineprofile/Common.kt +++ b/MacrobenchmarkSample/macrobenchmark/src/main/kotlin/com/example/macrobenchmark/baselineprofile/Common.kt @@ -16,4 +16,18 @@ package com.example.macrobenchmark.baselineprofile -const val TARGET_PACKAGE = "com.example.macrobenchmark.target" \ No newline at end of file +import androidx.benchmark.macro.MacrobenchmarkScope +import androidx.test.uiautomator.UiDevice + +const val TARGET_PACKAGE = "com.example.macrobenchmark.target" + +/** + * Clears the application data for the package specified in the [MacrobenchmarkScope]. + * @param scope The [MacrobenchmarkScope] providing information about the benchmark, + * including the package name of the app under test. + */ +fun UiDevice.clearData(scope: MacrobenchmarkScope) { + val command = "pm clear $scope.packageName" + val output = executeShellCommand(command) +// Assert.assertEquals("Success", output) +} \ No newline at end of file diff --git a/MacrobenchmarkSample/macrobenchmark/src/main/kotlin/com/example/macrobenchmark/baselineprofile/LoginBaselineProfileGenerator.kt b/MacrobenchmarkSample/macrobenchmark/src/main/kotlin/com/example/macrobenchmark/baselineprofile/LoginBaselineProfileGenerator.kt index eff0a37..9792a33 100644 --- a/MacrobenchmarkSample/macrobenchmark/src/main/kotlin/com/example/macrobenchmark/baselineprofile/LoginBaselineProfileGenerator.kt +++ b/MacrobenchmarkSample/macrobenchmark/src/main/kotlin/com/example/macrobenchmark/baselineprofile/LoginBaselineProfileGenerator.kt @@ -37,6 +37,7 @@ class LoginBaselineProfileGenerator { maxIterations = 15, stableIterations = 3 ) { + device.clearData(this) startActivityAndWait(Intent("$packageName.LOGIN_ACTIVITY")) device.findObject(By.res("userName")).text = "user" device.findObject(By.res("password")).text = "password"