Skip to content

Commit 7451f15

Browse files
Dianne HackbornAndroid (Google) Code Review
authored andcommitted
Merge "Fix issue #6926562: Ensure all multi-user cache files are managed correctly" into jb-mr1-dev
2 parents b00df8e + 556b09e commit 7451f15

File tree

3 files changed

+48
-9
lines changed

3 files changed

+48
-9
lines changed

api/current.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5440,8 +5440,8 @@ package android.content {
54405440
field public static final int MODE_ENABLE_WRITE_AHEAD_LOGGING = 8; // 0x8
54415441
field public static final int MODE_MULTI_PROCESS = 4; // 0x4
54425442
field public static final int MODE_PRIVATE = 0; // 0x0
5443-
field public static final int MODE_WORLD_READABLE = 1; // 0x1
5444-
field public static final int MODE_WORLD_WRITEABLE = 2; // 0x2
5443+
field public static final deprecated int MODE_WORLD_READABLE = 1; // 0x1
5444+
field public static final deprecated int MODE_WORLD_WRITEABLE = 2; // 0x2
54455445
field public static final java.lang.String NFC_SERVICE = "nfc";
54465446
field public static final java.lang.String NOTIFICATION_SERVICE = "notification";
54475447
field public static final java.lang.String NSD_SERVICE = "servicediscovery";

cmds/installd/commands.c

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -338,13 +338,32 @@ int free_cache(int64_t free_size)
338338
closedir(d);
339339
}
340340

341-
// Collect cache files on external storage (if it is mounted as part
341+
// Collect cache files on external storage for all users (if it is mounted as part
342342
// of the internal storage).
343343
strcpy(tmpdir, android_media_dir.path);
344-
if (lookup_media_dir(tmpdir, "Android") == 0
345-
&& lookup_media_dir(tmpdir, "data") == 0) {
346-
//ALOGI("adding cache files from %s\n", tmpdir);
347-
add_cache_files(cache, tmpdir, "cache");
344+
dirpos = tmpdir + strlen(tmpdir);
345+
d = opendir(tmpdir);
346+
if (d != NULL) {
347+
while ((de = readdir(d))) {
348+
if (de->d_type == DT_DIR) {
349+
const char *name = de->d_name;
350+
/* skip any dir that doesn't start with a number, so not a user */
351+
if (name[0] < '0' || name[0] > '9') {
352+
continue;
353+
}
354+
if ((strlen(name)+(dirpos-tmpdir)) < (sizeof(tmpdir)-1)) {
355+
strcpy(dirpos, name);
356+
if (lookup_media_dir(tmpdir, "Android") == 0
357+
&& lookup_media_dir(tmpdir, "data") == 0) {
358+
//ALOGI("adding cache files from %s\n", tmpdir);
359+
add_cache_files(cache, tmpdir, "cache");
360+
}
361+
} else {
362+
ALOGW("Path exceeds limit: %s%s", tmpdir, name);
363+
}
364+
}
365+
}
366+
closedir(d);
348367
}
349368

350369
clear_cache_files(cache, free_size);

core/java/android/content/Context.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,34 @@ public abstract class Context {
6363
*/
6464
public static final int MODE_PRIVATE = 0x0000;
6565
/**
66+
* @deprecated Creating world-readable files is very dangerous, and likely
67+
* to cause security holes in applications. It is strongly discouraged;
68+
* instead, applications should use more formal mechanism for interactions
69+
* such as {@link ContentProvider}, {@link BroadcastReceiver}, and
70+
* {@link android.app.Service}. There are no guarantees that this
71+
* access mode will remain on a file, such as when it goes through a
72+
* backup and restore.
6673
* File creation mode: allow all other applications to have read access
6774
* to the created file.
6875
* @see #MODE_PRIVATE
6976
* @see #MODE_WORLD_WRITEABLE
7077
*/
78+
@Deprecated
7179
public static final int MODE_WORLD_READABLE = 0x0001;
7280
/**
81+
* @deprecated Creating world-writable files is very dangerous, and likely
82+
* to cause security holes in applications. It is strongly discouraged;
83+
* instead, applications should use more formal mechanism for interactions
84+
* such as {@link ContentProvider}, {@link BroadcastReceiver}, and
85+
* {@link android.app.Service}. There are no guarantees that this
86+
* access mode will remain on a file, such as when it goes through a
87+
* backup and restore.
7388
* File creation mode: allow all other applications to have write access
7489
* to the created file.
7590
* @see #MODE_PRIVATE
7691
* @see #MODE_WORLD_READABLE
7792
*/
93+
@Deprecated
7894
public static final int MODE_WORLD_WRITEABLE = 0x0002;
7995
/**
8096
* File creation mode: for use with {@link #openFileOutput}, if the file
@@ -645,8 +661,12 @@ public abstract FileOutputStream openFileOutput(String name, int mode)
645661
* are some important differences:
646662
*
647663
* <ul>
648-
* <li>The platform does not monitor the space available in external storage,
649-
* and thus will not automatically delete these files. Note that you should
664+
* <li>The platform does not always monitor the space available in external
665+
* storage, and thus may not automatically delete these files. Currently
666+
* the only time files here will be deleted by the platform is when running
667+
* on {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
668+
* {@link android.os.Environment#isExternalStorageEmulated()
669+
* Environment.isExternalStorageEmulated()} returns true. Note that you should
650670
* be managing the maximum space you will use for these anyway, just like
651671
* with {@link #getCacheDir()}.
652672
* <li>External files are not always available: they will disappear if the

0 commit comments

Comments
 (0)