Avoid checking logcat command locally
saves ~70ms
Also instrument foldable state
Test: presubmit
Bug: 283110414
Change-Id: I6e090524ce57a9fd982b5b726f80c212c6d88e95
diff --git a/src/com/android/tradefed/device/LogcatReceiver.java b/src/com/android/tradefed/device/LogcatReceiver.java
index 8993b1c..96a3acf 100644
--- a/src/com/android/tradefed/device/LogcatReceiver.java
+++ b/src/com/android/tradefed/device/LogcatReceiver.java
@@ -17,6 +17,7 @@
import com.android.tradefed.log.LogUtil;
import com.android.tradefed.result.InputStreamSource;
+import com.android.tradefed.util.SystemUtil;
import com.google.errorprone.annotations.MustBeClosed;
@@ -97,7 +98,7 @@
String logcatCmd = "logcat -v threadtime";
// Logcat format support UID started from api level 24.
try {
- if (device.getApiLevel() >= 24) {
+ if (SystemUtil.isLocalMode() || device.getApiLevel() >= 24) {
logcatCmd = logcatCmd + ",uid";
}
} catch (DeviceNotAvailableException e) {
diff --git a/src/com/android/tradefed/device/TestDevice.java b/src/com/android/tradefed/device/TestDevice.java
index 864985e..7cccc64 100644
--- a/src/com/android/tradefed/device/TestDevice.java
+++ b/src/com/android/tradefed/device/TestDevice.java
@@ -2525,35 +2525,42 @@
if (getIDevice() instanceof StubDevice) {
return new HashSet<>();
}
- CommandResult result = executeShellV2Command("cmd device_state print-states");
- if (!CommandStatus.SUCCESS.equals(result.getStatus())) {
- // Can't throw an exception since it would fail on non-supported version
- return new HashSet<>();
- }
- Set<DeviceFoldableState> foldableStates = new LinkedHashSet<>();
- Pattern deviceStatePattern =
- Pattern.compile(
- "DeviceState\\{identifier=(\\d+), name='(\\S+)'"
- + "(?:, app_accessible=)?(\\S+)?"
- + "(?:, cancel_when_requester_not_on_top=)?(\\S+)?"
- + "\\}\\S*");
- for (String line : result.getStdout().split("\n")) {
- Matcher m = deviceStatePattern.matcher(line.trim());
- if (m.matches()) {
- // Move onto the next state if the device state is not accessible by apps
- if (m.groupCount() > 2 && m.group(3) != null && !Boolean.parseBoolean(m.group(3))) {
- continue;
- }
- // Move onto the next state if the device state is canceled when the requesting app
- // is not on top.
- if (m.groupCount() > 3 && m.group(4) != null && Boolean.parseBoolean(m.group(4))) {
- continue;
- }
- foldableStates.add(
- new DeviceFoldableState(Integer.parseInt(m.group(1)), m.group(2)));
+ try (CloseableTraceScope foldable = new CloseableTraceScope("getFoldableStates")) {
+ CommandResult result = executeShellV2Command("cmd device_state print-states");
+ if (!CommandStatus.SUCCESS.equals(result.getStatus())) {
+ // Can't throw an exception since it would fail on non-supported version
+ return new HashSet<>();
}
+ Set<DeviceFoldableState> foldableStates = new LinkedHashSet<>();
+ Pattern deviceStatePattern =
+ Pattern.compile(
+ "DeviceState\\{identifier=(\\d+), name='(\\S+)'"
+ + "(?:, app_accessible=)?(\\S+)?"
+ + "(?:, cancel_when_requester_not_on_top=)?(\\S+)?"
+ + "\\}\\S*");
+ for (String line : result.getStdout().split("\n")) {
+ Matcher m = deviceStatePattern.matcher(line.trim());
+ if (m.matches()) {
+ // Move onto the next state if the device state is not accessible by apps
+ if (m.groupCount() > 2
+ && m.group(3) != null
+ && !Boolean.parseBoolean(m.group(3))) {
+ continue;
+ }
+ // Move onto the next state if the device state is canceled when the requesting
+ // app
+ // is not on top.
+ if (m.groupCount() > 3
+ && m.group(4) != null
+ && Boolean.parseBoolean(m.group(4))) {
+ continue;
+ }
+ foldableStates.add(
+ new DeviceFoldableState(Integer.parseInt(m.group(1)), m.group(2)));
+ }
+ }
+ return foldableStates;
}
- return foldableStates;
}
@Override