|
|
@ -1248,11 +1248,8 @@ public class FragmentCompose extends FragmentBase {
|
|
|
|
onAddMedia(data);
|
|
|
|
onAddMedia(data);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case REQUEST_ENCRYPT:
|
|
|
|
case REQUEST_ENCRYPT:
|
|
|
|
if (resultCode == RESULT_OK && data != null) {
|
|
|
|
if (resultCode == RESULT_OK && data != null)
|
|
|
|
if (BuildConfig.DEBUG || BuildConfig.BETA_RELEASE)
|
|
|
|
|
|
|
|
Log.logExtras(data);
|
|
|
|
|
|
|
|
onPgp(data);
|
|
|
|
onPgp(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case REQUEST_REF_DELETE:
|
|
|
|
case REQUEST_REF_DELETE:
|
|
|
|
if (resultCode == RESULT_OK)
|
|
|
|
if (resultCode == RESULT_OK)
|
|
|
@ -1489,21 +1486,13 @@ public class FragmentCompose extends FragmentBase {
|
|
|
|
OpenPgpApi.ACTION_SIGN_AND_ENCRYPT.equals(data.getAction()))
|
|
|
|
OpenPgpApi.ACTION_SIGN_AND_ENCRYPT.equals(data.getAction()))
|
|
|
|
encrypted = new ByteArrayOutputStream();
|
|
|
|
encrypted = new ByteArrayOutputStream();
|
|
|
|
|
|
|
|
|
|
|
|
if (BuildConfig.DEBUG || BuildConfig.BETA_RELEASE) {
|
|
|
|
|
|
|
|
Log.i("Execute " + data);
|
|
|
|
|
|
|
|
Log.logExtras(data);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Encrypt message
|
|
|
|
// Encrypt message
|
|
|
|
|
|
|
|
Log.i("Executing " + data.getAction());
|
|
|
|
OpenPgpApi api = new OpenPgpApi(context, pgpService.getService());
|
|
|
|
OpenPgpApi api = new OpenPgpApi(context, pgpService.getService());
|
|
|
|
Intent result = api.executeApi(data, decrypted, encrypted);
|
|
|
|
Intent result = api.executeApi(data, decrypted, encrypted);
|
|
|
|
|
|
|
|
|
|
|
|
if (BuildConfig.DEBUG || BuildConfig.BETA_RELEASE) {
|
|
|
|
|
|
|
|
Log.i("Result " + result);
|
|
|
|
|
|
|
|
Log.logExtras(result);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int resultCode = result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR);
|
|
|
|
int resultCode = result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR);
|
|
|
|
|
|
|
|
Log.i("Result action=" + data.getAction() + " code=" + resultCode);
|
|
|
|
switch (resultCode) {
|
|
|
|
switch (resultCode) {
|
|
|
|
case OpenPgpApi.RESULT_CODE_SUCCESS:
|
|
|
|
case OpenPgpApi.RESULT_CODE_SUCCESS:
|
|
|
|
// Attach encrypted data / signature
|
|
|
|
// Attach encrypted data / signature
|
|
|
@ -1543,8 +1532,7 @@ public class FragmentCompose extends FragmentBase {
|
|
|
|
bytes = encrypted.toByteArray();
|
|
|
|
bytes = encrypted.toByteArray();
|
|
|
|
|
|
|
|
|
|
|
|
File file = attachment.getFile(context);
|
|
|
|
File file = attachment.getFile(context);
|
|
|
|
if (BuildConfig.DEBUG || BuildConfig.BETA_RELEASE)
|
|
|
|
Log.i("Writing " + file + " size=" + bytes.length);
|
|
|
|
Log.i("Writing " + file + " size=" + bytes.length);
|
|
|
|
|
|
|
|
try (OutputStream out = new FileOutputStream(file)) {
|
|
|
|
try (OutputStream out = new FileOutputStream(file)) {
|
|
|
|
out.write(bytes);
|
|
|
|
out.write(bytes);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1557,8 +1545,7 @@ public class FragmentCompose extends FragmentBase {
|
|
|
|
|
|
|
|
|
|
|
|
if (OpenPgpApi.ACTION_GET_KEY_IDS.equals(data.getAction())) {
|
|
|
|
if (OpenPgpApi.ACTION_GET_KEY_IDS.equals(data.getAction())) {
|
|
|
|
pgpKeyIds = result.getLongArrayExtra(OpenPgpApi.EXTRA_KEY_IDS);
|
|
|
|
pgpKeyIds = result.getLongArrayExtra(OpenPgpApi.EXTRA_KEY_IDS);
|
|
|
|
if (BuildConfig.DEBUG || BuildConfig.BETA_RELEASE)
|
|
|
|
Log.i("Keys=" + pgpKeyIds.length);
|
|
|
|
Log.i("Keys=" + pgpKeyIds.length);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Send without encryption
|
|
|
|
// Send without encryption
|
|
|
|
if (pgpKeyIds.length == 0)
|
|
|
|
if (pgpKeyIds.length == 0)
|
|
|
@ -1570,7 +1557,7 @@ public class FragmentCompose extends FragmentBase {
|
|
|
|
intent.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
|
|
|
|
intent.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
|
|
|
|
return intent;
|
|
|
|
return intent;
|
|
|
|
} else if (OpenPgpApi.ACTION_GET_KEY.equals(data.getAction())) {
|
|
|
|
} else if (OpenPgpApi.ACTION_GET_KEY.equals(data.getAction())) {
|
|
|
|
if (identity != null && identity.sign_key != null) {
|
|
|
|
if (identity.sign_key != null) {
|
|
|
|
// Encrypt message
|
|
|
|
// Encrypt message
|
|
|
|
Intent intent = new Intent(OpenPgpApi.ACTION_SIGN_AND_ENCRYPT);
|
|
|
|
Intent intent = new Intent(OpenPgpApi.ACTION_SIGN_AND_ENCRYPT);
|
|
|
|
intent.putExtra(OpenPgpApi.EXTRA_KEY_IDS, pgpKeyIds);
|
|
|
|
intent.putExtra(OpenPgpApi.EXTRA_KEY_IDS, pgpKeyIds);
|
|
|
@ -1583,8 +1570,7 @@ public class FragmentCompose extends FragmentBase {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (OpenPgpApi.ACTION_GET_SIGN_KEY_ID.equals(data.getAction())) {
|
|
|
|
} else if (OpenPgpApi.ACTION_GET_SIGN_KEY_ID.equals(data.getAction())) {
|
|
|
|
pgpSignKeyId = result.getLongExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, -1);
|
|
|
|
pgpSignKeyId = result.getLongExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, -1);
|
|
|
|
if (identity != null)
|
|
|
|
db.identity().setIdentitySignKey(identity.id, pgpSignKeyId);
|
|
|
|
db.identity().setIdentitySignKey(identity.id, pgpSignKeyId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Encrypt message
|
|
|
|
// Encrypt message
|
|
|
|
Intent intent = new Intent(OpenPgpApi.ACTION_SIGN_AND_ENCRYPT);
|
|
|
|
Intent intent = new Intent(OpenPgpApi.ACTION_SIGN_AND_ENCRYPT);
|
|
|
@ -1606,8 +1592,7 @@ public class FragmentCompose extends FragmentBase {
|
|
|
|
return result.getParcelableExtra(OpenPgpApi.RESULT_INTENT);
|
|
|
|
return result.getParcelableExtra(OpenPgpApi.RESULT_INTENT);
|
|
|
|
|
|
|
|
|
|
|
|
case OpenPgpApi.RESULT_CODE_ERROR:
|
|
|
|
case OpenPgpApi.RESULT_CODE_ERROR:
|
|
|
|
if (identity != null)
|
|
|
|
db.identity().setIdentitySignKey(identity.id, null);
|
|
|
|
db.identity().setIdentitySignKey(identity.id, null);
|
|
|
|
|
|
|
|
OpenPgpError error = result.getParcelableExtra(OpenPgpApi.RESULT_ERROR);
|
|
|
|
OpenPgpError error = result.getParcelableExtra(OpenPgpApi.RESULT_ERROR);
|
|
|
|
if (error == null)
|
|
|
|
if (error == null)
|
|
|
|
throw new IllegalArgumentException("Unknown error");
|
|
|
|
throw new IllegalArgumentException("Unknown error");
|
|
|
@ -1621,6 +1606,7 @@ public class FragmentCompose extends FragmentBase {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void onExecuted(Bundle args, Object result) {
|
|
|
|
protected void onExecuted(Bundle args, Object result) {
|
|
|
|
|
|
|
|
Log.i("Result= " + result);
|
|
|
|
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) {
|
|
|
|