From ec99d6a0f0b1930ffba6e0f30ee5bd3f1eec2be2 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 8 Nov 2019 13:31:01 +0100 Subject: [PATCH] Added OpenPGP provider selection --- .../email/FragmentOptionsPrivacy.java | 42 +++++++++++++++++++ .../main/java/eu/faircode/email/Helper.java | 9 ++-- .../res/layout/fragment_options_privacy.xml | 23 +++++++++- app/src/main/res/values/strings.xml | 1 + 4 files changed, 70 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsPrivacy.java b/app/src/main/java/eu/faircode/email/FragmentOptionsPrivacy.java index ed40775f40..8265125508 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsPrivacy.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsPrivacy.java @@ -23,6 +23,7 @@ import android.app.Dialog; import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; +import android.content.pm.ResolveInfo; import android.os.Bundle; import android.os.Handler; import android.text.TextUtils; @@ -36,6 +37,7 @@ 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; @@ -50,15 +52,23 @@ import androidx.appcompat.widget.SwitchCompat; import androidx.lifecycle.Lifecycle; import androidx.preference.PreferenceManager; +import org.openintents.openpgp.util.OpenPgpApi; + +import java.util.ArrayList; +import java.util.List; + public class FragmentOptionsPrivacy extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener { private SwitchCompat swDisableTracking; private SwitchCompat swDisplayHidden; + private Spinner spOpenPgp; private SwitchCompat swAutoDecrypt; private SwitchCompat swNoHistory; private Button btnBiometrics; private Spinner spBiometricsTimeout; private Button btnPin; + private List openPgpProvider = new ArrayList<>(); + private final static String[] RESET_OPTIONS = new String[]{ "disable_tracking", "display_hidden", "auto_decrypt", "no_history", "biometrics", "pin", "biometrics_timeout" }; @@ -75,12 +85,24 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer swDisableTracking = view.findViewById(R.id.swDisableTracking); swDisplayHidden = view.findViewById(R.id.swDisplayHidden); + spOpenPgp = view.findViewById(R.id.spOpenPgp); swAutoDecrypt = view.findViewById(R.id.swAutoDecrypt); swNoHistory = view.findViewById(R.id.swNoHistory); btnBiometrics = view.findViewById(R.id.btnBiometrics); spBiometricsTimeout = view.findViewById(R.id.spBiometricsTimeout); btnPin = view.findViewById(R.id.btnPin); + Intent intent = new Intent(OpenPgpApi.SERVICE_INTENT_2); + List ris = getContext().getPackageManager().queryIntentServices(intent, 0); + for (ResolveInfo ri : ris) + if (ri.serviceInfo != null) + openPgpProvider.add(ri.serviceInfo.packageName); + + ArrayAdapter adapter = new ArrayAdapter<>(getContext(), R.layout.spinner_item1, android.R.id.text1); + adapter.setDropDownViewResource(R.layout.spinner_item1_dropdown); + adapter.addAll(openPgpProvider); + spOpenPgp.setAdapter(adapter); + setOptions(); // Wire controls @@ -101,6 +123,18 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer } }); + 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(); + } + }); + swAutoDecrypt.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { @@ -211,6 +245,14 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer swDisableTracking.setChecked(prefs.getBoolean("disable_tracking", true)); swDisplayHidden.setChecked(prefs.getBoolean("display_hidden", 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; + } + swAutoDecrypt.setChecked(prefs.getBoolean("auto_decrypt", false)); swNoHistory.setChecked(prefs.getBoolean("no_history", false)); diff --git a/app/src/main/java/eu/faircode/email/Helper.java b/app/src/main/java/eu/faircode/email/Helper.java index 20c1f637e3..4eee12f1f4 100644 --- a/app/src/main/java/eu/faircode/email/Helper.java +++ b/app/src/main/java/eu/faircode/email/Helper.java @@ -284,6 +284,11 @@ public class Helper { return intent; } + static String getOpenKeychainPackage(Context context) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + return prefs.getString("openpgp_provider", "org.sufficientlysecure.keychain"); + } + static Intent getIntentIssue(Context context) { if (ActivityBilling.isPro(context)) { String version = BuildConfig.VERSION_NAME + "/" + @@ -892,10 +897,6 @@ public class Helper { prefs.edit().remove("last_authentication").apply(); } - static String getOpenKeychainPackage(Context context) { - return "org.sufficientlysecure.keychain"; - } - // Miscellaneous static List> chunkList(List list, int size) { diff --git a/app/src/main/res/layout/fragment_options_privacy.xml b/app/src/main/res/layout/fragment_options_privacy.xml index db8fcfb2e9..92ab5f443f 100644 --- a/app/src/main/res/layout/fragment_options_privacy.xml +++ b/app/src/main/res/layout/fragment_options_privacy.xml @@ -59,6 +59,27 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/swDisplayHidden" /> + + + + Automatically recognize and disable tracking images Display hidden message texts + OpenPGP provider Automatically decrypt messages Hide FairEmail from screen with recent apps Biometric authentication timeout