diff --git a/AGENTS.md b/AGENTS.md index 14cd87c..82306e2 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -2,7 +2,7 @@ ## Scope & Project Status -These instructions apply throughout the repository. Remember is an experimental, local-only microphone recorder for round Wear OS watches, with Galaxy Watch 7 as the primary design target. Physical-watch validation is still pending; successful builds or emulator tests do not establish production or Play Store readiness. Keep changes focused on the requested behavior and preserve unrelated work. +These instructions apply throughout the repository. Remember is an experimental microphone recorder with optional self-hosted SFTP backup for round Wear OS watches, with Galaxy Watch 7 as the primary design target. Physical-watch validation is still pending; successful builds or emulator tests do not establish production or Play Store readiness. Keep changes focused on the requested behavior and preserve unrelated work. ## Project Structure & Module Organization @@ -60,6 +60,17 @@ The UI uses native Android views and custom drawing, without Compose or a runtim - Preserve five-second storage refresh while that page is open, manual Refresh, and stale-result guards. Do not request usage access to other apps for this feature. - Stop decorative motion when animations are disabled, battery saver is active, the activity is backgrounded, or capture is paused. Avoid extra background polling or animation work. +## Backup Invariants + +- `BackupActivity.kt` owns backup pages; `BackupSettings.kt` stores destination details, encrypted key material, and receipts. `BackupTransport.kt` handles pinned-key SFTP; `BackupWorker.kt` schedules persisted Android jobs and serializes network actions with `BackupGate`. +- Require an explicit server configuration and an approved SHA256 host-key fingerprint. First-time discovery must reject the fetched key before authentication and save nothing until the user approves the approval screen. Block changed identities; explicit Forget trust pauses backups. Never disable host verification, authenticate an unapproved server, or log/export private keys. Encrypt stored SSH private keys using Android Keystore. +- Generate new watch identities as Ed25519 using the Android-compatible BC backend and OpenSSH private-key format. Preserve existing RSA identities until explicit replacement; pause backups and require server authorization of the new public key when replacing one. +- Upload only finalized clips. Preserve local audio, metadata, and bookmarks. Local deletion must not propagate to server backups. Scope receipts to the destination; acknowledge only the snapshot actually uploaded. +- Resume temporary uploads, verify full-file SHA-256, then publish metadata as the completion marker. Do not mark a failed or incomplete upload as backed up. Respect cancellation, socket timeouts, bounded buffers, and one active connection at a time. +- Keep automatic uploads opt-in, constrained to charging and unmetered connections by default. Use Android JobScheduler; scheduling is approximate and must not claim exact-time execution. +- Remote listening uses a verified temporary cache, not streaming. Pause playback outside the foreground and retain the previous cache if download verification fails. Remote filenames and manifests are untrusted: enforce safe IDs, sizes, and bounded metadata reads. +- SSH encrypts transport, not stored server files. Do not present at-rest encryption, restore, or remote deletion controls until implemented. + ## Testing Guidelines Use JUnit 4 for JVM tests and AndroidJUnit4/AndroidX instrumentation for device tests; Espresso is available. Name test classes `*Test` and methods after expected behavior. Cover changed boundaries and recording behavior; no numeric coverage threshold is configured. Recording-service changes require device tests on a disposable microphone-enabled emulator. Ensure only the intended emulator is connected, and never test during a personal recording. @@ -76,6 +87,6 @@ Use concise, descriptive commit subjects. Keep PRs focused, explain behavior cha Preserve audio and bookmarks, rotary access, spoken descriptions, and animation/battery preferences. Discuss accounts, networking, or analytics before introducing them. Keep personal audio, credentials, signing keys, local configuration, and build output untracked. See `CONTRIBUTING.md` and `PRIVACY.md` for additional guidance. -Keep the app standalone and local-only, with no internet permission, accounts, analytics, ads, or uploads unless an explicitly discussed feature changes that scope. Backups are disabled; uninstalling removes recordings and preferences. Do not include private recordings, identifying logs, or machine-specific paths in documentation, issues, or screenshots. +Keep capture standalone and local. Optional SFTP networking is authorized for user-configured backups and remote playback; automatic backup is off by default. Do not add app accounts, analytics, ads, or other network services without discussing them. Android backups are disabled; uninstalling removes local recordings, SSH identity, and preferences but leaves server copies intact. Do not include private recordings, identifying logs, or machine-specific paths in documentation, issues, or screenshots. Keep `README.md`, `PRIVACY.md`, and screenshots aligned with changes to behavior, setup, permissions, or limitations. Code and original artwork use MIT; maintain `THIRD_PARTY_NOTICES.md` and relevant notices when adding dependencies or assets. The design is inspired by Samsung's Spatial Number face, but no Samsung font or wallpaper is bundled; use original or appropriately licensed assets. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index eb875c4..0b7c9bb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -25,6 +25,7 @@ Recording-service changes also need the device tests. Use a disposable emulator: - Keep microphone activity visible to the user. Recording should begin with an explicit action. - Preserve saved audio and bookmarks when changing recording or storage behavior. - Respect disabled system animations and battery-saving mode. -- Do not introduce accounts, networking, or analytics without discussing the change first. +- SFTP backup and remote playback are opt-in network features. Preserve fingerprint verification, encrypted key storage, cancellation, checksums, local retention, and charging/network preferences. Test against disposable server folders and recordings. +- Do not introduce app accounts, additional network services, or analytics without discussing the change first. Do not include local IDE/device configuration, credentials, signing keys, build output, or personal audio in a pull request. Avoid attaching private recordings or identifying information to issues. Contributions are covered by the repository's [MIT license](LICENSE). diff --git a/PRIVACY.md b/PRIVACY.md index 2fb6e15..0f014ad 100644 --- a/PRIVACY.md +++ b/PRIVACY.md @@ -3,11 +3,15 @@ Remember records audio only after the user starts capture and grants microphone access. - Recordings and bookmark metadata are stored in the app's private local storage. -- The app has no internet permission, accounts, analytics, advertising, or upload feature. +- The app has internet/network-state permission for optional SFTP backups and remote playback. It connects to the server you configure when you request a connection, upload, or remote recording, or enable scheduled backup. Automatic backup is off by default. There are no app accounts, analytics, advertising, or third-party upload services. +- Backups send audio, titles, timestamps, duration, bookmarks, file size, and checksums to your server. SSH encrypts the connection; these files remain readable on that server. Local deletion does not remove server copies. +- The watch generates its own SSH key. The private key is encrypted with an Android Keystore key; only the public key can be exported. Server configuration and transfer status remain in app-private preferences. The app fetches a server fingerprint without sending watch credentials, then asks for explicit first-time approval. Approved fingerprints are saved and checked before authentication; changed keys are blocked. Forgetting trust is an explicit action that pauses backups. +- Remote playback downloads audio into the app's private temporary cache. You can clear it under Backup → Advanced; Android may also evict cached files. +- Scheduled backups use Android JobScheduler with your selected charging/network constraints. Boot permission allows scheduled jobs to persist after restarting the watch. Jobs may retry failed transfers within your configured retry limit. - Storage monitoring reads device capacity and Remember's own usage; it does not request access to another app's data. - Recording uses a microphone foreground service so it can continue when the screen is off. An ongoing recording notification includes a Save action when notifications are allowed. - Playback pauses when the playback activity leaves the foreground. - Renaming updates a recording's local metadata. Deletion removes the recording after confirmation. -- Uninstalling the app removes its recordings and preferences. Export and phone transfer are not implemented. +- Uninstalling the app removes local recordings, preferences, playback cache, and the stored SSH identity. It does not delete server backups. You will need to authorize a new watch public key after reinstalling. Restoring backups into the local library and phone transfer are not implemented. Developer tools and test runs can access the debug app's files. Use disposable emulator recordings for testing, and do not publish private audio or logs in issues or pull requests. diff --git a/README.md b/README.md index 0e176e5..4482afa 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ Screenshots from a Wear OS round-screen emulator: - Floating rounded numerals show captured minutes; the background sweep shows seconds within the current minute. - A live microphone edge meter and an interactive bookmark/playback edge. - Device and app storage monitoring with a large proportional chart. +- Optional SFTP backups to your own server, a transfer queue, scheduled uploads, and remote playback. - Optional minute limits: save and stop, or save each clip and start the next at zero. - Native controls, spoken descriptions for custom visuals, and rotary input. @@ -30,7 +31,9 @@ The appearance is inspired by Samsung's [Spatial Number watch face](https://gala **Experimental: suitable for development and evaluation.** Build, lint, unit tests, and recording integration tests have passed locally. The UI has been checked on a Wear OS round-screen emulator; recording integration tests used a separate Android emulator. Physical Galaxy Watch 7 validation is still pending. - Captures microphone sound, not internal system audio or call audio. -- Recordings stay on the watch. Export, phone transfer, and transcription are not implemented. +- Recordings stay on the watch unless you configure and trigger SFTP backups. Phone transfer, restore into the local library, and transcription are not implemented. +- Backup is experimental. Your real server and its 128 MB memory budget have not yet been validated. +- Backup generates Ed25519 watch keys and pins the server fingerprint. Existing RSA watch keys remain usable until explicitly replaced. Password login and private-key import are not implemented; RSA, ECDSA, and Ed25519 server host keys are supported. - Playback pauses when you leave the playback activity. - A brief gap can occur between automatically split clips. - Each clip has a 500 MB safety cap; reaching it saves the clip and stops the session. @@ -116,6 +119,27 @@ Turn the limit off for unlimited recording by time, or turn it on and choose **1 Under **At the limit**, choose **Save & stop** to end the recording, or **Save & start next** to continue with a new clip at zero. Split clips have numbered titles and their own bookmarks. Paused time does not count. Changes apply to the next recording session, including all its parts. The 500 MB safety cap applies in either mode. +## Backup + +Open **Settings → Backup**. Dedicated pages keep setup, transfer status, remote listening, and scheduling separate. + +

