summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Lee Shombert <shombert@google.com> 2025-01-22 16:10:42 -0800
committer Lee Shombert <shombert@google.com> 2025-01-22 16:11:47 -0800
commite9bff95e3cf6c02d66b4b682f96d18c1604ec4cd (patch)
tree66133c01ce2bb75ba221309a7fe2f3a0e1376943
parent82da37e4d18e22a4f7381cf3a1e7154804374356 (diff)
Do not freeze system_server
In early testing, freezing the current process generated an error but did no harm. Now it does harm. This CL disables freezing because of an ANR timeout if the target pid is 0 (often passed in to signify "self") or the pid of system_server. Flag: com.android.server.utils.anr_timer_freezer Bug: 391491604 Test: atest * FrameworksServicesTests:AnrTimerTest * FrameworksServicesTests:com.android.server.am * FrameworksMockingServicesTests:com.android.server.am Change-Id: I78189987f4dee398a02f6ca50df9d4e1a83b5419
-rw-r--r--services/core/jni/com_android_server_utils_AnrTimer.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/services/core/jni/com_android_server_utils_AnrTimer.cpp b/services/core/jni/com_android_server_utils_AnrTimer.cpp
index 2add5b09f15b..24909ac6150b 100644
--- a/services/core/jni/com_android_server_utils_AnrTimer.cpp
+++ b/services/core/jni/com_android_server_utils_AnrTimer.cpp
@@ -101,6 +101,9 @@ nsecs_t now() {
return systemTime(SYSTEM_TIME_MONOTONIC);
}
+// The current process. This is cached here on startup.
+const pid_t sThisProcess = getpid();
+
// Return true if the process exists and false if we cannot know.
bool processExists(pid_t pid) {
char path[PATH_MAX];
@@ -726,7 +729,7 @@ class AnrTimerService::Timer {
uid(uid),
timeout(timeout),
extend(extend),
- freeze(pid != 0 && freeze),
+ freeze(freeze),
split(trace.earlyTimeout),
action(trace.action),
status(Running),
@@ -1188,8 +1191,11 @@ const char* AnrTimerService::statusString(Status s) {
}
AnrTimerService::timer_id_t AnrTimerService::start(int pid, int uid, nsecs_t timeout) {
+ // Use the freezer only if the pid is not 0 (a nonsense value) and the pid is not self.
+ // Freezing the current process is a fatal error.
+ bool useFreezer = freeze_ && (pid != 0) && (pid != sThisProcess);
AutoMutex _l(lock_);
- Timer t(pid, uid, timeout, extend_, freeze_, tracer_.getConfig(pid));
+ Timer t(pid, uid, timeout, extend_, useFreezer, tracer_.getConfig(pid));
insertLocked(t);
t.start();
counters_.started++;