Fix race condition on call initiation
When a call initiates and the IMS stack reports some state that's
transmitted via the registrants from Phone, there's a chance that it
could be transmitted before setOriginalConnection is called. This
results in the message getting lost since setOriginalConnection is what
registers the message handler, and in the worst case can result in a
change in originalConnection being ignored.
Fix this by registering for the messages before dialing, and set the
originalConnection after dialing on the main thread so that it
doesn't race with anything else trying to set the originalConnection
Fixes: 183247792
Test: manual
Change-Id: I5413d5f651373ae857242c9d0a63b3513204b8ff
diff --git a/tests/src/com/android/TestContext.java b/tests/src/com/android/TestContext.java
index 9d712d3..26dff9a 100644
--- a/tests/src/com/android/TestContext.java
+++ b/tests/src/com/android/TestContext.java
@@ -25,6 +25,7 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Handler;
+import android.os.Looper;
import android.os.PersistableBundle;
import android.telecom.TelecomManager;
import android.telephony.CarrierConfigManager;
@@ -150,6 +151,11 @@
return null;
}
+ @Override
+ public Handler getMainThreadHandler() {
+ return new Handler(Looper.getMainLooper());
+ }
+
/**
* @return CarrierConfig PersistableBundle for the subscription specified.
*/