Sync phoneAccountHandle when phone is changed
After triggering dial, phoneAccountHandle can be changed.
In this case, the stack to which dial is requested and
the stack to be displayed on the UI can be different.
So, phoneAccountHandle will be changed if the stack
to which dial is requested is changed.
Bug: 168681491
Test: manual
Signed-off-by: Sungjae <sung_jae.kim@samsung.com>
Change-Id: Ibc8b491d0b9286888402e35704a8f64723eb1869
diff --git a/src/com/android/services/telephony/TelecomAccountRegistry.java b/src/com/android/services/telephony/TelecomAccountRegistry.java
index 9f6c24f..18a9574 100644
--- a/src/com/android/services/telephony/TelecomAccountRegistry.java
+++ b/src/com/android/services/telephony/TelecomAccountRegistry.java
@@ -1412,6 +1412,17 @@
return false;
}
+ PhoneAccountHandle getPhoneAccountHandleForSubId(int subId) {
+ synchronized (mAccountsLock) {
+ for (AccountEntry entry : mAccounts) {
+ if (entry.getSubId() == subId) {
+ return entry.getPhoneAccountHandle();
+ }
+ }
+ }
+ return null;
+ }
+
/**
* Un-registers any {@link PhoneAccount}s which are no longer present in the list
* {@code AccountEntry}(s).
diff --git a/src/com/android/services/telephony/TelephonyConnectionService.java b/src/com/android/services/telephony/TelephonyConnectionService.java
index 953d415..a2e9565 100644
--- a/src/com/android/services/telephony/TelephonyConnectionService.java
+++ b/src/com/android/services/telephony/TelephonyConnectionService.java
@@ -1144,9 +1144,9 @@
phone.getPhoneId()));
}
-
+ PhoneAccountHandle accountHandle = adjustAccountHandle(phone, request.getAccountHandle());
final TelephonyConnection connection =
- createConnectionFor(phone, null, true /* isOutgoing */, request.getAccountHandle(),
+ createConnectionFor(phone, null, true /* isOutgoing */, accountHandle,
request.getTelecomCallId(), request.isAdhocConferenceCall());
if (connection == null) {
return Connection.createFailedConnection(
@@ -2466,4 +2466,20 @@
addConference(conference);
conference.addTelephonyConferenceListener(mTelephonyConferenceListener);
}
+
+ private PhoneAccountHandle adjustAccountHandle(Phone phone,
+ PhoneAccountHandle origAccountHandle) {
+ int origSubId = PhoneUtils.getSubIdForPhoneAccountHandle(origAccountHandle);
+ int subId = phone.getSubId();
+ if (origSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID
+ && subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID
+ && origSubId != subId) {
+ PhoneAccountHandle handle = TelecomAccountRegistry.getInstance(this)
+ .getPhoneAccountHandleForSubId(subId);
+ if (handle != null) {
+ return handle;
+ }
+ }
+ return origAccountHandle;
+ }
}