From 43e5414039186a2f9f40d91868d37a4bed8cd3fc Mon Sep 17 00:00:00 2001 From: Lee Shombert Date: Wed, 24 Apr 2024 17:02:15 -0700 Subject: Small reflow of the AnrTimer class The AnrTimer class is now abstract and requires two methods when instantiated with a type V. The methods extract a Linux pid and uid from an object of type V. The public start() method, which used to take an explicit pid and uid now computes the necessary pid/uid from the supplied instance of V. It is permitted to for the pid/uid methods to simply return 0, to indicate that there is no value. This change allows AnrTimer clients to compute pid/uid as necessary, without storing the information in the AnTimer system itself. Test: atest * FrameworksServicesTests:com.android.server.am * FrameworksMockingServicesTests:com.android.server.am * FrameworksServicesTests:AnrTimerTest Flag: com.android.server.utils.anr_timer_service Bug: 325594551 Change-Id: Ifc7779ce23d0884a7943b52d16aadc1419db96b7 --- .../java/com/android/server/am/ActiveServices.java | 23 ++++++++++++------ .../server/am/BroadcastQueueModernImpl.java | 10 ++++++-- .../java/com/android/server/utils/AnrTimer.java | 28 +++++++++++++++++----- .../src/com/android/server/utils/AnrTimerTest.java | 10 ++++++-- 4 files changed, 54 insertions(+), 17 deletions(-) diff --git a/services/core/java/com/android/server/am/ActiveServices.java b/services/core/java/com/android/server/am/ActiveServices.java index eec22c92b5dc..93beb647df97 100644 --- a/services/core/java/com/android/server/am/ActiveServices.java +++ b/services/core/java/com/android/server/am/ActiveServices.java @@ -7560,8 +7560,14 @@ public final class ActiveServices { super(Objects.requireNonNull(am).mHandler, msg, label); } - void start(@NonNull ProcessRecord proc, long millis) { - start(proc, proc.getPid(), proc.uid, millis); + @Override + public int getPid(@NonNull ProcessRecord proc) { + return proc.getPid(); + } + + @Override + public int getUid(@NonNull ProcessRecord proc) { + return proc.uid; } } @@ -7571,11 +7577,14 @@ public final class ActiveServices { super(Objects.requireNonNull(am).mHandler, msg, label); } - void start(@NonNull ServiceRecord service, long millis) { - start(service, - (service.app != null) ? service.app.getPid() : 0, - service.appInfo.uid, - millis); + @Override + public int getPid(@NonNull ServiceRecord service) { + return (service.app != null) ? service.app.getPid() : 0; + } + + @Override + public int getUid(@NonNull ServiceRecord service) { + return (service.appInfo != null) ? service.appInfo.uid : 0; } } diff --git a/services/core/java/com/android/server/am/BroadcastQueueModernImpl.java b/services/core/java/com/android/server/am/BroadcastQueueModernImpl.java index 48dd03922479..4425a388e9e1 100644 --- a/services/core/java/com/android/server/am/BroadcastQueueModernImpl.java +++ b/services/core/java/com/android/server/am/BroadcastQueueModernImpl.java @@ -1339,8 +1339,14 @@ class BroadcastQueueModernImpl extends BroadcastQueue { MSG_DELIVERY_TIMEOUT, "BROADCAST_TIMEOUT", true); } - void start(@NonNull BroadcastProcessQueue queue, long timeoutMillis) { - start(queue, queue.app.getPid(), queue.app.uid, timeoutMillis); + @Override + public int getPid(@NonNull BroadcastProcessQueue queue) { + return (queue.app != null) ? queue.app.getPid() : 0; + } + + @Override + public int getUid(@NonNull BroadcastProcessQueue queue) { + return (queue.app != null) ? queue.app.uid : 0; } } diff --git a/services/core/java/com/android/server/utils/AnrTimer.java b/services/core/java/com/android/server/utils/AnrTimer.java index e944eca63144..592d0396b349 100644 --- a/services/core/java/com/android/server/utils/AnrTimer.java +++ b/services/core/java/com/android/server/utils/AnrTimer.java @@ -47,7 +47,7 @@ import java.util.Objects; * mode, the timer just sends a delayed message. In modern mode, the timer is implemented in * native code; on expiration, the message is sent without delay. * - *

There are four external operations on a timer: + *

There are five external operations on a timer: *