diff options
| author | 2021-05-06 14:31:16 -0700 | |
|---|---|---|
| committer | 2021-06-18 14:38:55 -0700 | |
| commit | e33b1bf4e90c30be00325abf046f230edb6475bd (patch) | |
| tree | f6a4b88476562a387a4967d4f102119118c2ccc4 | |
| parent | 782ede8ca8ff70fa3d8bbfda4b93e6c178b4eac1 (diff) | |
Fix potential null error in clearEvents.
* This is follow up from previous patch to fix an unresolved
comment.
* We're still changing the clearEvents mechanic to not null the list but
actually clear the list of events. We also change when the
flush->clearEvents call happen during the destroy process so it occurs
on the handlerThread when each session does its own cleanup.
Bug: 185162720
Test: atest CtsContentCaptureServiceTestCases
Change-Id: Ide5490903deec8c4bc8aae5dc76b1fadca29dbd0
| -rw-r--r-- | core/java/android/view/contentcapture/ContentCaptureSession.java | 6 | ||||
| -rw-r--r-- | core/java/android/view/contentcapture/MainContentCaptureSession.java | 16 |
2 files changed, 13 insertions, 9 deletions
diff --git a/core/java/android/view/contentcapture/ContentCaptureSession.java b/core/java/android/view/contentcapture/ContentCaptureSession.java index c6332686bf7f..cc47f09d4e8d 100644 --- a/core/java/android/view/contentcapture/ContentCaptureSession.java +++ b/core/java/android/view/contentcapture/ContentCaptureSession.java @@ -341,11 +341,7 @@ public abstract class ContentCaptureSession implements AutoCloseable { } } - try { - flush(FLUSH_REASON_SESSION_FINISHED); - } finally { - onDestroy(); - } + onDestroy(); } abstract void onDestroy(); diff --git a/core/java/android/view/contentcapture/MainContentCaptureSession.java b/core/java/android/view/contentcapture/MainContentCaptureSession.java index d8ac779ddc27..bcb914208958 100644 --- a/core/java/android/view/contentcapture/MainContentCaptureSession.java +++ b/core/java/android/view/contentcapture/MainContentCaptureSession.java @@ -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); } |