From 68a22d8d8a024db94bb0d482d7f3e2de879b04ea Mon Sep 17 00:00:00 2001 From: beiyifb Date: Wed, 3 May 2023 16:25:12 -0700 Subject: [PATCH] Fixes a thread safety issue (a time-of-check-time-of-use bug) in BatteryExternalStatsWorker that causes system_server crashes in VROS device. Synchronize BatteryExternalStatsWorker.shutdown(). Without this, a shutdown can sneak in-between the checks to mExecutor.isShutdown() and other mExecutor calls, causing the later calls to fail with a RejectedExecutionException instead of having the intended behavior for a shutdown mExecutor. Test: There is no known test case for regression testing. This is a race condition, so any test case would inherently be flaky. The correctness of the patch is easily seen by observing the time-of-check-time-of-use issues that arise throughout BatteryExternalStatsWorker.java before the patch is applied. Change-Id: Id690f3451f86ac536b186021ef4fb63827bc863e --- .../java/com/android/server/am/BatteryExternalStatsWorker.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/am/BatteryExternalStatsWorker.java b/services/core/java/com/android/server/am/BatteryExternalStatsWorker.java index 702526a4beabe..1a0d291d375c4 100644 --- a/services/core/java/com/android/server/am/BatteryExternalStatsWorker.java +++ b/services/core/java/com/android/server/am/BatteryExternalStatsWorker.java @@ -399,7 +399,7 @@ class BatteryExternalStatsWorker implements BatteryStatsImpl.ExternalStatsSync { } } - public void shutdown() { + public synchronized void shutdown() { mExecutorService.shutdownNow(); }