Redesign end-to-end account settings

This commit is contained in:
Vincent Breitmoser 2018-03-23 23:42:39 +01:00
parent 032c3e4378
commit 909e9fbdd8
13 changed files with 190 additions and 73 deletions

View file

@ -203,6 +203,7 @@ public class Account implements BaseAccount, StoreConfig {
private boolean syncRemoteDeletions;
private long pgpCryptoKey;
private boolean autocryptPreferEncryptMutual;
private boolean pgpHideSignOnly;
private boolean markMessageAsReadOnView;
private boolean alwaysShowCcBcc;
private boolean allowRemoteSearch;
@ -429,6 +430,7 @@ public class Account implements BaseAccount, StoreConfig {
identities = loadIdentities(storage);
pgpCryptoKey = storage.getLong(accountUuid + ".cryptoKey", NO_OPENPGP_KEY);
pgpHideSignOnly = storage.getBoolean(accountUuid + ".pgpHideSignOnly", true);
allowRemoteSearch = storage.getBoolean(accountUuid + ".allowRemoteSearch", false);
remoteSearchFullText = storage.getBoolean(accountUuid + ".remoteSearchFullText", false);
remoteSearchNumResults = storage.getInt(accountUuid + ".remoteSearchNumResults", DEFAULT_REMOTE_SEARCH_NUM_RESULTS);
@ -695,6 +697,7 @@ public class Account implements BaseAccount, StoreConfig {
editor.putBoolean(accountUuid + ".replyAfterQuote", replyAfterQuote);
editor.putBoolean(accountUuid + ".stripSignature", stripSignature);
editor.putLong(accountUuid + ".cryptoKey", pgpCryptoKey);
editor.putBoolean(accountUuid + ".pgpHideSignOnly", pgpHideSignOnly);
editor.putBoolean(accountUuid + ".allowRemoteSearch", allowRemoteSearch);
editor.putBoolean(accountUuid + ".remoteSearchFullText", remoteSearchFullText);
editor.putInt(accountUuid + ".remoteSearchNumResults", remoteSearchNumResults);
@ -1517,6 +1520,14 @@ public class Account implements BaseAccount, StoreConfig {
this.autocryptPreferEncryptMutual = autocryptPreferEncryptMutual;
}
public boolean getPgpHideSignOnly() {
return pgpHideSignOnly;
}
public void setPgpHideSignOnly(boolean pgpHideSignOnly) {
this.pgpHideSignOnly = pgpHideSignOnly;
}
public boolean allowRemoteSearch() {
return allowRemoteSearch;
}

View file

@ -1257,14 +1257,6 @@ public class K9 extends Application {
K9.openPgpProvider = openPgpProvider;
}
public static boolean getOpenPgpSupportSignOnly() {
return openPgpSupportSignOnly;
}
public static void setOpenPgpSupportSignOnly(boolean supportSignOnly) {
openPgpSupportSignOnly = supportSignOnly;
}
public static String getAttachmentDefaultPath() {
return attachmentDefaultPath;
}

View file

@ -81,7 +81,6 @@ public class MessageLoaderHelper {
private LoaderManager loaderManager;
@Nullable // make this explicitly nullable, make sure to cancel/ignore any operation if this is null
private MessageLoaderCallbacks callback;
private final boolean processSignedOnly;
// transient state
@ -102,8 +101,6 @@ public class MessageLoaderHelper {
this.loaderManager = loaderManager;
this.fragmentManager = fragmentManager;
this.callback = callback;
processSignedOnly = K9.getOpenPgpSupportSignOnly();
}
@ -298,7 +295,7 @@ public class MessageLoaderHelper {
retainCryptoHelperFragment.setData(messageCryptoHelper);
}
messageCryptoHelper.asyncStartOrResumeProcessingMessage(
localMessage, messageCryptoCallback, cachedDecryptionResult, processSignedOnly);
localMessage, messageCryptoCallback, cachedDecryptionResult, !account.getPgpHideSignOnly());
}
private void cancelAndClearCryptoOperation() {

View file

@ -277,10 +277,10 @@ public class RecipientPresenter implements PermissionPingCallback {
menu.findItem(R.id.openpgp_encrypt_enable).setVisible(!isEncrypting);
menu.findItem(R.id.openpgp_encrypt_disable).setVisible(isEncrypting);
boolean showSignOnly = K9.getOpenPgpSupportSignOnly();
boolean hideSignOnly = account.getPgpHideSignOnly();
boolean isSignOnly = currentCryptoStatus.isSignOnly();
menu.findItem(R.id.openpgp_sign_only).setVisible(showSignOnly && !isSignOnly);
menu.findItem(R.id.openpgp_sign_only_disable).setVisible(showSignOnly && isSignOnly);
menu.findItem(R.id.openpgp_sign_only).setVisible(!hideSignOnly && !isSignOnly);
menu.findItem(R.id.openpgp_sign_only_disable).setVisible(!hideSignOnly && isSignOnly);
boolean pgpInlineModeEnabled = currentCryptoStatus.isPgpInlineModeEnabled();
boolean showPgpInlineEnable = (isEncrypting || isSignOnly) && !pgpInlineModeEnabled;

View file

@ -22,7 +22,7 @@ import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceScreen;
import android.preference.RingtonePreference;
import android.widget.Toast;
import android.preference.SwitchPreference;
import com.fsck.k9.Account;
import com.fsck.k9.Account.DeletePolicy;
@ -48,6 +48,7 @@ import com.fsck.k9.service.MailService;
import com.fsck.k9.ui.dialog.AutocryptPreferEncryptDialog;
import com.fsck.k9.ui.dialog.AutocryptPreferEncryptDialog.OnPreferEncryptChangedListener;
import org.openintents.openpgp.util.OpenPgpKeyPreference;
import org.openintents.openpgp.util.OpenPgpProviderUtil;
import timber.log.Timber;
@ -110,8 +111,10 @@ public class AccountSettings extends K9PreferenceActivity {
private static final String PREFERENCE_REPLY_AFTER_QUOTE = "reply_after_quote";
private static final String PREFERENCE_STRIP_SIGNATURE = "strip_signature";
private static final String PREFERENCE_SYNC_REMOTE_DELETIONS = "account_sync_remote_deletetions";
private static final String PREFERENCE_CRYPTO = "crypto";
private static final String PREFERENCE_CRYPTO_KEY = "crypto_key";
private static final String PREFERENCE_CRYPTO = "openpgp";
private static final String PREFERENCE_CRYPTO_PROVIDER = "openpgp_provider";
private static final String PREFERENCE_CRYPTO_KEY = "openpgp_key";
private static final String PREFERENCE_CRYPTO_HIDE_SIGN_ONLY = "openpgp_hide_sign_only";
private static final String PREFERENCE_AUTOCRYPT_PREFER_ENCRYPT = "autocrypt_prefer_encrypt";
private static final String PREFERENCE_CLOUD_SEARCH_ENABLED = "remote_search_enabled";
private static final String PREFERENCE_REMOTE_SEARCH_NUM_RESULTS = "account_remote_search_num_results";
@ -177,9 +180,9 @@ public class AccountSettings extends K9PreferenceActivity {
private CheckBoxPreference pushPollOnConnect;
private ListPreference idleRefreshPeriod;
private ListPreference mMaxPushFolders;
private boolean hasPgpCrypto = false;
private OpenPgpKeyPreference pgpCryptoKey;
private Preference autocryptPreferEncryptMutual;
private SwitchPreference pgpHideSignOnly;
private PreferenceScreen searchScreen;
private CheckBoxPreference cloudSearchEnabled;
@ -198,6 +201,7 @@ public class AccountSettings extends K9PreferenceActivity {
private ListPreference spamFolder;
private ListPreference trashFolder;
private CheckBoxPreference alwaysShowCcBcc;
private SwitchPreference pgpEnable;
public static void actionSettings(Context context, Account account) {
@ -693,49 +697,90 @@ public class AccountSettings extends K9PreferenceActivity {
return true;
}
});
}
hasPgpCrypto = K9.isOpenPgpProviderConfigured();
PreferenceScreen cryptoMenu = (PreferenceScreen) findPreference(PREFERENCE_CRYPTO);
if (hasPgpCrypto) {
pgpCryptoKey = (OpenPgpKeyPreference) findPreference(PREFERENCE_CRYPTO_KEY);
@Override
protected void onResume() {
super.onResume();
pgpCryptoKey.setValue(account.getCryptoKey());
pgpCryptoKey.setOpenPgpProvider(K9.getOpenPgpProvider());
// TODO: other identities?
pgpCryptoKey.setDefaultUserId(OpenPgpApiHelper.buildUserId(account.getIdentity(0)));
pgpCryptoKey.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
long value = (Long) newValue;
pgpCryptoKey.setValue(value);
return false;
}
});
// we might return here from the play store, so it's important we refresh on resume
setupCryptoStuff();
}
cryptoMenu.setOnPreferenceClickListener(null);
private void setupCryptoStuff() {
pgpEnable = (SwitchPreference) findPreference(PREFERENCE_CRYPTO_PROVIDER);
pgpCryptoKey = (OpenPgpKeyPreference) findPreference(PREFERENCE_CRYPTO_KEY);
autocryptPreferEncryptMutual = findPreference(PREFERENCE_AUTOCRYPT_PREFER_ENCRYPT);
pgpHideSignOnly = (SwitchPreference) findPreference(PREFERENCE_CRYPTO_HIDE_SIGN_ONLY);
autocryptPreferEncryptMutual = findPreference(PREFERENCE_AUTOCRYPT_PREFER_ENCRYPT);
autocryptPreferEncryptMutual.setOnPreferenceClickListener(new OnPreferenceClickListener() {
boolean isPgpConfigured = K9.isOpenPgpProviderConfigured();
if (!isPgpConfigured) {
pgpEnable.setChecked(false);
pgpEnable.setSummary(R.string.account_settings_crypto_summary_off);
pgpEnable.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
showDialog(DIALOG_AUTOCRYPT_PREFER_ENCRYPT);
return false;
}
});
} else {
cryptoMenu.setSummary(R.string.account_settings_no_openpgp_provider_configured);
cryptoMenu.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Dialog dialog = ((PreferenceScreen) preference).getDialog();
if (dialog != null) {
dialog.dismiss();
pgpEnable.setOnPreferenceClickListener(null);
List<String> openPgpProviderPackages =
OpenPgpProviderUtil.getOpenPgpProviderPackages(getApplicationContext());
if (openPgpProviderPackages.size() == 1) {
K9.setOpenPgpProvider(openPgpProviderPackages.get(0));
setupCryptoStuff();
} else {
Intent i = new Intent(getApplicationContext(), OpenPgpAppSelectDialog.class);
startActivity(i);
}
Toast.makeText(AccountSettings.this,
R.string.no_crypto_provider_see_global, Toast.LENGTH_SHORT).show();
return false;
}
});
pgpCryptoKey.setEnabled(false);
autocryptPreferEncryptMutual.setEnabled(false);
pgpHideSignOnly.setEnabled(false);
} else {
String pgpProvider = K9.getOpenPgpProvider();
String pgpProviderName = OpenPgpProviderUtil.getOpenPgpProviderName(getPackageManager(), pgpProvider);
pgpEnable.setChecked(true);
pgpEnable.setSummary(getString(R.string.account_settings_crypto_summary_on, pgpProviderName));
pgpEnable.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
pgpEnable.setOnPreferenceClickListener(null);
K9.setOpenPgpProvider("");
setupCryptoStuff();
return true;
}
});
pgpCryptoKey.setOpenPgpProvider(pgpProvider);
pgpCryptoKey.setEnabled(true);
autocryptPreferEncryptMutual.setEnabled(true);
pgpHideSignOnly.setEnabled(true);
}
pgpCryptoKey.setValue(account.getCryptoKey());
pgpCryptoKey.setDefaultUserId(OpenPgpApiHelper.buildUserId(account.getIdentity(0)));
pgpCryptoKey.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
long value = (Long) newValue;
pgpCryptoKey.setValue(value);
return false;
}
});
autocryptPreferEncryptMutual.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
showDialog(DIALOG_AUTOCRYPT_PREFER_ENCRYPT);
return false;
}
});
pgpHideSignOnly = (SwitchPreference) findPreference(PREFERENCE_CRYPTO_HIDE_SIGN_ONLY);
pgpHideSignOnly.setChecked(account.getPgpHideSignOnly());
}
private void removeListEntry(ListPreference listPreference, String remove) {
@ -796,11 +841,10 @@ public class AccountSettings extends K9PreferenceActivity {
account.setReplyAfterQuote(replyAfterQuote.isChecked());
account.setStripSignature(stripSignature.isChecked());
account.setLocalStorageProviderId(localStorageProvider.getValue());
if (hasPgpCrypto) {
if (pgpCryptoKey != null) {
account.setCryptoKey(pgpCryptoKey.getValue());
} else {
account.setCryptoKey(Account.NO_OPENPGP_KEY);
}
account.setPgpHideSignOnly(pgpHideSignOnly.isChecked());
account.setAutoExpandFolder(autoExpandFolder.getValue());

View file

@ -8,6 +8,7 @@ import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
@ -273,4 +274,14 @@ public class OpenPgpAppSelectDialog extends Activity {
return simpleName;
}
}
private void startInstallPackageActivity(String providerPackage) {
try {
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("market://details?id=" + providerPackage)));
} catch (ActivityNotFoundException anfe) {
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("https://play.google.com/store/apps/details?id=" + providerPackage)));
}
}
}

