Remember last used encryption method per identity

pull/178/head
M66B 4 years ago
parent f2959d07f6
commit 0ba03a5020

File diff suppressed because it is too large Load Diff

@ -145,6 +145,11 @@ public class AdapterIdentity extends RecyclerView.Adapter<AdapterIdentity.ViewHo
sb.append(", ");
sb.append(identity.sign_key_alias);
}
if (identity.encrypt == 1) {
if (sb.length() != 0)
sb.append(", ");
sb.append("S/MIME");
}
tvSignKeyId.setText(context.getString(R.string.title_sign_key, sb.toString()));
tvSignKeyId.setVisibility(sb.length() > 0 ? View.VISIBLE : View.GONE);

@ -60,7 +60,7 @@ import io.requery.android.database.sqlite.SQLiteDatabase;
// https://developer.android.com/topic/libraries/architecture/room.html
@Database(
version = 160,
version = 161,
entities = {
EntityIdentity.class,
EntityAccount.class,
@ -1590,6 +1590,16 @@ public abstract class DB extends RoomDatabase {
db.execSQL("DROP TRIGGER attachment_delete");
createTriggers(db);
}
})
.addMigrations(new Migration(160, 161) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase db) {
Log.i("DB migration from version " + startVersion + " to " + endVersion);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
String encrypt_method = prefs.getString("default_encrypt_method", "pgp");
db.execSQL("UPDATE identity SET encrypt = " + ("pgp".equals(encrypt_method) ? 0 : 1));
prefs.edit().remove("default_encrypt_method").apply();
}
});
}

