Symplify encryption flow

This commit is contained in:
M66B 2019-04-24 13:06:46 +02:00
parent e8d2ede596
commit 7b7ec3aff3
2 changed files with 20 additions and 28 deletions

View File

@ -46,9 +46,7 @@ public class ActivityCompose extends ActivityBilling implements FragmentManager.
static final int REQUEST_CONTACT_BCC = 3;
static final int REQUEST_IMAGE = 4;
static final int REQUEST_ATTACHMENT = 5;
static final int REQUEST_KEY = 6;
static final int REQUEST_ENCRYPT = 7;
static final int REQUEST_SIGN = 8;
static final int REQUEST_ENCRYPT = 6;
@Override
protected void onCreate(Bundle savedInstanceState) {

View File

@ -1101,9 +1101,9 @@ public class FragmentCompose extends FragmentBase {
for (int i = 0; i < ato.length; i++)
tos[i] = ato[i].getAddress();
Intent data = new Intent(OpenPgpApi.ACTION_GET_SIGN_KEY_ID);
data.putExtra(OpenPgpApi.EXTRA_USER_IDS, tos);
encrypt(data);
Intent intent = new Intent(OpenPgpApi.ACTION_GET_SIGN_KEY_ID);
intent.putExtra(OpenPgpApi.EXTRA_USER_IDS, tos);
encrypt(intent);
} catch (Throwable ex) {
if (ex instanceof IllegalArgumentException)
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show();
@ -1206,7 +1206,8 @@ public class FragmentCompose extends FragmentBase {
: result.getByteArrayExtra(OpenPgpApi.RESULT_DETACHED_SIGNATURE));
File file = attachment.getFile(context);
Log.i("Writing " + file + " size=" + bytes.length);
if (BuildConfig.BETA_RELEASE)
Log.i("Writing " + file + " size=" + bytes.length);
try (OutputStream out = new BufferedOutputStream(new FileOutputStream(file))) {
out.write(bytes);
db.attachment().setDownloaded(attachment.id, (long) bytes.length);
@ -1233,12 +1234,6 @@ public class FragmentCompose extends FragmentBase {
}
case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
if (OpenPgpApi.ACTION_GET_SIGN_KEY_ID.equals(data.getAction()))
args.putInt("request", ActivityCompose.REQUEST_KEY);
else if (OpenPgpApi.ACTION_SIGN_AND_ENCRYPT.equals(data.getAction()))
args.putInt("request", ActivityCompose.REQUEST_ENCRYPT);
else if (OpenPgpApi.ACTION_DETACHED_SIGN.equals(data.getAction()))
args.putInt("request", ActivityCompose.REQUEST_SIGN);
return result.getParcelableExtra(OpenPgpApi.RESULT_INTENT);
case OpenPgpApi.RESULT_CODE_ERROR:
@ -1255,14 +1250,14 @@ public class FragmentCompose extends FragmentBase {
if (result == null)
onAction(R.id.action_send);
else if (result instanceof Intent) {
Intent data = (Intent) result;
encrypt(data);
Intent intent = (Intent) result;
encrypt(intent);
} else if (result instanceof PendingIntent)
try {
PendingIntent pi = (PendingIntent) result;
startIntentSenderForResult(
pi.getIntentSender(),
args.getInt("request"),
ActivityCompose.REQUEST_ENCRYPT,
null, 0, 0, 0, null);
} catch (IntentSender.SendIntentException ex) {
Log.e(ex);
@ -1305,24 +1300,23 @@ public class FragmentCompose extends FragmentBase {
}
}
}
} else if (requestCode == ActivityCompose.REQUEST_KEY) {
} else if (requestCode == ActivityCompose.REQUEST_ENCRYPT) {
if (data != null) {
if (BuildConfig.BETA_RELEASE)
Log.logExtras(data);
if (OpenPgpApi.ACTION_GET_SIGN_KEY_ID.equals(data.getAction())) {
Intent intent = new Intent(OpenPgpApi.ACTION_SIGN_AND_ENCRYPT);
String action = data.getAction();
if (OpenPgpApi.ACTION_GET_SIGN_KEY_ID.equals(action))
action = OpenPgpApi.ACTION_SIGN_AND_ENCRYPT;
Intent intent = new Intent(action);
if (data.hasExtra(OpenPgpApi.EXTRA_USER_IDS))
intent.putExtra(OpenPgpApi.EXTRA_USER_IDS, data.getStringArrayExtra(OpenPgpApi.EXTRA_USER_IDS));
if (data.hasExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID))
intent.putExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, data.getLongExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, -1));
if (OpenPgpApi.ACTION_SIGN_AND_ENCRYPT.equals(action))
intent.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
encrypt(intent);
} else
encrypt(data);
}
} else if (requestCode == ActivityCompose.REQUEST_ENCRYPT || requestCode == ActivityCompose.REQUEST_SIGN) {
if (data != null) {
if (BuildConfig.BETA_RELEASE)
Log.logExtras(data);
encrypt(data);
encrypt(intent);
}
} else {
if (data != null)