Added OpenPGP provider selection

pull/167/head
M66B 5 years ago
parent 2429f0b26b
commit ec99d6a0f0

@ -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<String> 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<ResolveInfo> ris = getContext().getPackageManager().queryIntentServices(intent, 0);
for (ResolveInfo ri : ris)
if (ri.serviceInfo != null)
openPgpProvider.add(ri.serviceInfo.packageName);
ArrayAdapter<String> 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));

@ -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 <T> List<List<T>> chunkList(List<T> list, int size) {

@ -59,6 +59,27 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swDisplayHidden" />
<TextView
android:id="@+id/tvOpenPgp"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:layout_marginEnd="48dp"
android:text="@string/title_advanced_openpgp"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Small"
android:textColor="?android:attr/textColorPrimary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvDisplayHiddenHint" />
<Spinner
android:id="@+id/spOpenPgp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvOpenPgp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swAutoDecrypt"
android:layout_width="0dp"
@ -67,7 +88,7 @@
android:text="@string/title_advanced_auto_decrypt"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvDisplayHiddenHint"
app:layout_constraintTop_toBottomOf="@id/spOpenPgp"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat

@ -322,6 +322,7 @@
<string name="title_advanced_tracking">Automatically recognize and disable tracking images</string>
<string name="title_advanced_display_hidden">Display hidden message texts</string>
<string name="title_advanced_openpgp">OpenPGP provider</string>
<string name="title_advanced_auto_decrypt">Automatically decrypt messages</string>
<string name="title_advanced_recents">Hide FairEmail from screen with recent apps</string>
<string name="title_advanced_biometrics_timeout">Biometric authentication timeout</string>

Loading…
Cancel
Save