Merge pull request #369 from deltachat/track-shared-files

track a list of shared files
This commit is contained in:
björn petersen
2018-07-27 13:24:12 +02:00
committed by GitHub
3 changed files with 16 additions and 2 deletions
+6 -1
View File
@@ -227,7 +227,12 @@
<receiver android:name=".NotificationDismissReceiver" android:exported="false"/>
<provider android:name=".AttachmentsContentProvider" android:authorities="${applicationId}.attachments" android:exported="true" />
<provider
android:name=".AttachmentsContentProvider"
android:authorities="${applicationId}.attachments"
android:grantUriPermissions="true"
android:exported="false">
</provider>
<provider
android:name="android.support.v4.content.FileProvider"
@@ -80,6 +80,7 @@ import java.nio.channels.FileChannel;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
public class AndroidUtilities {
@@ -817,6 +818,8 @@ public class AndroidUtilities {
return mimeType;
}
public static HashMap<String, Integer> sharedFiles = new HashMap<>();
public static void openForViewOrShare(Activity activity, int msg_id, String cmd)
{
MrMsg msg = MrMailbox.getMsg(msg_id);
@@ -832,6 +835,7 @@ public class AndroidUtilities {
Uri uri;
if (path.startsWith(MrMailbox.getBlobdir())) {
uri = Uri.parse("content://" + BuildConfig.APPLICATION_ID + ".attachments/" + file.getName());
sharedFiles.put("/"+file.getName(), 1); // as different Android version handle uris in putExtra differently, we also check them on our own
} else {
if (Build.VERSION.SDK_INT >= 24) {
uri = FileProvider.getUriForFile(activity, BuildConfig.APPLICATION_ID + ".provider", file);
@@ -48,7 +48,12 @@ public class AttachmentsContentProvider extends ContentProvider {
@Override
public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
File privateFile = new File(MrMailbox.getBlobdir(), uri.getPath());
String path = uri.getPath();
if (!AndroidUtilities.sharedFiles.containsKey(path)) {
throw new FileNotFoundException("File was not shared before.");
}
File privateFile = new File(MrMailbox.getBlobdir(), path);
return ParcelFileDescriptor.open(privateFile, ParcelFileDescriptor.MODE_READ_ONLY);
}