Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ object UpdateFlow {
return r >= w
}

fun doneLine(app: String) = "Updated to v$app (KOReader loaded it)"
fun doneLine(app: String) = "v$app · Updated · KOReader restarted"

/**
* The patch is installed. [now]: the user started the update, KOReader restarts at once;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ object PatchInstaller {
val running = p.patchVersionSeen.ifEmpty { null }
// The app replace was confirmed by the user (UpdateFlow.restartNowAfter): a manual restart.
if (file != null && running != null && UpdateFlow.staleRestart(running, file, manual = true, screenOff = false, sent = emptySet()) == UpdateFlow.Restart.NOW) {
// A user-confirmed update completes in KOReader, including one started on our pages.
// Restart now; UpdateReturn restores the origin once the new plugin loads.
val now = UpdateReturn.restartNow(userConfirmed = true, fromPage = UpdateReturn.fromPage())
log("after the update: patch v$file on disk, KOReader runs v$running: ${if (now) "restarting now" else "waiting for a safe start"}")
p.patchAwaitVersion = file
Expand Down Expand Up @@ -195,7 +195,7 @@ object PatchInstaller {
}
UpdateFlow.Restart.NOW -> {
// Automatic updates wait behind a companion page, even at screen-off.
// A manual update brings KOReader forward to complete the install.
// A manual update restarts now; app updates return to their origin when loaded.
if (!manual && (EinkActivity.pageResumed() || UpdateReturn.awaitingLanding())) {
if (waitLogged != "page:$want") {
waitLogged = "page:$want"
Expand Down Expand Up @@ -260,6 +260,7 @@ object PatchInstaller {
p.patchRestartNow = ""
log("KOReader runs patch v$running now")
Updater.status(ctx, UpdateFlow.doneLine(want))
UpdateReturn.onPluginLoaded(ctx)
}

/** This version's release: tagged v<v> (android-v<v> is read too, AGENTS.md "Releases"). */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import android.os.SystemClock
* and Back from it fell out to KOReader). It lands once: after the reopened page has shown, a
* Home press is an ordinary Home press ([forHome]).
*
* The pages reopen to show installation progress. A user-confirmed update then finishes in
* KOReader with the new plugin loaded ([restartNow]), including updates started on our pages.
* The pages reopen to show installation progress. Android starts KOReader activities in the
* foreground for both halves of its restart. Once the new plugin reports that it loaded,
* [onPluginLoaded] brings this same task back, preserving the update origin through that restart.
* Kept in its own preferences file: the mark must outlive the process that wrote it.
*/
object UpdateReturn {
Expand All @@ -31,6 +32,8 @@ object UpdateReturn {
private const val FILE = "update_return"
private const val KEY_FROM = "from"
private const val KEY_AT = "at"
private const val KEY_FINISH_PAGES = "finish_pages"
private const val KEY_FINISH_AT = "finish_at"

/** The mark for an update started on [top]: its back stack, one intent URI per line. */
fun encode(top: Activity): String = encode(EinkActivity.returnStack(top))
Expand Down Expand Up @@ -109,11 +112,30 @@ object UpdateReturn {
}
sp.edit().clear().apply()
if (replaced.isEmpty()) return null
// Keep the final return durable too: the companion process may die during the restart.
sp.edit().putString(KEY_FINISH_PAGES, encode(replaced))
.putLong(KEY_FINISH_AT, System.currentTimeMillis()).apply()
reopenedAt = SystemClock.elapsedRealtime()
open(ctx, replaced, "after the update")
return top()
}

/** The replacement plugin is running: finish on the originating page, once per update. */
@Synchronized
fun onPluginLoaded(ctx: Context) {
val sp = prefs(ctx)
val pages = pages(sp.getString(KEY_FINISH_PAGES, null), sp.getLong(KEY_FINISH_AT, 0),
System.currentTimeMillis(), ctx.packageName)
sp.edit().remove(KEY_FINISH_PAGES).remove(KEY_FINISH_AT).apply()
if (pages.isEmpty()) return
// Reuse the restored stack; only reconstruct it if Android removed its task.
if (bringToFront(ctx, pages)) {
OLog.i("update: back to ${describe(pages)} (KOReader restarted)")
} else {
open(ctx, pages, "KOReader restarted")
}
}

private fun top(): String? = replaced.lastOrNull()?.component?.className

/** The update was started from one of our pages (after [onReplaced] ran in this process). */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,7 @@ class UpdateFlowTest {
assertFalse(UpdateFlow.loaded("0.5.1", null))
assertTrue(UpdateFlow.loaded("0.5.1", "0.5.1"))
assertTrue(UpdateFlow.loaded("0.5.1", "0.5.2"))
assertEquals("Updated to v0.5.1 (KOReader loaded it)", UpdateFlow.doneLine("0.5.1"))
assertEquals("v0.5.1 · Updated · KOReader restarted", UpdateFlow.doneLine("0.5.1"))
assertTrue(UpdateFlow.manualLine("0.5.1", "storage access isn't allowed").endsWith("storage access isn't allowed. Setup > BookSync plugin"))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import org.robolectric.annotation.Config
/**
* M8C 11-23 22:47: Update tapped on the Status page, and after the replace the user was in
* KOReader (the patch install's COMMAND=restart brought it to the front). An update started
* from one of our pages restores its progress page, then completes the plugin update in KOReader.
* from one of our pages restores that page after both halves of the plugin restart.
*/
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [34])
Expand Down Expand Up @@ -219,6 +219,88 @@ class UpdateReturnTest {
}
}

