summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/com/android/providers/media/MediaProvider.java45
-rw-r--r--src/com/android/providers/media/MediaScannerService.java1
-rw-r--r--src/com/android/providers/media/MtpService.java8
3 files changed, 37 insertions, 17 deletions
diff --git a/src/com/android/providers/media/MediaProvider.java b/src/com/android/providers/media/MediaProvider.java
index 89b6938f..1d4209aa 100755
--- a/src/com/android/providers/media/MediaProvider.java
+++ b/src/com/android/providers/media/MediaProvider.java
@@ -132,9 +132,13 @@ public class MediaProvider extends ContentProvider {
static {
try {
- sExternalPath = Environment.getExternalStorageDirectory().getCanonicalPath();
- sCachePath = Environment.getDownloadCacheDirectory().getCanonicalPath();
- sLegacyPath = Environment.getLegacyExternalStorageDirectory().getCanonicalPath();
+ sExternalPath =
+ Environment.getExternalStorageDirectory().getCanonicalPath() + File.separator;
+ sCachePath =
+ Environment.getDownloadCacheDirectory().getCanonicalPath() + File.separator;
+ sLegacyPath =
+ Environment.getLegacyExternalStorageDirectory().getCanonicalPath()
+ + File.separator;
} catch (IOException e) {
throw new RuntimeException("Unable to resolve canonical paths", e);
}
@@ -2999,7 +3003,7 @@ public class MediaProvider extends ContentProvider {
switch (mediaType) {
case FileColumns.MEDIA_TYPE_IMAGE: {
- values = ensureFile(helper.mInternal, initialValues, ".jpg", "DCIM/Camera");
+ values = ensureFile(helper.mInternal, initialValues, ".jpg", "Pictures");
values.put(MediaStore.MediaColumns.DATE_ADDED, System.currentTimeMillis() / 1000);
String data = values.getAsString(MediaColumns.DATA);
@@ -3651,6 +3655,8 @@ public class MediaProvider extends ContentProvider {
}
private void hidePath(DatabaseHelper helper, SQLiteDatabase db, String path) {
+ // a new nomedia path was added, so clear the media paths
+ MediaScanner.clearMediaPathCache(true /* media */, false /* nomedia */);
File nomedia = new File(path);
String hiddenroot = nomedia.isDirectory() ? path : nomedia.getParent();
ContentValues mediatype = new ContentValues();
@@ -3670,6 +3676,8 @@ public class MediaProvider extends ContentProvider {
* both of which call here.
*/
private void processRemovedNoMediaPath(final String path) {
+ // a nomedia path was removed, so clear the nomedia paths
+ MediaScanner.clearMediaPathCache(false /* media */, true /* nomedia */);
final DatabaseHelper helper;
if (path.startsWith(mExternalStoragePaths[0])) {
helper = getDatabaseForUri(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI);
@@ -4621,28 +4629,31 @@ public class MediaProvider extends ContentProvider {
}
Context c = getContext();
- boolean readGranted =
+ boolean readGranted = false;
+ boolean writeGranted = false;
+ if (isWrite) {
+ writeGranted =
+ (c.checkCallingOrSelfUriPermission(uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
+ == PackageManager.PERMISSION_GRANTED);
+ } else {
+ readGranted =
(c.checkCallingOrSelfUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION)
== PackageManager.PERMISSION_GRANTED);
+ }
if (path.startsWith(sExternalPath) || path.startsWith(sLegacyPath)) {
- if (!readGranted) {
- c.enforceCallingOrSelfPermission(
- READ_EXTERNAL_STORAGE, "External path: " + path);
- }
-
if (isWrite) {
- if (c.checkCallingOrSelfUriPermission(uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
- != PackageManager.PERMISSION_GRANTED) {
+ if (!writeGranted) {
c.enforceCallingOrSelfPermission(
- WRITE_EXTERNAL_STORAGE, "External path: " + path);
+ WRITE_EXTERNAL_STORAGE, "External path: " + path);
}
+ } else if (!readGranted) {
+ c.enforceCallingOrSelfPermission(
+ READ_EXTERNAL_STORAGE, "External path: " + path);
}
-
} else if (path.startsWith(sCachePath)) {
- if (!readGranted) {
- c.enforceCallingOrSelfPermission(
- ACCESS_CACHE_FILESYSTEM, "Cache path: " + path);
+ if ((isWrite && !writeGranted) || !readGranted) {
+ c.enforceCallingOrSelfPermission(ACCESS_CACHE_FILESYSTEM, "Cache path: " + path);
}
} else if (isSecondaryExternalPath(path)) {
// read access is OK with the appropriate permission
diff --git a/src/com/android/providers/media/MediaScannerService.java b/src/com/android/providers/media/MediaScannerService.java
index 40bb10a5..51d8514c 100644
--- a/src/com/android/providers/media/MediaScannerService.java
+++ b/src/com/android/providers/media/MediaScannerService.java
@@ -258,6 +258,7 @@ public class MediaScannerService extends Service implements Runnable
// scan internal media storage
directories = new String[] {
Environment.getRootDirectory() + "/media",
+ Environment.getOemDirectory() + "/media",
};
}
else if (MediaProvider.EXTERNAL_VOLUME.equals(volume)) {
diff --git a/src/com/android/providers/media/MtpService.java b/src/com/android/providers/media/MtpService.java
index 74fd747c..7f61d8ba 100644
--- a/src/com/android/providers/media/MtpService.java
+++ b/src/com/android/providers/media/MtpService.java
@@ -158,6 +158,9 @@ public class MtpService extends Service {
}
}
final StorageVolume primary = StorageManager.getPrimaryVolume(mVolumes);
+ if (mDatabase != null) {
+ mDatabase.setServer(null);
+ }
mDatabase = new MtpDatabase(this, MediaProvider.EXTERNAL_VOLUME,
primary.getPath(), subdirs);
manageServiceLocked();
@@ -186,6 +189,7 @@ public class MtpService extends Service {
if (mServer == null && isCurrentUser) {
Log.d(TAG, "starting MTP server in " + (mPtpMode ? "PTP mode" : "MTP mode"));
mServer = new MtpServer(mDatabase, mPtpMode);
+ mDatabase.setServer(mServer);
if (!mMtpDisabled) {
addStorageDevicesLocked();
}
@@ -195,6 +199,7 @@ public class MtpService extends Service {
// Internally, kernel will close our FD, and server thread will
// handle cleanup.
mServer = null;
+ mDatabase.setServer(null);
}
}
@@ -202,6 +207,9 @@ public class MtpService extends Service {
public void onDestroy() {
unregisterReceiver(mReceiver);
mStorageManager.unregisterListener(mStorageEventListener);
+ if (mDatabase != null) {
+ mDatabase.setServer(null);
+ }
}
private final IMtpService.Stub mBinder =