Merge "Fix potential null error in clearEvents." into sc-dev am: 6ea5a55ac5

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15023990

Change-Id: I9de1f8e9474af2294a90d9ed8e2bd4d6ef10b5d7
This commit is contained in:
TreeHugger Robot
2021-06-21 02:42:39 +00:00
committed by Automerger Merge Worker
2 changed files with 13 additions and 9 deletions

View File

@@ -341,11 +341,7 @@ public abstract class ContentCaptureSession implements AutoCloseable {
}
}
try {
flush(FLUSH_REASON_SESSION_FINISHED);
} finally {
onDestroy();
}
onDestroy();
}
abstract void onDestroy();

View File

@@ -263,7 +263,13 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
@Override
void onDestroy() {
mHandler.removeMessages(MSG_FLUSH);
mHandler.post(() -> destroySession());
mHandler.post(() -> {
try {
flush(FLUSH_REASON_SESSION_FINISHED);
} finally {
destroySession();
}
});
}
/**
@@ -571,9 +577,11 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
private ParceledListSlice<ContentCaptureEvent> clearEvents() {
// NOTE: we must save a reference to the current mEvents and then set it to to null,
// otherwise clearing it would clear it in the receiving side if the service is also local.
final List<ContentCaptureEvent> events = mEvents == null
? Collections.EMPTY_LIST
: new ArrayList<>(mEvents);
if (mEvents == null) {
return new ParceledListSlice<>(Collections.EMPTY_LIST);
}
final List<ContentCaptureEvent> events = new ArrayList<>(mEvents);
mEvents.clear();
return new ParceledListSlice<>(events);
}