Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / photos / AGENTS.md
| 1 | # AGENTS.md — photos/ (':photos') |
| 2 | |
| 3 | > Scoped supplement. Global rules in root `AGENTS.md` apply. Stay inside `photos/` + allowed shared modules. Do not root-scan. |
| 4 | |
| 5 | _Install: ./install photos (dev by default)._ |
| 6 | - Gradle: :photos / dir: photos/ |
| 7 | - Package roots present: ui, data, domain, platform, service, widget, intents |
| 8 | - Entry files: MainActivity.kt, Route.kt, Navigation.kt |
| 9 | - Deps: :library:map, :library:image, :library:ml, :library:room, :library:ink, :library:widgets, :library:biometric, :library:ocr, :library:downloadservice |
| 10 | - Metadata: metadata_data/photos.md (present) |
| 11 | - Rust: yes / screenshotTest: yes |
| 12 | |
| 13 | ## Overview |
| 14 | **Purpose:** A photos app with a full non-destructive editor and on-device AI search — faces, text, and content all indexed locally. Internet only for basemap tiles behind the map view. |
| 15 | **Key features:** |
| 16 | - Gallery with adjustable grid, albums, people (on-device face grouping), map view, trash, and separate photo/video editors (`EditActivity`/`VideoEditActivity`) |
| 17 | - Non-destructive editor: curves, HSL, levels, healing, liquify, layers, selective edits, undo/redo — edits stored as `data/*Data` docs, composited by `LayerCompositor` |
| 18 | - On-device search by content (CLIP), by text (OCR layout), and by person (face recognition + segmentation); biometric-locked secure folder with optional relock-on-exit |
| 19 | - Wallpaper/live-wallpaper, Glance home widget, motion-photo support, and background sync worker |
| 20 | **Architecture / data-flow:** `ui/` pages over `platform/` ViewModels (`GalleryViewModel`, `PhotoEditViewModel`, `VideoEditViewModel`, `PhotoMapViewModel`, `SecureFolderViewModel`) → `data/` Room (`PhotoDatabase`, `VaultDatabase`, `PhotosRepository`/`VaultRepository`) plus MediaStore indexing (`AlbumMediaStore`); ML (faces, CLIP, OCR, segmentation) runs on `:library:ml` with a Rust native bridge (`PhotosNative`). `onCreateBeforeContent`: widget previews + `ImageLoader.init`; `Content()` provides the column-count state behind a media-permissions gate into inline `Navigation()`. |
| 21 | **Entry points + reading order:** `Route` (`Gallery` / `PhotoPage` / `Map` / `People` / `Albums` / `Trash` / `SecureFolder` / `VaultViewer` / `Wallpaper`, inline) → `MainActivity.kt` → `ui/GalleryPage.kt` → `platform/GalleryViewModel.kt` → `data/PhotosRepository.kt`. |
| 22 | **Gotchas:** |
| 23 | - Re-tapping a photo replaces the viewer (`pushPhoto`/`setLast`) instead of stacking — don't `add()` photo routes or back steps through stale viewers |
| 24 | - `ACTION_VIEW` from another app (e.g. the camera) makes that one photo the stack root with no gallery beneath; in-app back handling must not swallow the system predictive-back gesture there |
| 25 | - `MaFragmentActivity` (not `MaActivity`) — biometric + fragment-hosting requirement |
| 26 | - Widget code is flat in `widget/` (widget + receiver in one file); ViewModels/ML/compositing live in `platform/`, pure helpers in `domain/` |
| 27 | - MediaStore sync writes already-known rows by column (`PhotoDao.updateSyncFields`), never as rebuilt-row upserts: the sync projection excludes the OCR/CLIP payload columns, so an upsert of a changed row would null its OCR text/geometry and CLIP embedding while leaving the scanned flags set |
| 28 | - Upgrades from app versions before v2.6.0 start with a fresh local database (supported upgrade floor: Photo DB v12 and Vault DB v1; Photo DB versions 1–11 open destructively, v12 onward migrates normally; Vault DB has no pre-floor versions) |
| 29 | |
| 30 | ## Key files |
| 31 | ### Root — entry + navigation |
| 32 | - com/vayunmathur/photos/MainActivity.kt — entry, pushPhoto, relock logic |
| 33 | - com/vayunmathur/photos/Route.kt — sealed `Route` incl. dialog destinations |
| 34 | - com/vayunmathur/photos/Navigation.kt — nav graph + dialog entries |
| 35 | ### data/ — Room + edit-document model |
| 36 | - com/vayunmathur/photos/data/PhotosRepository.kt |
| 37 | - com/vayunmathur/photos/data/PhotoDatabase.kt |
| 38 | - com/vayunmathur/photos/data/Photo.kt |
| 39 | - com/vayunmathur/photos/data/VaultRepository.kt |
| 40 | - com/vayunmathur/photos/data/VaultDatabase.kt |
| 41 | - com/vayunmathur/photos/data/EditDocument.kt |
| 42 | - com/vayunmathur/photos/data/ImageAdjustments.kt |
| 43 | - com/vayunmathur/photos/data/FxAdjustments.kt |
| 44 | - com/vayunmathur/photos/data/MoreAdjustmentsData.kt |
| 45 | - com/vayunmathur/photos/data/LayerData.kt |
| 46 | - com/vayunmathur/photos/data/LayerBlendMode.kt |
| 47 | - com/vayunmathur/photos/data/CurvesData.kt |
| 48 | - com/vayunmathur/photos/data/LevelsData.kt |
| 49 | - com/vayunmathur/photos/data/HslData.kt |
| 50 | - com/vayunmathur/photos/data/ColorBalanceData.kt |
| 51 | - com/vayunmathur/photos/data/ChannelMixerData.kt |
| 52 | - com/vayunmathur/photos/data/BlackAndWhiteData.kt |
| 53 | - com/vayunmathur/photos/data/BlurData.kt |
| 54 | - com/vayunmathur/photos/data/SharpenData.kt |
| 55 | - com/vayunmathur/photos/data/NoiseData.kt |
| 56 | - com/vayunmathur/photos/data/HealingData.kt |
| 57 | - com/vayunmathur/photos/data/ContentAwareData.kt |
| 58 | - com/vayunmathur/photos/data/LiquifyData.kt |
| 59 | - com/vayunmathur/photos/data/DodgeBurnData.kt |
| 60 | - com/vayunmathur/photos/data/GradientMapData.kt |
| 61 | - com/vayunmathur/photos/data/StylizeData.kt |
| 62 | - com/vayunmathur/photos/data/PerspectiveData.kt |
| 63 | - com/vayunmathur/photos/data/SelectionData.kt |
| 64 | - com/vayunmathur/photos/data/SelectiveEditData.kt |
| 65 | - com/vayunmathur/photos/data/Drawing.kt |
| 66 | - com/vayunmathur/photos/data/PaintOpsData.kt |
| 67 | - com/vayunmathur/photos/data/SmudgeData.kt |
| 68 | - com/vayunmathur/photos/data/OcrLayout.kt |
| 69 | - com/vayunmathur/photos/data/FaceData.kt |
| 70 | - com/vayunmathur/photos/data/RedEyeData.kt |
| 71 | - com/vayunmathur/photos/data/VideoEditState.kt |
| 72 | - com/vayunmathur/photos/data/BitmapExtensions.kt |
| 73 | ### domain/ — OCR, motion-photo and face-grouping logic (pure) |
| 74 | - com/vayunmathur/photos/domain/PhotoOcr.kt |
| 75 | - com/vayunmathur/photos/domain/MotionPhotoXmp.kt |
| 76 | - com/vayunmathur/photos/domain/FaceAlignment.kt — five-point ArcFace alignment |
| 77 | - com/vayunmathur/photos/domain/FaceQuality.kt — which faces may form people |
| 78 | - com/vayunmathur/photos/domain/FaceClustering.kt — batch average-linkage grouping |
| 79 | - com/vayunmathur/photos/domain/FaceClusterIdentity.kt — keeps person ids/names across regroups |
| 80 | ### intents/ — assistant IPC (metadata only) |
| 81 | - com/vayunmathur/photos/intents/SearchPhotosIntent.kt — `photos_search_photos`: filtered (file-name/folder/date) metadata search over `PhotoDao.searchPhotoMetadata`; returns the matching count plus at most 10 hits (`library.intents.photos.PhotoHitData`: id, file name, taken date, dimensions, album, MIME). Never returns image bytes, thumbnails, URIs/paths, location, OCR text or embeddings; trashed items are excluded in SQL and the secure-folder vault is never opened. Guarded by the signature permission `com.vayunmathur.photos.permissions.ACCESS_PHOTOS`. |
| 82 | - com/vayunmathur/photos/intents/PhotosSearchContract.kt — provider-side validation/clamping (limit 1–10, text/date-range normalisation) and row→hit mapping |
| 83 | ### widget/ — home widget |
| 84 | - com/vayunmathur/photos/widget/PhotoGlanceWidget.kt — includes `PhotoGlanceWidgetReceiver` (one widget, one file) |
| 85 | ### platform/ — motion-photo |
| 86 | - com/vayunmathur/photos/platform/MotionPhotoVideo.kt |
| 87 | ### service/ — live wallpaper |
| 88 | - com/vayunmathur/photos/service/LiveWallpaperService.kt |
| 89 | ### ui/ — gallery, albums, people, map |
| 90 | - com/vayunmathur/photos/ui/GalleryPage.kt |
| 91 | - com/vayunmathur/photos/ui/GalleryScreen.kt |
| 92 | - com/vayunmathur/photos/ui/GalleryGrouping.kt |
| 93 | - com/vayunmathur/photos/ui/AlbumsPage.kt |
| 94 | - com/vayunmathur/photos/ui/AlbumsScreen.kt |
| 95 | - com/vayunmathur/photos/ui/AlbumDetailPage.kt |
| 96 | - com/vayunmathur/photos/ui/AlbumDetailScreen.kt |
| 97 | - com/vayunmathur/photos/ui/PeoplePage.kt |
| 98 | - com/vayunmathur/photos/ui/MapPage.kt |
| 99 | - com/vayunmathur/photos/ui/TrashPage.kt |
| 100 | - com/vayunmathur/photos/ui/TrashScreen.kt — stateless trash grid (preview seam) |
| 101 | - com/vayunmathur/photos/ui/RememberAlbumMoveLauncher.kt — MANAGE_MEDIA + MediaStore write-request launcher for album dialog routes |
| 102 | - com/vayunmathur/photos/ui/VideoEditNavigation.kt — video-editor nav host incl. save dialog entry |
| 103 | ### ui/dialogs/ — dialog route contents (stateless) |
| 104 | - com/vayunmathur/photos/ui/dialogs/AlbumNameDialog.kt |
| 105 | - com/vayunmathur/photos/ui/dialogs/AlbumPickerDialog.kt |
| 106 | - com/vayunmathur/photos/ui/dialogs/DeleteAlbumDialog.kt |
| 107 | - com/vayunmathur/photos/ui/dialogs/DeletePersonDialog.kt |
| 108 | - com/vayunmathur/photos/ui/dialogs/SecureFolderRelockDialog.kt |
| 109 | - com/vayunmathur/photos/ui/dialogs/SaveDialog.kt |
| 110 | - com/vayunmathur/photos/ui/ImageFit.kt |
| 111 | ### ui/ — viewer + metadata |
| 112 | - com/vayunmathur/photos/ui/PhotoPage.kt |
| 113 | - com/vayunmathur/photos/ui/PhotoDetailView.kt |
| 114 | - com/vayunmathur/photos/ui/PhotoDetailSection.kt |
| 115 | - com/vayunmathur/photos/ui/PhotoDetailMedia.kt |
| 116 | - com/vayunmathur/photos/ui/PhotoMetadataCard.kt |
| 117 | - com/vayunmathur/photos/ui/PhotoFilmstrip.kt |
| 118 | - com/vayunmathur/photos/ui/PhotoViewerActions.kt |
| 119 | - com/vayunmathur/photos/ui/PhotoViewerWideLayout.kt |
| 120 | - com/vayunmathur/photos/ui/EditRoute.kt |
| 121 | - com/vayunmathur/photos/ui/EditActivity.kt |
| 122 | - com/vayunmathur/photos/ui/FaceBoxLayer.kt |
| 123 | - com/vayunmathur/photos/ui/OcrTextLayer.kt |
| 124 | - com/vayunmathur/photos/ui/PanoramaFlatView.kt |
| 125 | - com/vayunmathur/photos/ui/PanoramaSphereView.kt |
| 126 | ### ui/ — editor panels + canvas |
| 127 | - com/vayunmathur/photos/ui/EditPhotoPage.kt |
| 128 | - com/vayunmathur/photos/ui/EditPhotoEditorState.kt |
| 129 | - com/vayunmathur/photos/ui/EditPhotoModels.kt |
| 130 | - com/vayunmathur/photos/ui/EditPhotoModelHelpers.kt |
| 131 | - com/vayunmathur/photos/ui/EditPhotoCanvas.kt |
| 132 | - com/vayunmathur/photos/ui/EditPhotoPanels.kt |
| 133 | - com/vayunmathur/photos/ui/EditPhotoActivePanel.kt |
| 134 | - com/vayunmathur/photos/ui/EditPhotoAdjustPanels.kt |
| 135 | - com/vayunmathur/photos/ui/EditPhotoBrushPanels.kt |
| 136 | - com/vayunmathur/photos/ui/EditPhotoSelectionPanels.kt |
| 137 | - com/vayunmathur/photos/ui/EditPhotoBottomControls.kt |
| 138 | - com/vayunmathur/photos/ui/EditPhotoCropOverlay.kt |
| 139 | - com/vayunmathur/photos/ui/EditPhotoToolOverlays.kt |
| 140 | - com/vayunmathur/photos/ui/EditPhotoModeEffect.kt |
| 141 | - com/vayunmathur/photos/ui/EditPhotoTextDialog.kt |
| 142 | - com/vayunmathur/photos/ui/AdvancedPanels.kt |
| 143 | - com/vayunmathur/photos/ui/BlurPanel.kt |
| 144 | - com/vayunmathur/photos/ui/BlurOverlay.kt |
| 145 | - com/vayunmathur/photos/ui/CurvesPanel.kt |
| 146 | - com/vayunmathur/photos/ui/HslPanel.kt |
| 147 | - com/vayunmathur/photos/ui/HealingPanel.kt |
| 148 | - com/vayunmathur/photos/ui/HealingOverlay.kt |
| 149 | - com/vayunmathur/photos/ui/LayersPanel.kt |
| 150 | - com/vayunmathur/photos/ui/LayerRows.kt |
| 151 | - com/vayunmathur/photos/ui/MaskOverlay.kt |
| 152 | - com/vayunmathur/photos/ui/SelectiveEditPanel.kt |
| 153 | - com/vayunmathur/photos/ui/DrawingSettingsPage.kt |
| 154 | ### ui/ — video editor + wallpaper + vault |
| 155 | - com/vayunmathur/photos/ui/VideoEditRoute.kt |
| 156 | - com/vayunmathur/photos/ui/VideoEditActivity.kt |
| 157 | - com/vayunmathur/photos/ui/VideoEditPage.kt |
| 158 | - com/vayunmathur/photos/ui/VideoEditPanels.kt |
| 159 | - com/vayunmathur/photos/ui/VideoEditPreview.kt |
| 160 | - com/vayunmathur/photos/ui/VideoEditCropOverlay.kt |
| 161 | - com/vayunmathur/photos/ui/VideoEditDialogs.kt |
| 162 | - com/vayunmathur/photos/ui/VideoPlayer.kt |
| 163 | - com/vayunmathur/photos/ui/WallpaperPage.kt |
| 164 | - com/vayunmathur/photos/ui/WallpaperPreview.kt |
| 165 | - com/vayunmathur/photos/ui/WallpaperControls.kt |
| 166 | - com/vayunmathur/photos/ui/SecureFolderPage.kt |
| 167 | - com/vayunmathur/photos/ui/VaultViewerPage.kt |
| 168 | - com/vayunmathur/photos/ui/VaultViewerScreen.kt |
| 169 | ### platform/ — ViewModels, ML, compositing, sync |
| 170 | - com/vayunmathur/photos/platform/GalleryViewModel.kt |
| 171 | - com/vayunmathur/photos/platform/GalleryUiContract.kt |
| 172 | - com/vayunmathur/photos/platform/PhotoEditViewModel.kt |
| 173 | - com/vayunmathur/photos/platform/VideoEditViewModel.kt |
| 174 | - com/vayunmathur/photos/platform/PhotoMapViewModel.kt |
| 175 | - com/vayunmathur/photos/platform/SecureFolderViewModel.kt |
| 176 | - com/vayunmathur/photos/platform/SecureFolderManager.kt |
| 177 | - com/vayunmathur/photos/platform/LayerCompositor.kt |
| 178 | - com/vayunmathur/photos/domain/UndoRedoManager.kt |
| 179 | - com/vayunmathur/photos/platform/OverlayRendering.kt |
| 180 | - com/vayunmathur/photos/platform/FaceRecognizer.kt |
| 181 | - com/vayunmathur/photos/platform/FaceCropTransformation.kt |
| 182 | - com/vayunmathur/photos/platform/MlSegmentation.kt |
| 183 | - com/vayunmathur/photos/platform/ClipEmbedder.kt |
| 184 | - com/vayunmathur/photos/platform/ClipTokenizer.kt |
| 185 | - com/vayunmathur/photos/platform/ImageLoader.kt |
| 186 | - com/vayunmathur/photos/domain/PanoXmpParser.kt |
| 187 | - com/vayunmathur/photos/platform/PhotosNative.kt — Rust bridge |
| 188 | - com/vayunmathur/photos/platform/AlbumMediaStore.kt |
| 189 | - com/vayunmathur/photos/platform/SyncWorker.kt |
| 190 | - com/vayunmathur/photos/platform/SyncWorkerHelper.kt |
| 191 | - com/vayunmathur/photos/platform/LiveWallpaperLauncher.kt |
| 192 | - com/vayunmathur/photos/platform/WallpaperHelper.kt |
| 193 | - com/vayunmathur/photos/platform/AppBackupAgent.kt — platform backup agent: carries the photo database (file `passwords-db`, named by `PHOTO_DB_NAME` in `data/PhotoDatabase.kt` with its `photosDbConfigs`) through `SqlCipherDbCodec` plus the `datastore_default` file, so face/people metadata (person names, hidden flags, face/OCR/CLIP payloads) survives a restore re-encrypted under the new device's key. The raw SQLCipher file and `secure_prefs` never ship (non-exportable keystore wrapping); gallery photos are MediaStore content and stay out of the payload. The secure-folder vault (`vault-db` + `secure_vault`, keyed by the user's password) travels raw only on device transfer and through its own in-app password export, never in cloud backup. Extraction rules in `src/main/res/xml/data_extraction_rules.xml` govern device transfer and mirror these exclusions |
| 194 | |
| 195 | ## Verify (this module only) |
| 196 | ``` |
| 197 | ./gradlew :photos:compileDevKotlin |
| 198 | ./gradlew :photos:lint |
| 199 | ./gradlew :photos:checkMetadata |
| 200 | ``` |