summaryrefslogtreecommitdiffstats
path: root/hal/android/AndroidProcessPriority.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /hal/android/AndroidProcessPriority.cpp
parentInitial commit. (diff)
downloadthunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz
thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'hal/android/AndroidProcessPriority.cpp')
-rw-r--r--hal/android/AndroidProcessPriority.cpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/hal/android/AndroidProcessPriority.cpp b/hal/android/AndroidProcessPriority.cpp
new file mode 100644
index 0000000000..aab2bf50ef
--- /dev/null
+++ b/hal/android/AndroidProcessPriority.cpp
@@ -0,0 +1,62 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
+
+#include "Hal.h"
+
+#include "mozilla/java/GeckoProcessManagerWrappers.h"
+#include "mozilla/java/GeckoProcessTypeWrappers.h"
+#include "mozilla/java/ServiceAllocatorWrappers.h"
+
+using namespace mozilla::hal;
+
+/**
+ * Bucket the Gecko HAL process priority level into one of the three Android
+ * priority levels.
+ */
+static mozilla::java::ServiceAllocator::PriorityLevel::LocalRef
+ToJavaPriorityLevel(const ProcessPriority aPriority) {
+ if (aPriority >= PROCESS_PRIORITY_FOREGROUND) {
+ return mozilla::java::ServiceAllocator::PriorityLevel::FOREGROUND();
+ } else if (aPriority <= PROCESS_PRIORITY_PREALLOC &&
+ aPriority >= PROCESS_PRIORITY_BACKGROUND_PERCEIVABLE) {
+ return mozilla::java::ServiceAllocator::PriorityLevel::BACKGROUND();
+ }
+
+ return mozilla::java::ServiceAllocator::PriorityLevel::IDLE();
+}
+
+namespace mozilla {
+namespace hal_impl {
+
+void SetProcessPriority(int aPid, ProcessPriority aPriority) {
+ if (aPriority == PROCESS_PRIORITY_PARENT_PROCESS) {
+ // This is the parent process itself, which we do not control.
+ return;
+ }
+
+ const int32_t intPriority = static_cast<int32_t>(aPriority);
+ if (intPriority < 0 || intPriority >= NUM_PROCESS_PRIORITY) {
+ return;
+ }
+
+ auto contentProcType = java::GeckoProcessType::CONTENT();
+ auto selector =
+ java::GeckoProcessManager::Selector::New(contentProcType, aPid);
+ auto priorityLevel = ToJavaPriorityLevel(aPriority);
+
+ // To Android, a lower-valued integer is a higher relative priority.
+ // We take the integer value of the enum and subtract it from the value
+ // of the highest Gecko priority level to obtain a 0-based indicator of
+ // the relative priority within the Java PriorityLevel.
+ const int32_t relativeImportance =
+ (static_cast<int32_t>(NUM_PROCESS_PRIORITY) - 1) - intPriority;
+
+ java::GeckoProcessManager::SetProcessPriority(selector, priorityLevel,
+ relativeImportance);
+}
+
+} // namespace hal_impl
+} // namespace mozilla