Merge "Fix issue #6926562: Ensure all multi-user cache files are managed correctly" into jb-mr1-dev

This commit is contained in:
Dianne Hackborn
2012-09-24 11:07:25 -07:00
committed by Android (Google) Code Review
3 changed files with 48 additions and 9 deletions

View File

@@ -5440,8 +5440,8 @@ package android.content {
field public static final int MODE_ENABLE_WRITE_AHEAD_LOGGING = 8; // 0x8
field public static final int MODE_MULTI_PROCESS = 4; // 0x4
field public static final int MODE_PRIVATE = 0; // 0x0
field public static final int MODE_WORLD_READABLE = 1; // 0x1
field public static final int MODE_WORLD_WRITEABLE = 2; // 0x2
field public static final deprecated int MODE_WORLD_READABLE = 1; // 0x1
field public static final deprecated int MODE_WORLD_WRITEABLE = 2; // 0x2
field public static final java.lang.String NFC_SERVICE = "nfc";
field public static final java.lang.String NOTIFICATION_SERVICE = "notification";
field public static final java.lang.String NSD_SERVICE = "servicediscovery";

View File

@@ -338,13 +338,32 @@ int free_cache(int64_t free_size)
closedir(d);
}
// Collect cache files on external storage (if it is mounted as part
// Collect cache files on external storage for all users (if it is mounted as part
// of the internal storage).
strcpy(tmpdir, android_media_dir.path);
if (lookup_media_dir(tmpdir, "Android") == 0
&& lookup_media_dir(tmpdir, "data") == 0) {
//ALOGI("adding cache files from %s\n", tmpdir);
add_cache_files(cache, tmpdir, "cache");
dirpos = tmpdir + strlen(tmpdir);
d = opendir(tmpdir);
if (d != NULL) {
while ((de = readdir(d))) {
if (de->d_type == DT_DIR) {
const char *name = de->d_name;
/* skip any dir that doesn't start with a number, so not a user */
if (name[0] < '0' || name[0] > '9') {
continue;
}
if ((strlen(name)+(dirpos-tmpdir)) < (sizeof(tmpdir)-1)) {
strcpy(dirpos, name);
if (lookup_media_dir(tmpdir, "Android") == 0
&& lookup_media_dir(tmpdir, "data") == 0) {
//ALOGI("adding cache files from %s\n", tmpdir);
add_cache_files(cache, tmpdir, "cache");
}
} else {
ALOGW("Path exceeds limit: %s%s", tmpdir, name);
}
}
}
closedir(d);
}
clear_cache_files(cache, free_size);

View File

@@ -63,18 +63,34 @@ public abstract class Context {
*/
public static final int MODE_PRIVATE = 0x0000;
/**
* @deprecated Creating world-readable files is very dangerous, and likely
* to cause security holes in applications. It is strongly discouraged;
* instead, applications should use more formal mechanism for interactions
* such as {@link ContentProvider}, {@link BroadcastReceiver}, and
* {@link android.app.Service}. There are no guarantees that this
* access mode will remain on a file, such as when it goes through a
* backup and restore.
* File creation mode: allow all other applications to have read access
* to the created file.
* @see #MODE_PRIVATE
* @see #MODE_WORLD_WRITEABLE
*/
@Deprecated
public static final int MODE_WORLD_READABLE = 0x0001;
/**
* @deprecated Creating world-writable files is very dangerous, and likely
* to cause security holes in applications. It is strongly discouraged;
* instead, applications should use more formal mechanism for interactions
* such as {@link ContentProvider}, {@link BroadcastReceiver}, and
* {@link android.app.Service}. There are no guarantees that this
* access mode will remain on a file, such as when it goes through a
* backup and restore.
* File creation mode: allow all other applications to have write access
* to the created file.
* @see #MODE_PRIVATE
* @see #MODE_WORLD_READABLE
*/
@Deprecated
public static final int MODE_WORLD_WRITEABLE = 0x0002;
/**
* File creation mode: for use with {@link #openFileOutput}, if the file
@@ -645,8 +661,12 @@ public abstract class Context {
* are some important differences:
*
* <ul>
* <li>The platform does not monitor the space available in external storage,
* and thus will not automatically delete these files. Note that you should
* <li>The platform does not always monitor the space available in external
* storage, and thus may not automatically delete these files. Currently
* the only time files here will be deleted by the platform is when running
* on {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
* {@link android.os.Environment#isExternalStorageEmulated()
* Environment.isExternalStorageEmulated()} returns true. Note that you should
* be managing the maximum space you will use for these anyway, just like
* with {@link #getCacheDir()}.
* <li>External files are not always available: they will disappear if the