Skip to content

Commit

Permalink
Merge pull request #664 from kecson/develop
Browse files Browse the repository at this point in the history
Fix Android read data after boot
  • Loading branch information
juliansteenbakker authored May 6, 2024
2 parents eeed437 + b765ad4 commit 11cc153
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion flutter_secure_storage/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ android {
}

dependencies {
implementation "androidx.security:security-crypto:1.1.0-alpha06"
implementation "androidx.security:security-crypto:1.1.0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,22 @@ void deleteAll() {
editor.apply();
}

protected void ensureOptions(){
if (options.containsKey("sharedPreferencesName") && !((String) options.get("sharedPreferencesName")).isEmpty()) {
SHARED_PREFERENCES_NAME = (String) options.get("sharedPreferencesName");
}

if (options.containsKey("preferencesKeyPrefix") && !((String) options.get("preferencesKeyPrefix")).isEmpty()) {
ELEMENT_PREFERENCES_KEY_PREFIX = (String) options.get("preferencesKeyPrefix");
}
}
@SuppressWarnings({"ConstantConditions"})
private void ensureInitialized() {
// Check if already initialized.
// TODO: Disable for now because this will break mixed usage of secureSharedPreference
// if (preferences != null) return;

if (options.containsKey("sharedPreferencesName") && !((String) options.get("sharedPreferencesName")).isEmpty()) {
SHARED_PREFERENCES_NAME = (String) options.get("sharedPreferencesName");
}

if (options.containsKey("preferencesKeyPrefix") && !((String) options.get("preferencesKeyPrefix")).isEmpty()) {
ELEMENT_PREFERENCES_KEY_PREFIX = (String) options.get("preferencesKeyPrefix");
}
ensureOptions();

SharedPreferences nonEncryptedPreferences = applicationContext.getSharedPreferences(
SHARED_PREFERENCES_NAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public void run() {
boolean resetOnError = false;
try {
secureStorage.options = (Map<String, Object>) ((Map<String, Object>) call.arguments).get("options");
secureStorage.ensureOptions();
resetOnError = secureStorage.getResetOnError();
switch (call.method) {
case "write": {
Expand Down Expand Up @@ -189,12 +190,18 @@ public void run() {
secureStorage.deleteAll();
result.success("Data has been reset");
} catch (Exception ex) {
throw new RuntimeException(ex);
handleException(ex);
}
} else {
throw new RuntimeException(e);
handleException(e);
}
}
}

private void handleException(Exception e) {
StringWriter stringWriter = new StringWriter();
e.printStackTrace(new PrintWriter(stringWriter));
result.error("Exception encountered", call.method, stringWriter.toString());
}
}
}

0 comments on commit 11cc153

Please sign in to comment.