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 eu.siacs.conversations.Config;
import eu.siacs.conversations.crypto.OmemoSetting;
import eu.siacs.conversations.crypto.PgpDecryptionService;
import eu.siacs.conversations.crypto.axolotl.AxolotlService;
import eu.siacs.conversations.xmpp.chatstate.ChatState;
@ -592,14 +593,15 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
}
public int getNextEncryption() {
final int defaultEncryption;
if (!Config.supportOmemo() && !Config.supportOpenPgp()) {
return Message.ENCRYPTION_NONE;
}
if (contactJid.asBareJid().equals(Config.BUG_REPORTS)) {
defaultEncryption = Message.ENCRYPTION_NONE;
} else if (suitableForOmemoByDefault(this)) {
defaultEncryption = Message.ENCRYPTION_AXOLOTL;
if (OmemoSetting.isAlways()) {
return suitableForOmemoByDefault(this) ? Message.ENCRYPTION_AXOLOTL : Message.ENCRYPTION_NONE;
}
final int defaultEncryption;
if (suitableForOmemoByDefault(this)) {
defaultEncryption = OmemoSetting.getEncryption();
} else {
defaultEncryption = Message.ENCRYPTION_NONE;
}
@ -612,6 +614,9 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
}
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 account = conversation.getAccount().getServer();
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.R;
import eu.siacs.conversations.crypto.OmemoSetting;
import eu.siacs.conversations.crypto.PgpDecryptionService;
import eu.siacs.conversations.crypto.PgpEngine;
import eu.siacs.conversations.crypto.axolotl.AxolotlService;
@ -932,6 +933,7 @@ public class XmppConnectionService extends Service {
@SuppressLint("TrulyRandom")
@Override
public void onCreate() {
OmemoSetting.load(this);
ExceptionHelper.init(getApplicationContext());
PRNGFixes.apply();
Resolver.init(this);

View file

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

View file

@ -32,6 +32,7 @@ import java.util.List;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
import eu.siacs.conversations.crypto.OmemoSetting;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.services.ExportLogsService;
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 THEME = "theme";
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;
private SettingsFragment mSettingsFragment;
@ -84,6 +86,8 @@ public class SettingsActivity extends XmppActivity implements
super.onStart();
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
changeOmemoSettingSummary();
if (Config.FORCE_ORBOT) {
PreferenceCategory connectionOptions = (PreferenceCategory) mSettingsFragment.findPreference("connection_options");
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) {
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,
MANUALLY_CHANGE_PRESENCE,
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();
} else if (resendPresence.contains(name)) {
if (xmppConnectionServiceBound) {

View file

@ -38,6 +38,7 @@ import android.view.MenuItem;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
import eu.siacs.conversations.crypto.OmemoSetting;
import eu.siacs.conversations.crypto.axolotl.AxolotlService;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message;
@ -77,7 +78,9 @@ public class ConversationMenuConfigurator {
final MenuItem axolotl = menu.findItem(R.id.encryption_choice_axolotl);
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();
} else {
visible = Config.multipleEncryptionChoices();

View file

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

View file

@ -90,4 +90,16 @@
<item>2592000</item>
<item>15811200</item>
</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>

View file

@ -42,4 +42,5 @@
<bool name="validate_hostname">false</bool>
<bool name="show_qr_code_scan">true</bool>
<bool name="scroll_to_bottom">true</bool>
<string name="omemo_setting_default">default_on</string>
</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_now">Disable now</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>

View file

@ -17,6 +17,14 @@
</PreferenceScreen>
</PreferenceCategory>
<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
android:defaultValue="@bool/confirm_messages"
android:key="confirm_messages"