Add getFutureForListener to TestUtils

Abstract out listener registration logic from getFutureForIntent to
apply to other listener registration callbacks.

Add tests which ensure that the listener is unregistered when the future
completes or is cancelled.

Bug: 288333346
Bug: 294636572
Test: atest mediatestutilstests
Change-Id: I91f34ee2e215cafe0d0cd0b33f831b244850ab06
2 files changed