Merge "Messaging doesn\'t allow sharing of its own files" into nyc-dev
am: ca5fc9fa7d
* commit 'ca5fc9fa7dbba6cbab625d4a80f812b7206f0676':
Messaging doesn't allow sharing of its own files
Change-Id: Ice1aa04a938f9ff14ac3b321344c34bfd152b1dc
This commit is contained in:
@@ -34,6 +34,7 @@ import com.android.messaging.util.Assert;
|
||||
import com.android.messaging.util.ContentType;
|
||||
import com.android.messaging.util.LogUtil;
|
||||
import com.android.messaging.util.MediaMetadataRetrieverWrapper;
|
||||
import com.android.messaging.util.FileUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@@ -158,8 +159,12 @@ public class ShareIntentActivity extends BaseBugleActivity implements
|
||||
}
|
||||
|
||||
private void addSharedImagePartToDraft(final String contentType, final Uri imageUri) {
|
||||
mDraftMessage.addPart(PendingAttachmentData.createPendingAttachmentData(contentType,
|
||||
imageUri));
|
||||
if (FileUtil.isInPrivateDir(getBaseContext(), imageUri)) {
|
||||
Assert.fail("Cannot send private file " + imageUri.toString());
|
||||
} else {
|
||||
mDraftMessage.addPart(PendingAttachmentData.createPendingAttachmentData(contentType,
|
||||
imageUri));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,7 +16,10 @@
|
||||
|
||||
package com.android.messaging.util;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.text.TextUtils;
|
||||
import android.webkit.MimeTypeMap;
|
||||
|
||||
import com.android.messaging.Factory;
|
||||
@@ -116,6 +119,20 @@ public class FileUtil {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isFileUri(final Uri uri) {
|
||||
return TextUtils.equals(uri.getScheme(), ContentResolver.SCHEME_FILE);
|
||||
}
|
||||
|
||||
// Checks if the file is in /data/data/com.android.messaging
|
||||
// The other app folders are either symlinks to this, or hold non-private data like binaries.
|
||||
public static boolean isInPrivateDir(Context context, Uri uri) {
|
||||
if (!isFileUri(uri)) {
|
||||
return false;
|
||||
}
|
||||
final File file = new File(uri.getPath());
|
||||
return FileUtil.isSameOrSubDirectory(new File(context.getApplicationInfo().dataDir), file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks, whether the child directory is the same as, or a sub-directory of the base
|
||||
* directory.
|
||||
|
||||
Reference in New Issue
Block a user