summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-04-30 01:06:56 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-04-30 01:06:56 +0000
commitf3701bb223d4089c79ec2a7464eb8e7402a29f00 (patch)
treebf324e7fbedbda684aa01ba62235e489d9a5f30c
parent5eaef931a7a6cc6e0866453a6d92e692fd55cdcc (diff)
parent67b22096faaf53a16830fee5ca144bc5775fc241 (diff)
downloadservices-android13-d1-s2-release.tar.gz
Change-Id: I9ee8ab549e092604d6e65897e0f4c5fdf79aeef1
-rw-r--r--builtInServices/src/com/android/internal/car/CarServiceHelperService.java27
1 files changed, 18 insertions, 9 deletions
diff --git a/builtInServices/src/com/android/internal/car/CarServiceHelperService.java b/builtInServices/src/com/android/internal/car/CarServiceHelperService.java
index ddc4250..4e2333c 100644
--- a/builtInServices/src/com/android/internal/car/CarServiceHelperService.java
+++ b/builtInServices/src/com/android/internal/car/CarServiceHelperService.java
@@ -80,6 +80,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
+import java.util.Objects;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.regex.Matcher;
@@ -115,8 +116,8 @@ public class CarServiceHelperService extends SystemService
private static final String CSHS_UPDATABLE_CLASSNAME_STRING =
"com.android.internal.car.updatable.CarServiceHelperServiceUpdatableImpl";
private static final String PROC_PID_STAT_PATTERN =
- "([0-9]*)\\s\\((\\S+)\\)\\s\\S\\s(?:-?[0-9]*\\s){18}([0-9]*)\\s(?:-?[0-9]*\\s)*"
- + "-?[0-9]*";
+ "(?<pid>[0-9]*)\\s\\((?<name>\\S+)\\)\\s\\S\\s(?:-?[0-9]*\\s){18}"
+ + "(?<startClockTicks>[0-9]*)\\s(?:-?[0-9]*\\s)*-?[0-9]*";
private final Context mContext;
private final Object mLock = new Object();
@@ -541,7 +542,7 @@ public class CarServiceHelperService extends SystemService
line = line.substring(0, index);
}
return Paths.get(line).getFileName().toString();
- } catch (IOException e) {
+ } catch (IOException | RuntimeException e) {
Slogf.w(TAG, "Cannot read %s", filename);
return ProcessInfo.UNKNOWN_PROCESS;
}
@@ -553,11 +554,14 @@ public class CarServiceHelperService extends SystemService
String line = reader.readLine().replace('\0', ' ').trim();
Matcher m = mProcPidStatPattern.matcher(line);
if (m.find()) {
- return new ProcessInfo(Integer.parseInt(m.group(1)), m.group(2),
- Long.parseLong(m.group(3)));
+ int readPid = Integer.parseInt(Objects.requireNonNull(m.group("pid")));
+ if (readPid == pid) {
+ return new ProcessInfo(pid, m.group("name"),
+ Long.parseLong(Objects.requireNonNull(m.group("startClockTicks"))));
+ }
}
- } catch (IOException e) {
- Slogf.w(TAG, "Cannot read %s", filename);
+ } catch (IOException | RuntimeException e) {
+ Slogf.w(TAG, e, "Cannot read %s", filename);
}
return new ProcessInfo(pid, ProcessInfo.UNKNOWN_PROCESS, ProcessInfo.INVALID_START_TIME);
}
@@ -704,7 +708,8 @@ public class CarServiceHelperService extends SystemService
private static final class ProcessInfo {
public static final String UNKNOWN_PROCESS = "unknown process";
public static final int INVALID_START_TIME = -1;
- public static final long JIFFY_HZ = Os.sysconf(OsConstants._SC_CLK_TCK);
+
+ private static final long MILLIS_PER_JIFFY = 1000L / Os.sysconf(OsConstants._SC_CLK_TCK);
public final int pid;
public final String name;
@@ -714,10 +719,14 @@ public class CarServiceHelperService extends SystemService
this.pid = pid;
this.name = name;
this.startTimeMillis = startClockTicks != INVALID_START_TIME
- ? startClockTicks/JIFFY_HZ : INVALID_START_TIME;
+ ? startClockTicks * MILLIS_PER_JIFFY : INVALID_START_TIME;
}
boolean doMatch(int pid, long startTimeMillis) {
+ // Start time reported by the services that monitor the process health will be either
+ // the actual start time of the pid or the elapsed real time when the pid was last seen
+ // alive. Thus, verify whether the given start time is at least the actual start time of
+ // the pid.
return this.pid == pid && (this.startTimeMillis == INVALID_START_TIME
|| this.startTimeMillis <= startTimeMillis);
}