From 857ce7ace1925d449de46b031f9548834b85455b Mon Sep 17 00:00:00 2001 From: Ryan Mitchell Date: Thu, 20 Feb 2020 09:21:51 -0800 Subject: [PATCH] Remove exception from OverlayConfig zygote method The AssetManager constructor is marked UnsupportedAppUsage and the recent changes to OverlayConfig caused an exception to be thrown when the function is not called from the root process. Previously a warning message would be logged indicating that no static overlays would be loaded. Removing the uid check will restore the previous behavior. Also remove the system uid checks for initializeSystemInstance so PMS service can also be constructed during testing. Bug: 149806146 Test: invoke new AssetManager() from non-root thread Change-Id: I55af2cddeba4df7a99c281c93e0181b9e2139139 --- .../internal/content/om/OverlayConfig.java | 22 +++++-------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/core/java/com/android/internal/content/om/OverlayConfig.java b/core/java/com/android/internal/content/om/OverlayConfig.java index ffa347c168f65..72f16e4e4a82d 100644 --- a/core/java/com/android/internal/content/om/OverlayConfig.java +++ b/core/java/com/android/internal/content/om/OverlayConfig.java @@ -186,13 +186,6 @@ public class OverlayConfig { */ @NonNull public static OverlayConfig getZygoteInstance() { - if (Process.myUid() != Process.ROOT_UID) { - // Scan the overlays in the zygote process to generate configuration settings for - // overlays on the system image. Do not cache this instance so OverlayConfig will not - // be present in applications by default. - throw new IllegalStateException("Can only be invoked in the root process"); - } - Trace.traceBegin(Trace.TRACE_TAG_RRO, "OverlayConfig#getZygoteInstance"); try { return new OverlayConfig(null /* rootDirectory */, OverlayScanner::new, @@ -209,13 +202,12 @@ public class OverlayConfig { */ @NonNull public static OverlayConfig initializeSystemInstance(PackageProvider packageProvider) { - if (Process.myUid() != Process.SYSTEM_UID) { - throw new IllegalStateException("Can only be invoked in the system process"); - } - Trace.traceBegin(Trace.TRACE_TAG_RRO, "OverlayConfig#initializeSystemInstance"); - sInstance = new OverlayConfig(null, null, packageProvider); - Trace.traceEnd(Trace.TRACE_TAG_RRO); + try { + sInstance = new OverlayConfig(null, null, packageProvider); + } finally { + Trace.traceEnd(Trace.TRACE_TAG_RRO); + } return sInstance; } @@ -373,10 +365,6 @@ public class OverlayConfig { */ @NonNull public String[] createImmutableFrameworkIdmapsInZygote() { - if (Process.myUid() != Process.ROOT_UID) { - throw new IllegalStateException("This method can only be called from the root process"); - } - final String targetPath = "/system/framework/framework-res.apk"; final ArrayList idmapPaths = new ArrayList<>(); final ArrayList idmapInvocations =