Moved PGP debugging to encryption options

pull/178/head
M66B 5 years ago
parent a6e4296b1d
commit 63b83fb480

@ -136,7 +136,6 @@ import org.jsoup.nodes.Node;
import org.jsoup.nodes.TextNode; import org.jsoup.nodes.TextNode;
import org.jsoup.select.Elements; import org.jsoup.select.Elements;
import org.jsoup.select.NodeFilter; import org.jsoup.select.NodeFilter;
import org.openintents.openpgp.IOpenPgpService2;
import org.openintents.openpgp.OpenPgpError; import org.openintents.openpgp.OpenPgpError;
import org.openintents.openpgp.util.OpenPgpApi; import org.openintents.openpgp.util.OpenPgpApi;
import org.openintents.openpgp.util.OpenPgpServiceConnection; import org.openintents.openpgp.util.OpenPgpServiceConnection;
@ -885,20 +884,7 @@ public class FragmentCompose extends FragmentBase {
final String pkg = Helper.getOpenKeychainPackage(getContext()); final String pkg = Helper.getOpenKeychainPackage(getContext());
Log.i("PGP binding to " + pkg); Log.i("PGP binding to " + pkg);
pgpService = new OpenPgpServiceConnection(getContext(), pkg, new OpenPgpServiceConnection.OnBound() { pgpService = new OpenPgpServiceConnection(getContext(), pkg);
@Override
public void onBound(IOpenPgpService2 service) {
Log.i("PGP bound to " + pkg);
}
@Override
public void onError(Exception ex) {
if ("bindService() returned false!".equals(ex.getMessage()))
Log.i("PGP " + ex.getMessage());
else
Log.e("PGP", ex);
}
});
pgpService.bindToService(); pgpService.bindToService();
return view; return view;
@ -1016,8 +1002,10 @@ public class FragmentCompose extends FragmentBase {
public void onDestroyView() { public void onDestroyView() {
adapter = null; adapter = null;
if (pgpService != null && pgpService.isBound()) if (pgpService != null && pgpService.isBound()) {
Log.i("PGP unbinding");
pgpService.unbindFromService(); pgpService.unbindFromService();
}
pgpService = null; pgpService = null;
super.onDestroyView(); super.onDestroyView();

@ -145,7 +145,6 @@ import org.json.JSONException;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element; import org.jsoup.nodes.Element;
import org.openintents.openpgp.AutocryptPeerUpdate; import org.openintents.openpgp.AutocryptPeerUpdate;
import org.openintents.openpgp.IOpenPgpService2;
import org.openintents.openpgp.OpenPgpError; import org.openintents.openpgp.OpenPgpError;
import org.openintents.openpgp.OpenPgpSignatureResult; import org.openintents.openpgp.OpenPgpSignatureResult;
import org.openintents.openpgp.util.OpenPgpApi; import org.openintents.openpgp.util.OpenPgpApi;
@ -1262,20 +1261,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
final String pkg = Helper.getOpenKeychainPackage(getContext()); final String pkg = Helper.getOpenKeychainPackage(getContext());
Log.i("PGP binding to " + pkg); Log.i("PGP binding to " + pkg);
pgpService = new OpenPgpServiceConnection(getContext(), pkg, new OpenPgpServiceConnection.OnBound() { pgpService = new OpenPgpServiceConnection(getContext(), pkg);
@Override
public void onBound(IOpenPgpService2 service) {
Log.i("PGP bound to " + pkg);
}
@Override
public void onError(Exception ex) {
if ("bindService() returned false!".equals(ex.getMessage()))
Log.i("PGP " + ex.getMessage());
else
Log.e("PGP", ex);
}
});
pgpService.bindToService(); pgpService.bindToService();
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext()); LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext());
@ -1292,8 +1278,10 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext()); LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext());
lbm.unregisterReceiver(creceiver); lbm.unregisterReceiver(creceiver);
if (pgpService != null && pgpService.isBound()) if (pgpService != null && pgpService.isBound()) {
Log.i("PGP unbinding");
pgpService.unbindFromService(); pgpService.unbindFromService();
}
pgpService = null; pgpService = null;
kv.clear(); kv.clear();

