Merge "Check if freezer cgroup configuration is valid" into udc-dev

This commit is contained in:
Li Li
2023-05-02 04:30:37 +00:00
committed by Android (Google) Code Review
2 changed files with 25 additions and 6 deletions

View File

@@ -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) {

View File

@@ -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)
{