Suppress user interaction on auto decrypt

pull/164/head
M66B 5 years ago
parent f4e4784f73
commit a0c2386172

@ -1625,7 +1625,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean auto_decrypt = prefs.getBoolean("auto_decrypt", false); boolean auto_decrypt = prefs.getBoolean("auto_decrypt", false);
if (auto_decrypt && is_encrypted) if (auto_decrypt && is_encrypted)
onActionDecrypt(message); onActionDecrypt(message, true);
cbInline.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { cbInline.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
@ -1973,7 +1973,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
onActionUnsubscribe(message); onActionUnsubscribe(message);
break; break;
case R.id.ibDecrypt: case R.id.ibDecrypt:
onActionDecrypt(message); onActionDecrypt(message, false);
break; break;
case R.id.ibDownloading: case R.id.ibDownloading:
@ -2650,11 +2650,12 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
onOpenLink(uri, context.getString(R.string.title_legend_show_unsubscribe)); onOpenLink(uri, context.getString(R.string.title_legend_show_unsubscribe));
} }
private void onActionDecrypt(TupleMessageEx message) { private void onActionDecrypt(TupleMessageEx message, boolean auto) {
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context); LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
lbm.sendBroadcast( lbm.sendBroadcast(
new Intent(FragmentMessages.ACTION_DECRYPT) new Intent(FragmentMessages.ACTION_DECRYPT)
.putExtra("id", message.id)); .putExtra("id", message.id)
.putExtra("auto", auto));
} }
private void onActionReplyMenu(TupleMessageEx message) { private void onActionReplyMenu(TupleMessageEx message) {

@ -3746,7 +3746,10 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
Intent data = new Intent(); Intent data = new Intent();
data.setAction(OpenPgpApi.ACTION_DECRYPT_VERIFY); data.setAction(OpenPgpApi.ACTION_DECRYPT_VERIFY);
onDecrypt(data, intent.getLongExtra("id", -1)); long id = intent.getLongExtra("id", -1);
boolean auto = intent.getBooleanExtra("auto", false);
onDecrypt(data, id, auto);
} else } else
Snackbar.make(view, R.string.title_no_openpgp, Snackbar.LENGTH_LONG).show(); Snackbar.make(view, R.string.title_no_openpgp, Snackbar.LENGTH_LONG).show();
} }
@ -3763,7 +3766,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
break; break;
case REQUEST_DECRYPT: case REQUEST_DECRYPT:
if (resultCode == RESULT_OK && data != null) if (resultCode == RESULT_OK && data != null)
onDecrypt(data, message); onDecrypt(data, message, false);
break; break;
case REQUEST_MESSAGE_DELETE: case REQUEST_MESSAGE_DELETE:
if (resultCode == RESULT_OK && data != null) if (resultCode == RESULT_OK && data != null)
@ -3926,16 +3929,18 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
}.execute(this, args, "raw:save"); }.execute(this, args, "raw:save");
} }
private void onDecrypt(Intent data, long id) { private void onDecrypt(Intent data, long id, boolean auto) {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("id", id); args.putLong("id", id);
args.putParcelable("data", data); args.putParcelable("data", data);
args.putBoolean("auto", auto);
new SimpleTask<PendingIntent>() { new SimpleTask<PendingIntent>() {
@Override @Override
protected PendingIntent onExecute(Context context, Bundle args) throws Throwable { protected PendingIntent onExecute(Context context, Bundle args) throws Throwable {
// Get arguments // Get arguments
long id = args.getLong("id"); long id = args.getLong("id");
boolean auto = args.getBoolean("auto");
Intent data = args.getParcelable("data"); Intent data = args.getParcelable("data");
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
@ -3980,8 +3985,11 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
} }
} }
if (in == null) if (in == null) {
if (auto)
return null;
throw new IllegalArgumentException(context.getString(R.string.title_not_encrypted)); throw new IllegalArgumentException(context.getString(R.string.title_not_encrypted));
}
Intent result; Intent result;
File plain = File.createTempFile("plain", "." + id, context.getCacheDir()); File plain = File.createTempFile("plain", "." + id, context.getCacheDir());
@ -4069,6 +4077,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
break; break;
case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED: case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
if (auto)
return null;
FragmentMessages.this.message = id; FragmentMessages.this.message = id;
return result.getParcelableExtra(OpenPgpApi.RESULT_INTENT); return result.getParcelableExtra(OpenPgpApi.RESULT_INTENT);

Loading…
Cancel
Save