@Test
fun companionUpdateReturnsToItsSettingsStackAfterTheNewPluginLoads() {
Robolectric.buildActivity(LauncherActivity::class.java).create()
Robolectric.buildActivity(SettingsActivity::class.java).create()
val section = Robolectric.buildActivity(SettingsSectionActivity::class.java,
SettingsPage.section(app, "updates")).create().get()
install(section)
Updater.onReplaced(app)
val stack = drain().filter { it.component?.packageName == app.packageName }
restartAndLoadPlugin(fromCompanion = true)
val returned = drain()
assertEquals(stack.map { it.component }, returned.map { it.component })
assertEquals("updates", returned.last().getStringExtra(SettingsPage.EXTRA_SECTION))
assertEquals(SettingsPage.UPDATE_ROW, returned.last().getStringExtra(SettingsPage.EXTRA_FOCUS))
assertEquals("v0.11.4-preview.3 · Updated · KOReader restarted", Prefs(app).updateStatus)
PatchInstaller.onPatchSeen(app, "0.11.4-preview.3")
UpdateReturn.onPluginLoaded(app)
assertTrue("completion returns only once", drain().isEmpty())
}

@Test
fun completedRestartBringsTheExistingCompanionTaskForwardWithoutDuplicatingPages() {
val section = Robolectric.buildActivity(SettingsSectionActivity::class.java,
SettingsPage.section(app, "updates")).create().get()
install(section)
Updater.onReplaced(app)
val top = drain().last()
val task = org.robolectric.shadows.ShadowAppTask.newInstance()
shadowOf(task).setTaskInfo(android.app.ActivityManager.RecentTaskInfo().apply {
topActivity = top.component
})
shadowOf(app.getSystemService(android.app.ActivityManager::class.java)).setAppTasks(listOf(task))
restartAndLoadPlugin(fromCompanion = true)
assertTrue("the original task returns with its existing back stack", shadowOf(task).hasMovedToFront())
assertTrue("no second stack is started", drain().isEmpty())
}

@Test
fun koreaderUpdateFinishesInKoreaderAndReopensItsBook() {
install(app) // KOReader opens the installer without a companion page origin.
Updater.onReplaced(app)
drain()
restartAndLoadPlugin(fromCompanion = false)
assertTrue("no companion page covers the reopened book", drain().isEmpty())
assertEquals("v0.11.4-preview.3 · Updated · KOReader restarted", Prefs(app).updateStatus)
}

/** Both activity starts must finish before the new plugin's version can complete the return. */
private fun restartAndLoadPlugin(fromCompanion: Boolean) {
val p = Prefs(app)
p.patchVersionSeen = "0.11.4-preview.2"
p.patchAwaitVersion = "0.11.4-preview.3"
p.patchRestartNow = p.patchAwaitVersion
p.patchRestartSentFor = ""
p.koreaderBook = "1"
val trusted = KoreaderTrust.signersOf
KoreaderTrust.signersOf = { _, _ -> setOf("AA:01") }
try {
assertTrue(PatchInstaller.follow(app, "app update"))
assertEquals(HomeCommands.RESTART, drain().single().getStringExtra(Contract.EXTRA_COMMAND))
assertEquals("1", p.restartReopen)
assertTrue(p.restartUserStarted)
PatchInstaller.onPatchSeen(app, "0.11.4-preview.2")
assertTrue("the old plugin cannot complete the return", drain().isEmpty())
Koreader.restartRead()
assertTrue(Koreader.relaunch(app, "restart after patch update",
UpdateFlow.relaunchCommand(p.restartReopen == "1"), plugin = p.patchAwaitVersion,
fromCompanion = fromCompanion, userStarted = p.restartUserStarted))
assertEquals(HomeCommands.REOPEN_BOOK, drain().single().getStringExtra(Contract.EXTRA_COMMAND))
PatchInstaller.onPatchSeen(app, "0.11.4-preview.3")
} finally {
KoreaderTrust.signersOf = trusted
Koreader.restartRead()
p.patchVersionSeen = ""
p.patchAwaitVersion = ""
p.patchRestartNow = ""
p.patchRestartSentFor = ""
p.restartUserStarted = false
p.restartReopen = ""
}
}

