From c31c4f9b313dff8f8a0630f15b66b53338e6049a Mon Sep 17 00:00:00 2001 From: Chris Wailes Date: Tue, 25 Feb 2020 15:48:58 -0800 Subject: [PATCH] Cleanup of Zygote files This CL cleans up some warnings in the ZygoteInit.java and ZygoteServer.java files. These warnings were mostly about unused variables, protection class changes, and dead code. Some changes to code in Zygote.java and ZygoteConnection.java were needed due to function signature changes. Test: Built and booted image Merged-In: I6ba33cfcb4729a75dbbd4f908f4b46110d3bb991 Change-Id: I6ba33cfcb4729a75dbbd4f908f4b46110d3bb991 --- core/java/com/android/internal/os/Zygote.java | 2 +- .../android/internal/os/ZygoteConnection.java | 4 +-- .../com/android/internal/os/ZygoteInit.java | 34 +++++++------------ .../com/android/internal/os/ZygoteServer.java | 2 +- 4 files changed, 17 insertions(+), 25 deletions(-) diff --git a/core/java/com/android/internal/os/Zygote.java b/core/java/com/android/internal/os/Zygote.java index a41018000d776..65beb93602414 100644 --- a/core/java/com/android/internal/os/Zygote.java +++ b/core/java/com/android/internal/os/Zygote.java @@ -590,7 +590,7 @@ public final class Zygote { static Runnable forkUsap(LocalServerSocket usapPoolSocket, int[] sessionSocketRawFDs, boolean isPriorityFork) { - FileDescriptor[] pipeFDs = null; + FileDescriptor[] pipeFDs; try { pipeFDs = Os.pipe2(O_CLOEXEC); diff --git a/core/java/com/android/internal/os/ZygoteConnection.java b/core/java/com/android/internal/os/ZygoteConnection.java index 6573e4217a7f5..5a576ebbc442c 100644 --- a/core/java/com/android/internal/os/ZygoteConnection.java +++ b/core/java/com/android/internal/os/ZygoteConnection.java @@ -505,8 +505,8 @@ class ZygoteConnection { parsedArgs.mDisabledCompatChanges, parsedArgs.mRemainingArgs, null /* classLoader */); } else { - return ZygoteInit.childZygoteInit(parsedArgs.mTargetSdkVersion, - parsedArgs.mRemainingArgs, null /* classLoader */); + return ZygoteInit.childZygoteInit( + parsedArgs.mRemainingArgs /* classLoader */); } } } diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java index 7fde5474ec920..ef1c50f436814 100644 --- a/core/java/com/android/internal/os/ZygoteInit.java +++ b/core/java/com/android/internal/os/ZygoteInit.java @@ -117,7 +117,7 @@ public class ZygoteInit { /** * Controls whether we should preload resources during zygote init. */ - public static final boolean PRELOAD_RESOURCES = true; + private static final boolean PRELOAD_RESOURCES = true; private static final int UNPRIVILEGED_UID = 9999; private static final int UNPRIVILEGED_GID = 9999; @@ -159,7 +159,7 @@ public class ZygoteInit { sPreloadComplete = true; } - public static void lazyPreload() { + static void lazyPreload() { Preconditions.checkState(!sPreloadComplete); Log.i(TAG, "Lazily preloading resources."); @@ -364,7 +364,7 @@ public class ZygoteInit { } if ("true".equals(prop)) { Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "ResetJitCounters"); - runtime.resetJitCounters(); + VMRuntime.resetJitCounters(); Trace.traceEnd(Trace.TRACE_TAG_DALVIK); } @@ -418,8 +418,6 @@ public class ZygoteInit { * larger. */ private static void preloadResources() { - final VMRuntime runtime = VMRuntime.getRuntime(); - try { mResources = Resources.getSystem(); mResources.startPreloading(); @@ -463,9 +461,7 @@ public class ZygoteInit { int N = ar.length(); for (int i = 0; i < N; i++) { int id = ar.getResourceId(i, 0); - if (false) { - Log.v(TAG, "Preloading resource #" + Integer.toHexString(id)); - } + if (id != 0) { if (mResources.getColorStateList(id, null) == null) { throw new IllegalArgumentException( @@ -483,9 +479,7 @@ public class ZygoteInit { int N = ar.length(); for (int i = 0; i < N; i++) { int id = ar.getResourceId(i, 0); - if (false) { - Log.v(TAG, "Preloading resource #" + Integer.toHexString(id)); - } + if (id != 0) { if (mResources.getDrawable(id, null) == null) { throw new IllegalArgumentException( @@ -688,13 +682,12 @@ public class ZygoteInit { final String packageName = "*"; final String outputPath = null; final int dexFlags = 0; - final String compilerFilter = systemServerFilter; final String uuid = StorageManager.UUID_PRIVATE_INTERNAL; final String seInfo = null; final int targetSdkVersion = 0; // SystemServer targets the system's SDK version try { installd.dexopt(classPathElement, Process.SYSTEM_UID, packageName, - instructionSet, dexoptNeeded, outputPath, dexFlags, compilerFilter, + instructionSet, dexoptNeeded, outputPath, dexFlags, systemServerFilter, uuid, classLoaderContext, seInfo, false /* downgrade */, targetSdkVersion, /*profileName*/ null, /*dexMetadataPath*/ null, "server-dexopt"); @@ -770,7 +763,7 @@ public class ZygoteInit { capabilities &= ((long) data[0].effective) | (((long) data[1].effective) << 32); /* Hardcoded command line to start the system server */ - String args[] = { + String[] args = { "--setuid=1000", "--setgid=1000", "--setgroups=1001,1002,1003,1004,1005,1006,1007,1008,1009,1010,1018,1021,1023," @@ -781,7 +774,7 @@ public class ZygoteInit { "--target-sdk-version=" + VMRuntime.SDK_VERSION_CUR_DEVELOPMENT, "com.android.server.SystemServer", }; - ZygoteArguments parsedArgs = null; + ZygoteArguments parsedArgs; int pid; @@ -870,7 +863,7 @@ public class ZygoteInit { * @param argv Command line arguments used to specify the Zygote's configuration. */ @UnsupportedAppUsage - public static void main(String argv[]) { + public static void main(String[] argv) { ZygoteServer zygoteServer = null; // Mark zygote start. This ensures that thread creation will throw @@ -1029,7 +1022,7 @@ public class ZygoteInit { * are enabled) * @param argv arg strings */ - public static final Runnable zygoteInit(int targetSdkVersion, long[] disabledCompatChanges, + public static Runnable zygoteInit(int targetSdkVersion, long[] disabledCompatChanges, String[] argv, ClassLoader classLoader) { if (RuntimeInit.DEBUG) { Slog.d(RuntimeInit.TAG, "RuntimeInit: Starting application from zygote"); @@ -1049,11 +1042,10 @@ public class ZygoteInit { * to zygoteInit(), which skips calling into initialization routines that start the Binder * threadpool. */ - static final Runnable childZygoteInit( - int targetSdkVersion, String[] argv, ClassLoader classLoader) { + static Runnable childZygoteInit(String[] argv) { RuntimeInit.Arguments args = new RuntimeInit.Arguments(argv); - return RuntimeInit.findStaticMain(args.startClass, args.startArgs, classLoader); + return RuntimeInit.findStaticMain(args.startClass, args.startArgs, /* classLoader= */null); } - private static final native void nativeZygoteInit(); + private static native void nativeZygoteInit(); } diff --git a/core/java/com/android/internal/os/ZygoteServer.java b/core/java/com/android/internal/os/ZygoteServer.java index db7cbbca450e2..585ddf6ddf98d 100644 --- a/core/java/com/android/internal/os/ZygoteServer.java +++ b/core/java/com/android/internal/os/ZygoteServer.java @@ -411,7 +411,7 @@ class ZygoteServer { } } - void resetUsapRefillState() { + private void resetUsapRefillState() { mUsapPoolRefillAction = UsapPoolRefillAction.NONE; mUsapPoolRefillTriggerTimestamp = INVALID_TIMESTAMP; }