Skip to content

Commit 8335c66

Browse files
committed
mobile: pin shared_preferences_android to 2.4.28; storage can no longer hang the app
The pairing finally worked on the PC (paired device d_122677006c20674e at 20:48, with the phone's own credentials) - but the user reported Settings spinning forever, and the cause is now identified: shared_preferences_android 2.5.0 looks up Kotlin classes - kotlin.coroutines.Continuation and friends - by name through package:jni, and R8 renames them in release builds, so every preferences call in a release APK throws NoSuchMethodError at getAll (flutter/flutter#194649). Debug and flutter test never see it, which is why 184 green tests never predicted it. The Android implementation is pinned to 2.4.28, the last version before the JNI backend. And because a storage channel can break in other ways too, neither the pairing store nor the settings loader can take it out with it anymore: both catch, both say exactly why on the trace, and Settings now always reaches its controls (defaults when storage is unreadable) - no spin forever, and the settings screen carries the same trace strip. Harden at the screen level too: the pairing screen's strip already had a cap; the settings screen now shows the strip, so a future failure names itself where the user can read it.
1 parent 76ee743 commit 8335c66

5 files changed

Lines changed: 62 additions & 49 deletions

File tree

‎mobile/lib/screens/settings_screen.dart‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'package:provider/provider.dart';
33

44
import '../state/settings.dart';
55
import '../theme/tokens.dart';
6+
import '../ui/diagnostics_strip.dart';
67
import '../ui/haptics.dart';
78

89
/// The settings screen.
@@ -56,8 +57,7 @@ class SettingsScreen extends StatelessWidget {
5657
TapDeskSpace.s6,
5758
),
5859
children: [
59-
_SectionLabel('This phone'),
60-
_Card(children: [
60+
_SectionLabel('This phone'), _Card(children: [
6161
_ToggleRow(
6262
title: 'Haptic feedback',
6363
subtitle:
@@ -131,6 +131,10 @@ class SettingsScreen extends StatelessWidget {
131131
_ForgetRow(settings: settings),
132132
]),
133133
const SizedBox(height: TapDeskSpace.s5),
134+
// The same trace the pairing and controls screens show: a
135+
// settings failure that lands here has a name here.
136+
const DiagnosticsStrip(),
137+
const SizedBox(height: TapDeskSpace.s5),
134138
const _Diagnostics(),
135139
],
136140
),

‎mobile/lib/state/pairing_store.dart‎

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import 'dart:convert';
33
import 'package:flutter/foundation.dart';
44
import 'package:shared_preferences/shared_preferences.dart';
55

6+
import 'diagnostics.dart';
7+
68
import '../transport/pairing_payload.dart';
79

810
/// A PC this phone has paired with before.
@@ -121,19 +123,29 @@ class PairingStore extends ChangeNotifier {
121123
PairedDevice? get mostRecent => _devices.isEmpty ? null : _devices.first;
122124

123125
Future<void> load() async {
124-
_prefs ??= await SharedPreferences.getInstance();
125-
final raw = _prefs?.getStringList(_prefsKey) ?? const [];
126-
_devices
127-
..clear()
128-
..addAll(raw
129-
.map((e) {
130-
try {
131-
return PairedDevice.fromJson(jsonDecode(e) as Map<String, dynamic>);
132-
} catch (_) {
133-
return null;
134-
}
135-
})
136-
.whereType<PairedDevice>());
126+
try {
127+
_prefs ??= await SharedPreferences.getInstance();
128+
final raw = _prefs?.getStringList(_prefsKey) ?? const [];
129+
_devices
130+
..clear()
131+
..addAll(raw
132+
.map((e) {
133+
try {
134+
return PairedDevice.fromJson(
135+
jsonDecode(e) as Map<String, dynamic>);
136+
} catch (_) {
137+
return null;
138+
}
139+
})
140+
.whereType<PairedDevice>());
141+
} catch (error) {
142+
// A broken preferences channel must not take the pairing flow with it:
143+
// an empty remembered list still pairs from a fresh scan, which is the
144+
// whole handshake. Unreadable storage is a named failure, not a hang -
145+
// shared_preferences_android 2.5.0 shipped exactly such a release-mode
146+
// channel break (flutter/flutter#194649) and this survived it.
147+
trace.add('stored pairings unreadable ($error); starting empty');
148+
}
137149
_sort();
138150
notifyListeners();
139151
}

‎mobile/lib/state/settings.dart‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import 'package:flutter/foundation.dart';
22

3+
import 'diagnostics.dart';
4+
35
/// What the computer is actually doing, as last reported by it.
46
///
57
/// These are not the user's settings. They are the companion's, and the phone
@@ -191,14 +193,24 @@ class AppSettings extends ChangeNotifier {
191193
bool get isConnectedToComputer => _remote.known;
192194

193195
/// Load stored preferences. Safe to call more than once.
196+
///
197+
/// Failure-proof on purpose: opened settings that spin forever are worse
198+
/// than controls built from defaults, and a broken preferences channel has
199+
/// actually shipped (shared_preferences_android 2.5.0, release-mode only -
200+
/// flutter/flutter#194649). A phone that cannot read its keys gets its
201+
/// defaults and one named trace line, not a permanent spinner.
194202
Future<void> load() async {
195203
if (_loaded) return;
196-
_haptics = await _storage.readBool(_kHaptics) ?? true;
197-
_leftHanded = await _storage.readBool(_kLeftHanded) ?? false;
198-
_keepAwake = await _storage.readBool(_kKeepAwake) ?? true;
199-
_wantedCursorSpeed =
200-
await _storage.readDouble(_kCursorSpeed) ?? 1.0;
201-
_wantedAccel = await _storage.readDouble(_kAccel) ?? 1.6;
204+
try {
205+
_haptics = await _storage.readBool(_kHaptics) ?? true;
206+
_leftHanded = await _storage.readBool(_kLeftHanded) ?? false;
207+
_keepAwake = await _storage.readBool(_kKeepAwake) ?? true;
208+
_wantedCursorSpeed =
209+
await _storage.readDouble(_kCursorSpeed) ?? 1.0;
210+
_wantedAccel = await _storage.readDouble(_kAccel) ?? 1.6;
211+
} catch (error) {
212+
trace.add('stored settings unreadable ($error); using defaults');
213+
}
202214
_loaded = true;
203215
notifyListeners();
204216
}

‎mobile/pubspec.lock‎

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -192,22 +192,6 @@ packages:
192192
url: "https://pub.dev"
193193
source: hosted
194194
version: "4.1.2"
195-
jni:
196-
dependency: transitive
197-
description:
198-
name: jni
199-
sha256: "6b9ca0602fef0230e83149afbe3f9f8227e94f2bbe84a1da4f14d699742f402d"
200-
url: "https://pub.dev"
201-
source: hosted
202-
version: "1.1.0"
203-
jni_util:
204-
dependency: transitive
205-
description:
206-
name: jni_util
207-
sha256: "1ba86da04a5f2bf18fde2edb235587e70c5b0fc5bd4ba955f46b00942c3fc35f"
208-
url: "https://pub.dev"
209-
source: hosted
210-
version: "1.0.0"
211195
js:
212196
dependency: transitive
213197
description:
@@ -304,14 +288,6 @@ packages:
304288
url: "https://pub.dev"
305289
source: hosted
306290
version: "9.5.0"
307-
package_config:
308-
dependency: transitive
309-
description:
310-
name: package_config
311-
sha256: ffcf4cf3d6c0b74ac43708d9f56625506e8a68aa935abe9d267a7330f320eb5d
312-
url: "https://pub.dev"
313-
source: hosted
314-
version: "3.0.0"
315291
package_info_plus:
316292
dependency: transitive
317293
description:
@@ -441,13 +417,13 @@ packages:
441417
source: hosted
442418
version: "2.5.6"
443419
shared_preferences_android:
444-
dependency: transitive
420+
dependency: "direct overridden"
445421
description:
446422
name: shared_preferences_android
447-
sha256: b90caa27669d5f3ef9918d55343b44000f088ee9d4685ed822310848004c793e
423+
sha256: "1e12aafe408aa50da80edfd679a2a6bf63ba7ab37c7fa98286da459a757b3399"
448424
url: "https://pub.dev"
449425
source: hosted
450-
version: "2.5.0"
426+
version: "2.4.28"
451427
shared_preferences_foundation:
452428
dependency: transitive
453429
description:

‎mobile/pubspec.yaml‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ publish_to: 'none'
44

55
# Shown in the app store listing and in the website's download card.
66
# Kept in step with docs/protocol.md; bump only with the protocol.
7-
version: 1.0.0+8
7+
version: 1.0.0+9
88

99
environment:
1010
sdk: ^3.13.5
@@ -63,6 +63,15 @@ dev_dependencies:
6363
dependency_overrides:
6464
path_provider_android: 2.2.23
6565

66+
# 2.5.0 looks up Kotlin classes by name through JNI (package:jni), and R8
67+
# renames those classes in release builds - so every release-mode
68+
# preferences call throws NoSuchMethodError at getAll, which on the phone
69+
# took Settings (spinner forever) and the pairing store down with it.
70+
# flutter/flutter#194649. 2.4.28 is the last version before the JNI
71+
# backend, and still receives updates: unpin once that issue ships a fix
72+
# and re-verify with `flutter build apk --release`.
73+
shared_preferences_android: 2.4.28
74+
6675
flutter:
6776
uses-material-design: true
6877
assets:

0 commit comments

Comments
 (0)