Added settings to enable confirming actions that might leak info

pull/146/head
M66B 6 years ago
parent 9a7802d319
commit 370bd9d701

@ -86,6 +86,7 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc
"avatars".equals(key) || "avatars".equals(key) ||
"identicons".equals(key) || "identicons".equals(key) ||
"preview".equals(key) || "preview".equals(key) ||
"confirm".equals(key) ||
"debug".equals(key))) "debug".equals(key)))
finish(); finish();
} }

@ -21,6 +21,7 @@ package eu.faircode.email;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
@ -59,6 +60,7 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
private Context context; private Context context;
private LifecycleOwner owner; private LifecycleOwner owner;
private boolean readonly; private boolean readonly;
private boolean confirm;
private boolean debug; private boolean debug;
private List<EntityAttachment> all = new ArrayList<>(); private List<EntityAttachment> all = new ArrayList<>();
@ -181,6 +183,7 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
List<ResolveInfo> ris = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); List<ResolveInfo> ris = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo ri : ris) { for (ResolveInfo ri : ris) {
Log.i(Helper.TAG, "Target=" + ri); Log.i(Helper.TAG, "Target=" + ri);
context.grantUriPermission(ri.activityInfo.packageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
targets.add(new NameResolveInfo( targets.add(new NameResolveInfo(
pm.getApplicationIcon(ri.activityInfo.applicationInfo), pm.getApplicationIcon(ri.activityInfo.applicationInfo),
pm.getApplicationLabel(ri.activityInfo.applicationInfo).toString(), pm.getApplicationLabel(ri.activityInfo.applicationInfo).toString(),
@ -193,32 +196,34 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
return; return;
} }
View dview = LayoutInflater.from(context).inflate(R.layout.dialog_attachment, null); if (confirm) {
final AlertDialog dialog = new DialogBuilderLifecycle(context, owner) View dview = LayoutInflater.from(context).inflate(R.layout.dialog_attachment, null);
.setView(dview) final AlertDialog dialog = new DialogBuilderLifecycle(context, owner)
.setNegativeButton(android.R.string.cancel, null) .setView(dview)
.create(); .setNegativeButton(android.R.string.cancel, null)
.create();
TextView tvName = dview.findViewById(R.id.tvName);
TextView tvType = dview.findViewById(R.id.tvType); TextView tvName = dview.findViewById(R.id.tvName);
ListView lvApp = dview.findViewById(R.id.lvApp); TextView tvType = dview.findViewById(R.id.tvType);
ListView lvApp = dview.findViewById(R.id.lvApp);
tvName.setText(attachment.name);
tvType.setText(attachment.type); tvName.setText(attachment.name);
tvType.setText(attachment.type);
lvApp.setAdapter(new TargetAdapter(context, R.layout.item_target, targets));
lvApp.setOnItemClickListener(new AdapterView.OnItemClickListener() { lvApp.setAdapter(new TargetAdapter(context, R.layout.item_target, targets));
@Override lvApp.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { @Override
NameResolveInfo selected = (NameResolveInfo) parent.getItemAtPosition(position); public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
context.grantUriPermission(selected.info.activityInfo.packageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION); NameResolveInfo selected = (NameResolveInfo) parent.getItemAtPosition(position);
intent.setPackage(selected.info.activityInfo.packageName); intent.setPackage(selected.info.activityInfo.packageName);
context.startActivity(intent); context.startActivity(intent);
dialog.dismiss(); dialog.dismiss();
} }
}); });
dialog.show(); dialog.show();
} else
context.startActivity(intent);
} else { } else {
if (attachment.progress == null) { if (attachment.progress == null) {
Bundle args = new Bundle(); Bundle args = new Bundle();
@ -293,10 +298,12 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
} }
AdapterAttachment(Context context, LifecycleOwner owner, boolean readonly) { AdapterAttachment(Context context, LifecycleOwner owner, boolean readonly) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
this.context = context; this.context = context;
this.owner = owner; this.owner = owner;
this.readonly = readonly; this.readonly = readonly;
this.debug = PreferenceManager.getDefaultSharedPreferences(context).getBoolean("debug", false); this.confirm = prefs.getBoolean("confirm", false);
this.debug = prefs.getBoolean("debug", false);
setHasStableIds(true); setHasStableIds(true);
} }

@ -115,6 +115,7 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
private boolean avatars; private boolean avatars;
private boolean identicons; private boolean identicons;
private boolean preview; private boolean preview;
private boolean confirm;
private boolean debug; private boolean debug;
private int dp24; private int dp24;
@ -618,38 +619,52 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
} }
private void onShowHtml(final TupleMessageEx message) { private void onShowHtml(final TupleMessageEx message) {
new DialogBuilderLifecycle(context, owner) if (confirm)
.setMessage(R.string.title_ask_show_html) new DialogBuilderLifecycle(context, owner)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { .setMessage(R.string.title_ask_show_html)
@Override .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) { @Override
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context); public void onClick(DialogInterface dialog, int which) {
lbm.sendBroadcast( onShowHtmlConfirmed(message);
new Intent(ActivityView.ACTION_VIEW_FULL) }
.putExtra("id", message.id) })
.putExtra("from", MessageHelper.getFormattedAddresses(message.from, true))); .setNegativeButton(android.R.string.cancel, null)
} .show();
}) else
.setNegativeButton(android.R.string.cancel, null) onShowHtmlConfirmed(message);
.show(); }
private void onShowHtmlConfirmed(final TupleMessageEx message) {
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
lbm.sendBroadcast(
new Intent(ActivityView.ACTION_VIEW_FULL)
.putExtra("id", message.id)
.putExtra("from", MessageHelper.getFormattedAddresses(message.from, true)));
} }
private void onShowImages(final TupleMessageEx message) { private void onShowImages(final TupleMessageEx message) {
new DialogBuilderLifecycle(context, owner) if (confirm)
.setMessage(R.string.title_ask_show_image) new DialogBuilderLifecycle(context, owner)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { .setMessage(R.string.title_ask_show_image)
@Override .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) { @Override
properties.setImages(message.id, true); public void onClick(DialogInterface dialog, int which) {
btnImages.setEnabled(false); onShowImagesConfirmed(message);
}
})
.setNegativeButton(android.R.string.cancel, null)
.show();
else
onShowImagesConfirmed(message);
}
Bundle args = new Bundle(); private void onShowImagesConfirmed(final TupleMessageEx message) {
args.putSerializable("message", message); properties.setImages(message.id, true);
bodyTask.load(context, owner, args); btnImages.setEnabled(false);
}
}) Bundle args = new Bundle();
.setNegativeButton(android.R.string.cancel, null) args.putSerializable("message", message);
.show(); bodyTask.load(context, owner, args);
} }
private SimpleTask<Spanned> bodyTask = new SimpleTask<Spanned>() { private SimpleTask<Spanned> bodyTask = new SimpleTask<Spanned>() {
@ -1469,6 +1484,7 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
this.avatars = (prefs.getBoolean("avatars", true) && this.contacts); this.avatars = (prefs.getBoolean("avatars", true) && this.contacts);
this.identicons = prefs.getBoolean("identicons", false); this.identicons = prefs.getBoolean("identicons", false);
this.preview = prefs.getBoolean("preview", false); this.preview = prefs.getBoolean("preview", false);
this.confirm = prefs.getBoolean("confirm", false);
this.debug = prefs.getBoolean("debug", false); this.debug = prefs.getBoolean("debug", false);
this.dp24 = Math.round(24 * context.getResources().getDisplayMetrics().density); this.dp24 = Math.round(24 * context.getResources().getDisplayMetrics().density);

@ -50,6 +50,7 @@ public class FragmentOptions extends FragmentEx implements SharedPreferences.OnS
private SwitchCompat swBrowse; private SwitchCompat swBrowse;
private SwitchCompat swSwipe; private SwitchCompat swSwipe;
private SwitchCompat swNav; private SwitchCompat swNav;
private SwitchCompat swConfirm;
private SwitchCompat swSender; private SwitchCompat swSender;
private SwitchCompat swInsecure; private SwitchCompat swInsecure;
private Spinner spDownload; private Spinner spDownload;
@ -73,6 +74,7 @@ public class FragmentOptions extends FragmentEx implements SharedPreferences.OnS
swBrowse = view.findViewById(R.id.swBrowse); swBrowse = view.findViewById(R.id.swBrowse);
swSwipe = view.findViewById(R.id.swSwipe); swSwipe = view.findViewById(R.id.swSwipe);
swNav = view.findViewById(R.id.swNav); swNav = view.findViewById(R.id.swNav);
swConfirm = view.findViewById(R.id.swConfirm);
swSender = view.findViewById(R.id.swSender); swSender = view.findViewById(R.id.swSender);
swInsecure = view.findViewById(R.id.swInsecure); swInsecure = view.findViewById(R.id.swInsecure);
spDownload = view.findViewById(R.id.spDownload); spDownload = view.findViewById(R.id.spDownload);
@ -181,6 +183,14 @@ public class FragmentOptions extends FragmentEx implements SharedPreferences.OnS
} }
}); });
swConfirm.setChecked(prefs.getBoolean("confirm", false));
swConfirm.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("confirm", checked).apply();
}
});
swNav.setChecked(prefs.getBoolean("navigation", true)); swNav.setChecked(prefs.getBoolean("navigation", true));
swNav.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { swNav.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override

@ -92,6 +92,15 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swSwipe" /> app:layout_constraintTop_toBottomOf="@id/swSwipe" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swConfirm"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_confirm"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swNav" />
<androidx.appcompat.widget.SwitchCompat <androidx.appcompat.widget.SwitchCompat
android:id="@+id/swSender" android:id="@+id/swSender"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -99,7 +108,7 @@
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:text="@string/title_advanced_sender" android:text="@string/title_advanced_sender"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swNav" /> app:layout_constraintTop_toBottomOf="@id/swConfirm" />
<TextView <TextView
android:id="@+id/tvSender" android:id="@+id/tvSender"

@ -101,6 +101,7 @@
<string name="title_advanced_browse">Browse messages on the server</string> <string name="title_advanced_browse">Browse messages on the server</string>
<string name="title_advanced_swipe">Swipe actions</string> <string name="title_advanced_swipe">Swipe actions</string>
<string name="title_advanced_nav">Previous/next navigation</string> <string name="title_advanced_nav">Previous/next navigation</string>
<string name="title_advanced_confirm">Confirm actions that might leak privacy sensitive information</string>
<string name="title_advanced_sender">Allow editing sender address</string> <string name="title_advanced_sender">Allow editing sender address</string>
<string name="title_advanced_sender_hint">Most providers do not allow modified sender addresses</string> <string name="title_advanced_sender_hint">Most providers do not allow modified sender addresses</string>
<string name="title_advanced_download">Automatically download messages and attachments on a metered connection up to</string> <string name="title_advanced_download">Automatically download messages and attachments on a metered connection up to</string>

Loading…
Cancel
Save