Merge "Fix AttachmentProvider to work properly w/ EmailProvider"
This commit is contained in:
commit
b6ad4c252f
@ -33,6 +33,7 @@ import android.database.MatrixCursor;
|
|||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.Binder;
|
||||||
import android.os.ParcelFileDescriptor;
|
import android.os.ParcelFileDescriptor;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.webkit.MimeTypeMap;
|
import android.webkit.MimeTypeMap;
|
||||||
@ -150,8 +151,9 @@ public class AttachmentProvider extends ContentProvider {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getType(Uri uri) {
|
public String getType(Uri uri) {
|
||||||
|
long callingId = Binder.clearCallingIdentity();
|
||||||
|
try {
|
||||||
List<String> segments = uri.getPathSegments();
|
List<String> segments = uri.getPathSegments();
|
||||||
String accountId = segments.get(0);
|
|
||||||
String id = segments.get(1);
|
String id = segments.get(1);
|
||||||
String format = segments.get(2);
|
String format = segments.get(2);
|
||||||
if (FORMAT_THUMBNAIL.equals(format)) {
|
if (FORMAT_THUMBNAIL.equals(format)) {
|
||||||
@ -172,6 +174,9 @@ public class AttachmentProvider extends ContentProvider {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
Binder.restoreCallingIdentity(callingId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -234,6 +239,8 @@ public class AttachmentProvider extends ContentProvider {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
|
public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
|
||||||
|
long callingId = Binder.clearCallingIdentity();
|
||||||
|
try {
|
||||||
List<String> segments = uri.getPathSegments();
|
List<String> segments = uri.getPathSegments();
|
||||||
String accountId = segments.get(0);
|
String accountId = segments.get(0);
|
||||||
String id = segments.get(1);
|
String id = segments.get(1);
|
||||||
@ -245,7 +252,8 @@ public class AttachmentProvider extends ContentProvider {
|
|||||||
File dir = getContext().getCacheDir();
|
File dir = getContext().getCacheDir();
|
||||||
File file = new File(dir, filename);
|
File file = new File(dir, filename);
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
Uri attachmentUri = getAttachmentUri(Long.parseLong(accountId), Long.parseLong(id));
|
Uri attachmentUri =
|
||||||
|
getAttachmentUri(Long.parseLong(accountId), Long.parseLong(id));
|
||||||
Cursor c = query(attachmentUri,
|
Cursor c = query(attachmentUri,
|
||||||
new String[] { AttachmentProviderColumns.DATA }, null, null, null);
|
new String[] { AttachmentProviderColumns.DATA }, null, null, null);
|
||||||
if (c != null) {
|
if (c != null) {
|
||||||
@ -281,6 +289,9 @@ public class AttachmentProvider extends ContentProvider {
|
|||||||
new File(getContext().getDatabasePath(accountId + ".db_att"), id),
|
new File(getContext().getDatabasePath(accountId + ".db_att"), id),
|
||||||
ParcelFileDescriptor.MODE_READ_ONLY);
|
ParcelFileDescriptor.MODE_READ_ONLY);
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
Binder.restoreCallingIdentity(callingId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -303,6 +314,8 @@ public class AttachmentProvider extends ContentProvider {
|
|||||||
@Override
|
@Override
|
||||||
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
|
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
|
||||||
String sortOrder) {
|
String sortOrder) {
|
||||||
|
long callingId = Binder.clearCallingIdentity();
|
||||||
|
try {
|
||||||
if (projection == null) {
|
if (projection == null) {
|
||||||
projection =
|
projection =
|
||||||
new String[] {
|
new String[] {
|
||||||
@ -353,6 +366,9 @@ public class AttachmentProvider extends ContentProvider {
|
|||||||
}
|
}
|
||||||
ret.addRow(values);
|
ret.addRow(values);
|
||||||
return ret;
|
return ret;
|
||||||
|
} finally {
|
||||||
|
Binder.restoreCallingIdentity(callingId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user