fix: silent-restart on exit from KOReader auth and OTA update (#2036)

PR #1908 silent-restarts on exit from any wifi-using activity to defuse
LWIP/mbedTLS heap fragmentation, but two of the wifi-using paths slipped
through that audit:

  KOReaderAuthActivity (Settings -> KOReader sync -> Authenticate)
  OtaUpdateActivity    (Settings -> Check for update, back-out paths)

Both used WiFi.disconnect + WiFi.mode(WIFI_OFF) on exit and returned
control to Settings, leaving ~50KB of contiguous heap stranded for the
rest of the session.

Mirror the FontDownloadActivity pattern: if WiFi was activated,
disconnect and silentRestart. OTA's success path is unchanged:
SHUTTING_DOWN already calls plain ESP.restart() so the new firmware
boots normally; only the cancel/fail/no-update back-out paths now go
through silentRestart().


Did you use AI tools to help write this code? partial
This commit is contained in:
Jeremy Klein
2026-05-18 21:04:11 -04:00
committed by GitHub
parent 06d28d6ffa
commit 151bf1dae4
2 changed files with 16 additions and 10 deletions
@@ -7,6 +7,7 @@
#include "KOReaderCredentialStore.h" #include "KOReaderCredentialStore.h"
#include "KOReaderSyncClient.h" #include "KOReaderSyncClient.h"
#include "MappedInputManager.h" #include "MappedInputManager.h"
#include "SilentRestart.h"
#include "activities/network/WifiSelectionActivity.h" #include "activities/network/WifiSelectionActivity.h"
#include "components/UITheme.h" #include "components/UITheme.h"
#include "fontIds.h" #include "fontIds.h"
@@ -65,11 +66,11 @@ void KOReaderAuthActivity::onEnter() {
void KOReaderAuthActivity::onExit() { void KOReaderAuthActivity::onExit() {
Activity::onExit(); Activity::onExit();
// Turn off wifi if (WiFi.getMode() != WIFI_MODE_NULL) {
WiFi.disconnect(false); WiFi.disconnect(false);
delay(100); delay(30);
WiFi.mode(WIFI_OFF); silentRestart();
delay(100); }
} }
void KOReaderAuthActivity::render(RenderLock&&) { void KOReaderAuthActivity::render(RenderLock&&) {
+10 -5
View File
@@ -5,6 +5,7 @@
#include <WiFi.h> #include <WiFi.h>
#include "MappedInputManager.h" #include "MappedInputManager.h"
#include "SilentRestart.h"
#include "activities/network/WifiSelectionActivity.h" #include "activities/network/WifiSelectionActivity.h"
#include "components/UITheme.h" #include "components/UITheme.h"
#include "fontIds.h" #include "fontIds.h"
@@ -66,11 +67,15 @@ void OtaUpdateActivity::onEnter() {
void OtaUpdateActivity::onExit() { void OtaUpdateActivity::onExit() {
Activity::onExit(); Activity::onExit();
// Turn off wifi // Success path reboots via the SHUTTING_DOWN state's plain ESP.restart()
WiFi.disconnect(false); // false = don't erase credentials, send disconnect frame // (loop() above) so the new firmware boots normally. Back-out paths land
delay(100); // Allow disconnect frame to be sent // here with wifi still active; silent-restart to free the LWIP/mbedTLS
WiFi.mode(WIFI_OFF); // fragmentation, same as the other wifi activities.
delay(100); // Allow WiFi hardware to fully power down if (WiFi.getMode() != WIFI_MODE_NULL) {
WiFi.disconnect(false);
delay(30);
silentRestart();
}
} }
void OtaUpdateActivity::render(RenderLock&&) { void OtaUpdateActivity::render(RenderLock&&) {