Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Kimblebee committed Dec 6, 2023
1 parent 7c115e0 commit e1a1327
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,36 +32,38 @@ class ImageCaptureLatencyBenchmark {
@get:Rule
val benchmarkRule = MacrobenchmarkRule()

@Test
fun rearCameraNoFlashLatency() {
imageCaptureLatency(shouldFaceFront = false, flashMode = FlashMode.OFF)
}

@Test
fun frontCameraNoFlashLatency() {
imageCaptureLatency(shouldFaceFront = true, flashMode = FlashMode.OFF)
}

// Flash test needs extra time at the end to ensure the trace is closed
@Test
fun rearCameraNoFlashLatency() {
imageCaptureLatency(shouldFaceFront = false, flashMode = FlashMode.OFF)
fun rearCameraWithFlashLatency() {
imageCaptureLatency(shouldFaceFront = false, flashMode = FlashMode.ON, sleepInterval = 5000)
}


//todo: front flash latency test
/*
@Test
fun frontCameraWithFlashLatency() {
imageCaptureLatency(shouldFaceFront = true, flashMode = FlashMode.ON)
}
*/

// Flash test needs extra time at the end to ensure the trace is closed
@Test
fun rearCameraWithFlashLatency() {
imageCaptureLatency(shouldFaceFront = false, flashMode = FlashMode.ON, sleepInterval = 5000)
}

// Measures the time between an onClick event on the Capture Button and onImageCapture callback being fired
// added sleep interval option due to flash taking extra time
@OptIn(ExperimentalMetricApi::class)
private fun imageCaptureLatency(
shouldFaceFront: Boolean,
flashMode: FlashMode,
sleepInterval: Long = 100
sleepInterval: Long = 500
) {
benchmarkRule.measureRepeated(
packageName = JCA_PACKAGE,
Expand All @@ -83,7 +85,6 @@ class ImageCaptureLatencyBenchmark {
}

) {
Thread.sleep(100)
val selector = By.res("CaptureButton")

if (!device.wait(Until.hasObject(selector), 2_500)) {
Expand All @@ -92,6 +93,8 @@ class ImageCaptureLatencyBenchmark {
device
.findObject(selector)
.click()

// ensure trace is closed
Thread.sleep(sleepInterval)
}
}
Expand Down
5 changes: 3 additions & 2 deletions benchmark/src/main/java/com/example/benchmark/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ enum class FlashMode {
OFF,
AUTO
}
//todo: designate "default testing settings" to ensure consistency of benchmarks

// open or close quick settings menu on device
fun toggleQuickSettings(device: UiDevice) {
device.findObject(By.res("QuickSettingDropDown")).click()
}

// set device direction using quick seting
// set device direction using quick setting
fun setQuickFrontFacingCamera(shouldFaceFront: Boolean, device: UiDevice) {
// flash on with front camera will automatically enable screen flash

Expand All @@ -54,4 +55,4 @@ fun setQuickSetFlash(flashMode: FlashMode, device: UiDevice) {
while (device.findObject(selector) == null) {
device.findObject(By.res("QuickSetFlash")).click()
}
}
}

0 comments on commit e1a1327

Please # to comment.