2014-12-12 09:03:24 +00:00
|
|
|
package org.thoughtcrime.securesms.mms;
|
|
|
|
|
|
|
|
import android.content.ContentUris;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.UriMatcher;
|
|
|
|
import android.net.Uri;
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
|
|
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
|
|
|
import org.thoughtcrime.securesms.database.PartDatabase;
|
|
|
|
import org.thoughtcrime.securesms.providers.PartProvider;
|
|
|
|
|
2014-12-30 09:36:51 +00:00
|
|
|
import java.io.IOException;
|
2014-12-12 09:03:24 +00:00
|
|
|
import java.io.InputStream;
|
|
|
|
|
|
|
|
public class PartAuthority {
|
|
|
|
|
2015-01-19 02:11:30 +00:00
|
|
|
private static final String PART_URI_STRING = "content://org.thoughtcrime.securesms/part";
|
|
|
|
public static final Uri PART_CONTENT_URI = Uri.parse(PART_URI_STRING);
|
2014-12-12 09:03:24 +00:00
|
|
|
|
|
|
|
private static final int PART_ROW = 1;
|
|
|
|
|
|
|
|
private static final UriMatcher uriMatcher;
|
|
|
|
|
|
|
|
static {
|
|
|
|
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
|
|
|
|
uriMatcher.addURI("org.thoughtcrime.securesms", "part/#", PART_ROW);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static InputStream getPartStream(Context context, MasterSecret masterSecret, Uri uri)
|
2014-12-30 09:36:51 +00:00
|
|
|
throws IOException
|
2014-12-12 09:03:24 +00:00
|
|
|
{
|
|
|
|
PartDatabase partDatabase = DatabaseFactory.getPartDatabase(context);
|
|
|
|
int match = uriMatcher.match(uri);
|
|
|
|
|
2015-01-13 19:47:32 +00:00
|
|
|
try {
|
|
|
|
switch (match) {
|
2014-12-12 09:03:24 +00:00
|
|
|
case PART_ROW: return partDatabase.getPartStream(masterSecret, ContentUris.parseId(uri));
|
|
|
|
default: return context.getContentResolver().openInputStream(uri);
|
2015-01-13 19:47:32 +00:00
|
|
|
}
|
|
|
|
} catch (SecurityException se) {
|
|
|
|
throw new IOException(se);
|
2014-12-12 09:03:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-30 06:37:01 +00:00
|
|
|
public static InputStream getThumbnail(Context context, MasterSecret masterSecret, Uri uri)
|
|
|
|
throws IOException
|
|
|
|
{
|
|
|
|
PartDatabase partDatabase = DatabaseFactory.getPartDatabase(context);
|
|
|
|
int match = uriMatcher.match(uri);
|
|
|
|
|
|
|
|
switch (match) {
|
|
|
|
case PART_ROW: return partDatabase.getThumbnailStream(masterSecret, ContentUris.parseId(uri));
|
|
|
|
default: return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-12 09:03:24 +00:00
|
|
|
public static Uri getPublicPartUri(Uri uri) {
|
|
|
|
return ContentUris.withAppendedId(PartProvider.CONTENT_URI, ContentUris.parseId(uri));
|
|
|
|
}
|
|
|
|
}
|