Addd manage private keys

pull/169/head
M66B 5 years ago
parent 8dd9c62365
commit dc1e6ae733

@ -23,9 +23,11 @@ import android.app.Dialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.provider.Settings;
import android.security.KeyChain; import android.security.KeyChain;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.KeyEvent; import android.view.KeyEvent;
@ -74,6 +76,7 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer
private Spinner spBiometricsTimeout; private Spinner spBiometricsTimeout;
private Button btnManageCertificates; private Button btnManageCertificates;
private Button btnImportKey; private Button btnImportKey;
private Button btnManageKeys;
private TextView tvKeySize; private TextView tvKeySize;
private List<String> openPgpProvider = new ArrayList<>(); private List<String> openPgpProvider = new ArrayList<>();
@ -91,6 +94,7 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer
setSubtitle(R.string.title_setup); setSubtitle(R.string.title_setup);
setHasOptionsMenu(true); setHasOptionsMenu(true);
PackageManager pm = getContext().getPackageManager();
View view = inflater.inflate(R.layout.fragment_options_privacy, container, false); View view = inflater.inflate(R.layout.fragment_options_privacy, container, false);
// Get controls // Get controls
@ -108,10 +112,11 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer
spBiometricsTimeout = view.findViewById(R.id.spBiometricsTimeout); spBiometricsTimeout = view.findViewById(R.id.spBiometricsTimeout);
btnManageCertificates = view.findViewById(R.id.btnManageCertificates); btnManageCertificates = view.findViewById(R.id.btnManageCertificates);
btnImportKey = view.findViewById(R.id.btnImportKey); btnImportKey = view.findViewById(R.id.btnImportKey);
btnManageKeys = view.findViewById(R.id.btnManageKeys);
tvKeySize = view.findViewById(R.id.tvKeySize); tvKeySize = view.findViewById(R.id.tvKeySize);
Intent intent = new Intent(OpenPgpApi.SERVICE_INTENT_2); Intent intent = new Intent(OpenPgpApi.SERVICE_INTENT_2);
List<ResolveInfo> ris = getContext().getPackageManager().queryIntentServices(intent, 0); List<ResolveInfo> ris = pm.queryIntentServices(intent, 0);
for (ResolveInfo ri : ris) for (ResolveInfo ri : ris)
if (ri.serviceInfo != null) if (ri.serviceInfo != null)
openPgpProvider.add(ri.serviceInfo.packageName); openPgpProvider.add(ri.serviceInfo.packageName);
@ -254,7 +259,7 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer
}); });
final Intent importKey = KeyChain.createInstallIntent(); final Intent importKey = KeyChain.createInstallIntent();
btnImportKey.setEnabled(importKey.resolveActivity(getContext().getPackageManager()) != null); btnImportKey.setEnabled(importKey.resolveActivity(pm) != null);
btnImportKey.setOnClickListener(new View.OnClickListener() { btnImportKey.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -262,6 +267,15 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer
} }
}); });
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 { try {
int maxKeySize = javax.crypto.Cipher.getMaxAllowedKeyLength("AES"); int maxKeySize = javax.crypto.Cipher.getMaxAllowedKeyLength("AES");
tvKeySize.setText(getString(R.string.title_advanced_aes_key_size, maxKeySize)); tvKeySize.setText(getString(R.string.title_advanced_aes_key_size, maxKeySize));

@ -253,6 +253,18 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnManageCertificates" /> app:layout_constraintTop_toBottomOf="@id/btnManageCertificates" />
<Button
android:id="@+id/btnManageKeys"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:minWidth="0dp"
android:minHeight="0dp"
android:text="@string/title_advanced_manage_keys"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnImportKey" />
<TextView <TextView
android:id="@+id/tvKeySize" android:id="@+id/tvKeySize"
android:layout_width="0dp" android:layout_width="0dp"
@ -261,6 +273,6 @@
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnImportKey" /> app:layout_constraintTop_toBottomOf="@id/btnManageKeys" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView> </ScrollView>

@ -340,6 +340,7 @@
<string name="title_advanced_biometrics_timeout">Biometric authentication timeout</string> <string name="title_advanced_biometrics_timeout">Biometric authentication timeout</string>
<string name="title_advanced_manage_certificates">Manage public keys</string> <string name="title_advanced_manage_certificates">Manage public keys</string>
<string name="title_advanced_import_key">Import private key</string> <string name="title_advanced_import_key">Import private key</string>
<string name="title_advanced_manage_keys">Manage private keys</string>
<string name="title_advanced_aes_key_size" translatable="false">Max AES key size: %1$d</string> <string name="title_advanced_aes_key_size" translatable="false">Max AES key size: %1$d</string>
<string name="title_advanced_english">Force English language</string> <string name="title_advanced_english">Force English language</string>

Loading…
Cancel
Save