Skip to content

Target API 36 and harden the PC-to-Android file sync - #19

Open
wmergenthal wants to merge 61 commits into
masterfrom
lightsys-api36
Open

wmergenthal wants to merge 61 commits into
masterfrom
lightsys-api36

Conversation

@wmergenthal

@wmergenthal wmergenthal commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Update the build for Android 15 / API 36: AGP and Gradle updates, Jetifier and deprecated config options removed, Robolectric tests now run against SDK 36.
  • Fix PC-to-Android file sync: read the raw body, keep the socket open, close connections only when a request body may be unread, and disable Nagle's algorithm on accepted sync connections.
  • Rework AcceptFileHandler: stream uploads to disk, remove multipart-form support, report failed receives, return 411 for a missing Content-Length, and tighten the path traversal check in the directory and file handlers.
  • Fix crashes and potential bugs: null path in RecordActivity, foreground service start in SyncActivity, a null ipView, and a missing recording path that failed silently.
  • Smaller changes: FloatPreference accepts comma decimals and clamps its range, BookButton uses an explicit locale for toUpperCase, and formatting is cleaned up in HearThisPreferences.
  • Tests: update AcceptFileHandlerTest for streaming uploads and add new cases. The JVM is updated so no unit tests are skipped.

Test plan

  • ./gradlew testDebugUnitTest
  • Sync a file from the desktop app to a device or emulator

🤖 Generated with Claude Code


This change is Reviewable

GroveOfGraves and others added 30 commits February 9, 2026 18:19
* Moved hardcoded strings to strings.xml and gave many methods Edge-to-Edge display capabilities. Additionally, updated gradle scripts to target proper versions and changed SyncService to properly channel for newer versions

* Minor updates and error cleanups

---------

Co-authored-by: elith <elith@DESKTOP-9R0HDQ5>
* Initial changes to ensure foreground operation compliancy

* Patch out small issues

* Stop sync automatically, add content intent from notification
* Moved hardcoded strings to strings.xml and gave many methods Edge-to-Edge display capabilities. Additionally, updated gradle scripts to target proper versions and changed SyncService to properly channel for newer versions

* Minor updates and error cleanups

* Updating Edge-to-Edge and various other useful updates :)

Signed-off-by: elith <elith@DESKTOP-9R0HDQ5>

---------

Signed-off-by: elith <elith@DESKTOP-9R0HDQ5>
Co-authored-by: elith <elith@DESKTOP-9R0HDQ5>
* Moved hardcoded strings to strings.xml and gave many methods Edge-to-Edge display capabilities. Additionally, updated gradle scripts to target proper versions and changed SyncService to properly channel for newer versions

* Minor updates and error cleanups

* Updating Edge-to-Edge and various other useful updates :)

Signed-off-by: elith <elith@DESKTOP-9R0HDQ5>

