Fix Activity leak from ContentCapture Context-Updated event.

How it leaks: When a session is destroyed, mDirectServiceInterface is
set to null. If an event is added to the buffer after this, it cannot be
flushed because of that. But the flush() call will still keep
rescheduling itself regularly (to handle the case of
mDirectServiceInterface not being ready when the session is created).
The flush message holds a reference to the session, which holds the
Context that created it (the Activity). The message effectively stays
forever in the handler queue, preventing it from being GC'd.

When destroyed, the mDestroyed flag is set which prevents new events
from being queued (through isContentCaptureEnabled()). However,
setContentCaptureContext() is missing this check. This cl adds it there.
Note: There is possibly a race condition if ContentCaptureSession calls
happen on different threads (Framework code always calls these methods
on the main thread). This will be fixed separately.

Bug: 204891006
Test: atest NexusLauncherTests:com.android.quickstep.StartLauncherViaGestureTests#testStressSwipeToOverview --iterations 5
Change-Id: If69a17e828d928007232db76af6e0cac16502875
(cherry picked from commit 97757ea0c4878fd576e0f2520f8b8f3675b04cf4)
1 file changed