Fix race condition in OomAdjuster.

OomAdjuster accesses the not-thread-safe HandlerThread.getThreadId from
outside the thread.
Modify so it posts a message to thread instead.

See bug 22476742

Bug: 151407445
Test: See repro instructions in bug
Change-Id: Iae03d46896561f0442af6595a8d0bdf617ccd61e
This commit is contained in:
Brett Chabot
2020-03-13 15:17:08 -07:00
parent a8375cc9f8
commit 1f8455d42f

View File

@@ -227,7 +227,8 @@ public final class OomAdjuster {
final ServiceThread adjusterThread =
new ServiceThread(TAG, TOP_APP_PRIORITY_BOOST, false /* allowIo */);
adjusterThread.start();
Process.setThreadGroupAndCpuset(adjusterThread.getThreadId(), THREAD_GROUP_TOP_APP);
adjusterThread.getThreadHandler().post(() -> Process.setThreadGroupAndCpuset(
adjusterThread.getThreadId(), THREAD_GROUP_TOP_APP));
return adjusterThread;
}