Merge "Media Provider and MTP now use emulated /mnt/sdcard instead of /data/media" into honeycomb
This commit is contained in:
committed by
Android (Google) Code Review
commit
a29464335a
@@ -292,7 +292,6 @@ public class MediaScanner
|
||||
private boolean mProcessPlaylists, mProcessGenres;
|
||||
private int mMtpObjectHandle;
|
||||
|
||||
private final String mMediaStoragePath;
|
||||
private final String mExternalStoragePath;
|
||||
|
||||
// used when scanning the image database so we know whether we have to prune
|
||||
@@ -365,12 +364,6 @@ public class MediaScanner
|
||||
|
||||
setDefaultRingtoneFileNames();
|
||||
|
||||
String mediaStoragePath = SystemProperties.get("ro.media.storage");
|
||||
if (mediaStoragePath != null && mediaStoragePath.length() > 0) {
|
||||
mMediaStoragePath = mediaStoragePath;
|
||||
} else {
|
||||
mMediaStoragePath = null;
|
||||
}
|
||||
mExternalStoragePath = Environment.getExternalStorageDirectory().getAbsolutePath();
|
||||
}
|
||||
|
||||
@@ -390,13 +383,6 @@ public class MediaScanner
|
||||
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 String mArtist;
|
||||
@@ -471,9 +457,7 @@ public class MediaScanner
|
||||
}
|
||||
}
|
||||
|
||||
// MediaProvider uses external variant of path for _data, so we need to match
|
||||
// against that path instead.
|
||||
String key = mediaToExternalPath(path);
|
||||
String key = path;
|
||||
if (mCaseInsensitivePaths) {
|
||||
key = path.toLowerCase();
|
||||
}
|
||||
@@ -886,8 +870,6 @@ public class MediaScanner
|
||||
}
|
||||
|
||||
public void addNoMediaFolder(String path) {
|
||||
path = mediaToExternalPath(path);
|
||||
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(MediaStore.Images.ImageColumns.DATA, "");
|
||||
String [] pathSpec = new String[] {path + '%'};
|
||||
@@ -946,10 +928,6 @@ public class MediaScanner
|
||||
}
|
||||
|
||||
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
|
||||
where = Files.FileColumns.DATA + "=?";
|
||||
selectionArgs = new String[] { filePath };
|
||||
@@ -1007,10 +985,6 @@ public class MediaScanner
|
||||
private boolean inScanDirectory(String path, String[] directories) {
|
||||
for (int i = 0; i < directories.length; i++) {
|
||||
String directory = directories[i];
|
||||
if (mExternalStoragePath != null && directory.equals(mMediaStoragePath)) {
|
||||
// database paths use external storage prefix
|
||||
directory = mExternalStoragePath;
|
||||
}
|
||||
if (path.startsWith(directory)) {
|
||||
return true;
|
||||
}
|
||||
@@ -1217,9 +1191,7 @@ public class MediaScanner
|
||||
// build file cache so we can look up tracks in the playlist
|
||||
prescan(null, true);
|
||||
|
||||
// MediaProvider uses external variant of path for _data, so we need to match
|
||||
// against that path instead.
|
||||
String key = mediaToExternalPath(path);
|
||||
String key = path;
|
||||
if (mCaseInsensitivePaths) {
|
||||
key = path.toLowerCase();
|
||||
}
|
||||
|
||||
@@ -50,7 +50,6 @@ public class MtpDatabase {
|
||||
private final String mVolumeName;
|
||||
private final Uri mObjectsUri;
|
||||
private final String mMediaStoragePath;
|
||||
private final String mExternalStoragePath;
|
||||
|
||||
// cached property groups for single properties
|
||||
private final HashMap<Integer, MtpPropertyGroup> mPropertyGroupsByProperty
|
||||
@@ -113,7 +112,6 @@ public class MtpDatabase {
|
||||
mMediaProvider = context.getContentResolver().acquireProvider("media");
|
||||
mVolumeName = volumeName;
|
||||
mMediaStoragePath = storagePath;
|
||||
mExternalStoragePath = Environment.getExternalStorageDirectory().getAbsolutePath();
|
||||
mObjectsUri = Files.getMtpObjectsUri(volumeName);
|
||||
mMediaScanner = new MediaScanner(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) {
|
||||
mDevicePropDb = context.openOrCreateDatabase("device-properties", Context.MODE_PRIVATE, null);
|
||||
int version = mDevicePropDb.getVersion();
|
||||
@@ -525,7 +513,7 @@ public class MtpDatabase {
|
||||
try {
|
||||
c = mMediaProvider.query(mObjectsUri, PATH_PROJECTION, ID_WHERE, whereArgs, null);
|
||||
if (c != null && c.moveToNext()) {
|
||||
path = externalToMediaPath(c.getString(1));
|
||||
path = c.getString(1);
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "RemoteException in getObjectFilePath", e);
|
||||
@@ -707,7 +695,7 @@ public class MtpDatabase {
|
||||
c = mMediaProvider.query(mObjectsUri, PATH_SIZE_FORMAT_PROJECTION,
|
||||
ID_WHERE, new String[] { Integer.toString(handle) }, null);
|
||||
if (c != null && c.moveToNext()) {
|
||||
String path = externalToMediaPath(c.getString(1));
|
||||
String path = c.getString(1);
|
||||
path.getChars(0, path.length(), outFilePath, 0);
|
||||
outFilePath[path.length()] = 0;
|
||||
outFileLengthFormat[0] = c.getLong(2);
|
||||
|
||||
Reference in New Issue
Block a user