From 135ac0999036b05ccb4ae4b19b4e9000f2ca185e Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 1 Apr 2022 17:16:13 -0700 Subject: [PATCH] Optimize EROFS detection code. The EROFS detection code is rather expensive. On Android 13 kernels we can use a faster detection using /sys/fs/erofs. Bug: 225092276 Test: erofs detected on android13-5.10 Change-Id: I0f1c2975f1de7810ee2334d2f09c9fa3722d0174 --- core/java/com/android/server/SystemConfig.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/core/java/com/android/server/SystemConfig.java b/core/java/com/android/server/SystemConfig.java index 1feb5d415e168..89ada35cb5796 100644 --- a/core/java/com/android/server/SystemConfig.java +++ b/core/java/com/android/server/SystemConfig.java @@ -58,7 +58,6 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -1487,7 +1486,7 @@ public class SystemConfig { addFeature(PackageManager.FEATURE_IPSEC_TUNNELS, 0); } - if (isFilesystemSupported("erofs")) { + if (isErofsSupported()) { if (isKernelVersionAtLeast(5, 10)) { addFeature(PackageManager.FEATURE_EROFS, 0); } else if (isKernelVersionAtLeast(4, 19)) { @@ -1865,11 +1864,10 @@ public class SystemConfig { return Process.myUid() == Process.SYSTEM_UID; } - private static boolean isFilesystemSupported(String fs) { + private static boolean isErofsSupported() { try { - final byte[] fsTableData = Files.readAllBytes(Paths.get("/proc/filesystems")); - final String fsTable = new String(fsTableData, StandardCharsets.UTF_8); - return fsTable.contains("\t" + fs + "\n"); + final Path path = Paths.get("/sys/fs/erofs"); + return Files.exists(path); } catch (Exception e) { return false; }