summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2013-01-16 12:14:53 -0800
committerAndroid Git Automerger <android-git-automerger@android.com>2013-01-16 12:14:53 -0800
commit7ed6c6d83b3301280a2150f0697a2a631a0168ad (patch)
treed5fcce8959f43f85e6586257eb6b6ab6c096cf8b /media
parent9f7803cbcb8a7733f5861ac521e4358e9bdceab4 (diff)
parent35654b61e8fe7bc85afcb076ddbb590d51c5865f (diff)
downloadframeworks_base-7ed6c6d83b3301280a2150f0697a2a631a0168ad.zip
frameworks_base-7ed6c6d83b3301280a2150f0697a2a631a0168ad.tar.gz
frameworks_base-7ed6c6d83b3301280a2150f0697a2a631a0168ad.tar.bz2
am 35654b61: More work on App Ops service.
* commit '35654b61e8fe7bc85afcb076ddbb590d51c5865f': More work on App Ops service.
Diffstat (limited to 'media')
-rw-r--r--media/java/android/media/MediaInserter.java10
-rw-r--r--media/java/android/media/MediaScanner.java50
-rw-r--r--media/java/android/mtp/MtpDatabase.java43
-rw-r--r--media/java/android/mtp/MtpPropertyGroup.java16
4 files changed, 69 insertions, 50 deletions
diff --git a/media/java/android/media/MediaInserter.java b/media/java/android/media/MediaInserter.java
index 7fcbffa..41b369d 100644
--- a/media/java/android/media/MediaInserter.java
+++ b/media/java/android/media/MediaInserter.java
@@ -37,11 +37,13 @@ public class MediaInserter {
private final HashMap<Uri, List<ContentValues>> mPriorityRowMap =
new HashMap<Uri, List<ContentValues>>();
- private IContentProvider mProvider;
- private int mBufferSizePerUri;
+ private final IContentProvider mProvider;
+ private final String mPackageName;
+ private final int mBufferSizePerUri;
- public MediaInserter(IContentProvider provider, int bufferSizePerUri) {
+ public MediaInserter(IContentProvider provider, String packageName, int bufferSizePerUri) {
mProvider = provider;
+ mPackageName = packageName;
mBufferSizePerUri = bufferSizePerUri;
}
@@ -88,7 +90,7 @@ public class MediaInserter {
if (!list.isEmpty()) {
ContentValues[] valuesArray = new ContentValues[list.size()];
valuesArray = list.toArray(valuesArray);
- mProvider.bulkInsert(tableUri, valuesArray);
+ mProvider.bulkInsert(mPackageName, tableUri, valuesArray);
list.clear();
}
}
diff --git a/media/java/android/media/MediaScanner.java b/media/java/android/media/MediaScanner.java
index 7768a61..619e71c 100644
--- a/media/java/android/media/MediaScanner.java
+++ b/media/java/android/media/MediaScanner.java
@@ -303,6 +303,7 @@ public class MediaScanner
private int mNativeContext;
private Context mContext;
+ private String mPackageName;
private IContentProvider mMediaProvider;
private Uri mAudioUri;
private Uri mVideoUri;
@@ -388,6 +389,7 @@ public class MediaScanner
public MediaScanner(Context c) {
native_setup();
mContext = c;
+ mPackageName = c.getPackageName();
mBitmapOptions.inSampleSize = 1;
mBitmapOptions.inJustDecodeBounds = true;
@@ -961,7 +963,7 @@ public class MediaScanner
if (inserter != null) {
inserter.flushAll();
}
- result = mMediaProvider.insert(tableUri, values);
+ result = mMediaProvider.insert(mPackageName, tableUri, values);
} else if (entry.mFormat == MtpConstants.FORMAT_ASSOCIATION) {
inserter.insertwithPriority(tableUri, values);
} else {
@@ -993,7 +995,7 @@ public class MediaScanner
}
values.put(FileColumns.MEDIA_TYPE, mediaType);
}
- mMediaProvider.update(result, values, null, null);
+ mMediaProvider.update(mPackageName, result, values, null, null);
}
if(needToSetSettings) {
@@ -1082,7 +1084,8 @@ public class MediaScanner
// filesystem is mounted and unmounted while the scanner is running).
Uri.Builder builder = mFilesUri.buildUpon();
builder.appendQueryParameter(MediaStore.PARAM_DELETE_DATA, "false");
- MediaBulkDeleter deleter = new MediaBulkDeleter(mMediaProvider, builder.build());
+ MediaBulkDeleter deleter = new MediaBulkDeleter(mMediaProvider, mPackageName,
+ builder.build());
// Build the list of files from the content provider
try {
@@ -1101,7 +1104,7 @@ public class MediaScanner
c.close();
c = null;
}
- c = mMediaProvider.query(limitUri, FILES_PRESCAN_PROJECTION,
+ c = mMediaProvider.query(mPackageName, limitUri, FILES_PRESCAN_PROJECTION,
where, selectionArgs, MediaStore.Files.FileColumns._ID, null);
if (c == null) {
break;
@@ -1142,7 +1145,8 @@ public class MediaScanner
if (path.toLowerCase(Locale.US).endsWith("/.nomedia")) {
deleter.flush();
String parent = new File(path).getParent();
- mMediaProvider.call(MediaStore.UNHIDE_CALL, parent, null);
+ mMediaProvider.call(mPackageName, MediaStore.UNHIDE_CALL,
+ parent, null);
}
}
}
@@ -1160,7 +1164,7 @@ public class MediaScanner
// compute original size of images
mOriginalCount = 0;
- c = mMediaProvider.query(mImagesUri, ID_PROJECTION, null, null, null, null);
+ c = mMediaProvider.query(mPackageName, mImagesUri, ID_PROJECTION, null, null, null, null);
if (c != null) {
mOriginalCount = c.getCount();
c.close();
@@ -1191,6 +1195,7 @@ public class MediaScanner
try {
Cursor c = mMediaProvider.query(
+ mPackageName,
mThumbsUri,
new String [] { "_data" },
null,
@@ -1225,11 +1230,13 @@ public class MediaScanner
static class MediaBulkDeleter {
StringBuilder whereClause = new StringBuilder();
ArrayList<String> whereArgs = new ArrayList<String>(100);
- IContentProvider mProvider;
- Uri mBaseUri;
+ final IContentProvider mProvider;
+ final String mPackageName;
+ final Uri mBaseUri;
- public MediaBulkDeleter(IContentProvider provider, Uri baseUri) {
+ public MediaBulkDeleter(IContentProvider provider, String packageName, Uri baseUri) {
mProvider = provider;
+ mPackageName = packageName;
mBaseUri = baseUri;
}
@@ -1248,7 +1255,8 @@ public class MediaScanner
if (size > 0) {
String [] foo = new String [size];
foo = whereArgs.toArray(foo);
- int numrows = mProvider.delete(mBaseUri, MediaStore.MediaColumns._ID + " IN (" +
+ int numrows = mProvider.delete(mPackageName, mBaseUri,
+ MediaStore.MediaColumns._ID + " IN (" +
whereClause.toString() + ")", foo);
//Log.i("@@@@@@@@@", "rows deleted: " + numrows);
whereClause.setLength(0);
@@ -1301,7 +1309,7 @@ public class MediaScanner
if (ENABLE_BULK_INSERTS) {
// create MediaInserter for bulk inserts
- mMediaInserter = new MediaInserter(mMediaProvider, 500);
+ mMediaInserter = new MediaInserter(mMediaProvider, mPackageName, 500);
}
for (int i = 0; i < directories.length; i++) {
@@ -1433,8 +1441,8 @@ public class MediaScanner
values.put(Files.FileColumns.DATE_MODIFIED, lastModifiedSeconds);
try {
String[] whereArgs = new String[] { Integer.toString(objectHandle) };
- mMediaProvider.update(Files.getMtpObjectsUri(volumeName), values, "_id=?",
- whereArgs);
+ mMediaProvider.update(mPackageName, Files.getMtpObjectsUri(volumeName), values,
+ "_id=?", whereArgs);
} catch (RemoteException e) {
Log.e(TAG, "RemoteException in scanMtpFile", e);
}
@@ -1450,8 +1458,8 @@ public class MediaScanner
FileEntry entry = makeEntryFor(path);
if (entry != null) {
- fileList = mMediaProvider.query(mFilesUri, FILES_PRESCAN_PROJECTION,
- null, null, null, null);
+ fileList = mMediaProvider.query(mPackageName, mFilesUri,
+ FILES_PRESCAN_PROJECTION, null, null, null, null);
processPlayList(entry, fileList);
}
} else {
@@ -1480,7 +1488,7 @@ public class MediaScanner
try {
where = Files.FileColumns.DATA + "=?";
selectionArgs = new String[] { path };
- c = mMediaProvider.query(mFilesUriNoNotify, FILES_PRESCAN_PROJECTION,
+ c = mMediaProvider.query(mPackageName, mFilesUriNoNotify, FILES_PRESCAN_PROJECTION,
where, selectionArgs, null, null);
if (c.moveToFirst()) {
long rowId = c.getLong(FILES_PRESCAN_ID_COLUMN_INDEX);
@@ -1592,7 +1600,7 @@ public class MediaScanner
values.clear();
values.put(MediaStore.Audio.Playlists.Members.PLAY_ORDER, Integer.valueOf(index));
values.put(MediaStore.Audio.Playlists.Members.AUDIO_ID, Long.valueOf(entry.bestmatchid));
- mMediaProvider.insert(playlistUri, values);
+ mMediaProvider.insert(mPackageName, playlistUri, values);
index++;
} catch (RemoteException e) {
Log.e(TAG, "RemoteException in MediaScanner.processCachedPlaylist()", e);
@@ -1757,16 +1765,16 @@ public class MediaScanner
if (rowId == 0) {
values.put(MediaStore.Audio.Playlists.DATA, path);
- uri = mMediaProvider.insert(mPlaylistsUri, values);
+ uri = mMediaProvider.insert(mPackageName, mPlaylistsUri, values);
rowId = ContentUris.parseId(uri);
membersUri = Uri.withAppendedPath(uri, Playlists.Members.CONTENT_DIRECTORY);
} else {
uri = ContentUris.withAppendedId(mPlaylistsUri, rowId);
- mMediaProvider.update(uri, values, null, null);
+ mMediaProvider.update(mPackageName, uri, values, null, null);
// delete members of existing playlist
membersUri = Uri.withAppendedPath(uri, Playlists.Members.CONTENT_DIRECTORY);
- mMediaProvider.delete(membersUri, null, null);
+ mMediaProvider.delete(mPackageName, membersUri, null, null);
}
String playListDirectory = path.substring(0, lastSlash + 1);
@@ -1788,7 +1796,7 @@ public class MediaScanner
try {
// use the files uri and projection because we need the format column,
// but restrict the query to just audio files
- fileList = mMediaProvider.query(mFilesUri, FILES_PRESCAN_PROJECTION,
+ fileList = mMediaProvider.query(mPackageName, mFilesUri, FILES_PRESCAN_PROJECTION,
"media_type=2", null, null, null);
while (iterator.hasNext()) {
FileEntry entry = iterator.next();
diff --git a/media/java/android/mtp/MtpDatabase.java b/media/java/android/mtp/MtpDatabase.java
index 487585e..ea12803 100644
--- a/media/java/android/mtp/MtpDatabase.java
+++ b/media/java/android/mtp/MtpDatabase.java
@@ -48,6 +48,7 @@ public class MtpDatabase {
private static final String TAG = "MtpDatabase";
private final Context mContext;
+ private final String mPackageName;
private final IContentProvider mMediaProvider;
private final String mVolumeName;
private final Uri mObjectsUri;
@@ -123,6 +124,7 @@ public class MtpDatabase {
native_setup();
mContext = context;
+ mPackageName = context.getPackageName();
mMediaProvider = context.getContentResolver().acquireProvider("media");
mVolumeName = volumeName;
mMediaStoragePath = storagePath;
@@ -263,7 +265,7 @@ public class MtpDatabase {
if (path != null) {
Cursor c = null;
try {
- c = mMediaProvider.query(mObjectsUri, ID_PROJECTION, PATH_WHERE,
+ c = mMediaProvider.query(mPackageName, mObjectsUri, ID_PROJECTION, PATH_WHERE,
new String[] { path }, null, null);
if (c != null && c.getCount() > 0) {
Log.w(TAG, "file already exists in beginSendObject: " + path);
@@ -288,7 +290,7 @@ public class MtpDatabase {
values.put(Files.FileColumns.DATE_MODIFIED, modified);
try {
- Uri uri = mMediaProvider.insert(mObjectsUri, values);
+ Uri uri = mMediaProvider.insert(mPackageName, mObjectsUri, values);
if (uri != null) {
return Integer.parseInt(uri.getPathSegments().get(2));
} else {
@@ -323,7 +325,8 @@ public class MtpDatabase {
values.put(Files.FileColumns.DATE_MODIFIED, System.currentTimeMillis() / 1000);
values.put(MediaColumns.MEDIA_SCANNER_NEW_OBJECT_ID, handle);
try {
- Uri uri = mMediaProvider.insert(Audio.Playlists.EXTERNAL_CONTENT_URI, values);
+ Uri uri = mMediaProvider.insert(mPackageName,
+ Audio.Playlists.EXTERNAL_CONTENT_URI, values);
} catch (RemoteException e) {
Log.e(TAG, "RemoteException in endSendObject", e);
}
@@ -431,7 +434,8 @@ public class MtpDatabase {
}
}
- return mMediaProvider.query(mObjectsUri, ID_PROJECTION, where, whereArgs, null, null);
+ return mMediaProvider.query(mPackageName, mObjectsUri, ID_PROJECTION, where,
+ whereArgs, null, null);
}
private int[] getObjectList(int storageID, int format, int parent) {
@@ -676,14 +680,16 @@ public class MtpDatabase {
propertyGroup = mPropertyGroupsByFormat.get(format);
if (propertyGroup == null) {
int[] propertyList = getSupportedObjectProperties(format);
- propertyGroup = new MtpPropertyGroup(this, mMediaProvider, mVolumeName, propertyList);
+ propertyGroup = new MtpPropertyGroup(this, mMediaProvider, mPackageName,
+ mVolumeName, propertyList);
mPropertyGroupsByFormat.put(new Integer(format), propertyGroup);
}
} else {
propertyGroup = mPropertyGroupsByProperty.get(property);
if (propertyGroup == null) {
int[] propertyList = new int[] { (int)property };
- propertyGroup = new MtpPropertyGroup(this, mMediaProvider, mVolumeName, propertyList);
+ propertyGroup = new MtpPropertyGroup(this, mMediaProvider, mPackageName,
+ mVolumeName, propertyList);
mPropertyGroupsByProperty.put(new Integer((int)property), propertyGroup);
}
}
@@ -698,7 +704,8 @@ public class MtpDatabase {
String path = null;
String[] whereArgs = new String[] { Integer.toString(handle) };
try {
- c = mMediaProvider.query(mObjectsUri, PATH_PROJECTION, ID_WHERE, whereArgs, null, null);
+ c = mMediaProvider.query(mPackageName, mObjectsUri, PATH_PROJECTION, ID_WHERE,
+ whereArgs, null, null);
if (c != null && c.moveToNext()) {
path = c.getString(1);
}
@@ -740,7 +747,7 @@ public class MtpDatabase {
try {
// note - we are relying on a special case in MediaProvider.update() to update
// the paths for all children in the case where this is a directory.
- updated = mMediaProvider.update(mObjectsUri, values, ID_WHERE, whereArgs);
+ updated = mMediaProvider.update(mPackageName, mObjectsUri, values, ID_WHERE, whereArgs);
} catch (RemoteException e) {
Log.e(TAG, "RemoteException in mMediaProvider.update", e);
}
@@ -757,7 +764,7 @@ public class MtpDatabase {
if (oldFile.getName().startsWith(".") && !newPath.startsWith(".")) {
// directory was unhidden
try {
- mMediaProvider.call(MediaStore.UNHIDE_CALL, newPath, null);
+ mMediaProvider.call(mPackageName, MediaStore.UNHIDE_CALL, newPath, null);
} catch (RemoteException e) {
Log.e(TAG, "failed to unhide/rescan for " + newPath);
}
@@ -767,7 +774,7 @@ public class MtpDatabase {
if (oldFile.getName().toLowerCase(Locale.US).equals(".nomedia")
&& !newPath.toLowerCase(Locale.US).equals(".nomedia")) {
try {
- mMediaProvider.call(MediaStore.UNHIDE_CALL, oldFile.getParent(), null);
+ mMediaProvider.call(mPackageName, MediaStore.UNHIDE_CALL, oldFile.getParent(), null);
} catch (RemoteException e) {
Log.e(TAG, "failed to unhide/rescan for " + newPath);
}
@@ -836,7 +843,7 @@ public class MtpDatabase {
char[] outName, long[] outModified) {
Cursor c = null;
try {
- c = mMediaProvider.query(mObjectsUri, OBJECT_INFO_PROJECTION,
+ c = mMediaProvider.query(mPackageName, mObjectsUri, OBJECT_INFO_PROJECTION,
ID_WHERE, new String[] { Integer.toString(handle) }, null, null);
if (c != null && c.moveToNext()) {
outStorageFormatParent[0] = c.getInt(1);
@@ -878,7 +885,7 @@ public class MtpDatabase {
}
Cursor c = null;
try {
- c = mMediaProvider.query(mObjectsUri, PATH_FORMAT_PROJECTION,
+ c = mMediaProvider.query(mPackageName, mObjectsUri, PATH_FORMAT_PROJECTION,
ID_WHERE, new String[] { Integer.toString(handle) }, null, null);
if (c != null && c.moveToNext()) {
String path = c.getString(1);
@@ -909,7 +916,7 @@ public class MtpDatabase {
Cursor c = null;
try {
- c = mMediaProvider.query(mObjectsUri, PATH_FORMAT_PROJECTION,
+ c = mMediaProvider.query(mPackageName, mObjectsUri, PATH_FORMAT_PROJECTION,
ID_WHERE, new String[] { Integer.toString(handle) }, null, null);
if (c != null && c.moveToNext()) {
// don't convert to media path here, since we will be matching
@@ -932,7 +939,7 @@ public class MtpDatabase {
if (format == MtpConstants.FORMAT_ASSOCIATION) {
// recursive case - delete all children first
Uri uri = Files.getMtpObjectsUri(mVolumeName);
- int count = mMediaProvider.delete(uri,
+ int count = mMediaProvider.delete(mPackageName, uri,
// the 'like' makes it use the index, the 'lower()' makes it correct
// when the path contains sqlite wildcard characters
"_data LIKE ?1 AND lower(substr(_data,1,?2))=lower(?3)",
@@ -940,12 +947,12 @@ public class MtpDatabase {
}
Uri uri = Files.getMtpObjectsUri(mVolumeName, handle);
- if (mMediaProvider.delete(uri, null, null) > 0) {
+ if (mMediaProvider.delete(mPackageName, uri, null, null) > 0) {
if (format != MtpConstants.FORMAT_ASSOCIATION
&& path.toLowerCase(Locale.US).endsWith("/.nomedia")) {
try {
String parentPath = path.substring(0, path.lastIndexOf("/"));
- mMediaProvider.call(MediaStore.UNHIDE_CALL, parentPath, null);
+ mMediaProvider.call(mPackageName, MediaStore.UNHIDE_CALL, parentPath, null);
} catch (RemoteException e) {
Log.e(TAG, "failed to unhide/rescan for " + path);
}
@@ -968,7 +975,7 @@ public class MtpDatabase {
Uri uri = Files.getMtpReferencesUri(mVolumeName, handle);
Cursor c = null;
try {
- c = mMediaProvider.query(uri, ID_PROJECTION, null, null, null, null);
+ c = mMediaProvider.query(mPackageName, uri, ID_PROJECTION, null, null, null, null);
if (c == null) {
return null;
}
@@ -1002,7 +1009,7 @@ public class MtpDatabase {
valuesList[i] = values;
}
try {
- if (mMediaProvider.bulkInsert(uri, valuesList) > 0) {
+ if (mMediaProvider.bulkInsert(mPackageName, uri, valuesList) > 0) {
return MtpConstants.RESPONSE_OK;
}
} catch (RemoteException e) {
diff --git a/media/java/android/mtp/MtpPropertyGroup.java b/media/java/android/mtp/MtpPropertyGroup.java
index dab5454..48da40f 100644
--- a/media/java/android/mtp/MtpPropertyGroup.java
+++ b/media/java/android/mtp/MtpPropertyGroup.java
@@ -50,6 +50,7 @@ class MtpPropertyGroup {
private final MtpDatabase mDatabase;
private final IContentProvider mProvider;
+ private final String mPackageName;
private final String mVolumeName;
private final Uri mUri;
@@ -65,10 +66,11 @@ class MtpPropertyGroup {
private static final String PARENT_WHERE = Files.FileColumns.PARENT + "=?";
private static final String PARENT_FORMAT_WHERE = PARENT_WHERE + " AND " + FORMAT_WHERE;
// constructs a property group for a list of properties
- public MtpPropertyGroup(MtpDatabase database, IContentProvider provider, String volume,
- int[] properties) {
+ public MtpPropertyGroup(MtpDatabase database, IContentProvider provider, String packageName,
+ String volume, int[] properties) {
mDatabase = database;
mProvider = provider;
+ mPackageName = packageName;
mVolumeName = volume;
mUri = Files.getMtpObjectsUri(volume);
@@ -189,7 +191,7 @@ class MtpPropertyGroup {
Cursor c = null;
try {
// for now we are only reading properties from the "objects" table
- c = mProvider.query(mUri,
+ c = mProvider.query(mPackageName, mUri,
new String [] { Files.FileColumns._ID, column },
ID_WHERE, new String[] { Integer.toString(id) }, null, null);
if (c != null && c.moveToNext()) {
@@ -209,7 +211,7 @@ class MtpPropertyGroup {
private String queryAudio(int id, String column) {
Cursor c = null;
try {
- c = mProvider.query(Audio.Media.getContentUri(mVolumeName),
+ c = mProvider.query(mPackageName, Audio.Media.getContentUri(mVolumeName),
new String [] { Files.FileColumns._ID, column },
ID_WHERE, new String[] { Integer.toString(id) }, null, null);
if (c != null && c.moveToNext()) {
@@ -230,7 +232,7 @@ class MtpPropertyGroup {
Cursor c = null;
try {
Uri uri = Audio.Genres.getContentUriForAudioId(mVolumeName, id);
- c = mProvider.query(uri,
+ c = mProvider.query(mPackageName, uri,
new String [] { Files.FileColumns._ID, Audio.GenresColumns.NAME },
null, null, null, null);
if (c != null && c.moveToNext()) {
@@ -252,7 +254,7 @@ class MtpPropertyGroup {
Cursor c = null;
try {
// for now we are only reading properties from the "objects" table
- c = mProvider.query(mUri,
+ c = mProvider.query(mPackageName, mUri,
new String [] { Files.FileColumns._ID, column },
ID_WHERE, new String[] { Integer.toString(id) }, null, null);
if (c != null && c.moveToNext()) {
@@ -323,7 +325,7 @@ class MtpPropertyGroup {
try {
// don't query if not necessary
if (depth > 0 || handle == 0xFFFFFFFF || mColumns.length > 1) {
- c = mProvider.query(mUri, mColumns, where, whereArgs, null, null);
+ c = mProvider.query(mPackageName, mUri, mColumns, where, whereArgs, null, null);
if (c == null) {
return new MtpPropertyList(0, MtpConstants.RESPONSE_INVALID_OBJECT_HANDLE);
}