fix: Start on Android and Linux

This commit is contained in:
Krille Fear 2021-11-18 07:59:35 +01:00
parent 6b5a121318
commit 28cfb6e5f9
5 changed files with 44 additions and 21 deletions

View File

@ -6,4 +6,5 @@
-keep class io.flutter.view.** { *; }
-keep class io.flutter.** { *; }
-keep class io.flutter.plugins.** { *; }
-dontwarn io.flutter.embedding.**
-dontwarn io.flutter.embedding.**
-keep class net.sqlcipher.** { *; }

View File

@ -10,6 +10,7 @@ import 'package:encrypt/encrypt.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:matrix/matrix.dart';
import 'package:path_provider/path_provider.dart';
import 'package:sqflite_common_ffi/sqflite_ffi.dart' as ffi;
import 'package:sqflite_sqlcipher/sqflite.dart' as sqflite;
class FlutterFluffyBoxDatabase extends FluffyBoxDatabase {
@ -27,26 +28,25 @@ class FlutterFluffyBoxDatabase extends FluffyBoxDatabase {
static Future<FluffyBoxDatabase> databaseBuilder(Client client) async {
Logs().d('Open FluffyBox...');
String? password;
try {
// Workaround for secure storage is calling Platform.operatingSystem on web
if (kIsWeb) throw MissingPluginException();
if (!kIsWeb && (Platform.isAndroid || Platform.isIOS)) {
try {
const secureStorage = FlutterSecureStorage();
final containsEncryptionKey =
await secureStorage.containsKey(key: _cipherStorageKey);
if (!containsEncryptionKey) {
final key = SecureRandom(_cipherStorageKeyLength).base64;
await secureStorage.write(
key: _cipherStorageKey,
value: key,
);
}
const secureStorage = FlutterSecureStorage();
final containsEncryptionKey =
await secureStorage.containsKey(key: _cipherStorageKey);
if (!containsEncryptionKey) {
final key = SecureRandom(_cipherStorageKeyLength).base64;
await secureStorage.write(
key: _cipherStorageKey,
value: key,
);
// workaround for if we just wrote to the key and it still doesn't exist
password = await secureStorage.read(key: _cipherStorageKey);
if (password == null) throw MissingPluginException();
} on MissingPluginException catch (_) {
Logs().i('FluffyBox encryption is not supported on this platform');
}
// workaround for if we just wrote to the key and it still doesn't exist
password = await secureStorage.read(key: _cipherStorageKey);
if (password == null) throw MissingPluginException();
} on MissingPluginException catch (_) {
Logs().i('FluffyBox encryption is not supported on this platform');
}
final db = FluffyBoxDatabase(
@ -63,7 +63,18 @@ class FlutterFluffyBoxDatabase extends FluffyBoxDatabase {
String? password,
) async {
final path = await _findDatabasePath(client);
return await sqflite.openDatabase(path, password: password);
try {
if (Platform.isAndroid || Platform.isIOS) {
//opensqflite.open.overrideFor(sqlite3.OperatingSystem.android, openCipherOnAndroid);
final db = await sqflite.openDatabase(path, password: password);
return db;
}
final db = await ffi.databaseFactoryFfi.openDatabase(path);
return db;
} catch (_) {
File(path).delete();
rethrow;
}
}
static Future<String> _findDatabasePath(Client client) async {

View File

@ -1319,7 +1319,7 @@ packages:
source: hosted
version: "2.0.1+1"
sqflite_common_ffi:
dependency: transitive
dependency: "direct main"
description:
name: sqflite_common_ffi
url: "https://pub.dartlang.org"
@ -1332,6 +1332,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
sqlcipher_flutter_libs:
dependency: "direct main"
description:
name: sqlcipher_flutter_libs
url: "https://pub.dartlang.org"
source: hosted
version: "0.5.1"
sqlite3:
dependency: transitive
description:

View File

@ -67,7 +67,9 @@ dependencies:
sentry: ^6.0.1
share: ^2.0.4
slugify: ^2.0.0
sqflite_common_ffi: ^2.1.0
sqflite_sqlcipher: ^2.1.0
sqlcipher_flutter_libs: ^0.5.1
swipe_to_action: ^0.2.0
uni_links: ^0.5.1
unifiedpush: ^1.0.6

View File

@ -67,6 +67,8 @@ parts:
stage-packages:
- libsecret-1-dev
- libjsoncpp-dev
- libsqlite3-0
- libsqlite3-dev
gnome-3-28-extension:
build-packages:
- gcc