diff options
| author | 2024-04-29 16:17:48 +0000 | |
|---|---|---|
| committer | 2024-04-29 16:17:48 +0000 | |
| commit | 54019790819e65a345c532df3fa8bdcf0623700f (patch) | |
| tree | 3fa31bd5891ab6f27d1fd4c0eb2eeeca30925e01 | |
| parent | 0b207335d04d5e42e6dac4953dff3c26c158b7b0 (diff) | |
| parent | 43e5414039186a2f9f40d91868d37a4bed8cd3fc (diff) | |
Merge "Small reflow of the AnrTimer class" into main
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 a6b78098fbf8..23891d23cf4f 100644 --- a/services/core/java/com/android/server/am/ActiveServices.java +++ b/services/core/java/com/android/server/am/ActiveServices.java @@ -7600,8 +7600,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; } } @@ -7611,11 +7617,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. * - * <p>There are four external operations on a timer: + * <p>There are five external operations on a timer: * <ul> * * <li>{@link #start} starts a timer. The timer is started with an object that the message @@ -74,9 +74,13 @@ import java.util.Objects; * exit. (So, instances in system server generally need not be explicitly closed since they are * created during process start and will last until process exit.) * + * <p>AnrTimer parameterized by the type <code>V</code>. The public methods on AnrTimer require + * an instance of <code>V</code>; the instance of <code>V</code> is a key that identifies a + * specific timer. + * * @hide */ -public class AnrTimer<V> implements AutoCloseable { +public abstract class AnrTimer<V> implements AutoCloseable { /** * The log tag. @@ -101,6 +105,20 @@ public class AnrTimer<V> implements AutoCloseable { private static final long TRACE_TAG = Trace.TRACE_TAG_ACTIVITY_MANAGER; /** + * Fetch the Linux pid from the object. The returned value may be zero to indicate that there + * is no valid pid available. + * @return a valid pid or zero. + */ + public abstract int getPid(V obj); + + /** + * Fetch the Linux uid from the object. The returned value may be zero to indicate that there + * is no valid uid available. + * @return a valid uid or zero. + */ + public abstract int getUid(V obj); + + /** * Return true if the feature is enabled. By default, the value is take from the Flags class * but it can be changed for local testing. */ @@ -564,13 +582,11 @@ public class AnrTimer<V> implements AutoCloseable { * allows a client to deliver an immediate timeout via the AnrTimer. * * @param arg The key by which the timer is known. This is never examined or modified. - * @param pid The Linux process ID of the target being timed. - * @param uid The Linux user ID of the target being timed. * @param timeoutMs The timer timeout, in milliseconds. */ - public void start(@NonNull V arg, int pid, int uid, long timeoutMs) { + public void start(@NonNull V arg, long timeoutMs) { if (timeoutMs < 0) timeoutMs = 0; - mFeature.start(arg, pid, uid, timeoutMs); + mFeature.start(arg, getPid(arg), getUid(arg), timeoutMs); } /** diff --git a/services/tests/servicestests/src/com/android/server/utils/AnrTimerTest.java b/services/tests/servicestests/src/com/android/server/utils/AnrTimerTest.java index 44d116181be5..06c3db87ed2d 100644 --- a/services/tests/servicestests/src/com/android/server/utils/AnrTimerTest.java +++ b/services/tests/servicestests/src/com/android/server/utils/AnrTimerTest.java @@ -136,8 +136,14 @@ public class AnrTimerTest { this(helper.mHandler, MSG_TIMEOUT, caller()); } - void start(TestArg arg, long millis) { - start(arg, arg.pid, arg.uid, millis); + @Override + public int getPid(TestArg arg) { + return arg.pid; + } + + @Override + public int getUid(TestArg arg) { + return arg.uid; } // Return the name of method that called the constructor, assuming that this function is |