let omemoOnly config overwrite OmemoSetting
This commit is contained in:
parent
5735bca517
commit
d435c1f2ae
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -298,26 +298,33 @@ 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;
|
||||||
switch (value) {
|
}
|
||||||
case "always":
|
final String value = omemoPreference.getValue();
|
||||||
omemoPreference.setSummary(R.string.pref_omemo_setting_summary_always);
|
switch (value) {
|
||||||
break;
|
case "always":
|
||||||
case "default_on":
|
omemoPreference.setSummary(R.string.pref_omemo_setting_summary_always);
|
||||||
omemoPreference.setSummary(R.string.pref_omemo_setting_summary_default_on);
|
break;
|
||||||
break;
|
case "default_on":
|
||||||
case "default_off":
|
omemoPreference.setSummary(R.string.pref_omemo_setting_summary_default_on);
|
||||||
omemoPreference.setSummary(R.string.pref_omemo_setting_summary_default_off);
|
break;
|
||||||
break;
|
case "default_off":
|
||||||
}
|
omemoPreference.setSummary(R.string.pref_omemo_setting_summary_default_off);
|
||||||
} else {
|
break;
|
||||||
Log.d(Config.LOGTAG, "unable to find preference named " + OMEMO_SETTING);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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"
|
||||||
|
|
Loading…
Reference in a new issue