+ Backup overview with backed-up and waiting counts and Back up now + Server approval with Trust server and Cancel buttons, without fingerprint typing + Server settings with address, port, and username fields + Automatic backup disabled, with charging and unmetered preferences enabled +

+ +- **Server:** configure address, port, username, and an existing absolute backup folder. **Connect & trust** fetches the fingerprint without typing; approve the server once to remember it. Create the watch key, export or copy its public key, and authorize it on your server. Test connection before uploading. See [server setup](docs/backup.md). +- **Transfers:** shows saved recordings and their status. **Back up / Retry** queues unfinished or changed recordings. **Pause all backups** cancels transfers and turns automatic backup off. Local recordings are never deleted by backup; local deletion does not delete server copies. +- **Server recordings:** Refresh lists completed Remember backups (up to 1,000 per folder). Select a recording to download a verified temporary copy and play it with seeking and bookmark buttons. This is cached playback, not live streaming; sufficient watch storage is required. Leaving the activity pauses playback. +- **Automatic backup:** opt in to checks every hour, every six hours, or daily. Charging and unmetered connections are required by default and can be changed. Unmetered does not necessarily mean Wi-Fi. Android schedules work when conditions allow, rather than at an exact clock time; jobs persist across reboot. +- **Advanced:** choose 1/3/5 retry attempts, a 20/40/60-second connection timeout, or clear the playback cache. Server identity shows the remembered fingerprint; Forget trust pauses backups and allows a verified server-key change to be approved again. + +Uploads use one SFTP connection at a time and bounded buffers, without a database, HTTP backend, shell commands, or compression. Interrupted audio uploads resume; the completed remote audio is read back and SHA-256 checked before publishing metadata and marking it backed up. This integrity check costs an additional full-file download. Each clip has its own audio file and JSON manifest containing title, duration, bookmarks, byte count, and checksum. Metadata changes queue another backup. Receipts are scoped to server address, account, folder, and pinned host key. A receipt records a successful transfer; it does not continuously check whether a server copy was subsequently removed. + +The watch's private SSH key is encrypted using Android Keystore. SSH encrypts transport; audio and metadata on your server are **not encrypted at rest**. End-to-end encryption, exact-time scheduling, bandwidth caps, remote deletion, and restoration into the local library are not implemented. Automatic backup checks periodically for finished clips; saving a clip does not force an immediate upload. Interrupted jobs retain partial files for a later retry, subject to the configured retry limit. + ## Tests and automated checks Local checks: @@ -130,13 +154,13 @@ Device tests require a **disposable** emulator with a microphone. They create au ./gradlew :app:connectedDebugAndroidTest ``` -Coverage includes duration formatting, limit boundaries, pause exclusion, real one-minute automatic stop and split rollover, playable file output, bookmarks, settings persistence/navigation, storage accounting, and clip rename/delete behavior. +Coverage includes backup destination validation, encrypted watch-key persistence, backup-page navigation, manifest safety, and (with an opt-in disposable SFTP fixture) resumable transfers, checksum verification, host-key rejection, actual scheduled uploads, scheduling constraints, and cached remote playback/background pause. Network fixture instructions are in [docs/backup.md](docs/backup.md). Coverage also includes duration formatting, limit boundaries, pause exclusion, real one-minute automatic stop and split rollover, playable file output, bookmarks, settings persistence/navigation, storage accounting, and clip rename/delete behavior. [Android checks](.github/workflows/android.yml) runs on pushes, pull requests, and manual dispatch. It verifies the wrapper, builds the debug app, runs lint and unit tests, and compiles device tests. It uploads check reports and a debug APK with a 14-day retention period. Device tests are run locally; the workflow does not claim to run them. The workflow uses pinned action commits and read-only repository permissions. Its first hosted run will happen after the repository is pushed to GitHub. ## Privacy, contributions, and license -Recordings remain in the app's private local storage. There are no accounts, analytics, ads, or upload features, and no internet permission. See [PRIVACY.md](PRIVACY.md). +Recordings use private local storage, with optional uploads to your own SFTP server. Automatic backups are off by default. There are no app accounts, analytics, or ads. See [PRIVACY.md](PRIVACY.md). See [CONTRIBUTING.md](CONTRIBUTING.md) for development and pull-request guidance. Keep private audio, credentials, signing keys, local IDE/device configuration, and build output out of the repository. diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.md index ce9adf3..ab0d32d 100644 --- a/THIRD_PARTY_NOTICES.md +++ b/THIRD_PARTY_NOTICES.md @@ -8,8 +8,18 @@ The checked-in `gradlew`, `gradlew.bat`, and `gradle/wrapper/gradle-wrapper.jar` The wrapper configuration pins the Gradle distribution and its official SHA-256 checksum. The included JAR checksum also matches Gradle's published checksum. These generated wrapper files are not relicensed under MIT. +## JSch SSH/SFTP library + +The app includes [mwiede/JSch 2.28.8](https://github.com/mwiede/jsch/tree/jsch-2.28.8), a maintained fork of JCraft's JSch, under its BSD-style license. Its copyright, conditions, and disclaimer are retained in [licenses/JSch.txt](licenses/JSch.txt) and in the app's bundled license assets. JSch is not relicensed under MIT. + +## Bouncy Castle cryptography + +[Bouncy Castle bcprov-jdk18on 1.86](https://www.bouncycastle.org/) provides Android-compatible Ed25519 key generation and signatures through JSch's BC backend. It is distributed under the Bouncy Castle license (MIT-style), retained in [licenses/Bouncy-Castle.txt](licenses/Bouncy-Castle.txt) and bundled in the app's license assets. Android's installed security providers are not replaced. + ## Resolved dependencies and platform resources Android APIs, Kotlin runtime libraries, the Android Gradle Plugin, and test libraries are obtained through the Android SDK or Gradle rather than copied as source into this repository. Their own license notices apply. Dependency coordinates and versions are listed in `gradle/libs.versions.toml` and `app/build.gradle.kts`. The app uses Android's installed system fonts. No Samsung font, watch-face asset, or wallpaper is bundled. The Spatial Number appearance is referenced as design inspiration; the numeral paths and other app artwork are drawn in project code. Screenshots in `docs/` show the app running in an emulator. + +The optional Python SFTP test fixture uses separately installed Paramiko and cryptography packages under their upstream licenses. These development-only packages are not bundled in the Android app. diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 34e8c20..bd32303 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -35,7 +35,9 @@ android { } dependencies { + implementation(libs.jsch) + implementation(libs.bcprov) testImplementation(libs.junit) androidTestImplementation(libs.androidx.espresso.core) androidTestImplementation(libs.androidx.junit) -} \ No newline at end of file +} diff --git a/app/src/androidTest/java/meghdad/remember/BackupTest.kt b/app/src/androidTest/java/meghdad/remember/BackupTest.kt new file mode 100644 index 0000000..ffd11e4 --- /dev/null +++ b/app/src/androidTest/java/meghdad/remember/BackupTest.kt @@ -0,0 +1,302 @@ +package meghdad.remember + +import android.app.job.JobScheduler +import android.Manifest +import android.media.MediaRecorder +import android.media.MediaPlayer +import android.content.Intent +import android.view.View +import android.view.ViewGroup +import android.widget.Button +import android.widget.EditText +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.action.ViewActions.click +import androidx.test.espresso.matcher.ViewMatchers.withText +import androidx.test.espresso.matcher.ViewMatchers.isDisplayed +import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.platform.app.InstrumentationRegistry +import org.junit.Assert.* +import org.junit.Assume.assumeTrue +import org.junit.Test +import org.junit.runner.RunWith +import java.io.File +import java.util.UUID + +@RunWith(AndroidJUnit4::class) +class BackupTest { + private val instrumentation = InstrumentationRegistry.getInstrumentation() + private val context = instrumentation.targetContext + private val settings get() = BackupSettings(context) + private fun restorePreferences(previous: Map) { + val editor = settings.preferences.edit().clear() + previous.forEach { (key, value) -> when (value) { + is String -> editor.putString(key, value) + is Boolean -> editor.putBoolean(key, value) + is Int -> editor.putInt(key, value) + is Long -> editor.putLong(key, value) + } } + editor.commit() + } + @Test fun backupPagesAreReachableAndAutomaticUploadsDefaultOff() { + val activity = instrumentation.startActivitySync(Intent(context, BackupActivity::class.java).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)) + try { + instrumentation.runOnMainSync { + fun descendants(view: View): List = listOf(view) + if (view is ViewGroup) + (0 until view.childCount).flatMap { descendants(view.getChildAt(it)) } else emptyList() + fun button(label: String) = descendants(activity.window.decorView).filterIsInstance