View file

@ -67,11 +67,6 @@ public class MessageCryptoPresenter implements OnCryptoClickListener {
return false;
}
boolean suppressSignOnlyMessages = !K9.getOpenPgpSupportSignOnly();
if (suppressSignOnlyMessages && displayStatus.isUnencryptedSigned()) {
return false;
}
if (cryptoResultAnnotation.isOverrideSecurityWarning()) {
overrideCryptoWarning = true;
}

View file

@ -20,7 +20,6 @@ import android.widget.TextView;
import com.fsck.k9.Account;
import com.fsck.k9.Account.ShowPictures;
import com.fsck.k9.K9;
import com.fsck.k9.R;
import com.fsck.k9.helper.Contacts;
import com.fsck.k9.mail.Address;
@ -118,7 +117,7 @@ public class MessageTopView extends LinearLayout {
containerView, false);
containerView.addView(view);
boolean hideUnsignedTextDivider = !K9.getOpenPgpSupportSignOnly();
boolean hideUnsignedTextDivider = account.getPgpHideSignOnly();
view.displayMessageViewContainer(messageViewInfo, new OnRenderingFinishedListener() {
@Override
public void onLoadFinished() {

View file

@ -134,8 +134,8 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF
mController = MessagingController.getInstance(context);
downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
messageCryptoPresenter = new MessageCryptoPresenter(savedInstanceState, messageCryptoMvpView);
messageLoaderHelper =
new MessageLoaderHelper(context, getLoaderManager(), getFragmentManager(), messageLoaderCallbacks);
messageLoaderHelper = new MessageLoaderHelper(
context, getLoaderManager(), getFragmentManager(), messageLoaderCallbacks);
mInitialized = true;
}

View file

@ -589,10 +589,13 @@ Please submit bug reports, contribute new features and ask questions at
<string name="account_settings_sync">Fetching mail</string>
<string name="account_settings_folders">Folders</string>
<string name="account_settings_quote_prefix_label">Quoted text prefix</string>
<string name="account_settings_crypto">Cryptography</string>
<string name="account_settings_crypto_app">OpenPGP app</string>
<string name="account_settings_crypto_key">My Key</string>
<string name="account_settings_crypto">End-to-end encryption</string>
<string name="account_settings_crypto_app">Enable OpenPGP support</string>
<string name="account_settings_crypto_key">Configure end-to-end key</string>
<string name="account_settings_crypto_summary_off">No OpenPGP app configured</string>
<string name="account_settings_crypto_summary_on">Connected to %s</string>
<string name="account_settings_no_openpgp_provider_configured">No OpenPGP app configured</string>
<string name="account_settings_no_openpgp_provider_installed">No OpenPGP app found - click to install</string>
<string name="account_settings_mail_check_frequency_label">Folder poll frequency</string>
@ -1249,9 +1252,9 @@ Please submit bug reports, contribute new features and ask questions at
<string name="recipient_error_non_ascii">Special characters are currently not supported!</string>
<string name="recipient_error_parse_failed">Error parsing address!</string>
<string name="account_settings_crypto_support_sign_only">Show unencrypted signatures</string>
<string name="account_settings_crypto_support_sign_only_on">Unencrypted signatures will be displayed</string>
<string name="account_settings_crypto_support_sign_only_off">Unencrypted signatures will be ignored</string>
<string name="account_settings_crypto_hide_sign_only">Hide unencrypted signatures</string>
<string name="account_settings_crypto_hide_sign_only_on">Only encrypted signatures will be displayed</string>
<string name="account_settings_crypto_hide_sign_only_off">All signatures will be displayed</string>
<string name="error_sign_only_no_encryption">Encryption unavailable in sign-only mode!</string>
<string name="unsigned_text_divider_label">Unsigned Text</string>
<string name="apg_deprecated_title">APG Deprecation Warning</string>

View file

@ -472,11 +472,16 @@
<PreferenceScreen
android:title="@string/account_settings_crypto"
android:key="crypto">
android:key="openpgp">
<SwitchPreference
android:persistent="false"
android:key="openpgp_provider"
android:title="@string/account_settings_crypto_app" />
<org.openintents.openpgp.util.OpenPgpKeyPreference
android:persistent="false"
android:key="crypto_key"
android:key="openpgp_key"
android:title="@string/account_settings_crypto_key" />
<Preference
@ -484,6 +489,14 @@
android:title="@string/account_settings_crypto_prefer_encrypt"
/>
<SwitchPreference
android:persistent="false"
android:key="openpgp_hide_sign_only"
android:title="@string/account_settings_crypto_hide_sign_only"
android:summaryOn="@string/account_settings_crypto_hide_sign_only_on"
android:summaryOff="@string/account_settings_crypto_hide_sign_only_off"
/>
</PreferenceScreen>
</PreferenceScreen>

View file

@ -0,0 +1,52 @@
package org.openintents.openpgp.util;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
public class OpenPgpProviderUtil {
public static List<String> getOpenPgpProviderPackages(Context context) {
ArrayList<String> result = new ArrayList<>();
Intent intent = new Intent(OpenPgpApi.SERVICE_INTENT_2);
List<ResolveInfo> resInfo = context.getPackageManager().queryIntentServices(intent, 0);
if (resInfo == null) {
return result;
}
for (ResolveInfo resolveInfo : resInfo) {
if (resolveInfo.serviceInfo == null) {
continue;
}
result.add(resolveInfo.serviceInfo.packageName);
}
return result;
}
public static String getOpenPgpProviderName(PackageManager packageManager, String openPgpProvider) {
Intent intent = new Intent(OpenPgpApi.SERVICE_INTENT_2);
intent.setPackage(openPgpProvider);
List<ResolveInfo> resInfo = packageManager.queryIntentServices(intent, 0);
if (resInfo == null) {
return "";
}
for (ResolveInfo resolveInfo : resInfo) {
if (resolveInfo.serviceInfo == null) {
continue;
}
return String.valueOf(resolveInfo.serviceInfo.loadLabel(packageManager));
}
return "";
}
}

View file

@ -3,7 +3,7 @@
<string name="openpgp_list_preference_none">None</string>
<string name="openpgp_install_openkeychain_via">Install OpenKeychain via %s</string>
<string name="openpgp_no_key_selected">No key selected</string>
<string name="openpgp_key_selected">Key has been selected</string>
<string name="openpgp_no_key_selected">No end-to-end key selected</string>
<string name="openpgp_key_selected">End-to-end key selected</string>
</resources>