@ -103,6 +103,9 @@ public interface DaoIdentity {
@Query("UPDATE identity SET last_connected = :last_connected WHERE id = :id")
int setIdentityConnected(long id, long last_connected);
@Query("UPDATE identity SET encrypt = :encrypt WHERE id = :id")
int setIdentityEncrypt(long id, int encrypt);
@Query("UPDATE identity SET sign_key = :sign_key WHERE id = :id")
int setIdentitySignKey(long id, Long sign_key);

@ -100,7 +100,7 @@ public class EntityIdentity {
@NonNull
public Boolean plain_only = false; // obsolete
@NonNull
public Boolean encrypt = false; // obsolete
public Integer encrypt = 0; // Default method 0=PGP 1=S/MIME
@NonNull
public Boolean delivery_receipt = false; // obsolete
@NonNull

@ -1302,10 +1302,8 @@ public class FragmentCompose extends FragmentBase {
}
private void onMenuEncrypt() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
String encrypt_method = prefs.getString("default_encrypt_method", "pgp");
if ("pgp".equals(encrypt_method)) {
EntityIdentity identity = (EntityIdentity) spIdentity.getSelectedItem();
if (identity == null || identity.encrypt == 0) {
if (EntityMessage.ENCRYPT_NONE.equals(encrypt) || encrypt == null)
encrypt = EntityMessage.PGP_SIGNENCRYPT;
else if (EntityMessage.PGP_SIGNENCRYPT.equals(encrypt))
@ -3008,7 +3006,6 @@ public class FragmentCompose extends FragmentBase {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean plain_only = prefs.getBoolean("plain_only", false);
boolean resize_reply = prefs.getBoolean("resize_reply", true);
String encrypt_method = prefs.getString("default_encrypt_method", "pgp");
boolean sign_default = prefs.getBoolean("sign_default", false);
boolean encrypt_default = prefs.getBoolean("encrypt_default", false);
boolean receipt_default = prefs.getBoolean("receipt_default", false);
@ -3042,21 +3039,6 @@ public class FragmentCompose extends FragmentBase {
data.draft = new EntityMessage();
data.draft.msgid = EntityMessage.generateMessageId();
if (plain_only)
data.draft.plain_only = true;
if (encrypt_default)
if ("s/mime".equals(encrypt_method))
data.draft.ui_encrypt = EntityMessage.SMIME_SIGNENCRYPT;
else
data.draft.ui_encrypt = EntityMessage.PGP_SIGNENCRYPT;
else if (sign_default)
if ("s/mime".equals(encrypt_method))
data.draft.ui_encrypt = EntityMessage.SMIME_SIGNONLY;
else
data.draft.ui_encrypt = EntityMessage.PGP_SIGNONLY;
if (receipt_default)
data.draft.receipt_request = true;
// Select identity matching from address
EntityIdentity selected = null;
long aid = args.getLong("account", -1);
@ -3156,6 +3138,23 @@ public class FragmentCompose extends FragmentBase {
if (selected == null)
throw new IllegalArgumentException(context.getString(R.string.title_no_identities));
if (plain_only)
data.draft.plain_only = true;
if (encrypt_default)
if (selected.encrypt == 0)
data.draft.ui_encrypt = EntityMessage.PGP_SIGNENCRYPT;
else
data.draft.ui_encrypt = EntityMessage.SMIME_SIGNENCRYPT;
else if (sign_default)
if (selected.encrypt == 0)
data.draft.ui_encrypt = EntityMessage.PGP_SIGNONLY;
else
data.draft.ui_encrypt = EntityMessage.SMIME_SIGNONLY;
if (receipt_default)
data.draft.receipt_request = true;
Document document = Document.createShell("");
if (ref == null) {
@ -5101,7 +5100,27 @@ public class FragmentCompose extends FragmentBase {
int encrypt = args.getInt("encrypt");
DB db = DB.getInstance(context);
db.message().setMessageUiEncrypt(id, encrypt);
try {
db.beginTransaction();
EntityMessage message = db.message().getMessage(id);
if (message == null)
return null;
db.message().setMessageUiEncrypt(message.id, encrypt);
if (message.identity != null) {
int iencrypt =
(encrypt == EntityMessage.SMIME_SIGNONLY ||
encrypt == EntityMessage.SMIME_SIGNENCRYPT
? 1 : 0);
db.identity().setIdentityEncrypt(message.identity, iencrypt);
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
return null;
}

@ -56,7 +56,6 @@ import java.util.ArrayList;
import java.util.List;
public class FragmentOptionsEncryption extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener {
private Spinner spEncryptMethod;
private SwitchCompat swSign;
private SwitchCompat swEncrypt;
private SwitchCompat swAutoDecrypt;
@ -74,7 +73,7 @@ public class FragmentOptionsEncryption extends FragmentBase implements SharedPre
private List<String> openPgpProvider = new ArrayList<>();
private final static String[] RESET_OPTIONS = new String[]{
"default_encrypt_method", "sign_default", "encrypt_default", "auto_decrypt",
"sign_default", "encrypt_default", "auto_decrypt",
"openpgp_provider", "autocrypt", "autocrypt_mutual"
};
@ -89,7 +88,6 @@ public class FragmentOptionsEncryption extends FragmentBase implements SharedPre
// Get controls
spEncryptMethod = view.findViewById(R.id.spEncryptMethod);
swSign = view.findViewById(R.id.swSign);
swEncrypt = view.findViewById(R.id.swEncrypt);
swAutoDecrypt = view.findViewById(R.id.swAutoDecrypt);
@ -120,21 +118,6 @@ public class FragmentOptionsEncryption extends FragmentBase implements SharedPre
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
spEncryptMethod.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if (position == 1)
prefs.edit().putString("default_encrypt_method", "s/mime").apply();
else
onNothingSelected(parent);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
prefs.edit().remove("default_encrypt_method").apply();
}
});
swSign.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -281,10 +264,6 @@ public class FragmentOptionsEncryption extends FragmentBase implements SharedPre
private void setOptions() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
String encrypt_method = prefs.getString("default_encrypt_method", "pgp");
if ("s/mime".equals(encrypt_method))
spEncryptMethod.setSelection(1);
swSign.setChecked(prefs.getBoolean("sign_default", false));
swEncrypt.setChecked(prefs.getBoolean("encrypt_default", false));
swSign.setEnabled(!swEncrypt.isChecked());

@ -28,28 +28,6 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvEncryptMethod"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:layout_marginEnd="48dp"
android:text="@string/title_advanced_encrypt_method"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?android:attr/textColorPrimary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvCaptionGeneral" />
<Spinner
android:id="@+id/spEncryptMethod"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:entries="@array/encryptMethod"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvEncryptMethod" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swSign"
android:layout_width="0dp"
@ -58,7 +36,7 @@
android:text="@string/title_advanced_sign_default"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/spEncryptMethod"
app:layout_constraintTop_toBottomOf="@id/tvCaptionGeneral"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat

@ -425,7 +425,6 @@
<string name="title_advanced_biometrics_timeout">Biometric authentication timeout</string>
<string name="title_advanced_safe_browsing" translatable="false">Google Safe browsing</string>
<string name="title_advanced_encrypt_method">Default encryption method</string>
<string name="title_advanced_sign_default">Sign by default</string>
<string name="title_advanced_encrypt_default">Encrypt by default</string>
<string name="title_advanced_auto_decrypt">Automatically decrypt messages</string>
@ -1495,11 +1494,6 @@
<item>At the bottom</item>
</string-array>
<string-array name="encryptMethod" translatable="false">
<item>PGP</item>
<item>S/MIME</item>
</string-array>
<string-array name="encryptNames">
<item>None</item>
<item>PGP sign-only</item>

Loading…
Cancel
Save