diff options
author | Rick Yiu <rickyiu@google.com> | 2019-12-19 16:54:31 +0800 |
---|---|---|
committer | Rick Yiu <rickyiu@google.com> | 2020-01-03 14:38:25 +0800 |
commit | 85e8c8f52148c90c41c95ed6ef69edbe677d670b (patch) | |
tree | 829dcb73a308270afebd5b58429d74a5a626bfc4 /dalvik | |
parent | d760b7fecefa8e6c391b8fd04ecfe31f91ddf353 (diff) |
Use ThreadPrioritySetter to set thread priority
Use ThreadPrioritySetter registered in Android runtime to set thread
priority.
Bug: 139521784
Test: CtsLibcoreTestCases, device boot to home, thread priority set
as expected.
Change-Id: I71c5052beb171f966eba97401159306b87e397b7
Diffstat (limited to 'dalvik')
-rw-r--r-- | dalvik/src/main/java/dalvik/system/RuntimeHooks.java | 32 | ||||
-rw-r--r-- | dalvik/src/main/java/dalvik/system/ThreadPrioritySetter.java | 28 |
2 files changed, 60 insertions, 0 deletions
diff --git a/dalvik/src/main/java/dalvik/system/RuntimeHooks.java b/dalvik/src/main/java/dalvik/system/RuntimeHooks.java index 320ea28253..f1af86790c 100644 --- a/dalvik/src/main/java/dalvik/system/RuntimeHooks.java +++ b/dalvik/src/main/java/dalvik/system/RuntimeHooks.java @@ -16,10 +16,15 @@ package dalvik.system; +import dalvik.system.ThreadPrioritySetter; + import java.util.Objects; import java.util.TimeZone; import java.util.function.Supplier; +import libcore.util.NonNull; +import libcore.util.Nullable; + /** * Provides lifecycle methods and other hooks for an Android runtime "container" to call into the * runtime and core libraries during initialization. For example, from @@ -35,6 +40,10 @@ public final class RuntimeHooks { private static Supplier<String> zoneIdSupplier; + // BEGIN Android-added: Customize behavior of Thread.setPriority(). http://b/139521784 + private static volatile ThreadPrioritySetter threadPrioritySetter; + // END Android-added: Customize behavior of Thread.setPriority(). http://b/139521784 + private RuntimeHooks() { // No need to construct an instance. All methods are static. } @@ -77,4 +86,27 @@ public final class RuntimeHooks { Thread.UncaughtExceptionHandler uncaughtExceptionHandler) { Thread.setUncaughtExceptionPreHandler(uncaughtExceptionHandler); } + + // BEGIN Android-added: Customize behavior of Thread.setPriority(). http://b/139521784 + /** + * Sets a {@link ThreadPrioritySetter} that will be invoked instead of + * the default implementation during {@link Thread.setPriority(int)}. + * @hide + */ + @libcore.api.CorePlatformApi + public static void setThreadPrioritySetter(@NonNull ThreadPrioritySetter threadPrioritySetter) { + RuntimeHooks.threadPrioritySetter = Objects.requireNonNull(threadPrioritySetter); + } + + /** + * Returns the last {@code ThreadPrioritySetter} that has been + * {@code #setThreadPrioritySetter(ThreadPrioritySetter) set}, or + * null if the setter has not yet been called. + * @hide + */ + @libcore.api.CorePlatformApi + public static @Nullable ThreadPrioritySetter getThreadPrioritySetter() { + return threadPrioritySetter; + } + // END Android-added: Customize behavior of Thread.setPriority(). http://b/139521784 } diff --git a/dalvik/src/main/java/dalvik/system/ThreadPrioritySetter.java b/dalvik/src/main/java/dalvik/system/ThreadPrioritySetter.java new file mode 100644 index 0000000000..f1d5e7211a --- /dev/null +++ b/dalvik/src/main/java/dalvik/system/ThreadPrioritySetter.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dalvik.system; + +/** + * Interface for hooking to thread priority runtime setting + * @hide + */ +@libcore.api.CorePlatformApi +@FunctionalInterface +public interface ThreadPrioritySetter { + @libcore.api.CorePlatformApi + void setPriority(int priority); +} |