From d435c1f2aef1454141d4f5099224b5a03d579dba Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 1 Oct 2022 11:26:52 +0200 Subject: [PATCH] let omemoOnly config overwrite OmemoSetting --- .../java/eu/siacs/conversations/Config.java | 7 +++- .../conversations/crypto/OmemoSetting.java | 10 ++++- .../conversations/ui/SettingsActivity.java | 39 +++++++++++-------- src/main/res/xml/preferences.xml | 3 +- 4 files changed, 39 insertions(+), 20 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/Config.java b/src/main/java/eu/siacs/conversations/Config.java index a3eacc9db..47226eb6e 100644 --- a/src/main/java/eu/siacs/conversations/Config.java +++ b/src/main/java/eu/siacs/conversations/Config.java @@ -15,10 +15,9 @@ import eu.siacs.conversations.xmpp.chatstate.ChatState; public final class Config { private static final int UNENCRYPTED = 1; private static final int OPENPGP = 2; - private static final int OTR = 4; private static final int OMEMO = 8; - private static final int ENCRYPTION_MASK = UNENCRYPTED | OPENPGP | OTR | OMEMO; + private static final int ENCRYPTION_MASK = UNENCRYPTED | OPENPGP | OMEMO; public static boolean supportUnencrypted() { return (ENCRYPTION_MASK & UNENCRYPTED) != 0; @@ -32,6 +31,10 @@ public final class Config { return (ENCRYPTION_MASK & OMEMO) != 0; } + public static boolean omemoOnly() { + return !multipleEncryptionChoices() && supportOmemo(); + } + public static boolean multipleEncryptionChoices() { return (ENCRYPTION_MASK & (ENCRYPTION_MASK - 1)) != 0; } diff --git a/src/main/java/eu/siacs/conversations/crypto/OmemoSetting.java b/src/main/java/eu/siacs/conversations/crypto/OmemoSetting.java index 5326ecae0..a531c39f3 100644 --- a/src/main/java/eu/siacs/conversations/crypto/OmemoSetting.java +++ b/src/main/java/eu/siacs/conversations/crypto/OmemoSetting.java @@ -34,6 +34,9 @@ import android.content.Context; import android.content.SharedPreferences; import android.preference.PreferenceManager; +import com.google.common.base.Strings; + +import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.ui.SettingsActivity; @@ -52,8 +55,13 @@ public class OmemoSetting { } public static void load(final Context context, final SharedPreferences sharedPreferences) { + if (Config.omemoOnly()) { + always = true; + encryption = Message.ENCRYPTION_AXOLOTL; + return; + } final String value = sharedPreferences.getString(SettingsActivity.OMEMO_SETTING, context.getResources().getString(R.string.omemo_setting_default)); - switch (value) { + switch (Strings.nullToEmpty(value)) { case "always": always = true; encryption = Message.ENCRYPTION_AXOLOTL; diff --git a/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java b/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java index 21d2b956c..5e21e0b26 100644 --- a/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java @@ -298,26 +298,33 @@ public class SettingsActivity extends XmppActivity implements OnSharedPreference deleteOmemoPreference.setOnPreferenceClickListener( preference -> deleteOmemoIdentities()); } + if (Config.omemoOnly()) { + final PreferenceCategory privacyCategory = + (PreferenceCategory) mSettingsFragment.findPreference("privacy"); + final Preference omemoPreference =mSettingsFragment.findPreference(OMEMO_SETTING); + if (omemoPreference != null) { + privacyCategory.removePreference(omemoPreference); + } + } } private void changeOmemoSettingSummary() { - ListPreference omemoPreference = + final ListPreference omemoPreference = (ListPreference) mSettingsFragment.findPreference(OMEMO_SETTING); - if (omemoPreference != null) { - String value = omemoPreference.getValue(); - switch (value) { - case "always": - omemoPreference.setSummary(R.string.pref_omemo_setting_summary_always); - break; - case "default_on": - omemoPreference.setSummary(R.string.pref_omemo_setting_summary_default_on); - break; - case "default_off": - omemoPreference.setSummary(R.string.pref_omemo_setting_summary_default_off); - break; - } - } else { - Log.d(Config.LOGTAG, "unable to find preference named " + OMEMO_SETTING); + if (omemoPreference == null) { + return; + } + final String value = omemoPreference.getValue(); + switch (value) { + case "always": + omemoPreference.setSummary(R.string.pref_omemo_setting_summary_always); + break; + case "default_on": + omemoPreference.setSummary(R.string.pref_omemo_setting_summary_default_on); + break; + case "default_off": + omemoPreference.setSummary(R.string.pref_omemo_setting_summary_default_off); + break; } } diff --git a/src/main/res/xml/preferences.xml b/src/main/res/xml/preferences.xml index 91b07210c..b46155836 100644 --- a/src/main/res/xml/preferences.xml +++ b/src/main/res/xml/preferences.xml @@ -15,7 +15,8 @@ android:targetPackage="com.huawei.systemmanager" /> - +