diff options
| author | 2020-01-07 03:42:21 +0000 | |
|---|---|---|
| committer | 2020-01-07 03:42:21 +0000 | |
| commit | d6bf5aa253067af6397dc1743882aa8f0af07225 (patch) | |
| tree | b6e8d4e8e55e34063478e46782cbc17797209800 | |
| parent | 9f05b8921a27d4dc85e3e3a0ffcbee9e122b3e63 (diff) | |
| parent | 09b06a3f1f5b0afd801847012f3880132ea02dab (diff) | |
Merge "Implement the ThreadPrioritySetter interface" am: bc0290a7b0 am: 4db03331ac am: 09b06a3f1f
Change-Id: I54ee7272cd69f5e8e14777f8f717db8ce2239232
| -rw-r--r-- | core/java/com/android/internal/os/RuntimeInit.java | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/core/java/com/android/internal/os/RuntimeInit.java b/core/java/com/android/internal/os/RuntimeInit.java index 179828c4b456..a86d702ba323 100644 --- a/core/java/com/android/internal/os/RuntimeInit.java +++ b/core/java/com/android/internal/os/RuntimeInit.java @@ -35,6 +35,7 @@ import com.android.internal.logging.AndroidConfig; import com.android.server.NetworkManagementSocketTagger; import dalvik.system.RuntimeHooks; +import dalvik.system.ThreadPrioritySetter; import dalvik.system.VMRuntime; import libcore.content.type.MimeMap; @@ -204,6 +205,7 @@ public class RuntimeInit { */ public static void preForkInit() { if (DEBUG) Slog.d(TAG, "Entered preForkInit."); + RuntimeHooks.setThreadPrioritySetter(new RuntimeThreadPrioritySetter()); RuntimeInit.enableDdms(); // TODO(b/142019040#comment13): Decide whether to load the default instance eagerly, i.e. // MimeMap.setDefault(DefaultMimeMapFactory.create()); @@ -216,6 +218,35 @@ public class RuntimeInit { MimeMap.setDefaultSupplier(DefaultMimeMapFactory::create); } + private static class RuntimeThreadPrioritySetter implements ThreadPrioritySetter { + // Should remain consistent with kNiceValues[] in system/libartpalette/palette_android.cc + private static final int[] NICE_VALUES = { + Process.THREAD_PRIORITY_LOWEST, // 1 (MIN_PRIORITY) + Process.THREAD_PRIORITY_BACKGROUND + 6, + Process.THREAD_PRIORITY_BACKGROUND + 3, + Process.THREAD_PRIORITY_BACKGROUND, + Process.THREAD_PRIORITY_DEFAULT, // 5 (NORM_PRIORITY) + Process.THREAD_PRIORITY_DEFAULT - 2, + Process.THREAD_PRIORITY_DEFAULT - 4, + Process.THREAD_PRIORITY_URGENT_DISPLAY + 3, + Process.THREAD_PRIORITY_URGENT_DISPLAY + 2, + Process.THREAD_PRIORITY_URGENT_DISPLAY // 10 (MAX_PRIORITY) + }; + + @Override + public void setPriority(int priority) { + // Check NICE_VALUES[] length first. + if (NICE_VALUES.length != (1 + Thread.MAX_PRIORITY - Thread.MIN_PRIORITY)) { + throw new AssertionError("Unexpected NICE_VALUES.length=" + NICE_VALUES.length); + } + // Priority should be in the range of MIN_PRIORITY (1) to MAX_PRIORITY (10). + if (priority < Thread.MIN_PRIORITY || priority > Thread.MAX_PRIORITY) { + throw new IllegalArgumentException("Priority out of range: " + priority); + } + Process.setThreadPriority(NICE_VALUES[priority - Thread.MIN_PRIORITY]); + } + } + @UnsupportedAppUsage protected static final void commonInit() { if (DEBUG) Slog.d(TAG, "Entered RuntimeInit!"); |