From 9132ad0cd1928c62a97a0d27bdb4d56849a655d8 Mon Sep 17 00:00:00 2001 From: awaik Date: Tue, 13 Sep 2022 20:08:33 +0300 Subject: [PATCH] fix: bug with secure storage https://github.com/mogol/flutter_secure_storage/issues/43#issuecomment-471642126 --- .github/workflows/build_from_tags_ci.yml | 13 ++++++++++--- android/app/src/main/AndroidManifest.xml | 4 +++- android/app/src/main/res/xml/backup_rules.xml | 4 ++++ lib/core/app.dart | 16 ++++++++++++++-- lib/features/main/main_screen.dart | 7 ++++++- lib/main.dart | 9 ++++++++- 6 files changed, 45 insertions(+), 8 deletions(-) create mode 100644 android/app/src/main/res/xml/backup_rules.xml diff --git a/.github/workflows/build_from_tags_ci.yml b/.github/workflows/build_from_tags_ci.yml index a9c3001e..1df3fe4e 100644 --- a/.github/workflows/build_from_tags_ci.yml +++ b/.github/workflows/build_from_tags_ci.yml @@ -1,4 +1,11 @@ -# https://stefma.medium.com/how-to-store-a-android-keystore-safely-on-github-actions-f0cef9413784 +# Creates release when tag pushed +# Create tag: +# git tag +# Push it: +# git push origin +# After that release will be created. + +# Used Github secrets # KEY_PROPERTIES - file # RELEASE_AGORADESK_KEYSTORE # RELEASE_AGORADESK_KEYSTORE_SECRET @@ -14,8 +21,8 @@ name: BuildFromTagsCI on: push: -# tags: -# - "v*.*.*" + tags: + - "v*.*.*" jobs: build: name: Build APK & AppBundle diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 3a05e0e6..458c38f4 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -1,6 +1,8 @@ + package="com.agoradesk.app" + android:allowBackup="false" + android:fullBackupContent="@xml/backup_rules"> diff --git a/android/app/src/main/res/xml/backup_rules.xml b/android/app/src/main/res/xml/backup_rules.xml new file mode 100644 index 00000000..7eb6e3e6 --- /dev/null +++ b/android/app/src/main/res/xml/backup_rules.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/lib/core/app.dart b/lib/core/app.dart index 6d909413..76533bb2 100644 --- a/lib/core/app.dart +++ b/lib/core/app.dart @@ -237,12 +237,24 @@ class _AppState extends State with WidgetsBindingObserver, StringMixin, Cou } /// Configure [ApiClient] with cache - final String? token = await _secureStorage.read(SecureStorageKey.token); + String? token; + try { + token = await _secureStorage.read(SecureStorageKey.token); + } catch (e) { + _secureStorage.deleteAll(); + } + debugPrint('[init app, API token from secured storage] $token'); _api.accessToken = token; /// Set pin code state - final String? pin = await _secureStorage.read(SecureStorageKey.pin); + String? pin; + try { + pin = await _secureStorage.read(SecureStorageKey.pin); + } catch (e) { + _secureStorage.deleteAll(); + } + appState.hasPinCode = token != null && pin != null; appState.pinCode = pin; await _afterConfigInit(); diff --git a/lib/features/main/main_screen.dart b/lib/features/main/main_screen.dart index 3871b865..e1673cc3 100644 --- a/lib/features/main/main_screen.dart +++ b/lib/features/main/main_screen.dart @@ -153,7 +153,12 @@ class _MainScreenState extends State { } else { await SecureStorage.ensureInitialized(); final SecureStorage _secureStorage = SecureStorage(); - final l = await _secureStorage.read(SecureStorageKey.locale); + String? l; + try { + l = await _secureStorage.read(SecureStorageKey.locale); + } catch (e) { + _secureStorage.deleteAll(); + } final langCode = l ?? Platform.localeName.substring(0, 2); await FlutterForegroundTask.startService( notificationTitle: diff --git a/lib/main.dart b/lib/main.dart index c4159765..22130921 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -139,7 +139,14 @@ Future _firebaseMessagingBackgroundHandler(RemoteMessage message) async { try { await SecureStorage.ensureInitialized(); final SecureStorage _secureStorage = SecureStorage(); - final l = await _secureStorage.read(SecureStorageKey.locale); + + String? l; + try { + l = await _secureStorage.read(SecureStorageKey.locale); + } catch (e) { + _secureStorage.deleteAll(); + } + final String langCode = l ?? Platform.localeName.substring(0, 2); final PushModel push = PushModel.fromJson(message.data); final Map payload = push.toJson().map((key, value) => MapEntry(key, value?.toString() ?? ''));