Prevent crash

This commit is contained in:
M66B 2021-02-19 20:30:49 +01:00
parent 1cc9cc204a
commit 9a7085bc78
1 changed files with 35 additions and 23 deletions

View File

@ -125,12 +125,17 @@ public class FragmentOptionsEncryption extends FragmentBase implements SharedPre
btnCa = view.findViewById(R.id.btnCa); btnCa = view.findViewById(R.id.btnCa);
tvKeySize = view.findViewById(R.id.tvKeySize); tvKeySize = view.findViewById(R.id.tvKeySize);
Intent intent = new Intent(OpenPgpApi.SERVICE_INTENT_2); try {
List<ResolveInfo> ris = pm.queryIntentServices(intent, 0); // package whitelisted openPgpProvider.clear();
if (ris != null) Intent intent = new Intent(OpenPgpApi.SERVICE_INTENT_2);
for (ResolveInfo ri : ris) List<ResolveInfo> ris = pm.queryIntentServices(intent, 0); // package whitelisted
if (ri.serviceInfo != null) if (ris != null)
openPgpProvider.add(ri.serviceInfo.packageName); for (ResolveInfo ri : ris)
if (ri.serviceInfo != null)
openPgpProvider.add(ri.serviceInfo.packageName);
} catch (Throwable ex) {
Log.e(ex);
}
ArrayAdapter<String> adapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, android.R.id.text1); ArrayAdapter<String> adapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, android.R.id.text1);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
@ -390,24 +395,31 @@ public class FragmentOptionsEncryption extends FragmentBase implements SharedPre
} }
private void testOpenPgp(String pkg) { private void testOpenPgp(String pkg) {
if (pgpService != null && pgpService.isBound()) Log.i("Testing OpenPGP pkg=" + pkg);
pgpService.unbindFromService(); try {
if (pgpService != null && pgpService.isBound())
pgpService.unbindFromService();
tvOpenPgpStatus.setText("PGP binding to " + pkg); tvOpenPgpStatus.setText("PGP binding to " + pkg);
pgpService = new OpenPgpServiceConnection(getContext(), pkg, new OpenPgpServiceConnection.OnBound() { pgpService = new OpenPgpServiceConnection(getContext(), pkg, new OpenPgpServiceConnection.OnBound() {
@Override @Override
public void onBound(IOpenPgpService2 service) { public void onBound(IOpenPgpService2 service) {
tvOpenPgpStatus.setText("PGP bound to " + pkg); tvOpenPgpStatus.setText("PGP bound to " + pkg);
} }
@Override @Override
public void onError(Exception ex) { public void onError(Exception ex) {
if ("bindService() returned false!".equals(ex.getMessage())) if ("bindService() returned false!".equals(ex.getMessage()))
tvOpenPgpStatus.setText("No OpenPGP providers"); tvOpenPgpStatus.setText("No OpenPGP providers");
else else {
tvOpenPgpStatus.setText(ex.toString()); Log.e(ex);
} tvOpenPgpStatus.setText(ex.toString());
}); }
pgpService.bindToService(); }
});
pgpService.bindToService();
} catch (Throwable ex) {
Log.e(ex);
}
} }
} }