From 256825bd893a997f10abac4006335d55fdb54859 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 4 Mar 2020 13:23:47 +0100 Subject: [PATCH] Reorganized display and privacy settings --- .../eu/faircode/email/FragmentOptions.java | 10 +- .../email/FragmentOptionsDisplay.java | 123 ++++---- .../email/FragmentOptionsEncryption.java | 287 ++++++++++++++++++ .../email/FragmentOptionsPrivacy.java | 167 +--------- .../res/layout/fragment_options_display.xml | 163 ++++++---- .../layout/fragment_options_encryption.xml | 195 ++++++++++++ .../res/layout/fragment_options_privacy.xml | 172 +---------- app/src/main/res/values/strings.xml | 12 +- 8 files changed, 666 insertions(+), 463 deletions(-) create mode 100644 app/src/main/java/eu/faircode/email/FragmentOptionsEncryption.java create mode 100644 app/src/main/res/layout/fragment_options_encryption.xml diff --git a/app/src/main/java/eu/faircode/email/FragmentOptions.java b/app/src/main/java/eu/faircode/email/FragmentOptions.java index df0308abeb..b99dd0eca6 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptions.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptions.java @@ -116,7 +116,7 @@ public class FragmentOptions extends FragmentBase { @Override public int getCount() { - return 9; + return 10; } @Override @@ -137,8 +137,10 @@ public class FragmentOptions extends FragmentBase { case 6: return new FragmentOptionsPrivacy(); case 7: - return new FragmentOptionsNotifications(); + return new FragmentOptionsEncryption(); case 8: + return new FragmentOptionsNotifications(); + case 9: return new FragmentOptionsMisc(); default: throw new IllegalArgumentException(); @@ -163,8 +165,10 @@ public class FragmentOptions extends FragmentBase { case 6: return getString(R.string.title_advanced_section_privacy); case 7: - return getString(R.string.title_advanced_section_notifications); + return getString(R.string.title_advanced_section_encryption); case 8: + return getString(R.string.title_advanced_section_notifications); + case 9: return getString(R.string.title_advanced_section_misc); default: throw new IllegalArgumentException(); diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsDisplay.java b/app/src/main/java/eu/faircode/email/FragmentOptionsDisplay.java index 9daa302357..a3b153ade4 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsDisplay.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsDisplay.java @@ -56,13 +56,17 @@ import androidx.preference.PreferenceManager; public class FragmentOptionsDisplay extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener { private Button btnTheme; - private SwitchCompat swLandscape; - private SwitchCompat swLandscape3; private Spinner spStartup; private SwitchCompat swCards; private SwitchCompat swDate; + private SwitchCompat swNavBarColorize; + private SwitchCompat swLandscape; + private SwitchCompat swLandscape3; + private SwitchCompat swThreading; private SwitchCompat swIndentation; + private SwitchCompat swActionbar; + private SwitchCompat swHighlightUnread; private SwitchCompat swColorStripe; private SwitchCompat swAvatars; @@ -102,17 +106,17 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer private SwitchCompat swCollapseQuotes; private SwitchCompat swImagesInline; private SwitchCompat swSeekbar; - private SwitchCompat swActionbar; - private SwitchCompat swNavBarColorize; private final static String[] RESET_OPTIONS = new String[]{ - "theme", "landscape", "landscape3", "startup", "cards", "indentation", "date", "threading", "highlight_unread", "color_stripe", + "theme", "startup", "cards", "date", "navbar_colorize", "landscape", "landscape3", + "threading", "indentation", "actionbar", + "highlight_unread", "color_stripe", "avatars", "gravatars", "generated_icons", "identicons", "circular", "saturation", "brightness", "threshold", "name_email", "prefer_contact", "distinguish_contacts", "authentication", "subject_top", "font_size_sender", "font_size_subject", "subject_italic", "subject_ellipsize", "keywords_header", "flags", "flags_background", "preview", "preview_italic", "preview_lines", "addresses", "attachments_alt", "contrast", "monospaced", "text_color", "text_size", - "inline_images", "collapse_quotes", "seekbar", "actionbar", "navbar_colorize" + "inline_images", "collapse_quotes", "seekbar" }; @Override @@ -126,13 +130,17 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer // Get controls btnTheme = view.findViewById(R.id.btnTheme); - swLandscape = view.findViewById(R.id.swLandscape); - swLandscape3 = view.findViewById(R.id.swLandscape3); spStartup = view.findViewById(R.id.spStartup); swCards = view.findViewById(R.id.swCards); - swIndentation = view.findViewById(R.id.swIndentation); swDate = view.findViewById(R.id.swDate); + swNavBarColorize = view.findViewById(R.id.swNavBarColorize); + swLandscape = view.findViewById(R.id.swLandscape); + swLandscape3 = view.findViewById(R.id.swLandscape3); + swThreading = view.findViewById(R.id.swThreading); + swIndentation = view.findViewById(R.id.swIndentation); + swActionbar = view.findViewById(R.id.swActionbar); + swHighlightUnread = view.findViewById(R.id.swHighlightUnread); swColorStripe = view.findViewById(R.id.swColorStripe); swAvatars = view.findViewById(R.id.swAvatars); @@ -171,8 +179,6 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer swCollapseQuotes = view.findViewById(R.id.swCollapseQuotes); swImagesInline = view.findViewById(R.id.swImagesInline); swSeekbar = view.findViewById(R.id.swSeekbar); - swActionbar = view.findViewById(R.id.swActionbar); - swNavBarColorize = view.findViewById(R.id.swNavBarColorize); setOptions(); @@ -187,21 +193,6 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer } }); - swLandscape.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { - prefs.edit().putBoolean("landscape", checked).apply(); - swLandscape3.setEnabled(checked); - } - }); - - swLandscape3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { - prefs.edit().putBoolean("landscape3", checked).apply(); - } - }); - spStartup.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView adapterView, View view, int position, long id) { @@ -223,13 +214,6 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer } }); - swIndentation.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { - prefs.edit().putBoolean("indentation", checked).apply(); - } - }); - swDate.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { @@ -237,6 +221,30 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer } }); + swNavBarColorize.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + prefs.edit().putBoolean("navbar_colorize", checked).apply(); + setNavigationBarColor( + checked ? Helper.resolveColor(getContext(), R.attr.colorPrimaryDark) : Color.BLACK); + } + }); + + swLandscape.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + prefs.edit().putBoolean("landscape", checked).apply(); + swLandscape3.setEnabled(checked); + } + }); + + swLandscape3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + prefs.edit().putBoolean("landscape3", checked).apply(); + } + }); + swThreading.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { @@ -245,6 +253,20 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer } }); + swIndentation.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + prefs.edit().putBoolean("indentation", checked).apply(); + } + }); + + swActionbar.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + prefs.edit().putBoolean("actionbar", checked).apply(); + } + }); + swHighlightUnread.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { @@ -564,22 +586,6 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer } }); - swActionbar.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { - prefs.edit().putBoolean("actionbar", checked).apply(); - } - }); - - swNavBarColorize.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { - prefs.edit().putBoolean("navbar_colorize", checked).apply(); - setNavigationBarColor( - checked ? Helper.resolveColor(getContext(), R.attr.colorPrimaryDark) : Color.BLACK); - } - }); - PreferenceManager.getDefaultSharedPreferences(getContext()).registerOnSharedPreferenceChangeListener(this); return view; @@ -632,11 +638,6 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer boolean normal = getResources().getConfiguration() .isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_NORMAL); - swLandscape.setChecked(prefs.getBoolean("landscape", true)); - swLandscape.setEnabled(normal); - swLandscape3.setChecked(prefs.getBoolean("landscape3", false)); - swLandscape3.setEnabled(normal && swLandscape.isChecked()); - String startup = prefs.getString("startup", "unified"); String[] startupValues = getResources().getStringArray(R.array.startupValues); for (int pos = 0; pos < startupValues.length; pos++) @@ -646,10 +647,18 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer } swCards.setChecked(prefs.getBoolean("cards", true)); + swDate.setChecked(prefs.getBoolean("date", true)); + swNavBarColorize.setChecked(prefs.getBoolean("navbar_colorize", false)); + swLandscape.setChecked(prefs.getBoolean("landscape", true)); + swLandscape.setEnabled(normal); + swLandscape3.setChecked(prefs.getBoolean("landscape3", false)); + swLandscape3.setEnabled(normal && swLandscape.isChecked()); + + swThreading.setChecked(prefs.getBoolean("threading", true)); swIndentation.setChecked(prefs.getBoolean("indentation", false)); swIndentation.setEnabled(swCards.isChecked()); - swDate.setChecked(prefs.getBoolean("date", true)); - swThreading.setChecked(prefs.getBoolean("threading", true)); + swActionbar.setChecked(prefs.getBoolean("actionbar", true)); + swHighlightUnread.setChecked(prefs.getBoolean("highlight_unread", false)); swColorStripe.setChecked(prefs.getBoolean("color_stripe", true)); swAvatars.setChecked(prefs.getBoolean("avatars", true)); @@ -716,8 +725,6 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer swCollapseQuotes.setChecked(prefs.getBoolean("collapse_quotes", false)); swImagesInline.setChecked(prefs.getBoolean("inline_images", false)); swSeekbar.setChecked(prefs.getBoolean("seekbar", false)); - swActionbar.setChecked(prefs.getBoolean("actionbar", true)); - swNavBarColorize.setChecked(prefs.getBoolean("navbar_colorize", false)); updateColor(); } diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsEncryption.java b/app/src/main/java/eu/faircode/email/FragmentOptionsEncryption.java new file mode 100644 index 0000000000..9e7e358550 --- /dev/null +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsEncryption.java @@ -0,0 +1,287 @@ +package eu.faircode.email; + +/* + This file is part of FairEmail. + + FairEmail is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + FairEmail is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with FairEmail. If not, see . + + Copyright 2018-2020 by Marcel Bokhorst (M66B) +*/ + +import android.content.Intent; +import android.content.SharedPreferences; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; +import android.os.Bundle; +import android.provider.Settings; +import android.security.KeyChain; +import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.CompoundButton; +import android.widget.Spinner; +import android.widget.TextView; +import android.widget.Toast; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.widget.SwitchCompat; +import androidx.lifecycle.Lifecycle; +import androidx.localbroadcastmanager.content.LocalBroadcastManager; +import androidx.preference.PreferenceManager; + +import org.openintents.openpgp.util.OpenPgpApi; + +import java.security.NoSuchAlgorithmException; +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; + + private Spinner spOpenPgp; + private SwitchCompat swAutocrypt; + private SwitchCompat swAutocryptMutual; + + private Button btnManageCertificates; + private Button btnImportKey; + private Button btnManageKeys; + private TextView tvKeySize; + + private List openPgpProvider = new ArrayList<>(); + + private final static String[] RESET_OPTIONS = new String[]{ + "default_encrypt_method", "sign_default", "encrypt_default", "auto_decrypt", + "openpgp_provider", "autocrypt", "autocrypt_mutual" + }; + + @Override + @Nullable + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + setSubtitle(R.string.title_setup); + setHasOptionsMenu(true); + + PackageManager pm = getContext().getPackageManager(); + View view = inflater.inflate(R.layout.fragment_options_encryption, container, false); + + // 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); + + spOpenPgp = view.findViewById(R.id.spOpenPgp); + swAutocrypt = view.findViewById(R.id.swAutocrypt); + swAutocryptMutual = view.findViewById(R.id.swAutocryptMutual); + + btnManageCertificates = view.findViewById(R.id.btnManageCertificates); + btnImportKey = view.findViewById(R.id.btnImportKey); + btnManageKeys = view.findViewById(R.id.btnManageKeys); + tvKeySize = view.findViewById(R.id.tvKeySize); + + Intent intent = new Intent(OpenPgpApi.SERVICE_INTENT_2); + List ris = pm.queryIntentServices(intent, 0); + for (ResolveInfo ri : ris) + if (ri.serviceInfo != null) + openPgpProvider.add(ri.serviceInfo.packageName); + + ArrayAdapter adapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, android.R.id.text1); + adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + adapter.addAll(openPgpProvider); + spOpenPgp.setAdapter(adapter); + + setOptions(); + + // Wire controls + + 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) { + prefs.edit().putBoolean("sign_default", checked).apply(); + } + }); + + swEncrypt.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + prefs.edit().putBoolean("encrypt_default", checked).apply(); + swSign.setEnabled(!checked); + } + }); + + swAutoDecrypt.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + prefs.edit().putBoolean("auto_decrypt", checked).apply(); + } + }); + + // PGP + + spOpenPgp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView adapterView, View view, int position, long id) { + prefs.edit().putString("openpgp_provider", openPgpProvider.get(position)).apply(); + } + + @Override + public void onNothingSelected(AdapterView parent) { + prefs.edit().remove("openpgp_provider").apply(); + } + }); + + swAutocrypt.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + prefs.edit().putBoolean("autocrypt", checked).apply(); + swAutocryptMutual.setEnabled(checked); + } + }); + + swAutocryptMutual.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + prefs.edit().putBoolean("autocrypt_mutual", checked).apply(); + } + }); + + // S/MIME + + btnManageCertificates.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext()); + lbm.sendBroadcast(new Intent(ActivitySetup.ACTION_MANAGE_CERTIFICATES)); + } + }); + + final Intent importKey = KeyChain.createInstallIntent(); + btnImportKey.setEnabled(importKey.resolveActivity(pm) != null); + btnImportKey.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + startActivity(importKey); + } + }); + + final Intent security = new Intent(Settings.ACTION_SECURITY_SETTINGS); + btnImportKey.setEnabled(security.resolveActivity(pm) != null); + btnManageKeys.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + startActivity(security); + } + }); + + try { + int maxKeySize = javax.crypto.Cipher.getMaxAllowedKeyLength("AES"); + tvKeySize.setText(getString(R.string.title_advanced_aes_key_size, maxKeySize)); + } catch (NoSuchAlgorithmException ex) { + tvKeySize.setText(Log.formatThrowable(ex)); + } + + PreferenceManager.getDefaultSharedPreferences(getContext()).registerOnSharedPreferenceChangeListener(this); + + return view; + } + + @Override + public void onDestroyView() { + PreferenceManager.getDefaultSharedPreferences(getContext()).unregisterOnSharedPreferenceChangeListener(this); + super.onDestroyView(); + } + + @Override + public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) + setOptions(); + } + + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + inflater.inflate(R.menu.menu_options, menu); + super.onCreateOptionsMenu(menu, inflater); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.menu_default: + onMenuDefault(); + return true; + default: + return super.onOptionsItemSelected(item); + } + } + + private void onMenuDefault() { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); + SharedPreferences.Editor editor = prefs.edit(); + for (String option : RESET_OPTIONS) + editor.remove(option); + editor.apply(); + ToastEx.makeText(getContext(), R.string.title_setup_done, Toast.LENGTH_LONG).show(); + } + + 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()); + swAutoDecrypt.setChecked(prefs.getBoolean("auto_decrypt", false)); + + String provider = prefs.getString("openpgp_provider", "org.sufficientlysecure.keychain"); + for (int pos = 0; pos < openPgpProvider.size(); pos++) + if (provider.equals(openPgpProvider.get(pos))) { + spOpenPgp.setSelection(pos); + break; + } + + swAutocrypt.setChecked(prefs.getBoolean("autocrypt", true)); + swAutocryptMutual.setChecked(prefs.getBoolean("autocrypt_mutual", true)); + swAutocryptMutual.setEnabled(swAutocrypt.isChecked()); + } +} diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsPrivacy.java b/app/src/main/java/eu/faircode/email/FragmentOptionsPrivacy.java index 97dc5ea612..6e073fe0c6 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsPrivacy.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsPrivacy.java @@ -24,11 +24,8 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; -import android.content.pm.ResolveInfo; import android.os.Bundle; import android.os.Handler; -import android.provider.Settings; -import android.security.KeyChain; import android.text.TextUtils; import android.view.KeyEvent; import android.view.LayoutInflater; @@ -40,7 +37,6 @@ import android.view.ViewGroup; import android.view.WindowManager; import android.view.inputmethod.EditorInfo; import android.widget.AdapterView; -import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.CompoundButton; import android.widget.EditText; @@ -53,45 +49,22 @@ import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.widget.SwitchCompat; import androidx.lifecycle.Lifecycle; -import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.preference.PreferenceManager; -import org.openintents.openpgp.util.OpenPgpApi; - -import java.security.NoSuchAlgorithmException; -import java.util.ArrayList; -import java.util.List; - public class FragmentOptionsPrivacy extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener { private SwitchCompat swConfirmLinks; private SwitchCompat swConfirmImages; private SwitchCompat swConfirmHtml; private SwitchCompat swDisableTracking; private SwitchCompat swDisplayHidden; - private Spinner spEncryptMethod; - private Spinner spOpenPgp; - private SwitchCompat swAutocrypt; - private SwitchCompat swAutocryptMutual; - private SwitchCompat swSign; - private SwitchCompat swEncrypt; - private SwitchCompat swAutoDecrypt; private SwitchCompat swSecure; private Button btnBiometrics; private Button btnPin; private Spinner spBiometricsTimeout; - private Button btnManageCertificates; - private Button btnImportKey; - private Button btnManageKeys; - private TextView tvKeySize; - - private List openPgpProvider = new ArrayList<>(); private final static String[] RESET_OPTIONS = new String[]{ "confirm_links", "confirm_images", "confirm_html", - "disable_tracking", "display_hidden", - "default_encrypt_method", "openpgp_provider", "autocrypt", "autocrypt_mutual", - "sign_default", "encrypt_default", "auto_decrypt", - "secure", + "disable_tracking", "display_hidden", "secure", "biometrics", "pin", "biometrics_timeout" }; @@ -111,32 +84,10 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer swConfirmHtml = view.findViewById(R.id.swConfirmHtml); swDisableTracking = view.findViewById(R.id.swDisableTracking); swDisplayHidden = view.findViewById(R.id.swDisplayHidden); - spEncryptMethod = view.findViewById(R.id.spEncryptMethod); - spOpenPgp = view.findViewById(R.id.spOpenPgp); - swAutocrypt = view.findViewById(R.id.swAutocrypt); - swAutocryptMutual = view.findViewById(R.id.swAutocryptMutual); - swSign = view.findViewById(R.id.swSign); - swEncrypt = view.findViewById(R.id.swEncrypt); - swAutoDecrypt = view.findViewById(R.id.swAutoDecrypt); swSecure = view.findViewById(R.id.swSecure); btnBiometrics = view.findViewById(R.id.btnBiometrics); btnPin = view.findViewById(R.id.btnPin); spBiometricsTimeout = view.findViewById(R.id.spBiometricsTimeout); - btnManageCertificates = view.findViewById(R.id.btnManageCertificates); - btnImportKey = view.findViewById(R.id.btnImportKey); - btnManageKeys = view.findViewById(R.id.btnManageKeys); - tvKeySize = view.findViewById(R.id.tvKeySize); - - Intent intent = new Intent(OpenPgpApi.SERVICE_INTENT_2); - List ris = pm.queryIntentServices(intent, 0); - for (ResolveInfo ri : ris) - if (ri.serviceInfo != null) - openPgpProvider.add(ri.serviceInfo.packageName); - - ArrayAdapter adapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, android.R.id.text1); - adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - adapter.addAll(openPgpProvider); - spOpenPgp.setAdapter(adapter); setOptions(); @@ -179,70 +130,6 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer } }); - 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(); - } - }); - - spOpenPgp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { - @Override - public void onItemSelected(AdapterView adapterView, View view, int position, long id) { - prefs.edit().putString("openpgp_provider", openPgpProvider.get(position)).apply(); - } - - @Override - public void onNothingSelected(AdapterView parent) { - prefs.edit().remove("openpgp_provider").apply(); - } - }); - - swAutocrypt.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { - prefs.edit().putBoolean("autocrypt", checked).apply(); - swAutocryptMutual.setEnabled(checked); - } - }); - - swAutocryptMutual.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { - prefs.edit().putBoolean("autocrypt_mutual", checked).apply(); - } - }); - - swSign.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { - prefs.edit().putBoolean("sign_default", checked).apply(); - } - }); - - swEncrypt.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { - prefs.edit().putBoolean("encrypt_default", checked).apply(); - swSign.setEnabled(!checked); - } - }); - - swAutoDecrypt.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { - prefs.edit().putBoolean("auto_decrypt", checked).apply(); - } - }); - swSecure.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { @@ -302,39 +189,6 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer } }); - btnManageCertificates.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext()); - lbm.sendBroadcast(new Intent(ActivitySetup.ACTION_MANAGE_CERTIFICATES)); - } - }); - - final Intent importKey = KeyChain.createInstallIntent(); - btnImportKey.setEnabled(importKey.resolveActivity(pm) != null); - btnImportKey.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - startActivity(importKey); - } - }); - - final Intent security = new Intent(Settings.ACTION_SECURITY_SETTINGS); - btnImportKey.setEnabled(security.resolveActivity(pm) != null); - btnManageKeys.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - startActivity(security); - } - }); - - try { - int maxKeySize = javax.crypto.Cipher.getMaxAllowedKeyLength("AES"); - tvKeySize.setText(getString(R.string.title_advanced_aes_key_size, maxKeySize)); - } catch (NoSuchAlgorithmException ex) { - tvKeySize.setText(Log.formatThrowable(ex)); - } - PreferenceManager.getDefaultSharedPreferences(getContext()).registerOnSharedPreferenceChangeListener(this); return view; @@ -386,25 +240,6 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer swConfirmHtml.setChecked(prefs.getBoolean("confirm_html", true)); swDisableTracking.setChecked(prefs.getBoolean("disable_tracking", true)); swDisplayHidden.setChecked(prefs.getBoolean("display_hidden", false)); - - String encrypt_method = prefs.getString("default_encrypt_method", "pgp"); - if ("s/mime".equals(encrypt_method)) - spEncryptMethod.setSelection(1); - - String provider = prefs.getString("openpgp_provider", "org.sufficientlysecure.keychain"); - for (int pos = 0; pos < openPgpProvider.size(); pos++) - if (provider.equals(openPgpProvider.get(pos))) { - spOpenPgp.setSelection(pos); - break; - } - - swAutocrypt.setChecked(prefs.getBoolean("autocrypt", true)); - swAutocryptMutual.setChecked(prefs.getBoolean("autocrypt_mutual", true)); - swAutocryptMutual.setEnabled(swAutocrypt.isChecked()); - swSign.setChecked(prefs.getBoolean("sign_default", false)); - swEncrypt.setChecked(prefs.getBoolean("encrypt_default", false)); - swSign.setEnabled(!swEncrypt.isChecked()); - swAutoDecrypt.setChecked(prefs.getBoolean("auto_decrypt", false)); swSecure.setChecked(prefs.getBoolean("secure", false)); boolean biometrics = prefs.getBoolean("biometrics", false); diff --git a/app/src/main/res/layout/fragment_options_display.xml b/app/src/main/res/layout/fragment_options_display.xml index 90c1c27a05..7d8cb100cf 100644 --- a/app/src/main/res/layout/fragment_options_display.xml +++ b/app/src/main/res/layout/fragment_options_display.xml @@ -28,6 +28,17 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> + +