Skip to content

Commit 1178daf

Browse files
committed
Fixed issue with oppen ssl on some android devices
1 parent 75b049f commit 1178daf

File tree

2 files changed

+32
-25
lines changed

2 files changed

+32
-25
lines changed

docs/changelog.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Mobileraker - Changelog
22

3+
## [2.6.12] - 2024-02-20
4+
5+
### Bug Fixes
6+
7+
- Fixed an issue that prevented the app from starting on some android devices.
8+
39
## [2.6.11] - 2024-02-02
410

511
### Major Updates

lib/app_setup.dart

+26-25
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,14 @@ import 'package:worker_manager/worker_manager.dart';
4444

4545
part 'app_setup.g.dart';
4646

47+
const _hiveKeyName = 'hive_key';
48+
4749
setupBoxes() async {
4850
await Hive.initFlutter();
4951

50-
Uint8List keyMaterial = await _hiveKey();
52+
// For the key is not needed. It can be used to encrypt the data in the box. But this is not a high security app with sensitive data.
53+
// Caused problems on some devices and the key is not used for hive encryption.
54+
// Uint8List keyMaterial = await _hiveKey();
5155

5256
// Ignore old/deperecates types!
5357
// 2 - WebcamSetting
@@ -98,7 +102,8 @@ setupBoxes() async {
98102
// Hive.deleteBoxFromDisk('printers');
99103

100104
try {
101-
await openBoxes(keyMaterial);
105+
// await openBoxes(keyMaterial);
106+
await openBoxes();
102107
Hive.box<Machine>("printers").values.forEach((element) {
103108
logger.i('Machine in box is ${element.logName}#${element.hashCode}');
104109
// ToDo remove after machine migration!
@@ -130,7 +135,6 @@ setupBoxes() async {
130135
}
131136

132137
Future<Uint8List> _hiveKey() async {
133-
const keyName = 'hive_key';
134138

135139
/// due to the move to encSharedPref it could be that the hive_key is still in the normmal shared pref
136140
/// Therfore first try to load it from the secureShared pref else try the normal one else generate a new one
@@ -141,38 +145,35 @@ Future<Uint8List> _hiveKey() async {
141145
aOptions: AndroidOptions(encryptedSharedPreferences: false),
142146
);
143147

144-
Uint8List? encryptionKey;
145-
try {
146-
encryptionKey = await secureStorage.read(key: keyName).then((value) => value?.let(base64Decode));
147-
} on PlatformException catch (e) {
148-
logger.e('Error while reading hive_key from secure storage', e);
149-
encryptionKey = await nonEncSharedPrefSecureStorage
150-
.read(key: keyName)
151-
.then((value) => value?.let(base64Decode))
152-
.onError((error, stackTrace) {
153-
logger.e('Error while reading hive_key from non-encryptedSharedPreferences', error, stackTrace);
154-
return null;
155-
});
156-
await nonEncSharedPrefSecureStorage.delete(key: keyName);
157-
await secureStorage.write(
158-
key: keyName,
159-
value: encryptionKey?.let(base64Encode),
160-
);
161-
logger.e(
162-
'Transfered hive_key from non-encryptedSharedPreferences to secureStorage using encryptedSharedPreferences',
163-
);
148+
Uint8List? encryptionKey = await _readStorage(secureStorage);
149+
if (encryptionKey != null) {
150+
return encryptionKey;
164151
}
165152

153+
encryptionKey ??= await _readStorage(nonEncSharedPrefSecureStorage);
166154
if (encryptionKey != null) {
155+
await secureStorage.write(key: _hiveKeyName, value: encryptionKey.let(base64Encode));
156+
await nonEncSharedPrefSecureStorage.delete(key: _hiveKeyName);
167157
return encryptionKey;
168158
}
169159

170160
final key = Hive.generateSecureKey();
171-
await secureStorage.write(key: keyName, value: base64UrlEncode(key));
161+
await secureStorage.write(key: _hiveKeyName, value: base64UrlEncode(key));
172162
return Uint8List.fromList(key);
173163
}
174164

175-
Future<List<Box>> openBoxes(Uint8List _) {
165+
Future<Uint8List?> _readStorage(FlutterSecureStorage storage) async {
166+
try {
167+
String? value = await storage.read(key: _hiveKeyName);
168+
return value?.let(base64Decode);
169+
} catch (e) {
170+
logger.e('Error while reading $_hiveKeyName from storage', e);
171+
return null;
172+
}
173+
}
174+
175+
// Future<List<Box>> openBoxes(Uint8List _) {
176+
Future<List<Box>> openBoxes() {
176177
return Future.wait([
177178
Hive.openBox<Machine>('printers').then(_migrateMachine),
178179
Hive.openBox<String>('uuidbox'),

0 commit comments

Comments
 (0)