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) ||
"identicons".equals(key) ||
"preview".equals(key) ||
"confirm".equals(key) ||
"debug".equals(key)))
finish();
}

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

@ -115,6 +115,7 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
private boolean avatars;
private boolean identicons;
private boolean preview;
private boolean confirm;
private boolean debug;
private int dp24;
@ -618,38 +619,52 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
}
private void onShowHtml(final TupleMessageEx message) {
new DialogBuilderLifecycle(context, owner)
.setMessage(R.string.title_ask_show_html)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
lbm.sendBroadcast(
new Intent(ActivityView.ACTION_VIEW_FULL)
.putExtra("id", message.id)
.putExtra("from", MessageHelper.getFormattedAddresses(message.from, true)));
}
})
.setNegativeButton(android.R.string.cancel, null)
.show();
if (confirm)
new DialogBuilderLifecycle(context, owner)
.setMessage(R.string.title_ask_show_html)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
onShowHtmlConfirmed(message);
}
})
.setNegativeButton(android.R.string.cancel, null)
.show();
else
onShowHtmlConfirmed(message);
}
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) {
new DialogBuilderLifecycle(context, owner)
.setMessage(R.string.title_ask_show_image)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
properties.setImages(message.id, true);
btnImages.setEnabled(false);
if (confirm)
new DialogBuilderLifecycle(context, owner)
.setMessage(R.string.title_ask_show_image)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
onShowImagesConfirmed(message);
}
})
.setNegativeButton(android.R.string.cancel, null)
.show();
else
onShowImagesConfirmed(message);
}
Bundle args = new Bundle();
args.putSerializable("message", message);
bodyTask.load(context, owner, args);
}
})
.setNegativeButton(android.R.string.cancel, null)
.show();
private void onShowImagesConfirmed(final TupleMessageEx message) {
properties.setImages(message.id, true);
btnImages.setEnabled(false);
Bundle args = new Bundle();
args.putSerializable("message", message);
bodyTask.load(context, owner, args);
}
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.identicons = prefs.getBoolean("identicons", false);
this.preview = prefs.getBoolean("preview", false);
this.confirm = prefs.getBoolean("confirm", false);
this.debug = prefs.getBoolean("debug", false);
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 swSwipe;
private SwitchCompat swNav;
private SwitchCompat swConfirm;
private SwitchCompat swSender;
private SwitchCompat swInsecure;
private Spinner spDownload;
@ -73,6 +74,7 @@ public class FragmentOptions extends FragmentEx implements SharedPreferences.OnS
swBrowse = view.findViewById(R.id.swBrowse);
swSwipe = view.findViewById(R.id.swSwipe);
swNav = view.findViewById(R.id.swNav);
swConfirm = view.findViewById(R.id.swConfirm);
swSender = view.findViewById(R.id.swSender);
swInsecure = view.findViewById(R.id.swInsecure);
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.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override

@ -92,6 +92,15 @@
app:layout_constraintStart_toStartOf="parent"
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
android:id="@+id/swSender"
android:layout_width="match_parent"
@ -99,7 +108,7 @@
android:layout_marginTop="12dp"
android:text="@string/title_advanced_sender"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swNav" />
app:layout_constraintTop_toBottomOf="@id/swConfirm" />
<TextView
android:id="@+id/tvSender"

@ -101,6 +101,7 @@
<string name="title_advanced_browse">Browse messages on the server</string>
<string name="title_advanced_swipe">Swipe actions</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_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>

Loading…
Cancel
Save