mirror of https://github.com/M66B/FairEmail.git
Symplify encryption flow
This commit is contained in:
parent
e8d2ede596
commit
7b7ec3aff3
|
@ -46,9 +46,7 @@ public class ActivityCompose extends ActivityBilling implements FragmentManager.
|
||||||
static final int REQUEST_CONTACT_BCC = 3;
|
static final int REQUEST_CONTACT_BCC = 3;
|
||||||
static final int REQUEST_IMAGE = 4;
|
static final int REQUEST_IMAGE = 4;
|
||||||
static final int REQUEST_ATTACHMENT = 5;
|
static final int REQUEST_ATTACHMENT = 5;
|
||||||
static final int REQUEST_KEY = 6;
|
static final int REQUEST_ENCRYPT = 6;
|
||||||
static final int REQUEST_ENCRYPT = 7;
|
|
||||||
static final int REQUEST_SIGN = 8;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
|
@ -1101,9 +1101,9 @@ public class FragmentCompose extends FragmentBase {
|
||||||
for (int i = 0; i < ato.length; i++)
|
for (int i = 0; i < ato.length; i++)
|
||||||
tos[i] = ato[i].getAddress();
|
tos[i] = ato[i].getAddress();
|
||||||
|
|
||||||
Intent data = new Intent(OpenPgpApi.ACTION_GET_SIGN_KEY_ID);
|
Intent intent = new Intent(OpenPgpApi.ACTION_GET_SIGN_KEY_ID);
|
||||||
data.putExtra(OpenPgpApi.EXTRA_USER_IDS, tos);
|
intent.putExtra(OpenPgpApi.EXTRA_USER_IDS, tos);
|
||||||
encrypt(data);
|
encrypt(intent);
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
if (ex instanceof IllegalArgumentException)
|
if (ex instanceof IllegalArgumentException)
|
||||||
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show();
|
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show();
|
||||||
|
@ -1206,7 +1206,8 @@ public class FragmentCompose extends FragmentBase {
|
||||||
: result.getByteArrayExtra(OpenPgpApi.RESULT_DETACHED_SIGNATURE));
|
: result.getByteArrayExtra(OpenPgpApi.RESULT_DETACHED_SIGNATURE));
|
||||||
|
|
||||||
File file = attachment.getFile(context);
|
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))) {
|
try (OutputStream out = new BufferedOutputStream(new FileOutputStream(file))) {
|
||||||
out.write(bytes);
|
out.write(bytes);
|
||||||
db.attachment().setDownloaded(attachment.id, (long) bytes.length);
|
db.attachment().setDownloaded(attachment.id, (long) bytes.length);
|
||||||
|
@ -1233,12 +1234,6 @@ public class FragmentCompose extends FragmentBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
|
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);
|
return result.getParcelableExtra(OpenPgpApi.RESULT_INTENT);
|
||||||
|
|
||||||
case OpenPgpApi.RESULT_CODE_ERROR:
|
case OpenPgpApi.RESULT_CODE_ERROR:
|
||||||
|
@ -1255,14 +1250,14 @@ public class FragmentCompose extends FragmentBase {
|
||||||
if (result == null)
|
if (result == null)
|
||||||
onAction(R.id.action_send);
|
onAction(R.id.action_send);
|
||||||
else if (result instanceof Intent) {
|
else if (result instanceof Intent) {
|
||||||
Intent data = (Intent) result;
|
Intent intent = (Intent) result;
|
||||||
encrypt(data);
|
encrypt(intent);
|
||||||
} else if (result instanceof PendingIntent)
|
} else if (result instanceof PendingIntent)
|
||||||
try {
|
try {
|
||||||
PendingIntent pi = (PendingIntent) result;
|
PendingIntent pi = (PendingIntent) result;
|
||||||
startIntentSenderForResult(
|
startIntentSenderForResult(
|
||||||
pi.getIntentSender(),
|
pi.getIntentSender(),
|
||||||
args.getInt("request"),
|
ActivityCompose.REQUEST_ENCRYPT,
|
||||||
null, 0, 0, 0, null);
|
null, 0, 0, 0, null);
|
||||||
} catch (IntentSender.SendIntentException ex) {
|
} catch (IntentSender.SendIntentException ex) {
|
||||||
Log.e(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 (data != null) {
|
||||||
if (BuildConfig.BETA_RELEASE)
|
if (BuildConfig.BETA_RELEASE)
|
||||||
Log.logExtras(data);
|
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));
|
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));
|
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);
|
intent.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
|
||||||
encrypt(intent);
|
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);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (data != null)
|
if (data != null)
|
||||||
|
|
Loading…
Reference in New Issue