* Add a service that forwards the necessary ports for the desktop app (#1)

* Changes to versioning, hardcoded strings, and logic updates (#2)

* Moved hardcoded strings to strings.xml and gave many methods Edge-to-Edge display capabilities. Additionally, updated gradle scripts to target proper versions and changed SyncService to properly channel for newer versions

* Minor updates and error cleanups

---------

Co-authored-by: elith <elith@DESKTOP-9R0HDQ5>

* Feat/foreground service changes (#3)

* Initial changes to ensure foreground operation compliancy

* Patch out small issues

* Stop sync automatically, add content intent from notification

* Changing the spacing to give small padding for both sides of the screen and hopefully removing some inconsistency in the UI

Signed-off-by: elith <elith@DESKTOP-9R0HDQ5>

---------

Signed-off-by: elith <elith@DESKTOP-9R0HDQ5>
Co-authored-by: elith <elith@DESKTOP-9R0HDQ5>
Co-authored-by: GroveOfGraves <113633048+GroveOfGraves@users.noreply.github.com>
* Moved hardcoded strings to strings.xml and gave many methods Edge-to-Edge display capabilities. Additionally, updated gradle scripts to target proper versions and changed SyncService to properly channel for newer versions

* Minor updates and error cleanups

* Updating Edge-to-Edge and various other useful updates :)

Signed-off-by: elith <elith@DESKTOP-9R0HDQ5>

* Add a service that forwards the necessary ports for the desktop app (#1)

* Changes to versioning, hardcoded strings, and logic updates (#2)

* Moved hardcoded strings to strings.xml and gave many methods Edge-to-Edge display capabilities. Additionally, updated gradle scripts to target proper versions and changed SyncService to properly channel for newer versions

* Minor updates and error cleanups

---------

Co-authored-by: elith <elith@DESKTOP-9R0HDQ5>

* Feat/foreground service changes (#3)

* Initial changes to ensure foreground operation compliancy

* Patch out small issues

* Stop sync automatically, add content intent from notification

* Properly centering the bottom buttons within the bottom section

Signed-off-by: elith <elith@DESKTOP-9R0HDQ5>

* Added constants for hardcoded values within the project - mainly from menu_record.xml and added to strings.xml (I have been doing this through previous commits)

Signed-off-by: elith <elith@DESKTOP-9R0HDQ5>

---------

Signed-off-by: elith <elith@DESKTOP-9R0HDQ5>
Co-authored-by: elith <elith@DESKTOP-9R0HDQ5>
Co-authored-by: GroveOfGraves <113633048+GroveOfGraves@users.noreply.github.com>
* Update to newer Gradle version

* Update scanner and camera libraries
Updated the server from the old library to the new library nanohttpd
* Moved hardcoded strings to strings.xml and gave many methods Edge-to-Edge display capabilities. Additionally, updated gradle scripts to target proper versions and changed SyncService to properly channel for newer versions

* Minor updates and error cleanups

* Updating Edge-to-Edge and various other useful updates :)

Signed-off-by: elith <elith@DESKTOP-9R0HDQ5>

* Add a service that forwards the necessary ports for the desktop app (#1)

* Changes to versioning, hardcoded strings, and logic updates (#2)

* Moved hardcoded strings to strings.xml and gave many methods Edge-to-Edge display capabilities. Additionally, updated gradle scripts to target proper versions and changed SyncService to properly channel for newer versions

* Minor updates and error cleanups

---------

Co-authored-by: elith <elith@DESKTOP-9R0HDQ5>

* Feat/foreground service changes (#3)

* Initial changes to ensure foreground operation compliancy

* Patch out small issues

* Stop sync automatically, add content intent from notification

* Updated hardcoded strings, warnings, and added onTimeout function to handle a service timeout, as well as cleaned up errors in the manifest

Signed-off-by: elith <elith@DESKTOP-9R0HDQ5>

* Made a ton of updates to deprecated systems including color selection and other fun stuff :)

Signed-off-by: elith <elith@DESKTOP-9R0HDQ5>

---------

Signed-off-by: elith <elith@DESKTOP-9R0HDQ5>
Co-authored-by: elith <elith@DESKTOP-9R0HDQ5>
Co-authored-by: GroveOfGraves <113633048+GroveOfGraves@users.noreply.github.com>
* Initial update of tests

* Remove some warnings

* Remove additional warnings
* Moved hardcoded strings to strings.xml and gave many methods Edge-to-Edge display capabilities. Additionally, updated gradle scripts to target proper versions and changed SyncService to properly channel for newer versions

* Minor updates and error cleanups

* Updating Edge-to-Edge and various other useful updates :)

Signed-off-by: elith <elith@DESKTOP-9R0HDQ5>

* Add a service that forwards the necessary ports for the desktop app (#1)

* Changes to versioning, hardcoded strings, and logic updates (#2)

* Moved hardcoded strings to strings.xml and gave many methods Edge-to-Edge display capabilities. Additionally, updated gradle scripts to target proper versions and changed SyncService to properly channel for newer versions

* Minor updates and error cleanups

---------

Co-authored-by: elith <elith@DESKTOP-9R0HDQ5>

* Feat/foreground service changes (#3)

* Initial changes to ensure foreground operation compliancy

* Patch out small issues

* Stop sync automatically, add content intent from notification

* Many, many updates to warnings, java standards, and better code for updated versions and cleaner running

Signed-off-by: elith <elith@DESKTOP-9R0HDQ5>

---------

Signed-off-by: elith <elith@DESKTOP-9R0HDQ5>
Co-authored-by: elith <elith@DESKTOP-9R0HDQ5>
Co-authored-by: GroveOfGraves <113633048+GroveOfGraves@users.noreply.github.com>
* Moved hardcoded strings to strings.xml and gave many methods Edge-to-Edge display capabilities. Additionally, updated gradle scripts to target proper versions and changed SyncService to properly channel for newer versions

* Minor updates and error cleanups

* Updating Edge-to-Edge and various other useful updates :)

Signed-off-by: elith <elith@DESKTOP-9R0HDQ5>

* Add a service that forwards the necessary ports for the desktop app (#1)

* Changes to versioning, hardcoded strings, and logic updates (#2)

* Moved hardcoded strings to strings.xml and gave many methods Edge-to-Edge display capabilities. Additionally, updated gradle scripts to target proper versions and changed SyncService to properly channel for newer versions

* Minor updates and error cleanups

---------

Co-authored-by: elith <elith@DESKTOP-9R0HDQ5>

* Feat/foreground service changes (#3)

* Initial changes to ensure foreground operation compliancy

* Patch out small issues

* Stop sync automatically, add content intent from notification

* Many, many updates to warnings, java standards, and better code for updated versions and cleaner running

Signed-off-by: elith <elith@DESKTOP-9R0HDQ5>

* Many warnings fixed plus addition of FloatPreference.java, which handles some issues with how floats were being handled

Signed-off-by: elith <elith@DESKTOP-9R0HDQ5>

* Fixed problems with merge (oops)

Signed-off-by: elith <elith@DESKTOP-9R0HDQ5>

* Fixing various warnings throughout files

Signed-off-by: elith <elith@DESKTOP-9R0HDQ5>

---------

Signed-off-by: elith <elith@DESKTOP-9R0HDQ5>
Co-authored-by: elith <elith@DESKTOP-9R0HDQ5>
Co-authored-by: GroveOfGraves <113633048+GroveOfGraves@users.noreply.github.com>
* Clean up http server

Cleaned up the http server. Had some memory leak issues and some double server calls that should be fixed

* Fix live sync

Fixed an issue where the app didn't display the file being downloaded and then moving to the book view

* Clean up audio

The audio functions need a bit of cleanup. This commit cleans a little up
* Moved hardcoded strings to strings.xml and gave many methods Edge-to-Edge display capabilities. Additionally, updated gradle scripts to target proper versions and changed SyncService to properly channel for newer versions

* Minor updates and error cleanups

* Updating Edge-to-Edge and various other useful updates :)

Signed-off-by: elith <elith@DESKTOP-9R0HDQ5>

* Add a service that forwards the necessary ports for the desktop app (#1)

* Changes to versioning, hardcoded strings, and logic updates (#2)

* Moved hardcoded strings to strings.xml and gave many methods Edge-to-Edge display capabilities. Additionally, updated gradle scripts to target proper versions and changed SyncService to properly channel for newer versions

* Minor updates and error cleanups

---------

Co-authored-by: elith <elith@DESKTOP-9R0HDQ5>

* Feat/foreground service changes (#3)

* Initial changes to ensure foreground operation compliancy

* Patch out small issues

* Stop sync automatically, add content intent from notification

* Fixing various warnings throughout files caused by the merge, as well as changing deprecated functions

Signed-off-by: elith <elith@DESKTOP-9R0HDQ5>

---------

Signed-off-by: elith <elith@DESKTOP-9R0HDQ5>
Co-authored-by: elith <elith@DESKTOP-9R0HDQ5>
Co-authored-by: GroveOfGraves <113633048+GroveOfGraves@users.noreply.github.com>
* Moved hardcoded strings to strings.xml and gave many methods Edge-to-Edge display capabilities. Additionally, updated gradle scripts to target proper versions and changed SyncService to properly channel for newer versions

* Minor updates and error cleanups

* Updating Edge-to-Edge and various other useful updates :)

Signed-off-by: elith <elith@DESKTOP-9R0HDQ5>

* Add a service that forwards the necessary ports for the desktop app (#1)

* Changes to versioning, hardcoded strings, and logic updates (#2)

* Moved hardcoded strings to strings.xml and gave many methods Edge-to-Edge display capabilities. Additionally, updated gradle scripts to target proper versions and changed SyncService to properly channel for newer versions

* Minor updates and error cleanups

---------

Co-authored-by: elith <elith@DESKTOP-9R0HDQ5>

* Feat/foreground service changes (#3)

* Initial changes to ensure foreground operation compliancy

* Patch out small issues

* Stop sync automatically, add content intent from notification

* Fixing various warnings throughout files, making lambda functions, and cleaning up some unused functions and variables

Signed-off-by: elith <elith@DESKTOP-9R0HDQ5>

---------

Signed-off-by: elith <elith@DESKTOP-9R0HDQ5>
Co-authored-by: elith <elith@DESKTOP-9R0HDQ5>
Co-authored-by: GroveOfGraves <113633048+GroveOfGraves@users.noreply.github.com>
Added spanish, french, german, and chinese (simplified) as available languages
* Add tests for RecordActivity

* Add BookSelection test

* Add SyncActivity tests

* Add several new tests

* Remove references to Mockito

* Remove runtime warnings

* Move some tests

* Move RealScriptProviderTest and update to remove warnings
* Moved hardcoded strings to strings.xml and gave many methods Edge-to-Edge display capabilities. Additionally, updated gradle scripts to target proper versions and changed SyncService to properly channel for newer versions

* Minor updates and error cleanups

* Updating Edge-to-Edge and various other useful updates :)

Signed-off-by: elith <elith@DESKTOP-9R0HDQ5>

* Add a service that forwards the necessary ports for the desktop app (#1)

* Changes to versioning, hardcoded strings, and logic updates (#2)

* Moved hardcoded strings to strings.xml and gave many methods Edge-to-Edge display capabilities. Additionally, updated gradle scripts to target proper versions and changed SyncService to properly channel for newer versions

* Minor updates and error cleanups

---------

Co-authored-by: elith <elith@DESKTOP-9R0HDQ5>

* Feat/foreground service changes (#3)

* Initial changes to ensure foreground operation compliancy

* Patch out small issues

* Stop sync automatically, add content intent from notification

* Making a lot of changes to clean up warnings and errors in the IDE, making sure to avoid Test files as they were being worked on by others

Signed-off-by: elith <elith@DESKTOP-9R0HDQ5>

* Cleaned up the merge :)

Signed-off-by: elith <elith@DESKTOP-9R0HDQ5>

---------

Signed-off-by: elith <elith@DESKTOP-9R0HDQ5>
Co-authored-by: elith <elith@DESKTOP-9R0HDQ5>
Co-authored-by: GroveOfGraves <113633048+GroveOfGraves@users.noreply.github.com>
Major-Q and others added 27 commits March 6, 2026 15:16
* Update play button

The play button never stopped listening for a trigger, this caused an error when trigger with no recording to play. This has been fixed and the play button doesn't listen for a trigger when there is no recording to play.

* Play button update

Fixed potential memory leak, where the arrow.reset function is never called
* Moved hardcoded strings to strings.xml and gave many methods Edge-to-Edge display capabilities. Additionally, updated gradle scripts to target proper versions and changed SyncService to properly channel for newer versions

* Minor updates and error cleanups

* Updating Edge-to-Edge and various other useful updates :)

Signed-off-by: elith <elith@DESKTOP-9R0HDQ5>

* Add a service that forwards the necessary ports for the desktop app (#1)

* Changes to versioning, hardcoded strings, and logic updates (#2)

* Moved hardcoded strings to strings.xml and gave many methods Edge-to-Edge display capabilities. Additionally, updated gradle scripts to target proper versions and changed SyncService to properly channel for newer versions

* Minor updates and error cleanups

---------

Co-authored-by: elith <elith@DESKTOP-9R0HDQ5>

* Feat/foreground service changes (#3)

* Initial changes to ensure foreground operation compliancy

* Patch out small issues

* Stop sync automatically, add content intent from notification

* Fixed the last of the warnings and feelin GOOD

Signed-off-by: elith <elith@DESKTOP-9R0HDQ5>

* Why won't the status bar change

Signed-off-by: elith <elith@DESKTOP-9R0HDQ5>

* I FIXED IT WOOOOOOOOOO

Signed-off-by: elith <elith@DESKTOP-9R0HDQ5>

---------

Signed-off-by: elith <elith@DESKTOP-9R0HDQ5>
Co-authored-by: elith <elith@DESKTOP-9R0HDQ5>
Co-authored-by: GroveOfGraves <113633048+GroveOfGraves@users.noreply.github.com>
* Initial commit of patched tests

* Patch SyncActivityTest for Android 12

* Ensure wide compatibility, remove warnings

* Fix unit tests
…ndroid Studio requirements (#33)

* Initial plan

* Add Camera/Scanning, Build System, and Testing documentation sections to README

Co-authored-by: GroveOfGraves <113633048+GroveOfGraves@users.noreply.github.com>

* Add missing sections and update stale Testing notes in README

Co-authored-by: GroveOfGraves <113633048+GroveOfGraves@users.noreply.github.com>

* Rewrite #Building section to reflect current SDK 36 build configuration

Co-authored-by: GroveOfGraves <113633048+GroveOfGraves@users.noreply.github.com>

* Update #Building section: name Android Studio Panda 2 and explain simple setup workflow

Co-authored-by: GroveOfGraves <113633048+GroveOfGraves@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: GroveOfGraves <113633048+GroveOfGraves@users.noreply.github.com>
…onsistency (#34)

* Initial plan

* docs: consolidate duplicate Testing sections in README

Co-authored-by: GroveOfGraves <113633048+GroveOfGraves@users.noreply.github.com>

* docs: fix heading style consistency in README (add missing spaces after #)

Co-authored-by: GroveOfGraves <113633048+GroveOfGraves@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: GroveOfGraves <113633048+GroveOfGraves@users.noreply.github.com>
Devin: "NextButton.onDraw never resets pre-allocated Path, causing visual corruption on every redraw." Add a call to arrow.reset() as the method's first action, like PlayButton does.
Devin: "RealFileSystem.getDirectories crashes with NPE if directory does not exist." Added null checks to prevent this.
…this.

The full "potential bug": "In SyncActivity.java:217-232, the scanBtn and ipView fields are only initialized inside onCreateOptionsMenu(). However, handleBarcode() at line 296 uses ipView.setText(contents) which is called from the barcode scanner callback. If onCreateOptionsMenu() hasn't been called yet (which is unlikely but possible on configuration changes), or if the menu is not created, ipView will be null causing a crash. More importantly, scanBtn is only set up in the menu callback. While this was also the pattern in the old code, combining it with the camera initialization in startCamera() (called from scanBtn.setOnClickListener) means the scan button initialization is deferred and tightly coupled to the menu lifecycle."
I can't see any issue with 'scanBtn'. It is true that 'ipView' could be dereferenced as null if onCreateOptionsMenu() isn't called prior to handleBarcode(), but my study of a sync does not show that occurring. Nevertheless, it's safe to add a null check in handleBarcode() right after the one that is already there (for 'contents') and of the same form.
Also added a pair of TODOs, one for each side, to fix the silly issue of HT always sending an empty sync result and HTA always interpreting that as success.
…rectly by converting through UTF-8 String

Replaced the UTF_8 handling with raw byte handling.
Devin: "In AcceptFileHandler.java:83-85, when NanoHTTPD provides the uploaded content as raw data (the else branch at line 83), the handler writes it via contentOrPath.getBytes(StandardCharsets.UTF_8). For binary files like .wav audio recordings (which is the primary use case for this sync server), converting binary data through a String with UTF-8 encoding will corrupt the data. NanoHTTPD's parseBody() stores large POST bodies to temp files and puts the temp file path in the map — the isPath check at lines 73-78 handles this case. However, for smaller binary payloads (under 1024 bytes or not starting with /), or on platforms where NanoHTTPD returns content as a String, the binary data will be corrupted by the String round-trip. The old Apache HTTP implementation used EntityUtils.toByteArray() which preserved binary data correctly."
…vity finishes with no valid state

Really, it should have been flagged as a potential bug as it involves dereferencing a possibly null pointer. This change adds a null check.
…versesPerChapter or projectName"

The BookInfo class had two unused items removed. Operationally, yes, that shouldn't matter. But it does create the potential for a problem if a user interacts with old versions of BookInfo classes that DO have those fields. Even though they aren't used it is safer to leave them in.
… start in SyncActivity

RecordActivity: guard remaining _recordingFilePath null cases so
recording/playback code can't NPE, and make startWaveRecorder's early
return reset the waiting button state and release the startingLock
(previously calling notifyAll() outside a synchronized block, and
before that, never releasing waiting callers at all).

SyncActivity: start SyncService via ContextCompat.startForegroundService
instead of startService, and reset `scanning` before the ipView null
check in handleBarcode so a missing view doesn't leave barcode
scanning stuck disabled.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…onnections

AcceptFileHandler now reads the request body as raw bytes and extracts the
multipart file part without a String round-trip (binary-safe). It no longer
closes the socket input stream, which dropped the connection before the
response was sent. SyncServer adds "Connection: close" to all responses so
.NET WebClient doesn't reuse a connection after early-return handlers leave
body bytes unread.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Multipart-form support was added during debug of a PC-side unhandled exception during sync. The root cause turned out to have nothing to do with MPF, and in fact the MPF code was never used.
So we remove it since unused code adds bloat, has more to go wrong, offers a larger attack surface, etc.
…Handler

- Copy the request body in 8 KB chunks into a temporary .part file and
  move it into place only once Content-Length bytes have arrived, so a
  dropped connection cannot leave a truncated file.
- Reject uploads larger than 100 MB with 413 before reading any body, so
  a bogus Content-Length can no longer cause an OutOfMemoryError.
- Require a separator after the base directory in the path traversal
  check, so a sibling such as "<base>-evil" is rejected.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
When _recordingFilePath is null, release the recorder that was just
created, reset the record button, and tell the user via a toast
(new cannot_start_recording string in all locales). stopRecording now
returns early if recording never started, instead of showing a
misleading "too short" dialog.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The existing tests mocked parseBody, which the handler no longer uses.
The mock session now supplies the content-length header and a raw body
stream. New tests cover binary and multi-chunk bodies, overwrite,
sibling-directory and backslash path traversal, missing/invalid/oversized
Content-Length (400/413 without reading the body), and truncated uploads
leaving no partial file and preserving any existing file.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Add IFileReceivedNotification.receiveFailed (default no-op), called when
a file announced via receivingFile cannot be saved, and show it in
SyncActivity with a new receive_failed string in all locales. A missing
or invalid Content-Length now returns 411 Length Required instead of 400;
chunked uploads remain unsupported. Tests updated and extended.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
SyncServer added "Connection: close" to every response. Now it closes
only when the request carried a body that the handler may not have read
to the end (any failed /putfile, bodies on other endpoints, and chunked
requests), and keeps the connection alive for body-less requests and
for a successful /putfile. Adds SyncServerTest for the decision.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
With keep-alive restored, small writes on a reused connection (response
headers followed by body) could stall on the Nagle / delayed-ACK
interaction. SyncServer now sets TCP_NODELAY on each accepted socket by
overriding createClientHandler.

Measured on a real sync: ~61-63s with keep-alive alone, ~36-39s before
keep-alive was restored, and ~17-19s with TCP_NODELAY.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Treat a comma as a decimal separator, reject NaN/Infinity, and clamp
typed values to 0.5-5.0 to match the pinch-zoom limits in LinesView.
Add FloatPreferenceTest.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A bare startsWith on the canonical base path also matched siblings that
share the base name as a prefix (e.g. "<base>-secret"). Require the base
itself or the base followed by a separator, as AcceptFileHandler does.
Add ListDirectoryHandlerTest and RequestFileHandlerTest.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Tests in at least 5 files (AcceptFileHandlerTest, BookButtonTest, HearThisPreferencesTest, LevelMeterViewTest, RealScriptProviderTest) were being skipped because "Gradle JVM criteria" was set to 17, but JVM 21 is needed to run them. This change updates the criteria.
Note that, obviously, the JVM in use must now be 21 or later.  The current Android Studio (2026.2.1 as of today) ships with JVM 25 built-in, which gets used if the host system has no other JVM operating.
Fixes the two DefaultLocale lint warnings. Behavior is unchanged: the
abbreviation is display text, so Locale.getDefault() is used.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Update @config(sdk = 34) to 36 in all seven test classes so tests run
against the same API level as the app's targetSdk. All tests pass.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Resolve gradle-wrapper.properties conflict by keeping Gradle 9.3.1 (with
its checksum) and adopting networkTimeout/validateDistributionUrl from
master. Bump the new CI workflow to JDK 21 to match the project's Java 21
and Gradle 9 requirements.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

@tombogle tombogle left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review notes (Claude Code, /code-review max + Devin findings reconciled)

Devin's automated review never actually ran on this PR — its GitHub status check reads "Full review skipped: trial expired and no credits remaining." Tom pasted in the findings from the Devin web UI by hand, and I checked each one against the PR's head commit (8a377a0) alongside my own independent review. Everything below is de-duplicated and verified against the actual code; a couple of Devin's flags turned out to be pre-existing behavior rather than regressions, which I've noted inline.

20 findings, grouped and roughly ordered by severity:

Data loss / security

  1. SyncServer.java:91 — No authentication or pairing check on any endpoint (/getfile, /putfile, /list). Any device that can reach port 8087 on the LAN can read or overwrite another user's project scripts and recordings. (Devin) This predates the PR — the old Apache-based registry had the same unauthenticated routes — but since the whole server was rewritten here with NanoHTTPD, this was a natural point to add a pairing token. Worth a decision on whether it's in scope now or tracked separately.

  2. SyncActivity.java:303,321-336 — handleBarcode passes the scanned QR content straight into sendRegistrationMessage → InetAddress.getByName(desktopIpAddress) with no validation that it's a plausible LAN address. Scanning any QR code (not just one from the desktop HearThis app) redirects where the device announces its own IP via UDP. (Devin) This is new exposure — QR scanning via CameraX/ML Kit is new in this PR, replacing the old GMS Vision flow.

  3. AcceptFileHandler.java:110-124 — Two problems in the upload-finalize step: (a) the temp filename (file.getName() + ".part") is derived only from the destination path with no per-request uniqueness, so two concurrent uploads to the same destination (e.g. two sync passes racing) write into the same temp file and can corrupt or truncate each other's bytes; (b) on a normal single-request overwrite, the existing file is deleted before temp.renameTo(file) is attempted — renameTo is documented as unreliable on Android and can return false without throwing, and the catch block then deletes the temp file too, leaving no file at all at that path. (Mine + Devin, same code region, two distinct mechanisms) Fix: give each request a unique temp file and publish via an atomic replace that doesn't unlink the destination first.

  4. RealScriptProvider.java:116 — noteLineRecorded() now silently no-ops (skips writing the <Recordings> entry) when the line index falls outside the chapter's stored <ScriptLine> nodes, instead of the loud NullPointerException this replaced. The audio file still gets saved to disk, but the chapter's info.xml/info.txt never record it as done, with nothing in logcat to explain why — turning a visible crash into invisible, hard-to-diagnose data loss.

  5. RecordActivity.java:195 + AndroidManifest.xml:41 — onPause() → stopMonitoring() stops and releases waveRecorder directly, bypassing stopRecording()'s too-short-discard check and the noteBlockRecorded() bookkeeping that marks a line as recorded. This path already existed (the old code's onPause did the same thing), but it was previously only reachable via a true backgrounding/interruption during a push-and-hold recording. This PR removes RecordActivity's android:screenOrientation="nosensor" lock with no replacement (no configChanges), so a plain device rotation during recording now destroys/recreates the activity through this same path — turning a narrow, rare bug into one that's trivial to hit, with no user-visible error; the UI looks normal after recreate.

Build / protocol correctness

  1. app/build.gradle:90-125 — setupSyncTunnels is wired unconditionally into preBuild and shells out to adb with no existence check. On any machine without adb resolvable (CI, a fresh clone before local.properties/sdk.dir exist, a Docker build), fullArgs.execute() throws and the entire build fails — including plain unit-test runs unrelated to device syncing. Separately, even when adb is present, every build silently mutates the current device/emulator's port-forwarding (adb forward/adb reverse) as a side effect, whether or not syncing is what you're doing. (Mine + Devin) Devin's suggested fix: make it an opt-in task (./gradlew setupSyncTunnels) rather than a preBuild dependency.

  2. AcceptFileHandler.java:75 vs RequestFileHandler/ListDirectoryHandler — The canonical-path traversal check is hand-duplicated across all three handlers and has already diverged: AcceptFileHandler alone lacks the canonicalRequested.equals(canonicalBase) carve-out the other two have (so it alone forbids a request resolving to exactly the base dir), and ListDirectoryHandler silently defaults a missing path to "" while the other two return 400. Any future tightening of the traversal rule has three call sites to keep in sync.

  3. SyncServer.java:117-144 — requestHasBody()/shouldCloseConnection() disagree with AcceptFileHandler's own Content-Length parsing on a negative value: the handler treats < 0 as "no body, return 411 without reading," but requestHasBody() parses the same negative number and evaluates > 0 as false too, so shouldCloseConnection() reports "no body, keep-alive is fine." Any body bytes actually sent on a kept-alive connection are left unread on the socket and get parsed as the start of the next request, corrupting it.

  4. SyncActivity.java:279-287 — startCamera() binds only CameraSelector.DEFAULT_BACK_CAMERA and the bindToLifecycle call is guarded only against ExecutionException/InterruptedException. AndroidManifest.xml declares android.hardware.camera as android:required="false", so the app installs and runs on camera-less devices — tapping Scan on one of those throws an uncaught camera-selection exception and exits the sync screen instead of falling back to manual IP entry. (Devin)

  5. SyncActivity.java:386-402 — getOurIpAddress() was relaxed from requiring isSiteLocalAddress() (RFC1918 LAN ranges) to accepting any non-loopback, non-link-local IPv4 address. On a device with both Wi-Fi and mobile data active, this can now pick the cellular/VPN interface's address instead of the Wi-Fi LAN address, depending on unspecified JDK interface-enumeration order — the desktop app then can't route to the advertised address and sync silently fails. (Mine + Devin, same finding)

  6. SyncActivity.java:231ish (onCreateOptionsMenu) vs sendRegistrationMessage — Only sendRegistrationMessage was updated with a null check for getOurIpAddress()'s new nullable return; onCreateOptionsMenu's ourIpView.setText(ourIpAddress) wasn't, so on a device where no suitable interface is found, the "our IP address" field is silently left blank with no explanation.

Crash/correctness claims that don't hold up

  1. ChooseChapterActivity.java:50,54 and RecordActivity.java:124 — assert extras != null; / assert book != null; are no-ops on Android (JVM assertions are disabled by default), so these don't actually guard anything; the next line throws an unguarded NPE if the condition is true. This is the exact class of "null path in RecordActivity" crash the PR's own summary claims to have fixed.

  2. RecordActivity.java:73 (waveRecorder field) — Read and mutated from both the UI thread (onPause/onResume) and the background thread that starts a recording, with no volatile/synchronization — unlike the starting flag this same diff protects with startingLock. Can double-release the recorder or orphan a newly-constructed one that nothing can then stop.

  3. AcceptFileHandler.java:47 / RequestFileHandler's listener field — Written from the UI thread (SyncActivity.onResume/onPause) and read from NanoHTTPD's per-connection worker thread, with no volatile. With this PR's new keep-alive + TCP_NODELAY connections, a long-lived worker thread isn't guaranteed to promptly observe a paused activity's setListener(null), unlike AcceptNotificationHandler's listener state, which this same PR moved to a CopyOnWriteArrayList.

Smaller regressions

  1. RecordActivity.java:130 — onCreate() always recomputes _activeLine from the Intent's "line" extra whenever book != null, which now wins over the savedInstanceState restore branch on every rotation (newly reachable now that the orientation lock is gone) — navigating to line 20 and rotating silently jumps back to line 0.

  2. RecordActivity.java:207 — onPause() dropped the && !wasUsingSpeaker half of its speakerphone-restore condition, so leaving the activity now always turns off speakerphone and resets audio mode to NORMAL whenever usingSpeaker is true — even if speakerphone was already on before RecordActivity ran (e.g. during an active call). wasUsingSpeaker is now dead code.

  3. RecordActivity.java:572 — playButtonClicked() sets the Play button to "playing" before checking _recordingFilePath != null. On a line with no recording, the button (left enabled from a previously-displayed line) gets stuck showing "playing" forever, since onCompletion() — the only place that resets it — never fires.

  4. BookButton.java:94 — Changed .toUpperCase() to .toUpperCase(Locale.getDefault()), which the PR summary describes as fixing locale-sensitive casing, but is documented as behaviorally identical to the no-arg overload. The Turkish-I bug (isa → İsa instead of Isa on a Turkish device locale) is unchanged.

Known limitation, not a regression

  1. SyncActivity.java:358-366 (onNotification) — Always reports sync success and re-enables Continue, even when receiveFailed() was called for a failed upload. (Devin) Checked against the pre-PR code — this is pre-existing behavior, not new, and the PR's own author left a TODO acknowledging it ("HearThisAndroid ignores it and assumes success"). Flagging for visibility, not as something introduced here.

Docs

  1. README.md:20 vs app/build.gradle:23-24 and .github/workflows/gradle-build.yml:19 — The build guide says the project uses Java 17 source/target compatibility, but build.gradle actually sets JavaVersion.VERSION_21 and CI's setup-java step pins java-version: '21'. A contributor following the README's JDK guidance will hit a build mismatch. (Devin)

Separately: the fork's README (carried over unchanged into this branch) has several sections — "Http Server," "Build System," "Warnings," "Audio suggestion" — written as a code-a-thon wrap-up narrative ("we updated," "we looked into," "we believe") rather than as documentation of current behavior. Worth a follow-up discussion on trimming those into the PR description (or an issue, for "Audio suggestion") and keeping the README to the enduring parts (Building, Testing, Camera/Scanning rationale, License) — happy to draft that if useful.

@tombogle

Copy link
Copy Markdown
Contributor

README.md line 51 at r1 (raw file):

- `espresso-intents` is included for testing intent-based navigation flows between activities

### Http Server

From here down (at least) most of this added content is really notes that belong in the PR description, not here. This is noted near the end of the long review I posted. The Readme should be current information a developer needs to know, not a snapshot or changelog. Claude can help tease this apart and retain what is relevant here, and move the change-related stuff to the PR description.

handleBarcode() now rejects barcode contents that are not a valid
dotted-quad IPv4 address, logging an error and continuing to scan.
Adds SyncActivityTest covering isValidIpv4.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants