let omemoOnly config overwrite OmemoSetting

This commit is contained in:
Daniel Gultsch 2022-10-01 11:26:52 +02:00
parent 5735bca517
commit d435c1f2ae
4 changed files with 39 additions and 20 deletions

View file

@ -15,10 +15,9 @@ import eu.siacs.conversations.xmpp.chatstate.ChatState;
public final class Config { public final class Config {
private static final int UNENCRYPTED = 1; private static final int UNENCRYPTED = 1;
private static final int OPENPGP = 2; private static final int OPENPGP = 2;
private static final int OTR = 4;
private static final int OMEMO = 8; 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() { public static boolean supportUnencrypted() {
return (ENCRYPTION_MASK & UNENCRYPTED) != 0; return (ENCRYPTION_MASK & UNENCRYPTED) != 0;
@ -32,6 +31,10 @@ public final class Config {
return (ENCRYPTION_MASK & OMEMO) != 0; return (ENCRYPTION_MASK & OMEMO) != 0;
} }
public static boolean omemoOnly() {
return !multipleEncryptionChoices() && supportOmemo();
}
public static boolean multipleEncryptionChoices() { public static boolean multipleEncryptionChoices() {
return (ENCRYPTION_MASK & (ENCRYPTION_MASK - 1)) != 0; return (ENCRYPTION_MASK & (ENCRYPTION_MASK - 1)) != 0;
} }

View file

@ -34,6 +34,9 @@ import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import com.google.common.base.Strings;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.ui.SettingsActivity; import eu.siacs.conversations.ui.SettingsActivity;
@ -52,8 +55,13 @@ public class OmemoSetting {
} }
public static void load(final Context context, final SharedPreferences sharedPreferences) { 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)); final String value = sharedPreferences.getString(SettingsActivity.OMEMO_SETTING, context.getResources().getString(R.string.omemo_setting_default));
switch (value) { switch (Strings.nullToEmpty(value)) {
case "always": case "always":
always = true; always = true;
encryption = Message.ENCRYPTION_AXOLOTL; encryption = Message.ENCRYPTION_AXOLOTL;

View file

@ -298,13 +298,23 @@ public class SettingsActivity extends XmppActivity implements OnSharedPreference
deleteOmemoPreference.setOnPreferenceClickListener( deleteOmemoPreference.setOnPreferenceClickListener(
preference -> deleteOmemoIdentities()); 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() { private void changeOmemoSettingSummary() {
ListPreference omemoPreference = final ListPreference omemoPreference =
(ListPreference) mSettingsFragment.findPreference(OMEMO_SETTING); (ListPreference) mSettingsFragment.findPreference(OMEMO_SETTING);
if (omemoPreference != null) { if (omemoPreference == null) {
String value = omemoPreference.getValue(); return;
}
final String value = omemoPreference.getValue();
switch (value) { switch (value) {
case "always": case "always":
omemoPreference.setSummary(R.string.pref_omemo_setting_summary_always); omemoPreference.setSummary(R.string.pref_omemo_setting_summary_always);
@ -316,9 +326,6 @@ public class SettingsActivity extends XmppActivity implements OnSharedPreference
omemoPreference.setSummary(R.string.pref_omemo_setting_summary_default_off); omemoPreference.setSummary(R.string.pref_omemo_setting_summary_default_off);
break; break;
} }
} else {
Log.d(Config.LOGTAG, "unable to find preference named " + OMEMO_SETTING);
}
} }
private boolean isCallable(final Intent i) { private boolean isCallable(final Intent i) {

View file

@ -15,7 +15,8 @@
android:targetPackage="com.huawei.systemmanager" /> android:targetPackage="com.huawei.systemmanager" />
</PreferenceScreen> </PreferenceScreen>
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory android:title="@string/pref_privacy"> <PreferenceCategory android:title="@string/pref_privacy"
android:key="privacy">
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="@bool/confirm_messages" android:defaultValue="@bool/confirm_messages"
android:key="confirm_messages" android:key="confirm_messages"