Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 556b09e1 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Fix issue #6926562: Ensure all multi-user cache files are managed correctly

Now we correctly iterate through the different user cache dirs.

Also update documentation to describe the new cache pruning behavior,
and deprecate the file modes for making files world readable/writable
which we really don't want people using any more.

Change-Id: I3708df3ddc697b1f5c511143cce7cc40a5a3d0bd
parent 6b3292ce
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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";
+24 −5
Original line number Diff line number Diff line
@@ -338,14 +338,33 @@ 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);
    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);
    finish_cache_collection(cache);
+22 −2
Original line number Diff line number Diff line
@@ -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