Browse Source

Help installing OpenKeychain

main
M66B 6 years ago
parent
commit
b1bd26424c
3 changed files with 69 additions and 34 deletions
  1. +20
    -8
      app/src/main/java/eu/faircode/email/ActivityView.java
  2. +43
    -26
      app/src/main/java/eu/faircode/email/FragmentCompose.java
  3. +6
    -0
      app/src/main/java/eu/faircode/email/Helper.java

+ 20
- 8
app/src/main/java/eu/faircode/email/ActivityView.java View File

@ -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();
data.setAction(OpenPgpApi.ACTION_DECRYPT_VERIFY);
data.putExtra(OpenPgpApi.EXTRA_USER_IDS, new String[]{intent.getStringExtra("to")});
data.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
if (pgpService.isBound()) {
Intent data = new Intent();
data.setAction(OpenPgpApi.ACTION_DECRYPT_VERIFY);
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


+ 43
- 26
app/src/main/java/eu/faircode/email/FragmentCompose.java View File

@ -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()))
try {
String to = etTo.getText().toString();
InternetAddress ato[] = (TextUtils.isEmpty(to) ? new InternetAddress[0] : InternetAddress.parse(to));
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++)
tos[i] = ato[i].getAddress();
Intent data = new Intent();
data.setAction(OpenPgpApi.ACTION_SIGN_AND_ENCRYPT);
data.putExtra(OpenPgpApi.EXTRA_USER_IDS, tos);
data.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
encrypt(data);
} catch (Throwable ex) {
if (ex instanceof IllegalArgumentException)
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show();
else
Helper.unexpectedError(getContext(), ex);
if (Helper.isPro(getContext())) {
if (pgpService.isBound())
try {
String to = etTo.getText().toString();
InternetAddress ato[] = (TextUtils.isEmpty(to) ? new InternetAddress[0] : InternetAddress.parse(to));
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++)
tos[i] = ato[i].getAddress();
Intent data = new Intent();
data.setAction(OpenPgpApi.ACTION_SIGN_AND_ENCRYPT);
data.putExtra(OpenPgpApi.EXTRA_USER_IDS, tos);
data.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
encrypt(data);
} catch (Throwable ex) {
if (ex instanceof IllegalArgumentException)
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show();
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


+ 6
- 0
app/src/main/java/eu/faircode/email/Helper.java View File

@ -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