Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: config migration logic causes kits to deinit on re-upgrade #196

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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