Fix an NPE on cancellation when connection is closed

Store the future locally so the callback doesn't lose
a reference to it. Even when the field is cleared, the
callback will always receive the original value, avoiding
NPEs. This change also adds a test for cancellation instead
of falling through to an ignored CancellationException.

Bug: 219965002
Test: manual; timing dependent, dismiss screenshot while
      scroll capture request is in flight
Change-Id: I88918bbe9379208cad9456b53ed79d600c73a60b
1 file changed