From 36a5f1a127ca18869cd25cef0315076591a0b518 Mon Sep 17 00:00:00 2001 From: maxwelb Date: Tue, 10 Oct 2017 17:17:18 -0700 Subject: Handle race condition with CallComposerActivity.onBackPressed For fast users/testing suites, it's possible to hit a race condition where onBackPressed is called multiple times in a way that allows the second call to endCallComposerSession to happen and crash. This CL fixes the issue by checking that the session still exists prior to calling endCallComposerSession. I tried to write tests for this, but since the code guards against this from happening, I wasn't able to get the code into a situation to cause the crash. Bug: 64136293 Test: none PiperOrigin-RevId: 171758119 Change-Id: Ie12fd2f4390329b9bebb503fa3cf0f26d3bc1caf --- java/com/android/dialer/callcomposer/CallComposerActivity.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'java/com/android/dialer/callcomposer/CallComposerActivity.java') diff --git a/java/com/android/dialer/callcomposer/CallComposerActivity.java b/java/com/android/dialer/callcomposer/CallComposerActivity.java index b02e32543..83fe2d9de 100644 --- a/java/com/android/dialer/callcomposer/CallComposerActivity.java +++ b/java/com/android/dialer/callcomposer/CallComposerActivity.java @@ -528,12 +528,18 @@ public class CallComposerActivity extends AppCompatActivity @Override public void onBackPressed() { + LogUtil.enterBlock("CallComposerActivity.onBackPressed"); if (!isSendAndCallHidingOrHidden) { ((CallComposerFragment) adapter.instantiateItem(pager, currentIndex)).clearComposer(); } else if (!runningExitAnimation) { // Unregister first to avoid receiving a callback when the session closes getEnrichedCallManager().unregisterStateChangedListener(this); - getEnrichedCallManager().endCallComposerSession(sessionId); + + // If the user presses the back button when the session fails, there's a race condition here + // since we clean up failed sessions. + if (getEnrichedCallManager().getSession(sessionId) != null) { + getEnrichedCallManager().endCallComposerSession(sessionId); + } runExitAnimation(); } } -- cgit v1.2.3