No description
  • Kotlin 88.5%
  • Python 8.7%
  • Nix 1.8%
  • Shell 1%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-09-20 19:06:27 +02:00
app make all secondary text black instead of grey for e-ink readability 2026-09-20 19:06:27 +02:00
tolino/docs gitignore firmware extraction binaries; track the analysis doc 2026-09-18 22:32:19 +02:00
tools download from webserver directory interactively 2026-09-19 14:57:43 +02:00
.gitignore gitignore firmware extraction binaries; track the analysis doc 2026-09-18 22:32:19 +02:00
build.gradle.kts mvp 2026-09-17 20:21:58 +02:00
flake.lock mvp 2026-09-17 20:21:58 +02:00
flake.nix add test-app devshell helper 2026-09-19 09:53:52 +02:00
gradle.properties mvp 2026-09-17 20:21:58 +02:00
install_launcher.sh helper scripts 2026-09-18 16:58:14 +02:00
README.md stop backing up prefs (plaintext server password); add security notes to README 2026-09-20 15:18:28 +02:00
settings.gradle.kts mvp 2026-09-17 20:21:58 +02:00
start_koreader.sh helper scripts 2026-09-18 16:58:14 +02:00

My Books — e-book launcher for Tolino (Android 4.4.2)

A minimal Kotlin home-screen replacement for e-ink readers: it scans the SD card for .epub, .pdf and .md books, shows them in swipe-paginated pages of six covers (2 rows × 3 columns; EPUB covers/titles are extracted from inside the file, Markdown titles from its front matter or first heading). Ordering: books you have read come first — most recently opened on top (ReadHistory notes every open); never-read books follow alphabetically. Returning to home after reading re-sorts at once. Tapping a book hands it tapped book to an installed reader (KoReader on this device) via ACTION_VIEW. Its intent filter accepts all three formats (application/epub+zip, application/pdf, text/markdown — verified on-device with dumpsys).

Built for the tolino (ntx_6sl, Rakuten Kobo): Android 4.4.2 / API 19, 758×1024 @ ~212 dpi, no emulated internal storage — /sdcard is a symlink to the vfat microSD card where books live under Books/<Author>/<Title>.epub.


Research: building Android apps with Kotlin (and what matters on API 19)

The standard toolchain (2026)

A modern Kotlin Android app is built by Gradle with two plugins:

Piece What it does Version used here
Android Gradle Plugin (AGP, com.android.application) Compiles resources (aapt2), dexes Java/Kotlin bytecode (D8/R8), packages the APK, signs debug builds 8.13.2 (last stable 8.x)
Kotlin Gradle Plugin (org.jetbrains.kotlin.android) Runs kotlinc against android.jar, adds kotlin-stdlib 2.4.20
JDK 17+ Required by AGP 8.x to run the build (not shipped in the APK) Temurin 21 via nixpkgs
Gradle ≥ 8.13 for AGP 8.13 Build runner 8.14.4 via nixpkgs
Android SDK (platforms/android-<N>, build-tools) Provides android.jar (compile against) + aapt2/dx tooling platform 36, build-tools 37.0.0

Project shape: settings.gradle.kts (plugin repos), root build.gradle.kts (plugin versions, apply false), one module per app with sources in src/main/java, resources in src/main/res, and an AndroidManifest.xml. gradle :app:assembleDebug → signed debug APK under app/build/outputs/apk/debug/.

Three SDK levels matter, and they are independent:

  • compileSdk = 36 — the API surface the code compiles against (needs the matching platform in the SDK).
  • minSdk = 19 — oldest OS you run on. AGP lints every call for this level; R8 keeps older bytecode compatible.
  • targetSdk = 19 — behaviour contract with the OS. Targeting 19 deliberately keeps classic semantics: permissions are granted at install time (no runtime-permission code needed) and file:// intents are unrestricted (the FileUriExposure rule only exists on N+/API 24).

