Fixed incorrect SIM used for voice call
In some rare dual SIM scenarios, the voice call was
made on the wrong SIM. Fixed by always querying the
phone account for the default voice sub when we are
building the phone accounts. If phone account
information is out-of-sync between telephony and telecom,
then we set the correct phone account again.
Fix: 329049325
Test: Basic telephony functionality tests
Test: atest FrameworksTelephonyTests
Change-Id: I5c2b688237153c193cb6116c982d4cfd2ceb0a0e
diff --git a/src/com/android/services/telephony/TelecomAccountRegistry.java b/src/com/android/services/telephony/TelecomAccountRegistry.java
index a246a1c..064c69b 100644
--- a/src/com/android/services/telephony/TelecomAccountRegistry.java
+++ b/src/com/android/services/telephony/TelecomAccountRegistry.java
@@ -78,6 +78,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.Predicate;
@@ -1700,6 +1701,35 @@
new AccountEntry(PhoneFactory.getDefaultPhone(), true /* emergency */,
false /* isTest */));
}
+
+ // In some very rare cases, when setting the default voice sub in
+ // SubscriptionManagerService, the phone accounts here have not yet been built.
+ // So calling setUserSelectedOutgoingPhoneAccount in SubscriptionManagerService
+ // becomes a no-op. The workaround here is to reconcile and make sure the
+ // outgoing phone account is properly set in telecom.
+ int defaultVoiceSubId = SubscriptionManager.getDefaultVoiceSubscriptionId();
+ if (SubscriptionManager.isValidSubscriptionId(defaultVoiceSubId)) {
+ PhoneAccountHandle defaultVoiceAccountHandle =
+ getPhoneAccountHandleForSubId(defaultVoiceSubId);
+ if (defaultVoiceAccountHandle != null) {
+ PhoneAccountHandle currentAccount = mTelecomManager
+ .getUserSelectedOutgoingPhoneAccount();
+ // In some rare cases, the current phone account could be non-telephony
+ // phone account. We do not override in this case.
+ boolean wasPreviousAccountSameComponentOrUnset = currentAccount == null
+ || Objects.equals(defaultVoiceAccountHandle.getComponentName(),
+ currentAccount.getComponentName());
+
+ // Set the phone account again if it's out-of-sync.
+ if (!defaultVoiceAccountHandle.equals(currentAccount)
+ && wasPreviousAccountSameComponentOrUnset) {
+ Log.d(this, "setupAccounts: Re-setup phone account "
+ + "again for default voice sub " + defaultVoiceSubId);
+ mTelecomManager.setUserSelectedOutgoingPhoneAccount(
+ defaultVoiceAccountHandle);
+ }
+ }
+ }
}
// Add a fake account entry.