introduced tri state omemo setting (off by default, on by default, always)

This commit is contained in:
Daniel Gultsch 2018-03-27 15:35:53 +02:00
parent 06f8d8c5d6
commit a6539be52b
11 changed files with 148 additions and 8 deletions

View file

@ -0,0 +1,76 @@
/*
* Copyright (c) 2018, Daniel Gultsch All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package eu.siacs.conversations.crypto;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.ui.SettingsActivity;
public class OmemoSetting {
private static boolean always = false;
private static int encryption = Message.ENCRYPTION_AXOLOTL;
public static boolean isAlways() {
return always;
}
public static int getEncryption() {
return encryption;
}
public static void load(final Context context, final SharedPreferences sharedPreferences) {
final String value = sharedPreferences.getString(SettingsActivity.OMEMO_SETTING, context.getResources().getString(R.string.omemo_setting_default));
switch (value) {
case "always":
always = true;
encryption = Message.ENCRYPTION_AXOLOTL;
break;
case "default_off":
always = false;
encryption = Message.ENCRYPTION_NONE;
break;
default:
always = false;
encryption = Message.ENCRYPTION_AXOLOTL;
break;
}
}
public static void load(final Context context) {
load(context, PreferenceManager.getDefaultSharedPreferences(context));
}
}

View file

@ -20,6 +20,7 @@ import java.util.Locale;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import eu.siacs.conversations.Config; import eu.siacs.conversations.Config;
import eu.siacs.conversations.crypto.OmemoSetting;
import eu.siacs.conversations.crypto.PgpDecryptionService; import eu.siacs.conversations.crypto.PgpDecryptionService;
import eu.siacs.conversations.crypto.axolotl.AxolotlService; import eu.siacs.conversations.crypto.axolotl.AxolotlService;
import eu.siacs.conversations.xmpp.chatstate.ChatState; import eu.siacs.conversations.xmpp.chatstate.ChatState;
@ -592,14 +593,15 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
} }
public int getNextEncryption() { public int getNextEncryption() {
final int defaultEncryption;
if (!Config.supportOmemo() && !Config.supportOpenPgp()) { if (!Config.supportOmemo() && !Config.supportOpenPgp()) {
return Message.ENCRYPTION_NONE; return Message.ENCRYPTION_NONE;
} }
if (contactJid.asBareJid().equals(Config.BUG_REPORTS)) { if (OmemoSetting.isAlways()) {
defaultEncryption = Message.ENCRYPTION_NONE; return suitableForOmemoByDefault(this) ? Message.ENCRYPTION_AXOLOTL : Message.ENCRYPTION_NONE;
} else if (suitableForOmemoByDefault(this)) { }
defaultEncryption = Message.ENCRYPTION_AXOLOTL; final int defaultEncryption;
if (suitableForOmemoByDefault(this)) {
defaultEncryption = OmemoSetting.getEncryption();
} else { } else {
defaultEncryption = Message.ENCRYPTION_NONE; defaultEncryption = Message.ENCRYPTION_NONE;
} }
@ -612,6 +614,9 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
} }
private static boolean suitableForOmemoByDefault(final Conversation conversation) { private static boolean suitableForOmemoByDefault(final Conversation conversation) {
if (conversation.getJid().asBareJid().equals(Config.BUG_REPORTS)) {
return false;
}
final String contact = conversation.getJid().getDomain(); final String contact = conversation.getJid().getDomain();
final String account = conversation.getAccount().getServer(); final String account = conversation.getAccount().getServer();
if (Config.OMEMO_EXCEPTIONS.CONTACT_DOMAINS.contains(contact) || Config.OMEMO_EXCEPTIONS.ACCOUNT_DOMAINS.contains(account)) { if (Config.OMEMO_EXCEPTIONS.CONTACT_DOMAINS.contains(contact) || Config.OMEMO_EXCEPTIONS.ACCOUNT_DOMAINS.contains(account)) {

View file

@ -63,6 +63,7 @@ import java.util.concurrent.atomic.AtomicLong;
import eu.siacs.conversations.Config; import eu.siacs.conversations.Config;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.crypto.OmemoSetting;
import eu.siacs.conversations.crypto.PgpDecryptionService; import eu.siacs.conversations.crypto.PgpDecryptionService;
import eu.siacs.conversations.crypto.PgpEngine; import eu.siacs.conversations.crypto.PgpEngine;
import eu.siacs.conversations.crypto.axolotl.AxolotlService; import eu.siacs.conversations.crypto.axolotl.AxolotlService;
@ -932,6 +933,7 @@ public class XmppConnectionService extends Service {
@SuppressLint("TrulyRandom") @SuppressLint("TrulyRandom")
@Override @Override
public void onCreate() { public void onCreate() {
OmemoSetting.load(this);
ExceptionHelper.init(getApplicationContext()); ExceptionHelper.init(getApplicationContext());
PRNGFixes.apply(); PRNGFixes.apply();
Resolver.init(this); Resolver.init(this);

View file

@ -60,6 +60,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
import eu.siacs.conversations.Config; import eu.siacs.conversations.Config;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.crypto.OmemoSetting;
import eu.siacs.conversations.databinding.ActivityConversationsBinding; import eu.siacs.conversations.databinding.ActivityConversationsBinding;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversation;
@ -364,6 +365,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
@Override @Override
protected void onCreate(final Bundle savedInstanceState) { protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
OmemoSetting.load(this);
new EmojiService(this).init(); new EmojiService(this).init();
this.binding = DataBindingUtil.setContentView(this, R.layout.activity_conversations); this.binding = DataBindingUtil.setContentView(this, R.layout.activity_conversations);
setSupportActionBar((Toolbar) binding.toolbar); setSupportActionBar((Toolbar) binding.toolbar);

View file

@ -32,6 +32,7 @@ import java.util.List;
import eu.siacs.conversations.Config; import eu.siacs.conversations.Config;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.crypto.OmemoSetting;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.services.ExportLogsService; import eu.siacs.conversations.services.ExportLogsService;
import eu.siacs.conversations.services.MemorizingTrustManager; import eu.siacs.conversations.services.MemorizingTrustManager;
@ -52,6 +53,7 @@ public class SettingsActivity extends XmppActivity implements
public static final String BROADCAST_LAST_ACTIVITY = "last_activity"; public static final String BROADCAST_LAST_ACTIVITY = "last_activity";
public static final String THEME = "theme"; public static final String THEME = "theme";
public static final String SHOW_DYNAMIC_TAGS = "show_dynamic_tags"; public static final String SHOW_DYNAMIC_TAGS = "show_dynamic_tags";
public static final String OMEMO_SETTING = "omemo";
public static final int REQUEST_WRITE_LOGS = 0xbf8701; public static final int REQUEST_WRITE_LOGS = 0xbf8701;
private SettingsFragment mSettingsFragment; private SettingsFragment mSettingsFragment;
@ -84,6 +86,8 @@ public class SettingsActivity extends XmppActivity implements
super.onStart(); super.onStart();
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this); PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
changeOmemoSettingSummary();
if (Config.FORCE_ORBOT) { if (Config.FORCE_ORBOT) {
PreferenceCategory connectionOptions = (PreferenceCategory) mSettingsFragment.findPreference("connection_options"); PreferenceCategory connectionOptions = (PreferenceCategory) mSettingsFragment.findPreference("connection_options");
PreferenceScreen expert = (PreferenceScreen) mSettingsFragment.findPreference("expert"); PreferenceScreen expert = (PreferenceScreen) mSettingsFragment.findPreference("expert");
@ -231,6 +235,26 @@ public class SettingsActivity extends XmppActivity implements
} }
} }
private void changeOmemoSettingSummary() {
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);
}
}
private boolean isCallable(final Intent i) { private boolean isCallable(final Intent i) {
return i != null && getPackageManager().queryIntentActivities(i, PackageManager.MATCH_DEFAULT_ONLY).size() > 0; return i != null && getPackageManager().queryIntentActivities(i, PackageManager.MATCH_DEFAULT_ONLY).size() > 0;
} }
@ -350,7 +374,10 @@ public class SettingsActivity extends XmppActivity implements
TREAT_VIBRATE_AS_SILENT, TREAT_VIBRATE_AS_SILENT,
MANUALLY_CHANGE_PRESENCE, MANUALLY_CHANGE_PRESENCE,
BROADCAST_LAST_ACTIVITY); BROADCAST_LAST_ACTIVITY);
if (name.equals(KEEP_FOREGROUND_SERVICE)) { if (name.equals(OMEMO_SETTING)) {
OmemoSetting.load(this, preferences);
changeOmemoSettingSummary();
} else if (name.equals(KEEP_FOREGROUND_SERVICE)) {
xmppConnectionService.toggleForegroundService(); xmppConnectionService.toggleForegroundService();
} else if (resendPresence.contains(name)) { } else if (resendPresence.contains(name)) {
if (xmppConnectionServiceBound) { if (xmppConnectionServiceBound) {

View file

@ -38,6 +38,7 @@ import android.view.MenuItem;
import eu.siacs.conversations.Config; import eu.siacs.conversations.Config;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.crypto.OmemoSetting;
import eu.siacs.conversations.crypto.axolotl.AxolotlService; import eu.siacs.conversations.crypto.axolotl.AxolotlService;
import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.Message;
@ -77,7 +78,9 @@ public class ConversationMenuConfigurator {
final MenuItem axolotl = menu.findItem(R.id.encryption_choice_axolotl); final MenuItem axolotl = menu.findItem(R.id.encryption_choice_axolotl);
boolean visible; boolean visible;
if (conversation.getMode() == Conversation.MODE_MULTI) { if (OmemoSetting.isAlways()) {
visible = false;
} else if (conversation.getMode() == Conversation.MODE_MULTI) {
visible = (Config.supportOpenPgp() || Config.supportOmemo()) && Config.multipleEncryptionChoices(); visible = (Config.supportOpenPgp() || Config.supportOmemo()) && Config.multipleEncryptionChoices();
} else { } else {
visible = Config.multipleEncryptionChoices(); visible = Config.multipleEncryptionChoices();

View file

@ -69,7 +69,7 @@
android:id="@+id/action_muc_details" android:id="@+id/action_muc_details"
android:icon="?attr/icon_group" android:icon="?attr/icon_group"
android:orderInCategory="40" android:orderInCategory="40"
app:showAsAction="ifRoom" app:showAsAction="never"
android:title="@string/action_muc_details"/> android:title="@string/action_muc_details"/>
<item <item
android:id="@+id/action_invite" android:id="@+id/action_invite"

View file

@ -90,4 +90,16 @@
<item>2592000</item> <item>2592000</item>
<item>15811200</item> <item>15811200</item>
</integer-array> </integer-array>
<string-array name="omemo_setting_entry_values">
<item>always</item>
<item>default_on</item>
<item>default_off</item>
</string-array>
<string-array name="omemo_setting_entries">
<item>@string/always</item>
<item>@string/default_on</item>
<item>@string/default_off</item>
</string-array>
<string name="default_on">On by default</string>
<string name="default_off">Off by default</string>
</resources> </resources>

View file

@ -42,4 +42,5 @@
<bool name="validate_hostname">false</bool> <bool name="validate_hostname">false</bool>
<bool name="show_qr_code_scan">true</bool> <bool name="show_qr_code_scan">true</bool>
<bool name="scroll_to_bottom">true</bool> <bool name="scroll_to_bottom">true</bool>
<string name="omemo_setting_default">default_on</string>
</resources> </resources>

View file

@ -735,4 +735,8 @@
<string name="disable_encryption_message">Are you sure you want to disable OMEMO encryption for this conversation?\nThis will allow your server administrator to read your messages, but it might be the only way to communicate with people using outdated clients.</string> <string name="disable_encryption_message">Are you sure you want to disable OMEMO encryption for this conversation?\nThis will allow your server administrator to read your messages, but it might be the only way to communicate with people using outdated clients.</string>
<string name="disable_now">Disable now</string> <string name="disable_now">Disable now</string>
<string name="draft">Draft:</string> <string name="draft">Draft:</string>
<string name="pref_omemo_setting">OMEMO Encryption</string>
<string name="pref_omemo_setting_summary_always">OMEMO will always be used for one-on-one and private group chats.</string>
<string name="pref_omemo_setting_summary_default_on">OMEMO will be used by default for new conversations.</string>
<string name="pref_omemo_setting_summary_default_off">OMEMO will have to be turned on explicitly for new conversations.</string>
</resources> </resources>

View file

@ -17,6 +17,14 @@
</PreferenceScreen> </PreferenceScreen>
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory android:title="@string/pref_privacy"> <PreferenceCategory android:title="@string/pref_privacy">
<ListPreference
android:key="omemo"
android:title="@string/pref_omemo_setting"
android:summary="@string/pref_omemo_setting_summary_default_on"
android:defaultValue="@string/omemo_setting_default"
android:entryValues="@array/omemo_setting_entry_values"
android:entries="@array/omemo_setting_entries"
/>
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="@bool/confirm_messages" android:defaultValue="@bool/confirm_messages"
android:key="confirm_messages" android:key="confirm_messages"