Help installing OpenKeychain

pull/146/head
M66B 7 years ago
parent 293ba7ebe6
commit b1bd26424c

@ -316,6 +316,9 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
iff.addAction(ACTION_SHOW_PRO); iff.addAction(ACTION_SHOW_PRO);
lbm.registerReceiver(receiver, iff); lbm.registerReceiver(receiver, iff);
if (!pgpService.isBound())
pgpService.bindToService();
Intent intent = getIntent(); Intent intent = getIntent();
String action = intent.getAction(); String action = intent.getAction();
Log.i(Helper.TAG, "View intent=" + intent + " action=" + action); Log.i(Helper.TAG, "View intent=" + intent + " action=" + action);
@ -899,12 +902,24 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
private void onDecrypt(Intent intent) { private void onDecrypt(Intent intent) {
if (Helper.isPro(this)) { if (Helper.isPro(this)) {
Intent data = new Intent(); if (pgpService.isBound()) {
data.setAction(OpenPgpApi.ACTION_DECRYPT_VERIFY); Intent data = new Intent();
data.putExtra(OpenPgpApi.EXTRA_USER_IDS, new String[]{intent.getStringExtra("to")}); data.setAction(OpenPgpApi.ACTION_DECRYPT_VERIFY);
data.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true); data.putExtra(OpenPgpApi.EXTRA_USER_IDS, new String[]{intent.getStringExtra("to")});
data.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
decrypt(data, intent.getLongExtra("id", -1)); decrypt(data, intent.getLongExtra("id", -1));
} else {
Snackbar snackbar = Snackbar.make(view, R.string.title_no_openpgp, Snackbar.LENGTH_LONG);
if (Helper.getIntentOpenKeychain().resolveActivity(getPackageManager()) != null)
snackbar.setAction(R.string.title_fix, new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(Helper.getIntentOpenKeychain());
}
});
snackbar.show();
}
} else } else
onShowPro(intent); onShowPro(intent);
} }
@ -927,9 +942,6 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
long id = args.getLong("id"); long id = args.getLong("id");
Intent data = args.getParcelable("data"); Intent data = args.getParcelable("data");
if (!pgpService.isBound())
throw new IllegalArgumentException(getString(R.string.title_no_openpgp));
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
// Find encrypted data // Find encrypted data

@ -367,6 +367,14 @@ public class FragmentCompose extends FragmentEx {
} }
} }
@Override
public void onResume() {
super.onResume();
if (!pgpService.isBound())
pgpService.bindToService();
}
@Override @Override
public void onPause() { public void onPause() {
if (autosave) if (autosave)
@ -488,30 +496,42 @@ public class FragmentCompose extends FragmentEx {
} }
private void onEncrypt() { private void onEncrypt() {
if (Helper.isPro(getContext())) if (Helper.isPro(getContext())) {
try { if (pgpService.isBound())
String to = etTo.getText().toString(); try {
InternetAddress ato[] = (TextUtils.isEmpty(to) ? new InternetAddress[0] : InternetAddress.parse(to)); String to = etTo.getText().toString();
if (ato.length == 0) InternetAddress ato[] = (TextUtils.isEmpty(to) ? new InternetAddress[0] : InternetAddress.parse(to));
throw new IllegalArgumentException(getString(R.string.title_to_missing)); if (ato.length == 0)
throw new IllegalArgumentException(getString(R.string.title_to_missing));
String[] tos = new String[ato.length];
for (int i = 0; i < ato.length; i++) String[] tos = new String[ato.length];
tos[i] = ato[i].getAddress(); for (int i = 0; i < ato.length; i++)
tos[i] = ato[i].getAddress();
Intent data = new Intent();
data.setAction(OpenPgpApi.ACTION_SIGN_AND_ENCRYPT); Intent data = new Intent();
data.putExtra(OpenPgpApi.EXTRA_USER_IDS, tos); data.setAction(OpenPgpApi.ACTION_SIGN_AND_ENCRYPT);
data.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true); data.putExtra(OpenPgpApi.EXTRA_USER_IDS, tos);
data.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
encrypt(data);
} catch (Throwable ex) { encrypt(data);
if (ex instanceof IllegalArgumentException) } catch (Throwable ex) {
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show(); if (ex instanceof IllegalArgumentException)
else Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show();
Helper.unexpectedError(getContext(), ex); else
Helper.unexpectedError(getContext(), ex);
}
else {
Snackbar snackbar = Snackbar.make(view, R.string.title_no_openpgp, Snackbar.LENGTH_LONG);
if (Helper.getIntentOpenKeychain().resolveActivity(getContext().getPackageManager()) != null)
snackbar.setAction(R.string.title_fix, new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(Helper.getIntentOpenKeychain());
}
});
snackbar.show();
} }
else { } else {
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.content_frame, new FragmentPro()).addToBackStack("pro"); fragmentTransaction.replace(R.id.content_frame, new FragmentPro()).addToBackStack("pro");
fragmentTransaction.commit(); fragmentTransaction.commit();
@ -530,9 +550,6 @@ public class FragmentCompose extends FragmentEx {
long id = args.getLong("id"); long id = args.getLong("id");
Intent data = args.getParcelable("data"); Intent data = args.getParcelable("data");
if (!pgpService.isBound())
throw new IllegalArgumentException(getString(R.string.title_no_openpgp));
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
// Get attachments // Get attachments

@ -109,6 +109,12 @@ public class Helper {
return intent; return intent;
} }
static Intent getIntentOpenKeychain() {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("https://f-droid.org/en/packages/org.sufficientlysecure.keychain/"));
return intent;
}
static int resolveColor(Context context, int attr) { static int resolveColor(Context context, int attr) {
int[] attrs = new int[]{attr}; int[] attrs = new int[]{attr};
TypedArray a = context.getTheme().obtainStyledAttributes(attrs); TypedArray a = context.getTheme().obtainStyledAttributes(attrs);

Loading…
Cancel
Save