@ -47,7 +47,9 @@ import androidx.lifecycle.Lifecycle;
import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import org.openintents.openpgp.IOpenPgpService2;
import org.openintents.openpgp.util.OpenPgpApi; import org.openintents.openpgp.util.OpenPgpApi;
import org.openintents.openpgp.util.OpenPgpServiceConnection;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.ArrayList; import java.util.ArrayList;
@ -68,6 +70,7 @@ public class FragmentOptionsEncryption extends FragmentBase implements SharedPre
private Button btnManageKeys; private Button btnManageKeys;
private TextView tvKeySize; private TextView tvKeySize;
private OpenPgpServiceConnection pgpService;
private List<String> openPgpProvider = new ArrayList<>(); private List<String> openPgpProvider = new ArrayList<>();
private final static String[] RESET_OPTIONS = new String[]{ private final static String[] RESET_OPTIONS = new String[]{
@ -159,7 +162,14 @@ public class FragmentOptionsEncryption extends FragmentBase implements SharedPre
spOpenPgp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { spOpenPgp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override @Override
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) { public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
prefs.edit().putString("openpgp_provider", openPgpProvider.get(position)).apply(); String pkg = openPgpProvider.get(position);
prefs.edit().putString("openpgp_provider", pkg).apply();
String tag = (String) spOpenPgp.getTag();
if (tag != null && !tag.equals(pkg)) {
spOpenPgp.setTag(pkg);
testOpenPgp(pkg);
}
} }
@Override @Override
@ -226,6 +236,13 @@ public class FragmentOptionsEncryption extends FragmentBase implements SharedPre
@Override @Override
public void onDestroyView() { public void onDestroyView() {
PreferenceManager.getDefaultSharedPreferences(getContext()).unregisterOnSharedPreferenceChangeListener(this); PreferenceManager.getDefaultSharedPreferences(getContext()).unregisterOnSharedPreferenceChangeListener(this);
if (pgpService != null && pgpService.isBound()) {
Log.i("PGP unbinding");
pgpService.unbindFromService();
}
pgpService = null;
super.onDestroyView(); super.onDestroyView();
} }
@ -274,14 +291,35 @@ public class FragmentOptionsEncryption extends FragmentBase implements SharedPre
swAutoDecrypt.setChecked(prefs.getBoolean("auto_decrypt", false)); swAutoDecrypt.setChecked(prefs.getBoolean("auto_decrypt", false));
String provider = prefs.getString("openpgp_provider", "org.sufficientlysecure.keychain"); String provider = prefs.getString("openpgp_provider", "org.sufficientlysecure.keychain");
spOpenPgp.setTag(provider);
for (int pos = 0; pos < openPgpProvider.size(); pos++) for (int pos = 0; pos < openPgpProvider.size(); pos++)
if (provider.equals(openPgpProvider.get(pos))) { if (provider.equals(openPgpProvider.get(pos))) {
spOpenPgp.setSelection(pos); spOpenPgp.setSelection(pos);
break; break;
} }
testOpenPgp(provider);
swAutocrypt.setChecked(prefs.getBoolean("autocrypt", true)); swAutocrypt.setChecked(prefs.getBoolean("autocrypt", true));
swAutocryptMutual.setChecked(prefs.getBoolean("autocrypt_mutual", true)); swAutocryptMutual.setChecked(prefs.getBoolean("autocrypt_mutual", true));
swAutocryptMutual.setEnabled(swAutocrypt.isChecked()); swAutocryptMutual.setEnabled(swAutocrypt.isChecked());
} }
private void testOpenPgp(String pkg) {
if (pgpService != null && pgpService.isBound())
pgpService.unbindFromService();
Log.i("PGP binding to " + pkg);
pgpService = new OpenPgpServiceConnection(getContext(), pkg, new OpenPgpServiceConnection.OnBound() {
@Override
public void onBound(IOpenPgpService2 service) {
Log.i("PGP bound to " + pkg);
}
@Override
public void onError(Exception ex) {
Log.e("PGP", ex);
}
});
pgpService.bindToService();
}
} }

Loading…
Cancel
Save