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

Commit 5eb3eb58 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Offer to measure disk stats using quotas.

Now we're getting somewhere!  This CL starts measuring disk usage
using quotactl(), which is almost instant and has much lower impact
on flash memory lifetime.

We now grant the per-app cache GID to every launched app, and the
ContextImpl logic that creates cache directories matches the logic
down in installd.

Test: builds, boots, quota stats match manual stats
Bug: 27948817
Change-Id: Ie269a2958ce0e1c17cb74dbfecc791a5c12922cf
parent fce04dc0
Loading
Loading
Loading
Loading
+17 −4
Original line number Diff line number Diff line
@@ -509,10 +509,23 @@ class ContextImpl extends Context {
     * Common-path handling of app data dir creation
     */
    private static File ensurePrivateDirExists(File file) {
        return ensurePrivateDirExists(file, 0771, -1);
    }

    private static File ensurePrivateCacheDirExists(File file) {
        final int gid = UserHandle.getCacheAppGid(Process.myUid());
        return ensurePrivateDirExists(file, 02771, gid);
    }

    private static File ensurePrivateDirExists(File file, int mode, int gid) {
        if (!file.exists()) {
            final String path = file.getAbsolutePath();
            try {
                Os.mkdir(file.getAbsolutePath(), 0771);
                Os.chmod(file.getAbsolutePath(), 0771);
                Os.mkdir(path, mode);
                Os.chmod(path, mode);
                if (gid != -1) {
                    Os.chown(path, -1, gid);
                }
            } catch (ErrnoException e) {
                if (e.errno == OsConstants.EEXIST) {
                    // We must have raced with someone; that's okay
@@ -581,7 +594,7 @@ class ContextImpl extends Context {
            if (mCacheDir == null) {
                mCacheDir = new File(getDataDir(), "cache");
            }
            return ensurePrivateDirExists(mCacheDir);
            return ensurePrivateCacheDirExists(mCacheDir);
        }
    }

@@ -591,7 +604,7 @@ class ContextImpl extends Context {
            if (mCodeCacheDir == null) {
                mCodeCacheDir = new File(getDataDir(), "code_cache");
            }
            return ensurePrivateDirExists(mCodeCacheDir);
            return ensurePrivateCacheDirExists(mCodeCacheDir);
        }
    }

+5 −1
Original line number Diff line number Diff line
@@ -783,7 +783,7 @@ public class Build {
     */
    public static boolean isBuildConsistent() {
        // Don't care on eng builds.  Incremental build may trigger false negative.
        if ("eng".equals(TYPE)) return true;
        if (IS_ENG) return true;

        final String system = SystemProperties.get("ro.build.fingerprint");
        final String vendor = SystemProperties.get("ro.vendor.build.fingerprint");
@@ -847,6 +847,10 @@ public class Build {
    public static final boolean IS_DEBUGGABLE =
            SystemProperties.getInt("ro.debuggable", 0) == 1;

    /** {@hide} */
    public static final boolean IS_ENG =
            "eng".equals(getString("ro.build.type"));

    /**
     * Specifies whether the permissions needed by a legacy app should be
     * reviewed before any of its components can run. A legacy app is one
+5 −0
Original line number Diff line number Diff line
@@ -184,6 +184,11 @@ public class Process {
     */
    public static final int LAST_SHARED_APPLICATION_GID = 59999;

    /** {@hide} */
    public static final int FIRST_APPLICATION_CACHE_GID = 20000;
    /** {@hide} */
    public static final int LAST_APPLICATION_CACHE_GID = 29999;

    /**
     * Standard priority of application threads.
     * Use with {@link #setThreadPriority(int)} and
+9 −0
Original line number Diff line number Diff line
@@ -212,6 +212,15 @@ public final class UserHandle implements Parcelable {
        return appId;
    }

    /**
     * Returns the cache GID for a given UID or appId.
     * @hide
     */
    public static int getCacheAppGid(int id) {
        return Process.FIRST_APPLICATION_CACHE_GID + (id % PER_USER_RANGE)
                - Process.FIRST_APPLICATION_UID;
    }

    /**
     * Generate a text representation of the uid, breaking out its individual
     * components -- user, app, isolated, etc.
+2 −1
Original line number Diff line number Diff line
@@ -154,7 +154,8 @@ option java_package com.android.server
3110 unknown_sources_enabled (value|1)
# Package Manager critical info
3120 pm_critical_info (msg|3)

# Disk usage stats for verifying quota correctness
3121 pm_package_stats (manual_time|2|3),(quota_time|2|3),(manual_data|2|2),(quota_data|2|2),(manual_cache|2|2),(quota_cache|2|2)

# ---------------------------
# WindowManagerService.java
Loading