From 96ed46afd13849aa873ae3887bd51ca33a03c94e Mon Sep 17 00:00:00 2001 From: diffwireauto <330573775+diffwireauto@users.noreply.github.com> Date: Sat, 7 Nov 2026 22:39:01 -0500 Subject: [PATCH] fix(#1118): factory reset deletes the app data on send, no reconnect check Owner decision 2026-11-07: drop the wait. With the box ticked, the radio's app data is deleted as soon as the reset is sent and the link is closed, the same way Reboot just reboots. The pending record, the key check on the next connect, and its complete / kept / did-not-happen messages are gone. A failed delete still shows a banner that stays until dismissed. Co-Authored-By: Claude Opus 5.5 --- lib/connector/meshcore_connector.dart | 98 ++---------------- lib/l10n/app_en.arb | 13 +-- lib/l10n/app_localizations.dart | 38 +------ lib/l10n/app_localizations_bg.dart | 26 +---- lib/l10n/app_localizations_de.dart | 26 +---- lib/l10n/app_localizations_en.dart | 26 +---- lib/l10n/app_localizations_es.dart | 26 +---- lib/l10n/app_localizations_fr.dart | 26 +---- lib/l10n/app_localizations_hu.dart | 26 +---- lib/l10n/app_localizations_it.dart | 26 +---- lib/l10n/app_localizations_ja.dart | 26 +---- lib/l10n/app_localizations_ko.dart | 26 +---- lib/l10n/app_localizations_nl.dart | 26 +---- lib/l10n/app_localizations_pl.dart | 26 +---- lib/l10n/app_localizations_pt.dart | 26 +---- lib/l10n/app_localizations_ru.dart | 26 +---- lib/l10n/app_localizations_sk.dart | 26 +---- lib/l10n/app_localizations_sl.dart | 26 +---- lib/l10n/app_localizations_sv.dart | 26 +---- lib/l10n/app_localizations_uk.dart | 26 +---- lib/l10n/app_localizations_zh.dart | 26 +---- lib/storage/factory_reset_store.dart | 100 ------------------ lib/storage/scoping_inventory.dart | 9 -- lib/widgets/factory_reset_banner.dart | 24 +---- test/connector/factory_reset_test.dart | 138 ++++++------------------- test/storage/radio_data_wipe_test.dart | 68 +----------- untranslated.json | 85 --------------- 27 files changed, 129 insertions(+), 912 deletions(-) delete mode 100644 lib/storage/factory_reset_store.dart diff --git a/lib/connector/meshcore_connector.dart b/lib/connector/meshcore_connector.dart index 6904ad4e..2d24766c 100644 --- a/lib/connector/meshcore_connector.dart +++ b/lib/connector/meshcore_connector.dart @@ -56,7 +56,6 @@ import '../storage/client_id_store.dart'; import '../storage/contact_discovery_store.dart'; import '../storage/contact_settings_store.dart'; import '../storage/contact_store.dart'; -import '../storage/factory_reset_store.dart'; import '../storage/message_store.dart'; import '../storage/radio_data_wipe.dart'; import '../storage/unread_store.dart'; @@ -308,16 +307,7 @@ enum FactoryResetStatus { sentBle, sent, - /// The radio came back with a new identity and its app data was deleted. - complete, - - /// New identity; the user chose to keep the app data. - completeKept, - - /// Same identity on reconnect: the radio was not wiped. Nothing deleted. - notReset, - - /// New identity, but deleting the old app data failed. Retried next connect. + /// Sent, but deleting the radio's app data failed. deleteFailed, } @@ -6880,7 +6870,6 @@ class MeshCoreConnector extends ChangeNotifier { await sendFrame(buildRebootFrame()); } - final FactoryResetStore _factoryResetStore = FactoryResetStore(); FactoryResetStatus? _factoryResetStatus; FactoryResetStatus? get factoryResetStatus => _factoryResetStatus; @@ -6889,19 +6878,6 @@ class MeshCoreConnector extends ChangeNotifier { notifyListeners(); } - @visibleForTesting - String? transportIdentityForTest; - - /// Which physical device the link goes to, independent of its identity, - /// which a factory reset replaces. - String? get _transportIdentity => - transportIdentityForTest ?? - switch (_activeTransport) { - MeshCoreTransportType.bluetooth => _deviceId, - MeshCoreTransportType.usb => activeUsbPort, - MeshCoreTransportType.tcp => activeTcpEndpoint, - }; - String? get _radioPrefix { final hex = selfPublicKeyHex; return hex.length >= 10 ? hex.substring(0, 10) : null; @@ -6909,30 +6885,19 @@ class MeshCoreConnector extends ChangeNotifier { /// Wipes the connected radio (#1054). Null when sent, else why not. /// - /// The app data is NOT deleted here. The radio drops the link before it - /// formats, so nothing proves the wipe until it reconnects with a new - /// identity; see [_resolvePendingFactoryReset]. The session is ended on - /// purpose so it does not auto-reconnect into a wiped radio. + /// With [deleteAppData], the radio's app data is deleted once the link is + /// closed, so nothing from this session writes it back. Future factoryResetDevice({ required bool deleteAppData, }) async { - final deviceId = _transportIdentity; final prefix = _radioPrefix; - if (!isConnected || deviceId == null || prefix == null) { + if (!isConnected || prefix == null) { return FactoryResetRefusal.notConnected; } - await _factoryResetStore.save( - PendingFactoryReset( - deviceId: deviceId, - radioPrefix: prefix, - deleteAppData: deleteAppData, - ), - ); final overBle = _activeTransport == MeshCoreTransportType.bluetooth; _appDebugLogService?.info( - 'Factory reset sent device=$deviceId radio=$prefix ' - 'deleteAppData=$deleteAppData', + 'Factory reset sent radio=$prefix deleteAppData=$deleteAppData', tag: 'Connection', ); await sendFrame(buildFactoryResetFrame()); @@ -6943,64 +6908,27 @@ class MeshCoreConnector extends ChangeNotifier { // Give the frame time to leave before the transport closes. await Future.delayed(const Duration(milliseconds: 500)); await disconnect(); - return null; - } - - /// Settles a pending factory reset on the first SELF_INFO of a connect. - /// - /// Only a connect to the same device decides anything. Same identity means - /// the wipe did not happen and every byte of app data stays. A failed delete - /// keeps the record, so the next connect tries again. - Future _resolvePendingFactoryReset() async { - final pending = _factoryResetStore.load(); - final deviceId = _transportIdentity; - final prefix = _radioPrefix; - if (pending == null || deviceId == null || prefix == null) return; - final outcome = resolveFactoryReset( - pending, - deviceId: deviceId, - radioPrefix: prefix, - ); - if (outcome == null) return; - if (outcome == FactoryResetOutcome.wipeAppData) { + if (deleteAppData) { try { - final removed = await wipeRadioData(pending.radioPrefix); - await _appSettingsService?.forgetRadio(pending.radioPrefix); + final removed = await wipeRadioData(prefix); + await _appSettingsService?.forgetRadio(prefix); _appDebugLogService?.info( - 'Factory reset confirmed, removed $removed stored items for ' - '${pending.radioPrefix}', + 'Factory reset removed $removed stored items for $prefix', tag: 'Connection', ); } catch (e) { _appDebugLogService?.error( - 'Factory reset confirmed but deleting ${pending.radioPrefix} ' - 'failed, will retry next connect: $e', + 'Factory reset: deleting app data for $prefix failed: $e', tag: 'Connection', ); _factoryResetStatus = FactoryResetStatus.deleteFailed; notifyListeners(); - return; } } - - await _factoryResetStore.clear(); - _factoryResetStatus = switch (outcome) { - FactoryResetOutcome.wipeAppData => FactoryResetStatus.complete, - FactoryResetOutcome.keepAppData => FactoryResetStatus.completeKept, - FactoryResetOutcome.notReset => FactoryResetStatus.notReset, - }; - _appDebugLogService?.info( - 'Factory reset resolved: $outcome', - tag: 'Connection', - ); - notifyListeners(); + return null; } - @visibleForTesting - Future resolvePendingFactoryResetForTest() => - _resolvePendingFactoryReset(); - Future setPrivacyMode(bool enabled) async { await sendCliCommand('set privacy ${enabled ? 'on' : 'off'}'); } @@ -9056,10 +8984,6 @@ class MeshCoreConnector extends ChangeNotifier { // another radio's data. storageService?.setPublicKeyHex = selfPublicKeyHex; - // A factory reset is proven or disproven here, by the identity this - // device now reports (#1054). - unawaited(_resolvePendingFactoryReset()); - // Now that we have self info, we can load all the persisted data for this // node. Each step is timed: this sequence has stalled the UI isolate for // ~40s on a large store, and the timings say which step is responsible. diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index cb528347..ee39732b 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -439,15 +439,10 @@ "settings_factoryResetDeleteAppData": "Also delete this radio's data stored in the app", "settings_factoryResetNotConnected": "Factory reset not sent: no radio is connected.", "factoryResetSentTitle": "Factory reset sent", - "factoryResetSentBody": "The radio is erasing itself and will restart with a new identity. Reconnect to it to finish.", - "factoryResetSentBleBody": "The radio is erasing itself and will restart with a new identity. Its Bluetooth pairing is erased too: remove the old pairing for this radio in your phone or computer's Bluetooth settings, then reconnect to finish.", - "factoryResetCompleteTitle": "Factory reset complete", - "factoryResetCompleteBody": "The radio has a new identity. Its old data was deleted from the app.", - "factoryResetCompleteKeptBody": "The radio has a new identity. Its old data was kept in the app.", - "factoryResetNotResetTitle": "Factory reset did not happen", - "factoryResetNotResetBody": "The radio reconnected with the same identity, so it was not erased. Nothing was deleted from the app.", - "factoryResetDeleteFailedTitle": "Factory reset done, app cleanup failed", - "factoryResetDeleteFailedBody": "The radio was erased, but deleting its old data from the app failed. The app will try again the next time this radio connects.", + "factoryResetSentBody": "The radio is erasing itself and will restart with a new identity.", + "factoryResetSentBleBody": "The radio is erasing itself and will restart with a new identity. Its Bluetooth pairing is erased too: remove the old pairing for this radio in your phone or computer's Bluetooth settings, then reconnect.", + "factoryResetDeleteFailedTitle": "Factory reset sent, app cleanup failed", + "factoryResetDeleteFailedBody": "The reset was sent, but deleting this radio's data from the app failed.", "settings_blePin": "BLE pairing PIN", "settings_blePinDefault": "Firmware default", "settings_blePinHelp": "6 digits (100000-999999). New phones and PCs must enter it when pairing. Reset to default to return to the firmware's built-in behavior.", diff --git a/lib/l10n/app_localizations.dart b/lib/l10n/app_localizations.dart index 381ddb78..c3e399ee 100644 --- a/lib/l10n/app_localizations.dart +++ b/lib/l10n/app_localizations.dart @@ -1525,55 +1525,25 @@ abstract class AppLocalizations { /// No description provided for @factoryResetSentBody. /// /// In en, this message translates to: - /// **'The radio is erasing itself and will restart with a new identity. Reconnect to it to finish.'** + /// **'The radio is erasing itself and will restart with a new identity.'** String get factoryResetSentBody; /// No description provided for @factoryResetSentBleBody. /// /// In en, this message translates to: - /// **'The radio is erasing itself and will restart with a new identity. Its Bluetooth pairing is erased too: remove the old pairing for this radio in your phone or computer\'s Bluetooth settings, then reconnect to finish.'** + /// **'The radio is erasing itself and will restart with a new identity. Its Bluetooth pairing is erased too: remove the old pairing for this radio in your phone or computer\'s Bluetooth settings, then reconnect.'** String get factoryResetSentBleBody; - /// No description provided for @factoryResetCompleteTitle. - /// - /// In en, this message translates to: - /// **'Factory reset complete'** - String get factoryResetCompleteTitle; - - /// No description provided for @factoryResetCompleteBody. - /// - /// In en, this message translates to: - /// **'The radio has a new identity. Its old data was deleted from the app.'** - String get factoryResetCompleteBody; - - /// No description provided for @factoryResetCompleteKeptBody. - /// - /// In en, this message translates to: - /// **'The radio has a new identity. Its old data was kept in the app.'** - String get factoryResetCompleteKeptBody; - - /// No description provided for @factoryResetNotResetTitle. - /// - /// In en, this message translates to: - /// **'Factory reset did not happen'** - String get factoryResetNotResetTitle; - - /// No description provided for @factoryResetNotResetBody. - /// - /// In en, this message translates to: - /// **'The radio reconnected with the same identity, so it was not erased. Nothing was deleted from the app.'** - String get factoryResetNotResetBody; - /// No description provided for @factoryResetDeleteFailedTitle. /// /// In en, this message translates to: - /// **'Factory reset done, app cleanup failed'** + /// **'Factory reset sent, app cleanup failed'** String get factoryResetDeleteFailedTitle; /// No description provided for @factoryResetDeleteFailedBody. /// /// In en, this message translates to: - /// **'The radio was erased, but deleting its old data from the app failed. The app will try again the next time this radio connects.'** + /// **'The reset was sent, but deleting this radio\'s data from the app failed.'** String get factoryResetDeleteFailedBody; /// No description provided for @settings_blePin. diff --git a/lib/l10n/app_localizations_bg.dart b/lib/l10n/app_localizations_bg.dart index de9ee51a..42534f96 100644 --- a/lib/l10n/app_localizations_bg.dart +++ b/lib/l10n/app_localizations_bg.dart @@ -833,37 +833,19 @@ class AppLocalizationsBg extends AppLocalizations { @override String get factoryResetSentBody => - 'The radio is erasing itself and will restart with a new identity. Reconnect to it to finish.'; + 'The radio is erasing itself and will restart with a new identity.'; @override String get factoryResetSentBleBody => - 'The radio is erasing itself and will restart with a new identity. Its Bluetooth pairing is erased too: remove the old pairing for this radio in your phone or computer\'s Bluetooth settings, then reconnect to finish.'; - - @override - String get factoryResetCompleteTitle => 'Factory reset complete'; - - @override - String get factoryResetCompleteBody => - 'The radio has a new identity. Its old data was deleted from the app.'; - - @override - String get factoryResetCompleteKeptBody => - 'The radio has a new identity. Its old data was kept in the app.'; - - @override - String get factoryResetNotResetTitle => 'Factory reset did not happen'; - - @override - String get factoryResetNotResetBody => - 'The radio reconnected with the same identity, so it was not erased. Nothing was deleted from the app.'; + 'The radio is erasing itself and will restart with a new identity. Its Bluetooth pairing is erased too: remove the old pairing for this radio in your phone or computer\'s Bluetooth settings, then reconnect.'; @override String get factoryResetDeleteFailedTitle => - 'Factory reset done, app cleanup failed'; + 'Factory reset sent, app cleanup failed'; @override String get factoryResetDeleteFailedBody => - 'The radio was erased, but deleting its old data from the app failed. The app will try again the next time this radio connects.'; + 'The reset was sent, but deleting this radio\'s data from the app failed.'; @override String get settings_blePin => 'BLE pairing PIN'; diff --git a/lib/l10n/app_localizations_de.dart b/lib/l10n/app_localizations_de.dart index 7116eebb..a7445928 100644 --- a/lib/l10n/app_localizations_de.dart +++ b/lib/l10n/app_localizations_de.dart @@ -830,37 +830,19 @@ class AppLocalizationsDe extends AppLocalizations { @override String get factoryResetSentBody => - 'The radio is erasing itself and will restart with a new identity. Reconnect to it to finish.'; + 'The radio is erasing itself and will restart with a new identity.'; @override String get factoryResetSentBleBody => - 'The radio is erasing itself and will restart with a new identity. Its Bluetooth pairing is erased too: remove the old pairing for this radio in your phone or computer\'s Bluetooth settings, then reconnect to finish.'; - - @override - String get factoryResetCompleteTitle => 'Factory reset complete'; - - @override - String get factoryResetCompleteBody => - 'The radio has a new identity. Its old data was deleted from the app.'; - - @override - String get factoryResetCompleteKeptBody => - 'The radio has a new identity. Its old data was kept in the app.'; - - @override - String get factoryResetNotResetTitle => 'Factory reset did not happen'; - - @override - String get factoryResetNotResetBody => - 'The radio reconnected with the same identity, so it was not erased. Nothing was deleted from the app.'; + 'The radio is erasing itself and will restart with a new identity. Its Bluetooth pairing is erased too: remove the old pairing for this radio in your phone or computer\'s Bluetooth settings, then reconnect.'; @override String get factoryResetDeleteFailedTitle => - 'Factory reset done, app cleanup failed'; + 'Factory reset sent, app cleanup failed'; @override String get factoryResetDeleteFailedBody => - 'The radio was erased, but deleting its old data from the app failed. The app will try again the next time this radio connects.'; + 'The reset was sent, but deleting this radio\'s data from the app failed.'; @override String get settings_blePin => 'BLE pairing PIN'; diff --git a/lib/l10n/app_localizations_en.dart b/lib/l10n/app_localizations_en.dart index 1784ff17..b15dc39c 100644 --- a/lib/l10n/app_localizations_en.dart +++ b/lib/l10n/app_localizations_en.dart @@ -821,37 +821,19 @@ class AppLocalizationsEn extends AppLocalizations { @override String get factoryResetSentBody => - 'The radio is erasing itself and will restart with a new identity. Reconnect to it to finish.'; + 'The radio is erasing itself and will restart with a new identity.'; @override String get factoryResetSentBleBody => - 'The radio is erasing itself and will restart with a new identity. Its Bluetooth pairing is erased too: remove the old pairing for this radio in your phone or computer\'s Bluetooth settings, then reconnect to finish.'; - - @override - String get factoryResetCompleteTitle => 'Factory reset complete'; - - @override - String get factoryResetCompleteBody => - 'The radio has a new identity. Its old data was deleted from the app.'; - - @override - String get factoryResetCompleteKeptBody => - 'The radio has a new identity. Its old data was kept in the app.'; - - @override - String get factoryResetNotResetTitle => 'Factory reset did not happen'; - - @override - String get factoryResetNotResetBody => - 'The radio reconnected with the same identity, so it was not erased. Nothing was deleted from the app.'; + 'The radio is erasing itself and will restart with a new identity. Its Bluetooth pairing is erased too: remove the old pairing for this radio in your phone or computer\'s Bluetooth settings, then reconnect.'; @override String get factoryResetDeleteFailedTitle => - 'Factory reset done, app cleanup failed'; + 'Factory reset sent, app cleanup failed'; @override String get factoryResetDeleteFailedBody => - 'The radio was erased, but deleting its old data from the app failed. The app will try again the next time this radio connects.'; + 'The reset was sent, but deleting this radio\'s data from the app failed.'; @override String get settings_blePin => 'BLE pairing PIN'; diff --git a/lib/l10n/app_localizations_es.dart b/lib/l10n/app_localizations_es.dart index 4fa57309..b078fcbd 100644 --- a/lib/l10n/app_localizations_es.dart +++ b/lib/l10n/app_localizations_es.dart @@ -831,37 +831,19 @@ class AppLocalizationsEs extends AppLocalizations { @override String get factoryResetSentBody => - 'The radio is erasing itself and will restart with a new identity. Reconnect to it to finish.'; + 'The radio is erasing itself and will restart with a new identity.'; @override String get factoryResetSentBleBody => - 'The radio is erasing itself and will restart with a new identity. Its Bluetooth pairing is erased too: remove the old pairing for this radio in your phone or computer\'s Bluetooth settings, then reconnect to finish.'; - - @override - String get factoryResetCompleteTitle => 'Factory reset complete'; - - @override - String get factoryResetCompleteBody => - 'The radio has a new identity. Its old data was deleted from the app.'; - - @override - String get factoryResetCompleteKeptBody => - 'The radio has a new identity. Its old data was kept in the app.'; - - @override - String get factoryResetNotResetTitle => 'Factory reset did not happen'; - - @override - String get factoryResetNotResetBody => - 'The radio reconnected with the same identity, so it was not erased. Nothing was deleted from the app.'; + 'The radio is erasing itself and will restart with a new identity. Its Bluetooth pairing is erased too: remove the old pairing for this radio in your phone or computer\'s Bluetooth settings, then reconnect.'; @override String get factoryResetDeleteFailedTitle => - 'Factory reset done, app cleanup failed'; + 'Factory reset sent, app cleanup failed'; @override String get factoryResetDeleteFailedBody => - 'The radio was erased, but deleting its old data from the app failed. The app will try again the next time this radio connects.'; + 'The reset was sent, but deleting this radio\'s data from the app failed.'; @override String get settings_blePin => 'BLE pairing PIN'; diff --git a/lib/l10n/app_localizations_fr.dart b/lib/l10n/app_localizations_fr.dart index 07bee59b..3fa3998d 100644 --- a/lib/l10n/app_localizations_fr.dart +++ b/lib/l10n/app_localizations_fr.dart @@ -835,37 +835,19 @@ class AppLocalizationsFr extends AppLocalizations { @override String get factoryResetSentBody => - 'The radio is erasing itself and will restart with a new identity. Reconnect to it to finish.'; + 'The radio is erasing itself and will restart with a new identity.'; @override String get factoryResetSentBleBody => - 'The radio is erasing itself and will restart with a new identity. Its Bluetooth pairing is erased too: remove the old pairing for this radio in your phone or computer\'s Bluetooth settings, then reconnect to finish.'; - - @override - String get factoryResetCompleteTitle => 'Factory reset complete'; - - @override - String get factoryResetCompleteBody => - 'The radio has a new identity. Its old data was deleted from the app.'; - - @override - String get factoryResetCompleteKeptBody => - 'The radio has a new identity. Its old data was kept in the app.'; - - @override - String get factoryResetNotResetTitle => 'Factory reset did not happen'; - - @override - String get factoryResetNotResetBody => - 'The radio reconnected with the same identity, so it was not erased. Nothing was deleted from the app.'; + 'The radio is erasing itself and will restart with a new identity. Its Bluetooth pairing is erased too: remove the old pairing for this radio in your phone or computer\'s Bluetooth settings, then reconnect.'; @override String get factoryResetDeleteFailedTitle => - 'Factory reset done, app cleanup failed'; + 'Factory reset sent, app cleanup failed'; @override String get factoryResetDeleteFailedBody => - 'The radio was erased, but deleting its old data from the app failed. The app will try again the next time this radio connects.'; + 'The reset was sent, but deleting this radio\'s data from the app failed.'; @override String get settings_blePin => 'BLE pairing PIN'; diff --git a/lib/l10n/app_localizations_hu.dart b/lib/l10n/app_localizations_hu.dart index 6f7db77c..bf4f8823 100644 --- a/lib/l10n/app_localizations_hu.dart +++ b/lib/l10n/app_localizations_hu.dart @@ -833,37 +833,19 @@ class AppLocalizationsHu extends AppLocalizations { @override String get factoryResetSentBody => - 'The radio is erasing itself and will restart with a new identity. Reconnect to it to finish.'; + 'The radio is erasing itself and will restart with a new identity.'; @override String get factoryResetSentBleBody => - 'The radio is erasing itself and will restart with a new identity. Its Bluetooth pairing is erased too: remove the old pairing for this radio in your phone or computer\'s Bluetooth settings, then reconnect to finish.'; - - @override - String get factoryResetCompleteTitle => 'Factory reset complete'; - - @override - String get factoryResetCompleteBody => - 'The radio has a new identity. Its old data was deleted from the app.'; - - @override - String get factoryResetCompleteKeptBody => - 'The radio has a new identity. Its old data was kept in the app.'; - - @override - String get factoryResetNotResetTitle => 'Factory reset did not happen'; - - @override - String get factoryResetNotResetBody => - 'The radio reconnected with the same identity, so it was not erased. Nothing was deleted from the app.'; + 'The radio is erasing itself and will restart with a new identity. Its Bluetooth pairing is erased too: remove the old pairing for this radio in your phone or computer\'s Bluetooth settings, then reconnect.'; @override String get factoryResetDeleteFailedTitle => - 'Factory reset done, app cleanup failed'; + 'Factory reset sent, app cleanup failed'; @override String get factoryResetDeleteFailedBody => - 'The radio was erased, but deleting its old data from the app failed. The app will try again the next time this radio connects.'; + 'The reset was sent, but deleting this radio\'s data from the app failed.'; @override String get settings_blePin => 'BLE pairing PIN'; diff --git a/lib/l10n/app_localizations_it.dart b/lib/l10n/app_localizations_it.dart index cd01fdd5..81a29318 100644 --- a/lib/l10n/app_localizations_it.dart +++ b/lib/l10n/app_localizations_it.dart @@ -833,37 +833,19 @@ class AppLocalizationsIt extends AppLocalizations { @override String get factoryResetSentBody => - 'The radio is erasing itself and will restart with a new identity. Reconnect to it to finish.'; + 'The radio is erasing itself and will restart with a new identity.'; @override String get factoryResetSentBleBody => - 'The radio is erasing itself and will restart with a new identity. Its Bluetooth pairing is erased too: remove the old pairing for this radio in your phone or computer\'s Bluetooth settings, then reconnect to finish.'; - - @override - String get factoryResetCompleteTitle => 'Factory reset complete'; - - @override - String get factoryResetCompleteBody => - 'The radio has a new identity. Its old data was deleted from the app.'; - - @override - String get factoryResetCompleteKeptBody => - 'The radio has a new identity. Its old data was kept in the app.'; - - @override - String get factoryResetNotResetTitle => 'Factory reset did not happen'; - - @override - String get factoryResetNotResetBody => - 'The radio reconnected with the same identity, so it was not erased. Nothing was deleted from the app.'; + 'The radio is erasing itself and will restart with a new identity. Its Bluetooth pairing is erased too: remove the old pairing for this radio in your phone or computer\'s Bluetooth settings, then reconnect.'; @override String get factoryResetDeleteFailedTitle => - 'Factory reset done, app cleanup failed'; + 'Factory reset sent, app cleanup failed'; @override String get factoryResetDeleteFailedBody => - 'The radio was erased, but deleting its old data from the app failed. The app will try again the next time this radio connects.'; + 'The reset was sent, but deleting this radio\'s data from the app failed.'; @override String get settings_blePin => 'BLE pairing PIN'; diff --git a/lib/l10n/app_localizations_ja.dart b/lib/l10n/app_localizations_ja.dart index cf5f5651..5dd63388 100644 --- a/lib/l10n/app_localizations_ja.dart +++ b/lib/l10n/app_localizations_ja.dart @@ -807,37 +807,19 @@ class AppLocalizationsJa extends AppLocalizations { @override String get factoryResetSentBody => - 'The radio is erasing itself and will restart with a new identity. Reconnect to it to finish.'; + 'The radio is erasing itself and will restart with a new identity.'; @override String get factoryResetSentBleBody => - 'The radio is erasing itself and will restart with a new identity. Its Bluetooth pairing is erased too: remove the old pairing for this radio in your phone or computer\'s Bluetooth settings, then reconnect to finish.'; - - @override - String get factoryResetCompleteTitle => 'Factory reset complete'; - - @override - String get factoryResetCompleteBody => - 'The radio has a new identity. Its old data was deleted from the app.'; - - @override - String get factoryResetCompleteKeptBody => - 'The radio has a new identity. Its old data was kept in the app.'; - - @override - String get factoryResetNotResetTitle => 'Factory reset did not happen'; - - @override - String get factoryResetNotResetBody => - 'The radio reconnected with the same identity, so it was not erased. Nothing was deleted from the app.'; + 'The radio is erasing itself and will restart with a new identity. Its Bluetooth pairing is erased too: remove the old pairing for this radio in your phone or computer\'s Bluetooth settings, then reconnect.'; @override String get factoryResetDeleteFailedTitle => - 'Factory reset done, app cleanup failed'; + 'Factory reset sent, app cleanup failed'; @override String get factoryResetDeleteFailedBody => - 'The radio was erased, but deleting its old data from the app failed. The app will try again the next time this radio connects.'; + 'The reset was sent, but deleting this radio\'s data from the app failed.'; @override String get settings_blePin => 'BLE pairing PIN'; diff --git a/lib/l10n/app_localizations_ko.dart b/lib/l10n/app_localizations_ko.dart index 6497537a..a3056a61 100644 --- a/lib/l10n/app_localizations_ko.dart +++ b/lib/l10n/app_localizations_ko.dart @@ -807,37 +807,19 @@ class AppLocalizationsKo extends AppLocalizations { @override String get factoryResetSentBody => - 'The radio is erasing itself and will restart with a new identity. Reconnect to it to finish.'; + 'The radio is erasing itself and will restart with a new identity.'; @override String get factoryResetSentBleBody => - 'The radio is erasing itself and will restart with a new identity. Its Bluetooth pairing is erased too: remove the old pairing for this radio in your phone or computer\'s Bluetooth settings, then reconnect to finish.'; - - @override - String get factoryResetCompleteTitle => 'Factory reset complete'; - - @override - String get factoryResetCompleteBody => - 'The radio has a new identity. Its old data was deleted from the app.'; - - @override - String get factoryResetCompleteKeptBody => - 'The radio has a new identity. Its old data was kept in the app.'; - - @override - String get factoryResetNotResetTitle => 'Factory reset did not happen'; - - @override - String get factoryResetNotResetBody => - 'The radio reconnected with the same identity, so it was not erased. Nothing was deleted from the app.'; + 'The radio is erasing itself and will restart with a new identity. Its Bluetooth pairing is erased too: remove the old pairing for this radio in your phone or computer\'s Bluetooth settings, then reconnect.'; @override String get factoryResetDeleteFailedTitle => - 'Factory reset done, app cleanup failed'; + 'Factory reset sent, app cleanup failed'; @override String get factoryResetDeleteFailedBody => - 'The radio was erased, but deleting its old data from the app failed. The app will try again the next time this radio connects.'; + 'The reset was sent, but deleting this radio\'s data from the app failed.'; @override String get settings_blePin => 'BLE pairing PIN'; diff --git a/lib/l10n/app_localizations_nl.dart b/lib/l10n/app_localizations_nl.dart index dd1d3798..58ab517c 100644 --- a/lib/l10n/app_localizations_nl.dart +++ b/lib/l10n/app_localizations_nl.dart @@ -827,37 +827,19 @@ class AppLocalizationsNl extends AppLocalizations { @override String get factoryResetSentBody => - 'The radio is erasing itself and will restart with a new identity. Reconnect to it to finish.'; + 'The radio is erasing itself and will restart with a new identity.'; @override String get factoryResetSentBleBody => - 'The radio is erasing itself and will restart with a new identity. Its Bluetooth pairing is erased too: remove the old pairing for this radio in your phone or computer\'s Bluetooth settings, then reconnect to finish.'; - - @override - String get factoryResetCompleteTitle => 'Factory reset complete'; - - @override - String get factoryResetCompleteBody => - 'The radio has a new identity. Its old data was deleted from the app.'; - - @override - String get factoryResetCompleteKeptBody => - 'The radio has a new identity. Its old data was kept in the app.'; - - @override - String get factoryResetNotResetTitle => 'Factory reset did not happen'; - - @override - String get factoryResetNotResetBody => - 'The radio reconnected with the same identity, so it was not erased. Nothing was deleted from the app.'; + 'The radio is erasing itself and will restart with a new identity. Its Bluetooth pairing is erased too: remove the old pairing for this radio in your phone or computer\'s Bluetooth settings, then reconnect.'; @override String get factoryResetDeleteFailedTitle => - 'Factory reset done, app cleanup failed'; + 'Factory reset sent, app cleanup failed'; @override String get factoryResetDeleteFailedBody => - 'The radio was erased, but deleting its old data from the app failed. The app will try again the next time this radio connects.'; + 'The reset was sent, but deleting this radio\'s data from the app failed.'; @override String get settings_blePin => 'BLE pairing PIN'; diff --git a/lib/l10n/app_localizations_pl.dart b/lib/l10n/app_localizations_pl.dart index 9a781304..57ea8136 100644 --- a/lib/l10n/app_localizations_pl.dart +++ b/lib/l10n/app_localizations_pl.dart @@ -835,37 +835,19 @@ class AppLocalizationsPl extends AppLocalizations { @override String get factoryResetSentBody => - 'The radio is erasing itself and will restart with a new identity. Reconnect to it to finish.'; + 'The radio is erasing itself and will restart with a new identity.'; @override String get factoryResetSentBleBody => - 'The radio is erasing itself and will restart with a new identity. Its Bluetooth pairing is erased too: remove the old pairing for this radio in your phone or computer\'s Bluetooth settings, then reconnect to finish.'; - - @override - String get factoryResetCompleteTitle => 'Factory reset complete'; - - @override - String get factoryResetCompleteBody => - 'The radio has a new identity. Its old data was deleted from the app.'; - - @override - String get factoryResetCompleteKeptBody => - 'The radio has a new identity. Its old data was kept in the app.'; - - @override - String get factoryResetNotResetTitle => 'Factory reset did not happen'; - - @override - String get factoryResetNotResetBody => - 'The radio reconnected with the same identity, so it was not erased. Nothing was deleted from the app.'; + 'The radio is erasing itself and will restart with a new identity. Its Bluetooth pairing is erased too: remove the old pairing for this radio in your phone or computer\'s Bluetooth settings, then reconnect.'; @override String get factoryResetDeleteFailedTitle => - 'Factory reset done, app cleanup failed'; + 'Factory reset sent, app cleanup failed'; @override String get factoryResetDeleteFailedBody => - 'The radio was erased, but deleting its old data from the app failed. The app will try again the next time this radio connects.'; + 'The reset was sent, but deleting this radio\'s data from the app failed.'; @override String get settings_blePin => 'BLE pairing PIN'; diff --git a/lib/l10n/app_localizations_pt.dart b/lib/l10n/app_localizations_pt.dart index c923805f..1622dd33 100644 --- a/lib/l10n/app_localizations_pt.dart +++ b/lib/l10n/app_localizations_pt.dart @@ -833,37 +833,19 @@ class AppLocalizationsPt extends AppLocalizations { @override String get factoryResetSentBody => - 'The radio is erasing itself and will restart with a new identity. Reconnect to it to finish.'; + 'The radio is erasing itself and will restart with a new identity.'; @override String get factoryResetSentBleBody => - 'The radio is erasing itself and will restart with a new identity. Its Bluetooth pairing is erased too: remove the old pairing for this radio in your phone or computer\'s Bluetooth settings, then reconnect to finish.'; - - @override - String get factoryResetCompleteTitle => 'Factory reset complete'; - - @override - String get factoryResetCompleteBody => - 'The radio has a new identity. Its old data was deleted from the app.'; - - @override - String get factoryResetCompleteKeptBody => - 'The radio has a new identity. Its old data was kept in the app.'; - - @override - String get factoryResetNotResetTitle => 'Factory reset did not happen'; - - @override - String get factoryResetNotResetBody => - 'The radio reconnected with the same identity, so it was not erased. Nothing was deleted from the app.'; + 'The radio is erasing itself and will restart with a new identity. Its Bluetooth pairing is erased too: remove the old pairing for this radio in your phone or computer\'s Bluetooth settings, then reconnect.'; @override String get factoryResetDeleteFailedTitle => - 'Factory reset done, app cleanup failed'; + 'Factory reset sent, app cleanup failed'; @override String get factoryResetDeleteFailedBody => - 'The radio was erased, but deleting its old data from the app failed. The app will try again the next time this radio connects.'; + 'The reset was sent, but deleting this radio\'s data from the app failed.'; @override String get settings_blePin => 'BLE pairing PIN'; diff --git a/lib/l10n/app_localizations_ru.dart b/lib/l10n/app_localizations_ru.dart index d7cc917f..606cbf1f 100644 --- a/lib/l10n/app_localizations_ru.dart +++ b/lib/l10n/app_localizations_ru.dart @@ -832,37 +832,19 @@ class AppLocalizationsRu extends AppLocalizations { @override String get factoryResetSentBody => - 'The radio is erasing itself and will restart with a new identity. Reconnect to it to finish.'; + 'The radio is erasing itself and will restart with a new identity.'; @override String get factoryResetSentBleBody => - 'The radio is erasing itself and will restart with a new identity. Its Bluetooth pairing is erased too: remove the old pairing for this radio in your phone or computer\'s Bluetooth settings, then reconnect to finish.'; - - @override - String get factoryResetCompleteTitle => 'Factory reset complete'; - - @override - String get factoryResetCompleteBody => - 'The radio has a new identity. Its old data was deleted from the app.'; - - @override - String get factoryResetCompleteKeptBody => - 'The radio has a new identity. Its old data was kept in the app.'; - - @override - String get factoryResetNotResetTitle => 'Factory reset did not happen'; - - @override - String get factoryResetNotResetBody => - 'The radio reconnected with the same identity, so it was not erased. Nothing was deleted from the app.'; + 'The radio is erasing itself and will restart with a new identity. Its Bluetooth pairing is erased too: remove the old pairing for this radio in your phone or computer\'s Bluetooth settings, then reconnect.'; @override String get factoryResetDeleteFailedTitle => - 'Factory reset done, app cleanup failed'; + 'Factory reset sent, app cleanup failed'; @override String get factoryResetDeleteFailedBody => - 'The radio was erased, but deleting its old data from the app failed. The app will try again the next time this radio connects.'; + 'The reset was sent, but deleting this radio\'s data from the app failed.'; @override String get settings_blePin => 'BLE pairing PIN'; diff --git a/lib/l10n/app_localizations_sk.dart b/lib/l10n/app_localizations_sk.dart index 5ecf0703..99ab7e6a 100644 --- a/lib/l10n/app_localizations_sk.dart +++ b/lib/l10n/app_localizations_sk.dart @@ -827,37 +827,19 @@ class AppLocalizationsSk extends AppLocalizations { @override String get factoryResetSentBody => - 'The radio is erasing itself and will restart with a new identity. Reconnect to it to finish.'; + 'The radio is erasing itself and will restart with a new identity.'; @override String get factoryResetSentBleBody => - 'The radio is erasing itself and will restart with a new identity. Its Bluetooth pairing is erased too: remove the old pairing for this radio in your phone or computer\'s Bluetooth settings, then reconnect to finish.'; - - @override - String get factoryResetCompleteTitle => 'Factory reset complete'; - - @override - String get factoryResetCompleteBody => - 'The radio has a new identity. Its old data was deleted from the app.'; - - @override - String get factoryResetCompleteKeptBody => - 'The radio has a new identity. Its old data was kept in the app.'; - - @override - String get factoryResetNotResetTitle => 'Factory reset did not happen'; - - @override - String get factoryResetNotResetBody => - 'The radio reconnected with the same identity, so it was not erased. Nothing was deleted from the app.'; + 'The radio is erasing itself and will restart with a new identity. Its Bluetooth pairing is erased too: remove the old pairing for this radio in your phone or computer\'s Bluetooth settings, then reconnect.'; @override String get factoryResetDeleteFailedTitle => - 'Factory reset done, app cleanup failed'; + 'Factory reset sent, app cleanup failed'; @override String get factoryResetDeleteFailedBody => - 'The radio was erased, but deleting its old data from the app failed. The app will try again the next time this radio connects.'; + 'The reset was sent, but deleting this radio\'s data from the app failed.'; @override String get settings_blePin => 'BLE pairing PIN'; diff --git a/lib/l10n/app_localizations_sl.dart b/lib/l10n/app_localizations_sl.dart index 48b620f9..f399f48f 100644 --- a/lib/l10n/app_localizations_sl.dart +++ b/lib/l10n/app_localizations_sl.dart @@ -825,37 +825,19 @@ class AppLocalizationsSl extends AppLocalizations { @override String get factoryResetSentBody => - 'The radio is erasing itself and will restart with a new identity. Reconnect to it to finish.'; + 'The radio is erasing itself and will restart with a new identity.'; @override String get factoryResetSentBleBody => - 'The radio is erasing itself and will restart with a new identity. Its Bluetooth pairing is erased too: remove the old pairing for this radio in your phone or computer\'s Bluetooth settings, then reconnect to finish.'; - - @override - String get factoryResetCompleteTitle => 'Factory reset complete'; - - @override - String get factoryResetCompleteBody => - 'The radio has a new identity. Its old data was deleted from the app.'; - - @override - String get factoryResetCompleteKeptBody => - 'The radio has a new identity. Its old data was kept in the app.'; - - @override - String get factoryResetNotResetTitle => 'Factory reset did not happen'; - - @override - String get factoryResetNotResetBody => - 'The radio reconnected with the same identity, so it was not erased. Nothing was deleted from the app.'; + 'The radio is erasing itself and will restart with a new identity. Its Bluetooth pairing is erased too: remove the old pairing for this radio in your phone or computer\'s Bluetooth settings, then reconnect.'; @override String get factoryResetDeleteFailedTitle => - 'Factory reset done, app cleanup failed'; + 'Factory reset sent, app cleanup failed'; @override String get factoryResetDeleteFailedBody => - 'The radio was erased, but deleting its old data from the app failed. The app will try again the next time this radio connects.'; + 'The reset was sent, but deleting this radio\'s data from the app failed.'; @override String get settings_blePin => 'BLE pairing PIN'; diff --git a/lib/l10n/app_localizations_sv.dart b/lib/l10n/app_localizations_sv.dart index def070e3..b67eace8 100644 --- a/lib/l10n/app_localizations_sv.dart +++ b/lib/l10n/app_localizations_sv.dart @@ -822,37 +822,19 @@ class AppLocalizationsSv extends AppLocalizations { @override String get factoryResetSentBody => - 'The radio is erasing itself and will restart with a new identity. Reconnect to it to finish.'; + 'The radio is erasing itself and will restart with a new identity.'; @override String get factoryResetSentBleBody => - 'The radio is erasing itself and will restart with a new identity. Its Bluetooth pairing is erased too: remove the old pairing for this radio in your phone or computer\'s Bluetooth settings, then reconnect to finish.'; - - @override - String get factoryResetCompleteTitle => 'Factory reset complete'; - - @override - String get factoryResetCompleteBody => - 'The radio has a new identity. Its old data was deleted from the app.'; - - @override - String get factoryResetCompleteKeptBody => - 'The radio has a new identity. Its old data was kept in the app.'; - - @override - String get factoryResetNotResetTitle => 'Factory reset did not happen'; - - @override - String get factoryResetNotResetBody => - 'The radio reconnected with the same identity, so it was not erased. Nothing was deleted from the app.'; + 'The radio is erasing itself and will restart with a new identity. Its Bluetooth pairing is erased too: remove the old pairing for this radio in your phone or computer\'s Bluetooth settings, then reconnect.'; @override String get factoryResetDeleteFailedTitle => - 'Factory reset done, app cleanup failed'; + 'Factory reset sent, app cleanup failed'; @override String get factoryResetDeleteFailedBody => - 'The radio was erased, but deleting its old data from the app failed. The app will try again the next time this radio connects.'; + 'The reset was sent, but deleting this radio\'s data from the app failed.'; @override String get settings_blePin => 'BLE pairing PIN'; diff --git a/lib/l10n/app_localizations_uk.dart b/lib/l10n/app_localizations_uk.dart index 2626bffb..4f0a1e50 100644 --- a/lib/l10n/app_localizations_uk.dart +++ b/lib/l10n/app_localizations_uk.dart @@ -829,37 +829,19 @@ class AppLocalizationsUk extends AppLocalizations { @override String get factoryResetSentBody => - 'The radio is erasing itself and will restart with a new identity. Reconnect to it to finish.'; + 'The radio is erasing itself and will restart with a new identity.'; @override String get factoryResetSentBleBody => - 'The radio is erasing itself and will restart with a new identity. Its Bluetooth pairing is erased too: remove the old pairing for this radio in your phone or computer\'s Bluetooth settings, then reconnect to finish.'; - - @override - String get factoryResetCompleteTitle => 'Factory reset complete'; - - @override - String get factoryResetCompleteBody => - 'The radio has a new identity. Its old data was deleted from the app.'; - - @override - String get factoryResetCompleteKeptBody => - 'The radio has a new identity. Its old data was kept in the app.'; - - @override - String get factoryResetNotResetTitle => 'Factory reset did not happen'; - - @override - String get factoryResetNotResetBody => - 'The radio reconnected with the same identity, so it was not erased. Nothing was deleted from the app.'; + 'The radio is erasing itself and will restart with a new identity. Its Bluetooth pairing is erased too: remove the old pairing for this radio in your phone or computer\'s Bluetooth settings, then reconnect.'; @override String get factoryResetDeleteFailedTitle => - 'Factory reset done, app cleanup failed'; + 'Factory reset sent, app cleanup failed'; @override String get factoryResetDeleteFailedBody => - 'The radio was erased, but deleting its old data from the app failed. The app will try again the next time this radio connects.'; + 'The reset was sent, but deleting this radio\'s data from the app failed.'; @override String get settings_blePin => 'BLE pairing PIN'; diff --git a/lib/l10n/app_localizations_zh.dart b/lib/l10n/app_localizations_zh.dart index 803195ad..5ff24cd3 100644 --- a/lib/l10n/app_localizations_zh.dart +++ b/lib/l10n/app_localizations_zh.dart @@ -800,37 +800,19 @@ class AppLocalizationsZh extends AppLocalizations { @override String get factoryResetSentBody => - 'The radio is erasing itself and will restart with a new identity. Reconnect to it to finish.'; + 'The radio is erasing itself and will restart with a new identity.'; @override String get factoryResetSentBleBody => - 'The radio is erasing itself and will restart with a new identity. Its Bluetooth pairing is erased too: remove the old pairing for this radio in your phone or computer\'s Bluetooth settings, then reconnect to finish.'; - - @override - String get factoryResetCompleteTitle => 'Factory reset complete'; - - @override - String get factoryResetCompleteBody => - 'The radio has a new identity. Its old data was deleted from the app.'; - - @override - String get factoryResetCompleteKeptBody => - 'The radio has a new identity. Its old data was kept in the app.'; - - @override - String get factoryResetNotResetTitle => 'Factory reset did not happen'; - - @override - String get factoryResetNotResetBody => - 'The radio reconnected with the same identity, so it was not erased. Nothing was deleted from the app.'; + 'The radio is erasing itself and will restart with a new identity. Its Bluetooth pairing is erased too: remove the old pairing for this radio in your phone or computer\'s Bluetooth settings, then reconnect.'; @override String get factoryResetDeleteFailedTitle => - 'Factory reset done, app cleanup failed'; + 'Factory reset sent, app cleanup failed'; @override String get factoryResetDeleteFailedBody => - 'The radio was erased, but deleting its old data from the app failed. The app will try again the next time this radio connects.'; + 'The reset was sent, but deleting this radio\'s data from the app failed.'; @override String get settings_blePin => 'BLE pairing PIN'; diff --git a/lib/storage/factory_reset_store.dart b/lib/storage/factory_reset_store.dart deleted file mode 100644 index 5e71a36f..00000000 --- a/lib/storage/factory_reset_store.dart +++ /dev/null @@ -1,100 +0,0 @@ -import 'dart:convert'; - -import 'prefs_manager.dart'; - -/// A factory reset that was sent and not yet proven (#1054). -/// -/// The firmware disables the link before it formats, so the client never -/// hears whether the wipe worked. The proof is the next connect to the same -/// device: a new identity means it worked. Until then this record keeps the -/// old radio's data alive, so a reset that failed cannot cost the user their -/// history. -class PendingFactoryReset { - const PendingFactoryReset({ - required this.deviceId, - required this.radioPrefix, - required this.deleteAppData, - }); - - /// The transport identity the reset went to: BLE remote id, USB port key or - /// TCP endpoint. A connect to anything else says nothing about this reset. - final String deviceId; - - /// First 10 hex of the radio's key before the reset. - final String radioPrefix; - - /// The user's choice in the confirm dialog. - final bool deleteAppData; - - Map toJson() => { - 'device_id': deviceId, - 'radio_prefix': radioPrefix, - 'delete_app_data': deleteAppData, - }; - - static PendingFactoryReset? fromJson(Map json) { - final deviceId = json['device_id']; - final radioPrefix = json['radio_prefix']; - final deleteAppData = json['delete_app_data']; - if (deviceId is! String || - radioPrefix is! String || - deleteAppData is! bool) { - return null; - } - return PendingFactoryReset( - deviceId: deviceId, - radioPrefix: radioPrefix, - deleteAppData: deleteAppData, - ); - } -} - -enum FactoryResetOutcome { - /// New identity, and the user asked for the app data to go. - wipeAppData, - - /// New identity, and the user asked to keep the app data. - keepAppData, - - /// Same identity: the radio was not wiped. Nothing is deleted. - notReset, -} - -/// What connecting to [deviceId] as [radioPrefix] says about [pending]. -/// -/// Null when it is a different device, so the record stays and nothing is -/// decided on the strength of some other radio. -FactoryResetOutcome? resolveFactoryReset( - PendingFactoryReset pending, { - required String deviceId, - required String radioPrefix, -}) { - if (deviceId != pending.deviceId) return null; - if (radioPrefix == pending.radioPrefix) return FactoryResetOutcome.notReset; - return pending.deleteAppData - ? FactoryResetOutcome.wipeAppData - : FactoryResetOutcome.keepAppData; -} - -/// Survives an app restart between the reset and the reconnect, so closing -/// the app in between does not quietly skip the delete the user asked for. -class FactoryResetStore { - static const String _key = 'factory_reset_pending'; - - PendingFactoryReset? load() { - final raw = PrefsManager.instance.getString(_key); - if (raw == null) return null; - try { - return PendingFactoryReset.fromJson( - jsonDecode(raw) as Map, - ); - } catch (_) { - return null; - } - } - - Future save(PendingFactoryReset pending) => - PrefsManager.instance.setString(_key, jsonEncode(pending.toJson())); - - Future clear() => PrefsManager.instance.remove(_key); -} diff --git a/lib/storage/scoping_inventory.dart b/lib/storage/scoping_inventory.dart index 51532961..8c7d2858 100644 --- a/lib/storage/scoping_inventory.dart +++ b/lib/storage/scoping_inventory.dart @@ -248,15 +248,6 @@ const List storageSurfaces = [ reason: 'keyed by repeater node, same reasoning as repeater_passwords', owner: 'lib/services/storage_service.dart', ), - StorageSurface( - 'factory_reset_pending', - verdict: ScopingVerdict.globalOnPurpose, - reason: - 'one factory reset awaiting proof (#1054). It spans two identities of ' - 'the same device, the key before the wipe and the key after, so it ' - 'cannot live under either. It names the old radio inside the record', - owner: 'lib/storage/factory_reset_store.dart', - ), StorageSurface( 'map_removed_marker_ids', verdict: ScopingVerdict.globalOnPurpose, diff --git a/lib/widgets/factory_reset_banner.dart b/lib/widgets/factory_reset_banner.dart index c9ea51fc..d1584a90 100644 --- a/lib/widgets/factory_reset_banner.dart +++ b/lib/widgets/factory_reset_banner.dart @@ -3,10 +3,10 @@ import 'package:flutter/material.dart'; import '../connector/meshcore_connector.dart'; import '../l10n/l10n.dart'; -/// Shown above the whole app while a factory reset is outstanding and once it -/// settles (#1054). The settings screen is gone by then, because the reset -/// ends the session, so the outcome is reported here and stays until -/// dismissed. Sits in `MaterialApp.builder`, like [ContactSyncShortfallBanner]. +/// Shown above the whole app after a factory reset is sent (#1054). The +/// settings screen is gone by then, because the reset ends the session, so it +/// is reported here and stays until dismissed. Sits in `MaterialApp.builder`, +/// like [ContactSyncShortfallBanner]. class FactoryResetBanner extends StatelessWidget { final FactoryResetStatus? status; final VoidCallback onDismiss; @@ -34,9 +34,7 @@ class FactoryResetBanner extends StatelessWidget { Widget _banner(BuildContext context, FactoryResetStatus current) { final l10n = context.l10n; final scheme = Theme.of(context).colorScheme; - final failed = - current == FactoryResetStatus.notReset || - current == FactoryResetStatus.deleteFailed; + final failed = current == FactoryResetStatus.deleteFailed; final background = failed ? scheme.errorContainer : scheme.secondaryContainer; @@ -52,18 +50,6 @@ class FactoryResetBanner extends StatelessWidget { l10n.factoryResetSentTitle, l10n.factoryResetSentBody, ), - FactoryResetStatus.complete => ( - l10n.factoryResetCompleteTitle, - l10n.factoryResetCompleteBody, - ), - FactoryResetStatus.completeKept => ( - l10n.factoryResetCompleteTitle, - l10n.factoryResetCompleteKeptBody, - ), - FactoryResetStatus.notReset => ( - l10n.factoryResetNotResetTitle, - l10n.factoryResetNotResetBody, - ), FactoryResetStatus.deleteFailed => ( l10n.factoryResetDeleteFailedTitle, l10n.factoryResetDeleteFailedBody, diff --git a/test/connector/factory_reset_test.dart b/test/connector/factory_reset_test.dart index 6f5b7705..e3c76e2e 100644 --- a/test/connector/factory_reset_test.dart +++ b/test/connector/factory_reset_test.dart @@ -1,8 +1,5 @@ -// #1057 (epic #1054): factory reset of the connected radio. -// -// The radio drops the link before it formats, so success is only ever seen as -// the same device coming back with a new identity. These pin that the app data -// waits for that proof, and that every branch where it cannot tell keeps it. +// #1057 (epic #1054): factory reset of the connected radio. With the box +// ticked, the radio's app data is deleted as soon as the reset is sent (#1118). import 'dart:typed_data'; @@ -12,7 +9,6 @@ import 'package:meshcore_open/connector/meshcore_connector.dart'; import 'package:meshcore_open/connector/meshcore_protocol.dart'; import 'package:meshcore_open/storage/drift/blob_store.dart'; import 'package:meshcore_open/storage/drift/offband_database.dart'; -import 'package:meshcore_open/storage/factory_reset_store.dart'; import 'package:meshcore_open/storage/prefs_manager.dart'; import 'package:shared_preferences/shared_preferences.dart'; @@ -23,9 +19,8 @@ void main() { late MeshCoreConnector connector; late List sent; - const oldPrefix = 'aaaaaaaaaa'; - const newPrefix = 'bbbbbbbbbb'; - Uint8List keyOf(int fill) => Uint8List.fromList(List.filled(32, fill)); + const radioPrefix = 'aaaaaaaaaa'; + const otherPrefix = 'bbbbbbbbbb'; setUp(() async { SharedPreferences.setMockInitialValues({}); @@ -36,8 +31,7 @@ void main() { sent = []; connector = MeshCoreConnector() ..sendFrameOverrideForTest = sent.add - ..transportIdentityForTest = 'dev-1' - ..setSelfPublicKeyForTest(keyOf(0xaa)) + ..setSelfPublicKeyForTest(Uint8List.fromList(List.filled(32, 0xaa))) ..setFirmwareVerCodeForTest(14); }); @@ -46,37 +40,33 @@ void main() { BlobStore.clearTestOverride(); }); - Future seedOldRadio() async { - await BlobStore.instance.write('contacts$oldPrefix', '[]'); - await PrefsManager.instance.setString('channels$oldPrefix', '[]'); + Future seed(String prefix) async { + await BlobStore.instance.write('contacts$prefix', '[]'); + await PrefsManager.instance.setString('channels$prefix', '[]'); } - Future oldRadioDataExists() async => - (await BlobStore.instance.keysWithPrefix( - 'contacts$oldPrefix', - )).isNotEmpty || - PrefsManager.instance.getString('channels$oldPrefix') != null; + Future dataExists(String prefix) async => + (await BlobStore.instance.keysWithPrefix('contacts$prefix')).isNotEmpty || + PrefsManager.instance.getString('channels$prefix') != null; test('the frame is the command then "reset"', () { expect(buildFactoryResetFrame(), [cmdFactoryReset, ...'reset'.codeUnits]); expect(cmdFactoryReset, 51); }); - group('refusals send nothing', () { - test('not connected', () async { - final refusal = await connector.factoryResetDevice(deleteAppData: true); + test('not connected: nothing sent, nothing deleted', () async { + await seed(radioPrefix); - expect(refusal, FactoryResetRefusal.notConnected); - expect(sent, isEmpty); - expect(FactoryResetStore().load(), isNull); - }); + final refusal = await connector.factoryResetDevice(deleteAppData: true); + + expect(refusal, FactoryResetRefusal.notConnected); + expect(sent, isEmpty); + expect(await dataExists(radioPrefix), isTrue); }); - // Owner ruling: no FIRMWARE_VER_CODE gating. A radio that cannot reset keeps - // its identity, so the next connect resolves the record as "not reset". + // Owner ruling: no FIRMWARE_VER_CODE gating. for (final verCode in [null, 0, 6]) { test('ver code $verCode is never consulted: the reset is sent', () async { - await seedOldRadio(); connector ..setConnectedForTest() ..setFirmwareVerCodeForTest(verCode); @@ -88,93 +78,29 @@ void main() { }); } - test('a sent reset records the pending wipe, keeps the data, and ends the ' - 'session', () async { - await seedOldRadio(); + test('box ticked: the radio\'s app data is deleted on send, and only ' + 'that radio\'s', () async { + await seed(radioPrefix); + await seed(otherPrefix); connector.setConnectedForTest(); final refusal = await connector.factoryResetDevice(deleteAppData: true); expect(refusal, isNull); expect(sent.single, buildFactoryResetFrame()); - final pending = FactoryResetStore().load(); - expect(pending?.deviceId, 'dev-1'); - expect(pending?.radioPrefix, oldPrefix); - expect(pending?.deleteAppData, isTrue); - expect(await oldRadioDataExists(), isTrue); expect(connector.state, MeshCoreConnectionState.disconnected); - expect(connector.factoryResetStatus, isNotNull); + expect(connector.factoryResetStatus, FactoryResetStatus.sentBle); + expect(await dataExists(radioPrefix), isFalse); + expect(await dataExists(otherPrefix), isTrue); }); - group('the next connect settles it', () { - Future pend({bool deleteAppData = true}) => FactoryResetStore().save( - PendingFactoryReset( - deviceId: 'dev-1', - radioPrefix: oldPrefix, - deleteAppData: deleteAppData, - ), - ); - - test('new identity, box ticked: old data deleted', () async { - await seedOldRadio(); - await pend(); - connector.setSelfPublicKeyForTest(keyOf(0xbb)); - - await connector.resolvePendingFactoryResetForTest(); - - expect(await oldRadioDataExists(), isFalse); - expect(FactoryResetStore().load(), isNull); - expect(connector.factoryResetStatus, FactoryResetStatus.complete); - }); - - test('new identity, box unticked: old data kept', () async { - await seedOldRadio(); - await pend(deleteAppData: false); - connector.setSelfPublicKeyForTest(keyOf(0xbb)); - - await connector.resolvePendingFactoryResetForTest(); - - expect(await oldRadioDataExists(), isTrue); - expect(FactoryResetStore().load(), isNull); - expect(connector.factoryResetStatus, FactoryResetStatus.completeKept); - }); - - test('same identity: not reset, data kept', () async { - await seedOldRadio(); - await pend(); - - await connector.resolvePendingFactoryResetForTest(); - - expect(await oldRadioDataExists(), isTrue); - expect(FactoryResetStore().load(), isNull); - expect(connector.factoryResetStatus, FactoryResetStatus.notReset); - }); - - test('a different device: nothing decided, data and record kept', () async { - await seedOldRadio(); - await pend(); - connector - ..transportIdentityForTest = 'dev-2' - ..setSelfPublicKeyForTest(keyOf(0xbb)); - - await connector.resolvePendingFactoryResetForTest(); - - expect(await oldRadioDataExists(), isTrue); - expect(FactoryResetStore().load(), isNotNull); - expect(connector.factoryResetStatus, isNull); - }); - - test('the new radio\'s own data is never touched', () async { - await pend(); - await BlobStore.instance.write('contacts$newPrefix', '[]'); - connector.setSelfPublicKeyForTest(keyOf(0xbb)); + test('box unticked: the app data is kept', () async { + await seed(radioPrefix); + connector.setConnectedForTest(); - await connector.resolvePendingFactoryResetForTest(); + await connector.factoryResetDevice(deleteAppData: false); - expect( - await BlobStore.instance.keysWithPrefix('contacts$newPrefix'), - isNotEmpty, - ); - }); + expect(sent.single, buildFactoryResetFrame()); + expect(await dataExists(radioPrefix), isTrue); }); } diff --git a/test/storage/radio_data_wipe_test.dart b/test/storage/radio_data_wipe_test.dart index c60db357..82240625 100644 --- a/test/storage/radio_data_wipe_test.dart +++ b/test/storage/radio_data_wipe_test.dart @@ -2,13 +2,12 @@ import 'package:drift/native.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:meshcore_open/storage/drift/blob_store.dart'; import 'package:meshcore_open/storage/drift/offband_database.dart'; -import 'package:meshcore_open/storage/factory_reset_store.dart'; import 'package:meshcore_open/storage/prefs_manager.dart'; import 'package:meshcore_open/storage/radio_data_wipe.dart'; import 'package:meshcore_open/storage/scoping_inventory.dart'; import 'package:shared_preferences/shared_preferences.dart'; -/// #1057: the factory-reset app-data wipe and the reconnect decision. +/// #1057: the factory-reset app-data wipe. void main() { late OffbandDatabase db; @@ -106,69 +105,4 @@ void main() { } expect(await allKeys(), before); }); - - group('resolveFactoryReset', () { - const pending = PendingFactoryReset( - deviceId: 'dev-1', - radioPrefix: wiped, - deleteAppData: true, - ); - - test('new key on the same device with the box ticked wipes', () { - expect( - resolveFactoryReset(pending, deviceId: 'dev-1', radioPrefix: other), - FactoryResetOutcome.wipeAppData, - ); - }); - - test('new key with the box unticked keeps', () { - const keep = PendingFactoryReset( - deviceId: 'dev-1', - radioPrefix: wiped, - deleteAppData: false, - ); - expect( - resolveFactoryReset(keep, deviceId: 'dev-1', radioPrefix: other), - FactoryResetOutcome.keepAppData, - ); - }); - - test('same key means the radio was not reset', () { - expect( - resolveFactoryReset(pending, deviceId: 'dev-1', radioPrefix: wiped), - FactoryResetOutcome.notReset, - ); - }); - - test('a different device decides nothing', () { - expect( - resolveFactoryReset(pending, deviceId: 'dev-2', radioPrefix: other), - isNull, - ); - }); - }); - - test('the pending record survives a restart and clears', () async { - final store = FactoryResetStore(); - await store.save( - const PendingFactoryReset( - deviceId: 'COM7', - radioPrefix: wiped, - deleteAppData: true, - ), - ); - - final reloaded = FactoryResetStore().load(); - expect(reloaded?.deviceId, 'COM7'); - expect(reloaded?.radioPrefix, wiped); - expect(reloaded?.deleteAppData, isTrue); - - await store.clear(); - expect(FactoryResetStore().load(), isNull); - }); - - test('an unreadable pending record loads as none', () async { - await PrefsManager.instance.setString('factory_reset_pending', '{oops'); - expect(FactoryResetStore().load(), isNull); - }); } diff --git a/untranslated.json b/untranslated.json index 74e91850..11b9039f 100644 --- a/untranslated.json +++ b/untranslated.json @@ -87,11 +87,6 @@ "factoryResetSentTitle", "factoryResetSentBody", "factoryResetSentBleBody", - "factoryResetCompleteTitle", - "factoryResetCompleteBody", - "factoryResetCompleteKeptBody", - "factoryResetNotResetTitle", - "factoryResetNotResetBody", "factoryResetDeleteFailedTitle", "factoryResetDeleteFailedBody", "settings_blePin", @@ -481,11 +476,6 @@ "factoryResetSentTitle", "factoryResetSentBody", "factoryResetSentBleBody", - "factoryResetCompleteTitle", - "factoryResetCompleteBody", - "factoryResetCompleteKeptBody", - "factoryResetNotResetTitle", - "factoryResetNotResetBody", "factoryResetDeleteFailedTitle", "factoryResetDeleteFailedBody", "settings_blePin", @@ -875,11 +865,6 @@ "factoryResetSentTitle", "factoryResetSentBody", "factoryResetSentBleBody", - "factoryResetCompleteTitle", - "factoryResetCompleteBody", - "factoryResetCompleteKeptBody", - "factoryResetNotResetTitle", - "factoryResetNotResetBody", "factoryResetDeleteFailedTitle", "factoryResetDeleteFailedBody", "settings_blePin", @@ -1269,11 +1254,6 @@ "factoryResetSentTitle", "factoryResetSentBody", "factoryResetSentBleBody", - "factoryResetCompleteTitle", - "factoryResetCompleteBody", - "factoryResetCompleteKeptBody", - "factoryResetNotResetTitle", - "factoryResetNotResetBody", "factoryResetDeleteFailedTitle", "factoryResetDeleteFailedBody", "settings_blePin", @@ -1663,11 +1643,6 @@ "factoryResetSentTitle", "factoryResetSentBody", "factoryResetSentBleBody", - "factoryResetCompleteTitle", - "factoryResetCompleteBody", - "factoryResetCompleteKeptBody", - "factoryResetNotResetTitle", - "factoryResetNotResetBody", "factoryResetDeleteFailedTitle", "factoryResetDeleteFailedBody", "settings_blePin", @@ -2057,11 +2032,6 @@ "factoryResetSentTitle", "factoryResetSentBody", "factoryResetSentBleBody", - "factoryResetCompleteTitle", - "factoryResetCompleteBody", - "factoryResetCompleteKeptBody", - "factoryResetNotResetTitle", - "factoryResetNotResetBody", "factoryResetDeleteFailedTitle", "factoryResetDeleteFailedBody", "settings_blePin", @@ -2451,11 +2421,6 @@ "factoryResetSentTitle", "factoryResetSentBody", "factoryResetSentBleBody", - "factoryResetCompleteTitle", - "factoryResetCompleteBody", - "factoryResetCompleteKeptBody", - "factoryResetNotResetTitle", - "factoryResetNotResetBody", "factoryResetDeleteFailedTitle", "factoryResetDeleteFailedBody", "settings_blePin", @@ -2845,11 +2810,6 @@ "factoryResetSentTitle", "factoryResetSentBody", "factoryResetSentBleBody", - "factoryResetCompleteTitle", - "factoryResetCompleteBody", - "factoryResetCompleteKeptBody", - "factoryResetNotResetTitle", - "factoryResetNotResetBody", "factoryResetDeleteFailedTitle", "factoryResetDeleteFailedBody", "settings_blePin", @@ -3239,11 +3199,6 @@ "factoryResetSentTitle", "factoryResetSentBody", "factoryResetSentBleBody", - "factoryResetCompleteTitle", - "factoryResetCompleteBody", - "factoryResetCompleteKeptBody", - "factoryResetNotResetTitle", - "factoryResetNotResetBody", "factoryResetDeleteFailedTitle", "factoryResetDeleteFailedBody", "settings_blePin", @@ -3633,11 +3588,6 @@ "factoryResetSentTitle", "factoryResetSentBody", "factoryResetSentBleBody", - "factoryResetCompleteTitle", - "factoryResetCompleteBody", - "factoryResetCompleteKeptBody", - "factoryResetNotResetTitle", - "factoryResetNotResetBody", "factoryResetDeleteFailedTitle", "factoryResetDeleteFailedBody", "settings_blePin", @@ -4027,11 +3977,6 @@ "factoryResetSentTitle", "factoryResetSentBody", "factoryResetSentBleBody", - "factoryResetCompleteTitle", - "factoryResetCompleteBody", - "factoryResetCompleteKeptBody", - "factoryResetNotResetTitle", - "factoryResetNotResetBody", "factoryResetDeleteFailedTitle", "factoryResetDeleteFailedBody", "settings_blePin", @@ -4421,11 +4366,6 @@ "factoryResetSentTitle", "factoryResetSentBody", "factoryResetSentBleBody", - "factoryResetCompleteTitle", - "factoryResetCompleteBody", - "factoryResetCompleteKeptBody", - "factoryResetNotResetTitle", - "factoryResetNotResetBody", "factoryResetDeleteFailedTitle", "factoryResetDeleteFailedBody", "settings_blePin", @@ -4815,11 +4755,6 @@ "factoryResetSentTitle", "factoryResetSentBody", "factoryResetSentBleBody", - "factoryResetCompleteTitle", - "factoryResetCompleteBody", - "factoryResetCompleteKeptBody", - "factoryResetNotResetTitle", - "factoryResetNotResetBody", "factoryResetDeleteFailedTitle", "factoryResetDeleteFailedBody", "settings_blePin", @@ -5209,11 +5144,6 @@ "factoryResetSentTitle", "factoryResetSentBody", "factoryResetSentBleBody", - "factoryResetCompleteTitle", - "factoryResetCompleteBody", - "factoryResetCompleteKeptBody", - "factoryResetNotResetTitle", - "factoryResetNotResetBody", "factoryResetDeleteFailedTitle", "factoryResetDeleteFailedBody", "settings_blePin", @@ -5603,11 +5533,6 @@ "factoryResetSentTitle", "factoryResetSentBody", "factoryResetSentBleBody", - "factoryResetCompleteTitle", - "factoryResetCompleteBody", - "factoryResetCompleteKeptBody", - "factoryResetNotResetTitle", - "factoryResetNotResetBody", "factoryResetDeleteFailedTitle", "factoryResetDeleteFailedBody", "settings_blePin", @@ -5997,11 +5922,6 @@ "factoryResetSentTitle", "factoryResetSentBody", "factoryResetSentBleBody", - "factoryResetCompleteTitle", - "factoryResetCompleteBody", - "factoryResetCompleteKeptBody", - "factoryResetNotResetTitle", - "factoryResetNotResetBody", "factoryResetDeleteFailedTitle", "factoryResetDeleteFailedBody", "settings_blePin", @@ -6391,11 +6311,6 @@ "factoryResetSentTitle", "factoryResetSentBody", "factoryResetSentBleBody", - "factoryResetCompleteTitle", - "factoryResetCompleteBody", - "factoryResetCompleteKeptBody", - "factoryResetNotResetTitle", - "factoryResetNotResetBody", "factoryResetDeleteFailedTitle", "factoryResetDeleteFailedBody", "settings_blePin",