From 8f036fd4546789e32451df47dc416e17b475d699 Mon Sep 17 00:00:00 2001 From: Tobias Thierer Date: Mon, 21 Sep 2020 19:54:52 +0100 Subject: [PATCH] SystemConfig: Tolerate absent native lib paths. SystemConfig.readPublicNativeLibrariesList() has some hard-coded paths containing public.libraries*.txt files; these are not present when this code runs outside of an Android device, for example in a Robolectric test on host. This CL changes the code to log a warning, rather than crash, when one of those folders is missing or inaccessible. Note that this increases the chance that a future breakage will be missed, but there already was not test coverage for the method behaving correctly. Fixes: 169017157 Test: Checked that the following fails before this but passes after this CL: atest BackupManagerServiceRoboTest Change-Id: Id8430ea68901ce60dcc855f7013bafadea823297 --- core/java/com/android/server/SystemConfig.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/java/com/android/server/SystemConfig.java b/core/java/com/android/server/SystemConfig.java index 6b754ca301f35..396a84ffcfb8b 100644 --- a/core/java/com/android/server/SystemConfig.java +++ b/core/java/com/android/server/SystemConfig.java @@ -1520,7 +1520,12 @@ public class SystemConfig { readPublicLibrariesListFile(new File("/vendor/etc/public.libraries.txt")); String[] dirs = {"/system/etc", "/system_ext/etc", "/product/etc"}; for (String dir : dirs) { - for (File f : (new File(dir)).listFiles()) { + File[] files = new File(dir).listFiles(); + if (files == null) { + Slog.w(TAG, "Public libraries file folder missing: " + dir); + continue; + } + for (File f : files) { String name = f.getName(); if (name.startsWith("public.libraries-") && name.endsWith(".txt")) { readPublicLibrariesListFile(f);