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

Commit 6d697fc0 authored by Li Li's avatar Li Li
Browse files

Check if freezer cgroup configuration is valid

Project Treble allows Android to upgrade to the latest version without
modifying vendor implementation. Some old vendor code might contain
outdated cgroup profiles, which override the correct ones in the system
partition. Improve isFreezerSupported() to detect those rare cases.

Bug: 277233783
Test: manually verify freezer with outdated cgroup configuration
Change-Id: Ife8c02a6d424965fce3e8ca158bf337dcb4faf1e
parent 2238fdb8
Loading
Loading
Loading
Loading
+14 −5
Original line number Diff line number Diff line
@@ -1014,6 +1014,12 @@ public final class CachedAppOptimizer {
     */
    private static native String getFreezerCheckPath();

    /**
     * Check if task_profiles.json includes valid freezer profiles and actions
     * @return false if there are invalid profiles or actions
     */
    private static native boolean isFreezerProfileValid();

    /**
     * Determines whether the freezer is supported by this system
     */
@@ -1031,16 +1037,19 @@ public final class CachedAppOptimizer {
                // Also check freezer binder ioctl
                Slog.d(TAG_AM, "Checking binder freezer ioctl");
                getBinderFreezeInfo(Process.myPid());
                supported = true;

                // Check if task_profiles.json contains invalid profiles
                Slog.d(TAG_AM, "Checking freezer profiles");
                supported = isFreezerProfileValid();
            } else {
                Slog.e(TAG_AM, "unexpected value in cgroup.freeze");
                Slog.e(TAG_AM, "Unexpected value in cgroup.freeze");
            }
        } catch (java.io.FileNotFoundException e) {
            Slog.w(TAG_AM, "cgroup.freeze not present");
            Slog.w(TAG_AM, "File cgroup.freeze not present");
        } catch (RuntimeException e) {
            Slog.w(TAG_AM, "unable to read freezer info");
            Slog.w(TAG_AM, "Unable to read freezer info");
        } catch (Exception e) {
            Slog.w(TAG_AM, "unable to read cgroup.freeze: " + e.toString());
            Slog.w(TAG_AM, "Unable to read cgroup.freeze: " + e.toString());
        }

        if (fr != null) {
+11 −1
Original line number Diff line number Diff line
@@ -561,6 +561,14 @@ static jstring com_android_server_am_CachedAppOptimizer_getFreezerCheckPath(JNIE
    return env->NewStringUTF(path.c_str());
}

static jboolean com_android_server_am_CachedAppOptimizer_isFreezerProfileValid(JNIEnv* env) {
    int uid = getuid();
    int pid = getpid();

    return isProfileValidForProcess("Frozen", uid, pid) &&
            isProfileValidForProcess("Unfrozen", uid, pid);
}

static const JNINativeMethod sMethods[] = {
        /* name, signature, funcPtr */
        {"cancelCompaction", "()V",
@@ -578,7 +586,9 @@ static const JNINativeMethod sMethods[] = {
        {"getBinderFreezeInfo", "(I)I",
         (void*)com_android_server_am_CachedAppOptimizer_getBinderFreezeInfo},
        {"getFreezerCheckPath", "()Ljava/lang/String;",
         (void*)com_android_server_am_CachedAppOptimizer_getFreezerCheckPath}};
         (void*)com_android_server_am_CachedAppOptimizer_getFreezerCheckPath},
        {"isFreezerProfileValid", "()Z",
         (void*)com_android_server_am_CachedAppOptimizer_isFreezerProfileValid}};

int register_android_server_am_CachedAppOptimizer(JNIEnv* env)
{