photos: updated automated screenshot generation
- Commit
17ab519b4abab79baa24579470ddd57f3411b73d- Author
- Vayun Mathur <[email protected]>
- When
- 2026-07-07 05:32 UTC (5 months ago)
- Parents
81e615e
Diff
metadata_data/photos/photos/1.png
diff --git a/metadata_data/photos/photos/1.png b/metadata_data/photos/photos/1.pngindex 325243bf75..fa6f4a5d2e 100644Binary files a/metadata_data/photos/photos/1.png and b/metadata_data/photos/photos/1.png differ
metadata_data/photos/photos/2.png
diff --git a/metadata_data/photos/photos/2.png b/metadata_data/photos/photos/2.pngnew file mode 100644index 0000000000..0a0e068f79Binary files /dev/null and b/metadata_data/photos/photos/2.png differ
photos/build.gradle.kts
diff --git a/photos/build.gradle.kts b/photos/build.gradle.ktsindex eae294f7e7..4ae483fbb3 100644--- a/photos/build.gradle.kts+++ b/photos/build.gradle.kts@@ -55,4 +55,7 @@ dependencies { implementation(project(":library:widgets")) implementation(project(":library:biometric")) implementation(project(":library:ocr"))++ // The metadata screenshot generator writes EXIF GPS into seeded JPEGs.+ androidTestImplementation(libs.androidx.exifinterface) }
photos/src/androidTest/java/com/vayunmathur/photos/MetadataScreenshots.kt
diff --git a/photos/src/androidTest/java/com/vayunmathur/photos/MetadataScreenshots.kt b/photos/src/androidTest/java/com/vayunmathur/photos/MetadataScreenshots.ktindex 850a8f7436..41349a6e79 100644--- a/photos/src/androidTest/java/com/vayunmathur/photos/MetadataScreenshots.kt+++ b/photos/src/androidTest/java/com/vayunmathur/photos/MetadataScreenshots.kt@@ -8,21 +8,29 @@ import android.graphics.LinearGradient import android.graphics.Paint import android.graphics.Shader import android.provider.MediaStore+import android.view.accessibility.AccessibilityNodeInfo import androidx.compose.ui.graphics.asAndroidBitmap import androidx.compose.ui.test.captureToImage import androidx.compose.ui.test.junit4.createEmptyComposeRule import androidx.compose.ui.test.onRoot+import androidx.exifinterface.media.ExifInterface import androidx.test.core.app.ActivityScenario import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.platform.app.InstrumentationRegistry+import com.vayunmathur.library.util.buildDatabase+import com.vayunmathur.photos.data.PhotoDatabase+import com.vayunmathur.photos.util.setExifData+import com.vayunmathur.photos.util.syncPhotos+import kotlinx.coroutines.runBlocking import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import java.io.File /**- * Screenshot generator driven by `:photos:metadata`. Seeds a set of colorful images into- * MediaStore before launch, then captures the gallery grid.+ * Screenshot generator driven by `:photos:metadata`. Seeds a set of colourful geotagged+ * JPEGs into MediaStore, indexes them into the app DB, then captures the gallery grid and+ * the map (clustered markers). */ @RunWith(AndroidJUnit4::class) class MetadataScreenshots {@@ -30,7 +38,8 @@ class MetadataScreenshots { @get:Rule val composeRule = createEmptyComposeRule() - private val ctx = InstrumentationRegistry.getInstrumentation().targetContext+ private val instrumentation = InstrumentationRegistry.getInstrumentation()+ private val ctx = instrumentation.targetContext private val outDir: File by lazy { File(ctx.getExternalFilesDir(null), "metadata_screenshots").apply {@@ -46,6 +55,14 @@ class MetadataScreenshots { } } + /** Full-device screenshot (needed for the GL/SurfaceView MapLibre map). */+ private fun snapDevice(index: Int) {+ val bmp = instrumentation.uiAutomation.takeScreenshot()+ File(outDir, "$index.png").outputStream().use { out ->+ bmp.compress(Bitmap.CompressFormat.PNG, 100, out)+ }+ }+ private fun gradientBitmap(top: Int, bottom: Int): Bitmap { val size = 900 val bmp = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888)@@ -59,6 +76,16 @@ class MetadataScreenshots { return bmp } + /** Remove images seeded by a previous run so reruns don't accumulate duplicates. */+ private fun deleteSeeded() {+ val collection = MediaStore.Images.Media.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY)+ ctx.contentResolver.delete(+ collection,+ "${MediaStore.Images.Media.DISPLAY_NAME} LIKE ?",+ arrayOf("$NAME_PREFIX%"),+ )+ }+ private fun seedImages() { val palettes = listOf( Color.rgb(255, 138, 101) to Color.rgb(255, 209, 128),@@ -79,15 +106,26 @@ class MetadataScreenshots { val now = System.currentTimeMillis() palettes.forEachIndexed { i, (top, bottom) -> val values = ContentValues().apply {- put(MediaStore.Images.Media.DISPLAY_NAME, "sample_${i + 1}.png")- put(MediaStore.Images.Media.MIME_TYPE, "image/png")+ put(MediaStore.Images.Media.DISPLAY_NAME, "$NAME_PREFIX${i + 1}.jpg")+ put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg") put(MediaStore.Images.Media.RELATIVE_PATH, "DCIM/Camera") put(MediaStore.Images.Media.DATE_TAKEN, now - i * 3_600_000L) put(MediaStore.Images.Media.IS_PENDING, 1) } val uri = resolver.insert(collection, values) ?: return@forEachIndexed resolver.openOutputStream(uri)!!.use { out ->- gradientBitmap(top, bottom).compress(Bitmap.CompressFormat.PNG, 100, out)+ gradientBitmap(top, bottom).compress(Bitmap.CompressFormat.JPEG, 95, out)+ }+ // Geotag: cluster all photos near one city with small offsets. MediaStore+ // redacts the LATITUDE/LONGITUDE columns on API 29+, so the coordinates must+ // live in the file's EXIF (the app reads them via setRequireOriginal ++ // ACCESS_MEDIA_LOCATION).+ val lat = BASE_LAT + (i % 4) * 0.008+ val lon = BASE_LON + (i / 4) * 0.008+ resolver.openFileDescriptor(uri, "rw")!!.use { pfd ->+ val exif = ExifInterface(pfd.fileDescriptor)+ exif.setLatLong(lat, lon)+ exif.saveAttributes() } values.clear() values.put(MediaStore.Images.Media.IS_PENDING, 0)@@ -95,13 +133,84 @@ class MetadataScreenshots { } } + /** Click a bottom-nav item by its label through the accessibility tree (the map's+ * continuous re-projection loop would otherwise stall Compose's waitForIdle). */+ private fun clickByText(label: String): Boolean {+ val ui = instrumentation.uiAutomation+ repeat(10) {+ val root: AccessibilityNodeInfo? = ui.rootInActiveWindow+ if (root != null) {+ val nodes = root.findAccessibilityNodeInfosByText(label)+ for (node in nodes) {+ var target: AccessibilityNodeInfo? = node+ while (target != null && !target.isClickable) target = target.parent+ if (target != null) {+ target.performAction(AccessibilityNodeInfo.ACTION_CLICK)+ return true+ }+ }+ }+ Thread.sleep(300)+ }+ return false+ }++ /** Dismiss the system "built for a previous version / 16 KB" warning dialog if shown. */+ private fun dismissSystemDialog() {+ val ui = instrumentation.uiAutomation+ val labels = listOf("Close", "Got it", "OK", "Dismiss", "Cancel")+ repeat(3) {+ val root = ui.rootInActiveWindow ?: return+ for (label in labels) {+ for (node in root.findAccessibilityNodeInfosByText(label)) {+ var target: AccessibilityNodeInfo? = node+ while (target != null && !target.isClickable) target = target.parent+ if (target != null) {+ target.performAction(AccessibilityNodeInfo.ACTION_CLICK)+ Thread.sleep(500)+ return+ }+ }+ }+ Thread.sleep(300)+ }+ }+ @Test fun generateStoreScreenshots() {+ deleteSeeded() seedImages()++ // Index MediaStore into the app's shared Room DB and resolve EXIF GPS directly so+ // the gallery and map populate deterministically before capture.+ val db = ctx.buildDatabase<PhotoDatabase>()+ runBlocking {+ syncPhotos(ctx, db)+ setExifData(db.photoDao().getAll(), db, ctx)+ }+ ActivityScenario.launch(MainActivity::class.java).use { // Let the gallery index MediaStore and load thumbnails. Thread.sleep(6000)+ // The 16 KB-incompatibility warning can pop over the app on launch; clear it+ // before capturing or navigating so it neither pollutes the shot nor blocks+ // the bottom-nav taps.+ dismissSystemDialog() snap(1)++ // Map page: GL-backed MapLibre view. Navigate via accessibility, wait for+ // tiles + clustered markers to render, then capture the whole screen.+ dismissSystemDialog()+ clickByText("Map")+ Thread.sleep(9000)+ dismissSystemDialog()+ snapDevice(2) } }++ companion object {+ private const val NAME_PREFIX = "metadata_sample_"+ private const val BASE_LAT = 37.7749+ private const val BASE_LON = -122.4194+ } }
photos/src/main/ic_launcher-playstore.png
diff --git a/photos/src/main/ic_launcher-playstore.png b/photos/src/main/ic_launcher-playstore.pngindex b33a91d993..6877508e46 100644Binary files a/photos/src/main/ic_launcher-playstore.png and b/photos/src/main/ic_launcher-playstore.png differ