Refactored to ensure thread safety

clearServiceWatcher() called on the main thread but resetStaticState()
called on the instrumentation thread. Refactored the code to ensure
thread safety.

Fixes: 166685544
Test: atest ContentCapturePerfTests
Change-Id: I9adced9e068112c43554b495bd6dc591f8775945
This commit is contained in:
TYM Tsai
2020-08-31 23:46:59 +08:00
parent 400379c26f
commit b546aadd18

View File

@@ -51,13 +51,14 @@ public class MyContentCaptureService extends ContentCaptureService {
sServiceWatcher = null;
}
public static void clearServiceWatcher() {
if (sServiceWatcher != null) {
if (sServiceWatcher.mReadyToClear) {
sServiceWatcher.mService = null;
private static void clearServiceWatcher() {
final ServiceWatcher sw = sServiceWatcher;
if (sw != null) {
if (sw.mReadyToClear) {
sw.mService = null;
sServiceWatcher = null;
} else {
sServiceWatcher.mReadyToClear = true;
sw.mReadyToClear = true;
}
}
}