Skip to content

Commit c282661

Browse files
committed
Fix the profile case with clear app data
1 parent 75f0919 commit c282661

File tree

1 file changed

+15
-3
lines changed
  • firebase-sessions/benchmark/src/main/kotlin/com/google/firebase/benchmark/sessions

1 file changed

+15
-3
lines changed

firebase-sessions/benchmark/src/main/kotlin/com/google/firebase/benchmark/sessions/StartupBenchmark.kt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import androidx.benchmark.macro.StartupTimingMetric
2121
import androidx.benchmark.macro.junit4.MacrobenchmarkRule
2222
import androidx.test.ext.junit.runners.AndroidJUnit4
2323
import androidx.test.platform.app.InstrumentationRegistry
24+
import java.io.FileInputStream
2425
import org.junit.Rule
2526
import org.junit.Test
2627
import 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"

0 commit comments

Comments
 (0)