Release 1.0.0

- Initial release.
This commit is contained in:
OneWay committed 2026-11-16 05:26:00 +08:00
commit 98941c382f
127 files changed
+54011

No files matched your search

+33
View File
@@ -0,0 +1,33 @@
plugins {
alias(libs.plugins.android.test)
alias(libs.plugins.baselineprofile)
}
android {
namespace = "asia.oneway.onecamera.benchmark"
compileSdk = 37
targetProjectPath = ":app"
experimentalProperties["android.experimental.self-instrumenting"] = true
defaultConfig {
minSdk = 31
targetSdk = 37
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments["androidx.benchmark.suppressErrors"] = "EMULATOR"
}
buildTypes {
create("benchmarkRelease") {
isDebuggable = false
signingConfig = signingConfigs.getByName("debug")
matchingFallbacks += listOf("release")
}
}
}
dependencies {
implementation(libs.androidx.benchmark.macro.junit4)
implementation(libs.androidx.junit)
implementation(libs.androidx.uiautomator)
implementation(libs.junit)
}
+2
View File
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest />
@@ -0,0 +1,129 @@
package asia.oneway.onecamera.benchmark
import androidx.benchmark.macro.MacrobenchmarkScope
import androidx.benchmark.macro.junit4.BaselineProfileRule
import androidx.test.uiautomator.By
import androidx.test.uiautomator.BySelector
import androidx.test.uiautomator.Direction
import androidx.test.uiautomator.StaleObjectException
import androidx.test.uiautomator.Until
import org.junit.Rule
import org.junit.Test
class BaselineProfileGenerator {
@get:Rule
val baselineProfileRule = BaselineProfileRule()
@Test
fun generate() = baselineProfileRule.collect(
packageName = PACKAGE_NAME,
maxIterations = 5,
stableIterations = 2,
includeInStartupProfile = true,
) {
pressHome()
startActivityAndWait()
grantRootIfNeeded()
check(openFirstPhotoAlbum()) {
"No photo album found in the selected directory"
}
repeat(3) {
swipeGallery(Direction.UP)
}
device.waitForIdle()
}
private fun MacrobenchmarkScope.grantRootIfNeeded() {
if (device.hasObject(By.descStartsWith("Folder: "))) return
val chooseFolder = By.text("Choose folder")
check(device.wait(Until.hasObject(chooseFolder), UI_TIMEOUT_MS)) {
"Root selection button not found"
}
device.findObject(chooseFolder).click()
val documents = By.text("Documents")
if (!device.wait(Until.hasObject(documents), 3_000L)) {
device.swipe(
device.displayWidth / 2,
(device.displayHeight * 3) / 4,
device.displayWidth / 2,
device.displayHeight / 4,
10,
)
}
check(device.wait(Until.hasObject(documents), UI_TIMEOUT_MS)) {
"Documents directory not found in the picker"
}
device.findObject(documents).click()
val useThisFolder = By.text("USE THIS FOLDER")
check(device.wait(Until.hasObject(useThisFolder), UI_TIMEOUT_MS)) {
"Folder confirmation button not found"
}
device.findObject(useThisFolder).click()
val allow = By.text("ALLOW")
check(device.wait(Until.hasObject(allow), UI_TIMEOUT_MS)) {
"Permission grant button not found"
}
device.findObject(allow).click()
check(device.wait(Until.hasObject(By.descStartsWith("Folder: ")), UI_TIMEOUT_MS)) {
"Root folder did not load after granting access"
}
}
private fun MacrobenchmarkScope.openFirstPhotoAlbum(depth: Int = 0): Boolean {
if (depth > MAX_FOLDER_DEPTH) return false
val photos = By.descStartsWith("Photo: ")
val folders = By.descStartsWith("Folder: ")
if (device.wait(Until.hasObject(photos), 1_000L)) {
return device.wait(Until.hasObject(By.res("gallery_grid")), UI_TIMEOUT_MS)
}
check(device.wait(Until.hasObject(folders), UI_TIMEOUT_MS)) {
"No folders found at depth $depth"
}
for (description in visibleDescriptions(folders)) {
val folder = device.findObject(By.desc(description)) ?: continue
folder.click()
if (!device.wait(Until.gone(By.desc(description)), UI_TIMEOUT_MS)) return false
if (openFirstPhotoAlbum(depth + 1)) return true
device.pressBack()
if (!device.wait(Until.hasObject(By.desc(description)), UI_TIMEOUT_MS)) return false
}
return false
}
private fun MacrobenchmarkScope.visibleDescriptions(selector: BySelector): List<String> =
device.findObjects(selector).mapNotNull { item ->
try {
item.contentDescription
} catch (_: StaleObjectException) {
null
}
}
private fun MacrobenchmarkScope.swipeGallery(direction: Direction) {
val bounds = device.findObject(By.res("gallery_grid"))?.visibleBounds
?: error("Gallery grid not found")
val (startFraction, endFraction) = if (direction == Direction.UP) {
0.75f to 0.25f
} else {
0.25f to 0.75f
}
device.swipe(
bounds.centerX(),
bounds.top + (bounds.height() * startFraction).toInt(),
bounds.centerX(),
bounds.top + (bounds.height() * endFraction).toInt(),
10,
)
}
private companion object {
const val PACKAGE_NAME = "asia.oneway.onecamera"
const val UI_TIMEOUT_MS = 20_000L
const val MAX_FOLDER_DEPTH = 8
}
}
@@ -0,0 +1,202 @@
package asia.oneway.onecamera.benchmark
import androidx.benchmark.macro.CompilationMode
import androidx.benchmark.macro.ExperimentalMetricApi
import androidx.benchmark.macro.FrameTimingMetric
import androidx.benchmark.macro.StartupMode
import androidx.benchmark.macro.StartupTimingMetric
import androidx.benchmark.macro.TraceSectionMetric
import androidx.benchmark.macro.junit4.MacrobenchmarkRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.uiautomator.By
import androidx.test.uiautomator.Direction
import androidx.test.uiautomator.Until
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@OptIn(ExperimentalMetricApi::class)
@RunWith(AndroidJUnit4::class)
class GalleryBenchmark {
@get:Rule
val benchmarkRule = MacrobenchmarkRule()
@Test
fun coldStartup() = benchmarkRule.measureRepeated(
packageName = PACKAGE_NAME,
metrics = listOf(StartupTimingMetric()),
compilationMode = CompilationMode.None(),
startupMode = StartupMode.COLD,
iterations = 5,
setupBlock = { pressHome() },
) {
startActivityAndWait()
}
@Test
fun galleryResume() = benchmarkRule.measureRepeated(
packageName = PACKAGE_NAME,
metrics = listOf(
FrameTimingMetric(),
TraceSectionMetric(GALLERY_LOAD_TRACE),
),
compilationMode = CompilationMode.None(),
iterations = 5,
setupBlock = {
startActivityAndWait()
openGalleryIfNeeded()
},
) {
device.pressHome()
device.pressRecentApps()
val task = device.wait(
Until.findObject(By.descStartsWith("OneCamera")),
UI_TIMEOUT_MS,
) ?: error("OneCamera task not found in Recents")
task.click()
check(device.wait(Until.hasObject(galleryScreen()), UI_TIMEOUT_MS)) {
"Gallery did not become visible after resume"
}
check(device.wait(Until.hasObject(By.descStartsWith("Photo: ")), UI_TIMEOUT_MS)) {
"Gallery photos disappeared after resume"
}
}
@Test
fun galleryManualRefresh() = benchmarkRule.measureRepeated(
packageName = PACKAGE_NAME,
metrics = listOf(TraceSectionMetric(GALLERY_LOAD_TRACE)),
compilationMode = CompilationMode.None(),
iterations = 3,
setupBlock = {
startActivityAndWait()
openGalleryIfNeeded()
},
) {
device.swipe(
device.displayWidth / 2,
device.displayHeight / 4,
device.displayWidth / 2,
device.displayHeight * 3 / 4,
30,
)
check(device.wait(Until.hasObject(By.descStartsWith("Photo: ")), UI_TIMEOUT_MS)) {
"Gallery photos disappeared after manual refresh"
}
}
@Test
fun galleryFastScroll() = benchmarkRule.measureRepeated(
packageName = PACKAGE_NAME,
metrics = listOf(FrameTimingMetric()),
compilationMode = CompilationMode.None(),
iterations = 5,
setupBlock = {
startActivityAndWait()
openGalleryIfNeeded()
},
) {
check(device.wait(Until.hasObject(galleryScreen()), UI_TIMEOUT_MS)) {
"Gallery screen not found"
}
check(device.wait(Until.hasObject(By.res("gallery_grid")), UI_TIMEOUT_MS)) {
"Gallery grid not found"
}
repeat(3) {
swipeGallery(Direction.UP)
}
device.waitForIdle()
}
private fun androidx.benchmark.macro.MacrobenchmarkScope.openGalleryIfNeeded() {
val folderList = By.res("folders_grid")
repeat(MAX_FOLDER_DEPTH) {
if (device.wait(Until.hasObject(folderList), 1_000L)) return@repeat
if (device.wait(Until.hasObject(galleryScreen()), 1_000L)) {
device.pressBack()
}
}
check(device.wait(Until.hasObject(folderList), UI_TIMEOUT_MS)) {
"Folder list not found"
}
val diagnostics = mutableListOf<String>()
check(openScrollablePhotoAlbum(diagnostics = diagnostics)) {
"No scrollable photo album found in the selected directory: $diagnostics"
}
}
private fun androidx.benchmark.macro.MacrobenchmarkScope.openScrollablePhotoAlbum(
diagnostics: MutableList<String>,
depth: Int = 0,
): Boolean {
if (depth > MAX_FOLDER_DEPTH) return false
val photos = By.descStartsWith("Photo: ")
val folders = By.descStartsWith("Folder: ")
val hasPhotos = device.wait(Until.hasObject(photos), 1_000L)
if (hasPhotos) {
val visibleBefore = visibleDescriptions(photos)
swipeGallery(Direction.UP)
device.waitForIdle()
val visibleAfter = visibleDescriptions(photos)
val canScroll = visibleBefore != visibleAfter
diagnostics += "depth=$depth, visiblePhotos=${visibleBefore.size}, canScroll=$canScroll"
if (canScroll) {
repeat(3) { swipeGallery(Direction.DOWN) }
device.waitForIdle()
return true
}
} else {
device.wait(Until.hasObject(folders), UI_TIMEOUT_MS)
}
val folderDescriptions = visibleDescriptions(folders)
diagnostics += "depth=$depth, visibleFolders=${folderDescriptions.size}"
for (description in folderDescriptions) {
diagnostics += "open $description"
val folder = device.findObject(By.desc(description)) ?: continue
folder.click()
if (!device.wait(Until.gone(By.desc(description)), UI_TIMEOUT_MS)) return false
if (!device.wait(Until.hasObject(galleryScreen()), UI_TIMEOUT_MS)) return false
if (openScrollablePhotoAlbum(diagnostics, depth + 1)) return true
device.pressBack()
if (!device.wait(Until.hasObject(By.desc(description)), UI_TIMEOUT_MS)) return false
}
return false
}
private fun androidx.benchmark.macro.MacrobenchmarkScope.visibleDescriptions(
selector: androidx.test.uiautomator.BySelector,
): List<String> = device.findObjects(selector).mapNotNull { item ->
try {
item.contentDescription
} catch (_: androidx.test.uiautomator.StaleObjectException) {
null
}
}
private fun androidx.benchmark.macro.MacrobenchmarkScope.swipeGallery(direction: Direction) {
val bounds = device.findObject(By.res("gallery_grid"))?.visibleBounds
?: error("Gallery grid not found")
val (startFraction, endFraction) = if (direction == Direction.UP) {
0.75f to 0.25f
} else {
0.25f to 0.75f
}
device.swipe(
bounds.centerX(),
bounds.top + (bounds.height() * startFraction).toInt(),
bounds.centerX(),
bounds.top + (bounds.height() * endFraction).toInt(),
10,
)
}
private fun galleryScreen() = By.desc("Create subfolder")
private companion object {
const val PACKAGE_NAME = "asia.oneway.onecamera"
const val GALLERY_LOAD_TRACE = "OneCamera/Gallery/Load"
const val UI_TIMEOUT_MS = 20_000L
const val MAX_FOLDER_DEPTH = 8
}
}
@@ -0,0 +1,102 @@
package asia.oneway.onecamera.benchmark
import androidx.benchmark.macro.BaselineProfileMode
import androidx.benchmark.macro.CompilationMode
import androidx.benchmark.macro.MacrobenchmarkScope
import androidx.benchmark.macro.StartupMode
import androidx.benchmark.macro.StartupTimingMetric
import androidx.benchmark.macro.junit4.MacrobenchmarkRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.uiautomator.By
import androidx.test.uiautomator.Until
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class StartupBenchmark {
@get:Rule
val benchmarkRule = MacrobenchmarkRule()
@Test
fun startupWithoutBaselineProfile() = startup(CompilationMode.None())
@Test
fun startupWithBaselineProfile() = startup(
CompilationMode.Partial(baselineProfileMode = BaselineProfileMode.Require),
)
private fun startup(compilationMode: CompilationMode): Unit = with(benchmarkRule) {
measureRepeated(
packageName = PACKAGE_NAME,
metrics = listOf(StartupTimingMetric()),
compilationMode = compilationMode,
iterations = ITERATIONS,
startupMode = StartupMode.COLD,
setupBlock = {
pressHome()
startActivityAndWait()
grantRootIfNeeded()
device.pressHome()
},
) {
startActivityAndWait()
check(device.wait(Until.hasObject(By.descStartsWith("Folder: ")), FULL_DRAW_TIMEOUT_MS)) {
"Folder list did not load before full display"
}
}
}
private fun MacrobenchmarkScope.grantRootIfNeeded() {
if (device.hasObject(By.descStartsWith("Folder: "))) return
val chooseFolder = By.text("Choose folder")
check(device.wait(Until.hasObject(chooseFolder), UI_TIMEOUT_MS)) {
"Root selection button not found"
}
device.findObject(chooseFolder).click()
val download = By.text("Download")
if (!device.wait(Until.hasObject(download), 3_000L)) {
device.swipe(
device.displayWidth / 2,
(device.displayHeight * 3) / 4,
device.displayWidth / 2,
device.displayHeight / 4,
10,
)
}
check(device.wait(Until.hasObject(download), UI_TIMEOUT_MS)) {
"Download directory not found in the picker"
}
device.findObject(download).click()
val oneCamera = By.text("OneCamera")
check(device.wait(Until.hasObject(oneCamera), UI_TIMEOUT_MS)) {
"OneCamera directory not found in Download"
}
device.findObject(oneCamera).click()
val useThisFolder = By.text("USE THIS FOLDER")
check(device.wait(Until.hasObject(useThisFolder), UI_TIMEOUT_MS)) {
"Folder confirmation button not found"
}
device.findObject(useThisFolder).click()
val allow = By.text("ALLOW")
check(device.wait(Until.hasObject(allow), UI_TIMEOUT_MS)) {
"Permission grant button not found"
}
device.findObject(allow).click()
check(device.wait(Until.hasObject(By.descStartsWith("Folder: ")), UI_TIMEOUT_MS)) {
"Root folder did not load after granting access"
}
}
private companion object {
const val PACKAGE_NAME = "asia.oneway.onecamera"
const val ITERATIONS = 5
const val FULL_DRAW_TIMEOUT_MS = 15_000L
const val UI_TIMEOUT_MS = 20_000L
}
}