am 99df4d53: am b47d1a8a: am 126c9216: Block oversize attachments from being sent
Merge commit '99df4d53b620fae871fd45aaf9b8f110cb4d4288' * commit '99df4d53b620fae871fd45aaf9b8f110cb4d4288': Block oversize attachments from being sent
This commit is contained in:
commit
9e71be599e
|
@ -61,6 +61,7 @@ import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.view.View.OnFocusChangeListener;
|
import android.view.View.OnFocusChangeListener;
|
||||||
|
import android.view.Window;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
@ -70,6 +71,7 @@ import android.widget.MultiAutoCompleteTextView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -105,10 +107,15 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
|
||||||
|
|
||||||
private static final int ACTIVITY_REQUEST_PICK_ATTACHMENT = 1;
|
private static final int ACTIVITY_REQUEST_PICK_ATTACHMENT = 1;
|
||||||
|
|
||||||
private static final String[] ATTACHMENT_META_COLUMNS = {
|
private static final String[] ATTACHMENT_META_NAME_PROJECTION = {
|
||||||
OpenableColumns.DISPLAY_NAME,
|
OpenableColumns.DISPLAY_NAME
|
||||||
|
};
|
||||||
|
private static final int ATTACHMENT_META_NAME_COLUMN_DISPLAY_NAME = 0;
|
||||||
|
|
||||||
|
private static final String[] ATTACHMENT_META_SIZE_PROJECTION = {
|
||||||
OpenableColumns.SIZE
|
OpenableColumns.SIZE
|
||||||
};
|
};
|
||||||
|
private static final int ATTACHMENT_META_SIZE_COLUMN_SIZE = 0;
|
||||||
|
|
||||||
// Is set while the draft is saved by a background thread.
|
// Is set while the draft is saved by a background thread.
|
||||||
// Is static in order to be shared between the two activity instances
|
// Is static in order to be shared between the two activity instances
|
||||||
|
@ -1009,24 +1016,55 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
|
||||||
}
|
}
|
||||||
|
|
||||||
private Attachment loadAttachmentInfo(Uri uri) {
|
private Attachment loadAttachmentInfo(Uri uri) {
|
||||||
int size = -1;
|
long size = -1;
|
||||||
String name = null;
|
String name = null;
|
||||||
ContentResolver contentResolver = getContentResolver();
|
ContentResolver contentResolver = getContentResolver();
|
||||||
Cursor metadataCursor = contentResolver.query(uri,
|
|
||||||
ATTACHMENT_META_COLUMNS, null, null, null);
|
// Load name & size independently, because not all providers support both
|
||||||
|
Cursor metadataCursor = contentResolver.query(uri, ATTACHMENT_META_NAME_PROJECTION,
|
||||||
|
null, null, null);
|
||||||
if (metadataCursor != null) {
|
if (metadataCursor != null) {
|
||||||
try {
|
try {
|
||||||
if (metadataCursor.moveToFirst()) {
|
if (metadataCursor.moveToFirst()) {
|
||||||
name = metadataCursor.getString(0);
|
name = metadataCursor.getString(ATTACHMENT_META_NAME_COLUMN_DISPLAY_NAME);
|
||||||
size = metadataCursor.getInt(1);
|
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
metadataCursor.close();
|
metadataCursor.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
metadataCursor = contentResolver.query(uri, ATTACHMENT_META_SIZE_PROJECTION,
|
||||||
|
null, null, null);
|
||||||
|
if (metadataCursor != null) {
|
||||||
|
try {
|
||||||
|
if (metadataCursor.moveToFirst()) {
|
||||||
|
size = metadataCursor.getLong(ATTACHMENT_META_SIZE_COLUMN_SIZE);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
metadataCursor.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// When the name or size are not provided, we need to generate them locally.
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
name = uri.getLastPathSegment();
|
name = uri.getLastPathSegment();
|
||||||
}
|
}
|
||||||
|
if (size < 0) {
|
||||||
|
// if the URI is a file: URI, ask file system for its size
|
||||||
|
if ("file".equalsIgnoreCase(uri.getScheme())) {
|
||||||
|
String path = uri.getPath();
|
||||||
|
if (path != null) {
|
||||||
|
File file = new File(path);
|
||||||
|
size = file.length(); // Returns 0 for file not found
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size <= 0) {
|
||||||
|
// The size was not measurable; This attachment is not safe to use.
|
||||||
|
// Quick hack to force a relevant error into the UI
|
||||||
|
// TODO: A proper announcement of the problem
|
||||||
|
size = Email.MAX_ATTACHMENT_UPLOAD_SIZE + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
String contentType = contentResolver.getType(uri);
|
String contentType = contentResolver.getType(uri);
|
||||||
if (contentType == null) {
|
if (contentType == null) {
|
||||||
|
|
Loading…
Reference in New Issue