File tree Expand file tree Collapse file tree 1 file changed +15
-3
lines changed
firebase-sessions/benchmark/src/main/kotlin/com/google/firebase/benchmark/sessions Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ import androidx.benchmark.macro.StartupTimingMetric
2121import androidx.benchmark.macro.junit4.MacrobenchmarkRule
2222import androidx.test.ext.junit.runners.AndroidJUnit4
2323import androidx.test.platform.app.InstrumentationRegistry
24+ import java.io.FileInputStream
2425import org.junit.Rule
2526import org.junit.Test
2627import org.junit.runner.RunWith
@@ -48,14 +49,25 @@ class StartupBenchmark {
4849 metrics = listOf (StartupTimingMetric ()),
4950 iterations = 5 ,
5051 startupMode = StartupMode .COLD ,
52+ setupBlock = { clearAppData(packageName) },
5153 ) {
5254 pressHome()
55+ startActivityAndWait()
56+ }
57+
58+ private fun clearAppData (packageName : String ) {
59+ val fileDescriptor =
5360 InstrumentationRegistry .getInstrumentation()
5461 .uiAutomation
55- .executeShellCommand(" pm clear $PACKAGE_NAME " )
56- .close()
57- startActivityAndWait()
62+ .executeShellCommand(" pm clear $packageName " )
63+ val fileInputStream = FileInputStream (fileDescriptor.fileDescriptor)
64+ // Read the output to ensure the app data was cleared successfully
65+ val result = fileInputStream.bufferedReader().use { it.readText().trim() }
66+ fileDescriptor.close()
67+ if (result != " Success" ) {
68+ throw IllegalStateException (" Unable to clear app data for $packageName - $result " )
5869 }
70+ }
5971
6072 private companion object {
6173 const val PACKAGE_NAME = " com.google.firebase.testing.sessions"
You can’t perform that action at this time.
0 commit comments