Skip to content

Commit

Permalink
fix: config migration logic causes kits to deinit on re-upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
willpassidomo committed Jul 1, 2022
1 parent e9d5c30 commit d3cfdc5
Showing 1 changed file with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public class ConfigManager {
static final String DATAPLAN_BLOCK_USER_ATTRIBUTES = "ua";
static final String DATAPLAN_BLOCK_USER_IDENTITIES = "id";
static final String KIT_CONFIG_KEY = "kit_config";
static final String MIGRATED_TO_KIT_SHARED_PREFS = "is_mig_kit_sp";

private static final int DEVMODE_UPLOAD_INTERVAL_MILLISECONDS = 10 * 1000;
private static final int DEFAULT_MAX_ALIAS_WINDOW_DAYS = 90;
Expand Down Expand Up @@ -180,7 +181,7 @@ private void restoreCoreConfig() {
@Nullable
@WorkerThread
public JSONArray getLatestKitConfiguration() {
String oldConfig = getKitConfigPreferences().getString(KIT_CONFIG_KEY, new JSONArray().toString());
String oldConfig = getKitConfigPreferences().getString(KIT_CONFIG_KEY, null);
if (!MPUtility.isEmpty(oldConfig)) {
try {
return new JSONArray(oldConfig);
Expand Down Expand Up @@ -237,15 +238,19 @@ static void deleteConfigManager(Context context) {
}

void migrateConfigIfNeeded() {
String configString = sPreferences.getString(CONFIG_JSON, null);
if (!MPUtility.isEmpty(configString)) {
try {
//save ourselves some time and only parse the JSONObject if might contain the embedded kits key
if (configString.contains("\"" + KEY_EMBEDDED_KITS + "\":")) {
saveConfigJson(new JSONObject(configString), getEtag(), getIfModified(), getConfigTimestamp());
}
} catch (JSONException jse) {
if (!sPreferences.getBoolean(MIGRATED_TO_KIT_SHARED_PREFS, false)) {
sPreferences.edit().putBoolean(MIGRATED_TO_KIT_SHARED_PREFS, true).apply();
String configString = sPreferences.getString(CONFIG_JSON, null);
if (!MPUtility.isEmpty(configString)) {
try {
//save ourselves some time and only parse the JSONObject if might contain the embedded kits key
if (configString.contains("\"" + KEY_EMBEDDED_KITS + "\":")) {
Logger.info("Migrating kit configuration");
saveConfigJson(new JSONObject(configString), getEtag(), getIfModified(), getConfigTimestamp());
}
} catch (JSONException jse) {

}
}
}
}
Expand Down

0 comments on commit d3cfdc5

Please sign in to comment.