Merge "Media Provider and MTP now use emulated /mnt/sdcard instead of /data/media" into honeycomb

This commit is contained in:
Mike Lockwood
2011-01-12 14:25:13 -08:00
committed by Android (Google) Code Review
2 changed files with 4 additions and 44 deletions

View File

@@ -292,7 +292,6 @@ public class MediaScanner
private boolean mProcessPlaylists, mProcessGenres; private boolean mProcessPlaylists, mProcessGenres;
private int mMtpObjectHandle; private int mMtpObjectHandle;
private final String mMediaStoragePath;
private final String mExternalStoragePath; private final String mExternalStoragePath;
// used when scanning the image database so we know whether we have to prune // used when scanning the image database so we know whether we have to prune
@@ -365,12 +364,6 @@ public class MediaScanner
setDefaultRingtoneFileNames(); setDefaultRingtoneFileNames();
String mediaStoragePath = SystemProperties.get("ro.media.storage");
if (mediaStoragePath != null && mediaStoragePath.length() > 0) {
mMediaStoragePath = mediaStoragePath;
} else {
mMediaStoragePath = null;
}
mExternalStoragePath = Environment.getExternalStorageDirectory().getAbsolutePath(); mExternalStoragePath = Environment.getExternalStorageDirectory().getAbsolutePath();
} }
@@ -390,13 +383,6 @@ public class MediaScanner
return prop != null && prop.equals("true"); return prop != null && prop.equals("true");
} }
private final String mediaToExternalPath(String path) {
if (mMediaStoragePath != null && path.startsWith(mMediaStoragePath)) {
path = mExternalStoragePath + path.substring(mMediaStoragePath.length());
}
return path;
}
private class MyMediaScannerClient implements MediaScannerClient { private class MyMediaScannerClient implements MediaScannerClient {
private String mArtist; private String mArtist;
@@ -471,9 +457,7 @@ public class MediaScanner
} }
} }
// MediaProvider uses external variant of path for _data, so we need to match String key = path;
// against that path instead.
String key = mediaToExternalPath(path);
if (mCaseInsensitivePaths) { if (mCaseInsensitivePaths) {
key = path.toLowerCase(); key = path.toLowerCase();
} }
@@ -886,8 +870,6 @@ public class MediaScanner
} }
public void addNoMediaFolder(String path) { public void addNoMediaFolder(String path) {
path = mediaToExternalPath(path);
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
values.put(MediaStore.Images.ImageColumns.DATA, ""); values.put(MediaStore.Images.ImageColumns.DATA, "");
String [] pathSpec = new String[] {path + '%'}; String [] pathSpec = new String[] {path + '%'};
@@ -946,10 +928,6 @@ public class MediaScanner
} }
if (filePath != null) { if (filePath != null) {
// MediaProvider uses external variant of path for _data, so we need to query
// using that path instead.
filePath = mediaToExternalPath(filePath);
// query for only one file // query for only one file
where = Files.FileColumns.DATA + "=?"; where = Files.FileColumns.DATA + "=?";
selectionArgs = new String[] { filePath }; selectionArgs = new String[] { filePath };
@@ -1007,10 +985,6 @@ public class MediaScanner
private boolean inScanDirectory(String path, String[] directories) { private boolean inScanDirectory(String path, String[] directories) {
for (int i = 0; i < directories.length; i++) { for (int i = 0; i < directories.length; i++) {
String directory = directories[i]; String directory = directories[i];
if (mExternalStoragePath != null && directory.equals(mMediaStoragePath)) {
// database paths use external storage prefix
directory = mExternalStoragePath;
}
if (path.startsWith(directory)) { if (path.startsWith(directory)) {
return true; return true;
} }
@@ -1217,9 +1191,7 @@ public class MediaScanner
// build file cache so we can look up tracks in the playlist // build file cache so we can look up tracks in the playlist
prescan(null, true); prescan(null, true);
// MediaProvider uses external variant of path for _data, so we need to match String key = path;
// against that path instead.
String key = mediaToExternalPath(path);
if (mCaseInsensitivePaths) { if (mCaseInsensitivePaths) {
key = path.toLowerCase(); key = path.toLowerCase();
} }

View File

@@ -50,7 +50,6 @@ public class MtpDatabase {
private final String mVolumeName; private final String mVolumeName;
private final Uri mObjectsUri; private final Uri mObjectsUri;
private final String mMediaStoragePath; private final String mMediaStoragePath;
private final String mExternalStoragePath;
// cached property groups for single properties // cached property groups for single properties
private final HashMap<Integer, MtpPropertyGroup> mPropertyGroupsByProperty private final HashMap<Integer, MtpPropertyGroup> mPropertyGroupsByProperty
@@ -113,7 +112,6 @@ public class MtpDatabase {
mMediaProvider = context.getContentResolver().acquireProvider("media"); mMediaProvider = context.getContentResolver().acquireProvider("media");
mVolumeName = volumeName; mVolumeName = volumeName;
mMediaStoragePath = storagePath; mMediaStoragePath = storagePath;
mExternalStoragePath = Environment.getExternalStorageDirectory().getAbsolutePath();
mObjectsUri = Files.getMtpObjectsUri(volumeName); mObjectsUri = Files.getMtpObjectsUri(volumeName);
mMediaScanner = new MediaScanner(context); mMediaScanner = new MediaScanner(context);
openDevicePropertiesDatabase(context); openDevicePropertiesDatabase(context);
@@ -128,16 +126,6 @@ public class MtpDatabase {
} }
} }
private String externalToMediaPath(String path) {
// convert external storage path to media path
if (path != null && mMediaStoragePath != null
&& mExternalStoragePath != null
&& path.startsWith(mExternalStoragePath)) {
path = mMediaStoragePath + path.substring(mExternalStoragePath.length());
}
return path;
}
private void openDevicePropertiesDatabase(Context context) { private void openDevicePropertiesDatabase(Context context) {
mDevicePropDb = context.openOrCreateDatabase("device-properties", Context.MODE_PRIVATE, null); mDevicePropDb = context.openOrCreateDatabase("device-properties", Context.MODE_PRIVATE, null);
int version = mDevicePropDb.getVersion(); int version = mDevicePropDb.getVersion();
@@ -525,7 +513,7 @@ public class MtpDatabase {
try { try {
c = mMediaProvider.query(mObjectsUri, PATH_PROJECTION, ID_WHERE, whereArgs, null); c = mMediaProvider.query(mObjectsUri, PATH_PROJECTION, ID_WHERE, whereArgs, null);
if (c != null && c.moveToNext()) { if (c != null && c.moveToNext()) {
path = externalToMediaPath(c.getString(1)); path = c.getString(1);
} }
} catch (RemoteException e) { } catch (RemoteException e) {
Log.e(TAG, "RemoteException in getObjectFilePath", e); Log.e(TAG, "RemoteException in getObjectFilePath", e);
@@ -707,7 +695,7 @@ public class MtpDatabase {
c = mMediaProvider.query(mObjectsUri, PATH_SIZE_FORMAT_PROJECTION, c = mMediaProvider.query(mObjectsUri, PATH_SIZE_FORMAT_PROJECTION,
ID_WHERE, new String[] { Integer.toString(handle) }, null); ID_WHERE, new String[] { Integer.toString(handle) }, null);
if (c != null && c.moveToNext()) { if (c != null && c.moveToNext()) {
String path = externalToMediaPath(c.getString(1)); String path = c.getString(1);
path.getChars(0, path.length(), outFilePath, 0); path.getChars(0, path.length(), outFilePath, 0);
outFilePath[path.length()] = 0; outFilePath[path.length()] = 0;
outFileLengthFormat[0] = c.getLong(2); outFileLengthFormat[0] = c.getLong(2);