@Test
fun delayedRelaunchCannotCoverACompanionPageEvenAtScreenOff() {
val page = Robolectric.buildActivity(SettingsSectionActivity::class.java, SettingsPage.section(app, "sleep")).setup()
Expand Down
2 changes: 1 addition & 1 deletion docs/FEATURES.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Counts include settings exposure as separate rows; they are not feature quality
| Verify public BookOrbit TLS certificate before sending credentials | ✅ (v0.11.3-rc.17) Android platform TLS. [android/companion/app/src/main/java/net/fledgewing/orbitcompanion/Worker.kt:17](../android/companion/app/src/main/java/net/fledgewing/orbitcompanion/Worker.kt#L17) | ✅ (xteink-v2.0.0.373+bookorbit.1-rc3) Public hosts verified or fingerprint trusted; tailnet exempt. [xteink/orbify/ServerTrustNet.cpp:17](../xteink/orbify/ServerTrustNet.cpp#L17), [xteink/tailnet/tailnet_build.py:310](../xteink/tailnet/tailnet_build.py#L310) | ✅ (xteink-v2.0.0.373+bookorbit.1-rc3) Public hosts verified or fingerprint trusted; tailnet exempt. [xteink/orbify/ServerTrustNet.cpp:17](../xteink/orbify/ServerTrustNet.cpp#L17), [xteink/tailnet/tailnet_build.py:310](../xteink/tailnet/tailnet_build.py#L310) | ❌ Server trust verifier disabled; **hardware: historical ~9.6 KB cost; gate was tighter when disabled; remeasure with current headroom**. [xteink/tailnet/tailnet_build.py:310](../xteink/tailnet/tailnet_build.py#L310) |
| Self-update with artifact SHA-256 checks | ✅ (v0.11.3-rc.17) APK/plugin updater. [android/koreader/orbit.koplugin/ko/updater.lua:17](../android/koreader/orbit.koplugin/ko/updater.lua#L17), [android/companion/app/src/main/java/net/fledgewing/orbitcompanion/Installers.kt:25](../android/companion/app/src/main/java/net/fledgewing/orbitcompanion/Installers.kt#L25) | ✅ (xteink-v2.0.0.373+bookorbit.1-rc3) Firmware OTA and hash/signature hook. [xteink/overlay/patches/v2.0/0050-orbify-signed-ota.patch:12](../xteink/overlay/patches/v2.0/0050-orbify-signed-ota.patch#L12) | ✅ (xteink-v2.0.0.373+bookorbit.1-rc3) Firmware OTA and hash/signature hook. [xteink/overlay/patches/v2.0/0050-orbify-signed-ota.patch:12](../xteink/overlay/patches/v2.0/0050-orbify-signed-ota.patch#L12) | ✅ (xteink-v2.0.0.373+bookorbit.1-rc3) Firmware OTA and hash/signature hook. [xteink/overlay/patches/v2.0/0050-orbify-signed-ota.patch:12](../xteink/overlay/patches/v2.0/0050-orbify-signed-ota.patch#L12) |
| Root-certified release signatures enforced | 🟡 Verifier exists; enforcement off; **deliberately deferred: ROADMAP Next 16**. [shared/release-signing.json:4](../shared/release-signing.json#L4), [android/companion/app/src/main/java/net/fledgewing/orbitcompanion/ReleaseSignature.kt:144](../android/companion/app/src/main/java/net/fledgewing/orbitcompanion/ReleaseSignature.kt#L144) | 🟡 Verifier exists; enforcement off; **deliberately deferred: ROADMAP Next 16**. [shared/release-signing.json:4](../shared/release-signing.json#L4), [xteink/tailnet/tailnet_build.py:574](../xteink/tailnet/tailnet_build.py#L574) | 🟡 Verifier exists; enforcement off; **deliberately deferred: ROADMAP Next 16**. [shared/release-signing.json:4](../shared/release-signing.json#L4), [xteink/tailnet/tailnet_build.py:574](../xteink/tailnet/tailnet_build.py#L574) | 🟡 Verifier exists; enforcement off; **deliberately deferred: ROADMAP Next 16**. [shared/release-signing.json:4](../shared/release-signing.json#L4), [xteink/tailnet/tailnet_build.py:574](../xteink/tailnet/tailnet_build.py#L574) |
| Return after update; restore prior reading context | ✅ (v0.11.3-rc.17) User-started updates finish in KOReader with book/Home restored; restart deliveries are acknowledged once. [android/koreader/orbit.koplugin/ko/updater.lua:17](../android/koreader/orbit.koplugin/ko/updater.lua#L17) | ✅ (xteink-v2.0.0.373+bookorbit.1-rc3) OTA screen return marker; Android companion restart acknowledgements do not apply to standalone firmware. [xteink/orbify/OtaReturn.cpp:6](../xteink/orbify/OtaReturn.cpp#L6), [xteink/overlay/patches/v2.0/0043-orbify-ota-return.patch:8](../xteink/overlay/patches/v2.0/0043-orbify-ota-return.patch#L8) | ✅ (xteink-v2.0.0.373+bookorbit.1-rc3) OTA screen return marker; Android companion restart acknowledgements do not apply to standalone firmware. [xteink/orbify/OtaReturn.cpp:6](../xteink/orbify/OtaReturn.cpp#L6), [xteink/overlay/patches/v2.0/0043-orbify-ota-return.patch:8](../xteink/overlay/patches/v2.0/0043-orbify-ota-return.patch#L8) | ✅ (xteink-v2.0.0.373+bookorbit.1-rc3) OTA screen return marker; Android companion restart acknowledgements do not apply to standalone firmware. [xteink/orbify/OtaReturn.cpp:6](../xteink/orbify/OtaReturn.cpp#L6), [xteink/overlay/patches/v2.0/0043-orbify-ota-return.patch:8](../xteink/overlay/patches/v2.0/0043-orbify-ota-return.patch#L8) |
| Return after update; restore prior reading context | ✅ (v0.11.3-rc.17) Companion-started updates return to their screen and back stack after KOReader restarts; KOReader-started updates restore book/Home; restart deliveries are acknowledged once. [android/companion/app/src/main/java/net/fledgewing/orbitcompanion/UpdateReturn.kt:124](../android/companion/app/src/main/java/net/fledgewing/orbitcompanion/UpdateReturn.kt#L124) | ✅ (xteink-v2.0.0.373+bookorbit.1-rc3) OTA screen return marker; standalone firmware has no Android companion task to restore. [xteink/orbify/OtaReturn.cpp:6](../xteink/orbify/OtaReturn.cpp#L6), [xteink/overlay/patches/v2.0/0043-orbify-ota-return.patch:8](../xteink/overlay/patches/v2.0/0043-orbify-ota-return.patch#L8) | ✅ (xteink-v2.0.0.373+bookorbit.1-rc3) OTA screen return marker; standalone firmware has no Android companion task to restore. [xteink/orbify/OtaReturn.cpp:6](../xteink/orbify/OtaReturn.cpp#L6), [xteink/overlay/patches/v2.0/0043-orbify-ota-return.patch:8](../xteink/overlay/patches/v2.0/0043-orbify-ota-return.patch#L8) | ✅ (xteink-v2.0.0.373+bookorbit.1-rc3) OTA screen return marker; standalone firmware has no Android companion task to restore. [xteink/orbify/OtaReturn.cpp:6](../xteink/orbify/OtaReturn.cpp#L6), [xteink/overlay/patches/v2.0/0043-orbify-ota-return.patch:8](../xteink/overlay/patches/v2.0/0043-orbify-ota-return.patch#L8) |
| Settings grouped by purpose; searchable shared settings UI | ✅ (v0.11.3-rc.17) Eight sections with search. [android/companion/app/src/main/java/net/fledgewing/orbitcompanion/SettingsPages.kt:219](../android/companion/app/src/main/java/net/fledgewing/orbitcompanion/SettingsPages.kt#L219) | 🟡 Native categories and web settings; no shared-schema search UI; **gap — no reason**. [xteink/orbify/Settings.cpp:12](../xteink/orbify/Settings.cpp#L12), [xteink/orbify/SleepSettings.cpp:16](../xteink/orbify/SleepSettings.cpp#L16) | 🟡 Native categories and web settings; no shared-schema search UI; **gap — no reason**. [xteink/orbify/Settings.cpp:12](../xteink/orbify/Settings.cpp#L12), [xteink/orbify/SleepSettings.cpp:16](../xteink/orbify/SleepSettings.cpp#L16) | 🟡 Native categories and web settings; no shared-schema search UI; **gap — no reason**. [xteink/orbify/Settings.cpp:12](../xteink/orbify/Settings.cpp#L12), [xteink/orbify/SleepSettings.cpp:16](../xteink/orbify/SleepSettings.cpp#L16) |
| Settings PIN; public About remains available | ✅ (v0.11.3-rc.17) PIN helper and public About. [android/companion/app/src/main/java/net/fledgewing/orbitcompanion/PinLogic.kt:13](../android/companion/app/src/main/java/net/fledgewing/orbitcompanion/PinLogic.kt#L13), [android/companion/app/src/main/java/net/fledgewing/orbitcompanion/AboutActivity.kt:9](../android/companion/app/src/main/java/net/fledgewing/orbitcompanion/AboutActivity.kt#L9) | ✅ (xteink-v2.0.0.373+bookorbit.1-rc3) PIN and lock activity. [xteink/orbify/SettingsPin.cpp:26](../xteink/orbify/SettingsPin.cpp#L26) | ✅ (xteink-v2.0.0.373+bookorbit.1-rc3) PIN and lock activity. [xteink/orbify/SettingsPin.cpp:26](../xteink/orbify/SettingsPin.cpp#L26) | ✅ (xteink-v2.0.0.373+bookorbit.1-rc3) PIN and lock activity. [xteink/orbify/SettingsPin.cpp:26](../xteink/orbify/SettingsPin.cpp#L26) |
| Pair and use a wireless remote page-turn clicker | ✅ (v0.11.3-rc.17) Accessibility clicker service and key mappings. [android/companion/app/src/main/java/net/fledgewing/orbitcompanion/ClickerService.kt:19](../android/companion/app/src/main/java/net/fledgewing/orbitcompanion/ClickerService.kt#L19) | ➖ Bluetooth disabled in firmware; no enabled remote-clicker path; **not applicable: Maintainer ruling 2026-11-25: the device is so small a Bluetooth remote is often bigger than it; not planned.**. [platformio.ini:186](https://github.com/agosez/CrossInk-Bookorbit/blob/87e2e1984481e8a3d996f12b34b50a383f9013b8/platformio.ini#L186), [libs/hardware/BoardConfig/include/BoardConfig.h:307](https://github.com/Free-Ink/freeink-sdk/blob/9d5bba3ef02a1c35363ecadbb50ad0e1ac279653/libs/hardware/BoardConfig/include/BoardConfig.h#L307) | ➖ Bluetooth disabled in firmware; no enabled remote-clicker path; **not applicable: Maintainer ruling 2026-11-25: the device is so small a Bluetooth remote is often bigger than it; not planned.**. [platformio.ini:186](https://github.com/agosez/CrossInk-Bookorbit/blob/87e2e1984481e8a3d996f12b34b50a383f9013b8/platformio.ini#L186), [libs/hardware/BoardConfig/include/BoardConfig.h:307](https://github.com/Free-Ink/freeink-sdk/blob/9d5bba3ef02a1c35363ecadbb50ad0e1ac279653/libs/hardware/BoardConfig/include/BoardConfig.h#L307) | ➖ Bluetooth disabled in firmware; no enabled remote-clicker path; **not applicable: Maintainer ruling 2026-11-25: the device is so small a Bluetooth remote is often bigger than it; not planned.**. [platformio.ini:186](https://github.com/agosez/CrossInk-Bookorbit/blob/87e2e1984481e8a3d996f12b34b50a383f9013b8/platformio.ini#L186), [libs/hardware/BoardConfig/include/BoardConfig.h:307](https://github.com/Free-Ink/freeink-sdk/blob/9d5bba3ef02a1c35363ecadbb50ad0e1ac279653/libs/hardware/BoardConfig/include/BoardConfig.h#L307) |
Expand Down
Loading
Loading