Skip to content

Commit

Permalink
Fix config bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
topjohnwu committed Mar 13, 2019
1 parent ecf3d30 commit 650b2ce
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions app/src/main/java/com/topjohnwu/magisk/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,19 +239,19 @@ public static <T> T get(String key) {
App app = App.self;
switch (getConfigType(key)) {
case PREF_INT:
return (T) (Integer) app.prefs.getInt(key, 0);
return (T) (Integer) app.prefs.getInt(key, getDef(key));
case PREF_STR_INT:
return (T) (Integer) Utils.getPrefsInt(app.prefs, key, 0);
return (T) (Integer) Utils.getPrefsInt(app.prefs, key, getDef(key));
case PREF_BOOL:
return (T) (Boolean) app.prefs.getBoolean(key, false);
return (T) (Boolean) app.prefs.getBoolean(key, getDef(key));
case PREF_STR:
return (T) app.prefs.getString(key, null);
return (T) app.prefs.getString(key, getDef(key));
case DB_INT:
return (T) (Integer) app.mDB.getSettings(key, 0);
return (T) (Integer) app.mDB.getSettings(key, getDef(key));
case DB_BOOL:
return (T) (Boolean) (app.mDB.getSettings(key, 0) != 0);
return (T) (Boolean) (app.mDB.getSettings(key, getDef(key) ? 1 : 0) != 0);
case DB_STR:
return (T) app.mDB.getStrings(key, null);
return (T) app.mDB.getStrings(key, getDef(key));
}
/* Will never get here (IllegalArgumentException in getConfigType) */
return null;
Expand Down Expand Up @@ -342,6 +342,24 @@ public static void remove(String key) {
//defs.put(Key.SU_MANAGER, null);
}

private static <T> T getDef(String key) {
Object val = defs.get(key);
switch (getConfigType(key)) {
case PREF_INT:
case DB_INT:
case PREF_STR_INT:
return val != null ? (T) val : (T) (Integer) 0;
case DB_BOOL:
case PREF_BOOL:
return val != null ? (T) val : (T) (Boolean) false;
case DB_STR:
case PREF_STR:
return (T) val;
}
/* Will never get here (IllegalArgumentException in getConfigType) */
return null;
}

private static void setDefs(SharedPreferences pref, SharedPreferences.Editor editor) {
App app = App.self;
for (String key : defs.keySet()) {
Expand Down

0 comments on commit 650b2ce

Please sign in to comment.