Reset options on import

pull/214/head
M66B 9 months ago
parent 0ba95456d9
commit dbbc7111e9

@ -406,19 +406,14 @@ public class ApplicationEx extends Application
case "watchdog":
ServiceSynchronize.scheduleWatchdog(this);
break;
case "secure": // privacy
case "load_emoji": // privacy
case "shortcuts": // misc
case "language": // misc
case "wal": // misc
// Should be excluded for import
restart(this, key);
break;
case "debug":
case "log_level":
Log.setLevel(this);
FairEmailLoggingProvider.setLevel(this);
break;
default:
if (FragmentOptionsBackup.RESTART_OPTIONS.contains(key))
restart(this, key);
}
} catch (Throwable ex) {
Log.e(ex);

@ -86,6 +86,7 @@ import java.security.spec.KeySpec;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
@ -135,6 +136,32 @@ public class FragmentOptionsBackup extends FragmentBase implements SharedPrefere
private static final int REQUEST_EXPORT_HANDLE = 3;
private static final int REQUEST_IMPORT_HANDLE = 4;
final static List<String> DEFER_OPTIONS = Collections.unmodifiableList(Arrays.asList(
"theme",
"beige"
));
final static List<String> RESTART_OPTIONS = Collections.unmodifiableList(Arrays.asList(
"secure", // privacy
"load_emoji", // privacy
"shortcuts", // misc
"language", // misc
"wal" // misc
));
static final String[][] RESET_ALL_OPTIONS = {
FragmentOptionsSynchronize.RESET_OPTIONS.toArray(new String[0]),
FragmentOptionsSend.RESET_OPTIONS.toArray(new String[0]),
FragmentOptionsConnection.RESET_OPTIONS.toArray(new String[0]),
FragmentOptionsDisplay.RESET_OPTIONS.toArray(new String[0]),
FragmentOptionsBehavior.RESET_OPTIONS.toArray(new String[0]),
FragmentOptionsPrivacy.RESET_OPTIONS.toArray(new String[0]),
FragmentOptionsEncryption.RESET_OPTIONS.toArray(new String[0]),
FragmentOptionsNotifications.RESET_OPTIONS.toArray(new String[0]),
//FragmentOptionsIntegrations.RESET_OPTIONS.toArray(new String[0]),
FragmentOptionsMisc.RESET_OPTIONS.toArray(new String[0])
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -1136,65 +1163,34 @@ public class FragmentOptionsBackup extends FragmentBase implements SharedPrefere
// Settings
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = prefs.edit();
for (String[] options : RESET_ALL_OPTIONS)
for (String key : options)
if (!skipOption(key) &&
!DEFER_OPTIONS.contains(key) &&
!RESTART_OPTIONS.contains(key)) {
if (BuildConfig.DEBUG && prefs.contains(key))
postProgress("Clearing " + key);
editor.remove(key);
}
JSONArray jsettings = jimport.getJSONArray("settings");
for (int s = 0; s < jsettings.length(); s++) {
JSONObject jsetting = (JSONObject) jsettings.get(s);
String key = jsetting.getString("key");
if ("pro".equals(key) && !BuildConfig.DEBUG)
continue;
if ("iab_json".equals(key) || "iab_signature".equals(key))
continue;
if ("accept_unsupported".equals(key))
continue;
if ("biometrics".equals(key) || "pin".equals(key))
continue;
if ("alert_once".equals(key) && !Helper.isXiaomi())
continue;
if ("default_folder".equals(key))
continue;
if ("background_service".equals(key) &&
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
continue;
if ("tcp_keep_alive".equals(key))
continue;
// Prevent restart
if ("secure".equals(key) ||
"load_emoji".equals(key) ||
"shortcuts".equals(key) ||
"language".equals(key) ||
"wal".equals(key)) {
postProgress("Skipping " + key + "=" + jsetting.get("value"));
continue;
}
if ("theme".equals(key) || "beige".equals(key)) {
if (DEFER_OPTIONS.contains(key)) {
defer.put(key, jsetting.get("value"));
continue;
}
if (key != null && key.startsWith("widget."))
continue;
if (key != null && key.startsWith("unset."))
continue;
if ("external_search".equals(key)) {
boolean external_search = jsetting.getBoolean("value");
Helper.enableComponent(context, ActivitySearch.class, external_search);
// Prevent restart
if (RESTART_OPTIONS.contains(key)) {
postProgress("Skipping " + key + "=" + jsetting.get("value"));
continue;
}
if ("external_storage".equals(key))
continue;
if ("reformatted_hint".equals(key))
if (skipOption(key))
continue;
Object value = jsetting.get("value");
@ -1323,6 +1319,48 @@ public class FragmentOptionsBackup extends FragmentBase implements SharedPrefere
}.setHandler(tvLog.getHandler()).execute(this, args, "setup:import");
}
private static boolean skipOption(String key) {
if ("pro".equals(key) && !BuildConfig.DEBUG)
return true;
if ("iab_json".equals(key) || "iab_signature".equals(key))
return true;
if ("accept_unsupported".equals(key))
return true;
if ("biometrics".equals(key) || "pin".equals(key))
return true;
if ("alert_once".equals(key) && !Helper.isXiaomi())
return true;
if ("default_folder".equals(key))
return true;
if ("background_service".equals(key) &&
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
return true;
if ("tcp_keep_alive".equals(key))
return true;
if ("external_storage".equals(key))
return true;
if ("reformatted_hint".equals(key))
return true;
if ("external_search".equals(key))
return true;
if (key != null && key.startsWith("widget."))
return true;
if (key != null && key.startsWith("unset."))
return true;
return false;
}
private void handleK9Import(Uri uri) {
Bundle args = new Bundle();
args.putParcelable("uri", uri);

@ -118,7 +118,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
final static int REQUEST_DEFAULT_FOLDER = 1;
private final static List<String> RESET_OPTIONS = Collections.unmodifiableList(Arrays.asList(
final static List<String> RESET_OPTIONS = Collections.unmodifiableList(Arrays.asList(
"restore_on_launch", "sync_on_launch", "double_back", "conversation_actions", "conversation_actions_replies", "language_detection",
"photo_picker", "default_snooze",
"pull", "pull_all", "autoscroll", "quick_filter", "quick_scroll", "quick_actions", "swipe_sensitivity", "foldernav",

@ -128,7 +128,7 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre
private Group grpBC;
private Group grpCustomSsl;
private final static List<String> RESET_OPTIONS = Collections.unmodifiableList(Arrays.asList(
final static List<String> RESET_OPTIONS = Collections.unmodifiableList(Arrays.asList(
"metered", "download", "download_limited", "roaming", "rlah",
"download_headers", "download_eml", "download_plain",
"require_validated", "require_validated_captive", "vpn_only",

@ -209,7 +209,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
private NumberFormat NF = NumberFormat.getNumberInstance();
private final static List<String> RESET_OPTIONS = Collections.unmodifiableList(Arrays.asList(
final static List<String> RESET_OPTIONS = Collections.unmodifiableList(Arrays.asList(
"theme", "startup",
"date", "date_week", "date_fixed", "date_bold", "date_time", "group_category",
"cards", "beige", "tabular_card_bg", "shadow_unread", "shadow_border", "shadow_highlight", "dividers", "tabular_unread_bg",

@ -118,7 +118,7 @@ public class FragmentOptionsEncryption extends FragmentBase
static final int REQUEST_IMPORT_CERTIFICATE = 1;
private final static List<String> RESET_OPTIONS = Collections.unmodifiableList(Arrays.asList(
final static List<String> RESET_OPTIONS = Collections.unmodifiableList(Arrays.asList(
"sign_default", "encrypt_default", "encrypt_auto",
"auto_verify", "auto_decrypt", "auto_undecrypt",
"openpgp_provider", "autocrypt", "autocrypt_mutual", "encrypt_subject",

@ -268,7 +268,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
private static final int REQUEST_CLASSIFIER = 1;
private static final long MIN_FILE_SIZE = 1024 * 1024L;
private final static List<String> RESET_OPTIONS = Collections.unmodifiableList(Arrays.asList(
final static List<String> RESET_OPTIONS = Collections.unmodifiableList(Arrays.asList(
"sort_answers", "shortcuts", "ical_tentative", "fts",
"classification", "class_min_probability", "class_min_difference",
"show_filtered", "haptic_feedback",

@ -135,7 +135,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
private Group grpBackground;
private Group grpTiles;
private final static List<String> RESET_OPTIONS = Collections.unmodifiableList(Arrays.asList(
final static List<String> RESET_OPTIONS = Collections.unmodifiableList(Arrays.asList(
"notify_newest_first", "notify_summary",
"notify_trash", "notify_junk", "notify_block_sender", "notify_archive", "notify_move",
"notify_reply", "notify_reply_direct",

@ -114,7 +114,7 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer
private final static int BIP39_WORDS = 6;
private final static List<String> RESET_OPTIONS = Collections.unmodifiableList(Arrays.asList(
final static List<String> RESET_OPTIONS = Collections.unmodifiableList(Arrays.asList(
"confirm_links", "sanitize_links", "adguard", "adguard_auto_update",
"check_links_dbl", "confirm_files",
"confirm_images", "ask_images", "html_always_images", "confirm_html", "ask_html",

@ -130,7 +130,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
private EditText etSendRetryMax;
private SwitchCompat swSendPartial;
private final static List<String> RESET_OPTIONS = Collections.unmodifiableList(Arrays.asList(
final static List<String> RESET_OPTIONS = Collections.unmodifiableList(Arrays.asList(
"keyboard", "keyboard_no_fullscreen",
"suggest_names", "suggest_sent", "suggested_received", "suggest_frequently", "suggest_account", "auto_identity",
"purge_contact_age", "purge_contact_freq",

@ -126,7 +126,7 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
private int textColorTertiary;
private int colorAccent;
private final static List<String> RESET_OPTIONS = Collections.unmodifiableList(Arrays.asList(
final static List<String> RESET_OPTIONS = Collections.unmodifiableList(Arrays.asList(
"enabled", "poll_interval", "auto_optimize",
"poll_metered", "poll_unmetered",
"schedule", "schedule_start", "schedule_end", "schedule_start_weekend", "schedule_end_weekend", "weekend",

Loading…
Cancel
Save