Refactor to ensure thread safety

Make object pointer safety for multiple thread

Bug: 179834303
Test: atest ContentCapturePerfTests
Change-Id: I5c04dd3b1288fb3ac104738f159dba88b641a0bf
This commit is contained in:
TYM Tsai
2021-07-15 22:10:19 +08:00
parent 8b5ab6568e
commit a6861d86ba

View File

@@ -84,18 +84,18 @@ public class MyContentCaptureService extends ContentCaptureService {
@Override
public void onDisconnected() {
Log.i(TAG, "onDisconnected: sServiceWatcher=" + sServiceWatcher);
if (sServiceWatcher == null) {
final ServiceWatcher sw = sServiceWatcher;
Log.i(TAG, "onDisconnected: sServiceWatcher=" + sw);
if (sw == null) {
Log.e(TAG, "onDisconnected() without a watcher");
return;
}
if (sServiceWatcher.mService == null) {
Log.e(TAG, "onDisconnected(): no service on " + sServiceWatcher);
if (sw.mService == null) {
Log.e(TAG, "onDisconnected(): no service on " + sw);
return;
}
sServiceWatcher.mDestroyed.countDown();
sw.mDestroyed.countDown();
clearServiceWatcher();
}