The API-19 compatibility matrix (why this app has zero AndroidX dependencies)

Library minSdk requirement Consequence for us
androidx.appcompat:appcompat ≤ 1.6.x 14–19 usable, but unneeded — we use framework themes (Theme.Holo.Light.NoActionBar, present since API 13)
androidx.appcompat:appcompat ≥ 1.7.0 21 would force minSdk 21 → excluded
Material Components 21+ excluded
AndroidX core ≥ 1.15 / most modern Jetpack libs mostly 21+ (a few 19) excluded — none needed for this home screen
kotlin-stdlib API 14+ (verified at runtime on the device; lambdas compile to plain classes by default, no invokedynamic) kept — it's all we depend on

So the dependency list is empty: framework Views + Kotlin stdlib only. That is the cleanest way to stay on KitKat with a 2026 toolchain. (If you later add AndroidX libs, check each one's minSdk in its release notes — AGP fails the build automatically when an AAR declares a higher minimum.)

NixOS specifics

  • nixpkgs ships the whole Android SDK as androidenv.composeAndroidPackages { … }: it fetches official Google packages (sha1-pinned in repo.json), pre-accepts the licenses and writes the license-hash files into the store path, so AGP can use a read-only /nix/store/…/libexec/android-sdk without any interactive prompt. We compose only what we need: platform android-36 + build-tools latest (37.0.0) + platform-tools (adb) + cmdline-tools (sdkmanager), no emulator/cmake/NDK (~150 MB saved). buildToolsVersion is pinned in app/build.gradle.kts to exactly what the SDK provides, since AGP's own default build-tools version isn't installed.
  • The devshell adds JDK 21 + Gradle 8.14 and three helper commands: build-app, install-app, launch-app.

Device findings (explored via adb)

  • Model ntx_6sl ("tolino"), Android 4.4.2 / SDK 19, screen 758×1024 portrait, density 212.
  • Storage: no /storage/emulated/0; the vfat SD card is mounted at /mnt/media_rw/sdcard1 with symlink /sdcard → /storage/sdcard1. Books under /sdcard/Books/<Author>/…epub (Calibre-synced — driveinfo.calibre present).
  • Already installed: org.koreader.launcher (registers as HOME and handles VIEW application/epub+zip — it's the reader hand-off target), de.telekom.epub and org.ds.simple.ink.launcher (the other HOME apps; after installing this one, pressing Home shows the home-app chooser).
  • Minimal shell: no head, which, find; screencap -p returns empty output (capture blocked on e-ink firmware) — visual verification is by eye.

Usage

  1. Press Home on the Tolino → pick "My Books" in the chooser ("Always" to make it default).
  2. The grid lists every .epub/.pdf/.md found up to 4 folders deep (skips Android/, hidden dirs), sorted by title, with real EPUB covers (PDFs and Markdown show a letter placeholder); swipe left/right (or tap a dot) to turn pages of six.
  3. The tab bar above the grid filters the shelf: All / EPUB / PDF / MD. Only one format is shown at a time; the choice survives app restarts.
  4. Tap a book → opens in KoReader via the format's MIME type (application/epub+zip, application/pdf or text/markdown).
  5. Long-press → shows the file path.
  6. Tap the header → forces a rescan (after copying new books to the card).
  7. Swipe up from the bottom edge (over KoReader or any other app) → back here. The Tolino's own home gesture only works inside its bundled reader, so the launcher provides an equivalent via a transparent bottom-edge overlay strip (GestureStripService); see tolino/docs/ for why and how.
  8. Settings → Sleep screen → what the panel shows while the device is asleep: the cover of one chosen book, or automatically the last book opened from My Books (see below).
  9. Book server → Settings → Server & credentials (or long-press the top-bar sync icon): enter a folder URL + Basic-auth credentials and pick how it lists folders — WebDAV (Nextcloud/ownCloud PROPFIND) or plain web server (HTML directory index, e.g. Apache/nginx autoindex). As soon as a URL is set, a Server tab appears left of the shelf tabs on home: browse the remote tree, tap files to select them, long-press folders for their whole contents — a download icon then appears in the top bar (left of the date; tap = download, long-press = clear). Nothing downloads unless picked. The optional Auto-download new books switch (off by default) restores the old bulk behaviour: every missing book is fetched automatically on resume / every 30 min, capped at 20 per run.

Sleep screen (cover on the sleeping panel)

Mirrors the stock de.telekom.epub "sleep screen" feature — reverse-engineered in tolino/docs/tolino-page2-firmware-analysis.md (§5.3 + addendum §11):

  • At suspend, system_server asks ntx.fb.FrameBufferEx.Screen.getDispFile() for an image and it checks 1. the SD card root, 2. /data/data/de.telekom.epub/files/… (the stock app's own symlinks — private, we can't write there), 3. system defaults under /system/usr/sleep/drawable-<locale>-nodpi/. The winner goes to libepd ShowScreen(), which decodes the JPEG straight into the e-ink framebuffer.
  • We therefore install full-screen JPEGs (EPUB cover centred on black; PDF/Markdown get a title card) directly in the SD root. Check 1 runs first, so our image takes precedence over whatever the stock app is configured to show; "Off" removes our files again and the stock behaviour returns.
  • Modes: Last opened book re-renders automatically whenever you open a book from My Books; Choose a book… opens a picker with covers. The install also refreshes at boot (BootReceiver).

Verified paths (logcat Terry-FB at suspend, Sept 2025 firmware)

On this hardware (E60QV0) PMS asks for the _others-suffixed names in the SD root: suspend_others.jpg, suspend_charging_others.jpg, suspend_batteryfull_others.jpg (the plain names are what non-E70Q20 boards use). SleepScreen.SLEEP_FILE_NAMES writes both variants for all three battery states. Re-check with:

adb logcat -c && adb shell input keyevent 26   # sleep… wake again after a few seconds
adb logcat -d | grep Terry-FB                  # prints every candidate path it tried

Build & install (on this NixOS machine)

nix develop                      # enter the devshell (first run builds the SDK, ~a few minutes)
build-app                        # gradle :app:assembleDebug
install-app                      # adb install -r app-debug.apk  (needs device connected + USB debugging)
launch-app                       # adb shell am start -n de.goeranh.ebookhome/.MainActivity

Or one-shot without entering the shell:

nix develop --command build-app
nix develop --command install-app

Layout

flake.nix                     devshell: jdk21, gradle 8.14, composed Android SDK (platform 36 + bt 37), adb
settings.gradle.kts           plugin repos (google/mavenCentral)
build.gradle.kts              AGP 8.13.2 + Kotlin 2.4.20 versions
app/build.gradle.kts          compileSdk 36, minSdk/targetSdk 19, buildToolsVersion 37.0.0
app/src/main/AndroidManifest.xml   HOME intent filter + READ_EXTERNAL_STORAGE (install-time on API 19)
app/src/main/java/de/goeranh/ebookhome/
  MainActivity.kt             swipe-paginated cover grid (2×3) + Server tab (remote browse/pick), background scan
  WebFolder.kt                generic HTTP book-folder client: Basic auth, atomic .part downloads;
                              listing via HTML directory index or WebDAV PROPFIND (a specialisation)
  BookSync.kt                 sync engine: bulk auto-download (off by default) + selected downloads,
                              missing-file selection logic (unit tested), persisted state
  BookScanner.kt              storage roots (symlink-deduped), recursive .epub/.pdf/.md walk (depth ≤ 4)
  EpubParser.kt               container.xml → OPF: dc:title + cover item; ZipFile + XmlPullParser only
  Markdown.kt                 md title: front-matter `title:` or first ATX heading (capped read)
  Book.kt                     data class: file, title, format, cover entry name (+ Format enum with MIME chains)
app/src/main/res/             paper-white Holo layout (210dp uniform cover cells), generated mipmaps
tools/make_icon.py            stdlib-only PNG generator for the launcher icon (host-side)

Design notes / trade-offs

  • Book server is one HTTP client, two listing strategies. The core of WebFolder is plain web-server behaviour — Basic auth on every request and GET downloads streamed to .part files that are renamed into place (an interrupted transfer never leaves a half book on the vfat card). Listing has two modes: HTML directory indexes (the general case — Apache/nginx/ Python all render entries as <a href> links, directories with a trailing slash) and WebDAV PROPFIND (Nextcloud/ownCloud), which is just a structured alternative answer to the same question. Both parsers resolve hrefs through one shared segment-based relativiser, so neither can be talked into pointing at .. or outside the configured root.

  • E-ink first: pure white background, black ink, no shadows/gradients; one full refresh per screen change; FLAG_KEEP_SCREEN_ON behaviour via fullscreen home theme.

  • Memory: covers decoded at display size in RGB_565, cached in a small LRU (16 entries, a few hundred KB each) — fine on this RAM budget with largeHeap.

  • Titles come from dc:title inside each EPUB when present, else the file name with Calibre's " - Author" suffix stripped.

  • Kotlin stdlib on API 19: verified at runtime on the device (logcat clean). If a future Kotlin release ever raised its Android floor, pin org.jetbrains.kotlin.android to an older version in build.gradle.kts — nothing else changes.

  • Bottom-edge swipe-up (over any app): a single transparent overlay window pinned to the bottom edge owns gestures that start there; an upward swipe ≥ 90 px relaunches this launcher on top of whatever was running. It draws nothing and is never re-laid-out, so it costs at most one invisible e-ink partial refresh. SYSTEM_ALERT_WINDOW (auto-granted for our targetSdk-19 app) + a boot receiver keep it alive; the trade-off and tuning knobs are in GestureStripService.kt. Full firmware context: tolino/docs/tolino-page2-firmware-analysis.md.

Security notes

  • Server credentials are stored in plaintext (sync_user/sync_pass in the app's private SharedPreferences under /data/data/de.goeranh.ebookhome/). On this device that file is readable only by our UID and root, and android:allowBackup="false" keeps it out of adb backup. Encrypted storage is not an option on API 19 (AndroidX security-crypto needs minSdk 23). Accepted risk: this is a personal book server whose address sits in the same file — protect USB debugging/root instead, and treat any rooted or OS-upgraded device as exposed.
  • Network input is bounded. Directory-index bodies larger than 1 MB are rejected with a clear error (WebFolder.ResponseTooLarge) instead of being buffered; downloads check the card's free space up front (known sizes) and while streaming (unknown sizes), keeping a 16 MiB reserve so a transfer can never fill the vfat volume. Basic auth over an explicit http:// URL travels in cleartext — fine for a home LAN, the default is https.
  • Untrusted files are parsed defensively. Both listing parsers resolve hrefs through one segment-based relativiser that rejects .. / outside-root entries (unit tested); EPUB zip paths are normalised with .. clamped at the root; cover images (8 MB) and Markdown title scans (64 KB) have hard byte caps. XML parsing uses the framework pull parser, which never fetches external entities.

Troubleshooting

  • "No ebook reader found" → install KoReader/any EPUB app (the launcher hands off by MIME type).
  • Empty grid → check the storage permission was granted at install, and that books are .epub, .pdf or .md (not .sdr — Tolino's encrypted format is intentionally not parsed).
  • AGP complains about build-tools → keep buildToolsVersion in sync with what composeAndroidPackages { buildToolsVersions = [ … ]; } installs.
  • Updating nixpkgs → bump the pinned rev; re-check the "latest" build-tools version and pin it again in app/build.gradle.kts.