diff options
author | Brad Ebinger <breadley@google.com> | 2022-02-09 20:21:54 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2022-02-09 20:21:54 +0000 |
commit | a9f6eb417599adceaa2e0b7cbf06b4505567ff6b (patch) | |
tree | 9cc1e13624dab3da17c7abe232d6dfef010cb762 | |
parent | 6ecafd33612f4007aa6e051c85da91a0b4afe3fc (diff) | |
parent | 54a28ddc7e39fe9cb34ad1c21c63b388cc782369 (diff) | |
download | telephony-android-s-v2-beta-3.tar.gz |
Merge changes I18caf795,Ic2e2a177android-s-v2-beta-3android-s-qpr3-beta-1android-s-v2-beta-3android-s-qpr3-beta-1
* changes:
Reintroduce CARRIER_CONFIG_CHANGED to handle config changes properly
Do not push carrier configs when they are not for an identified carrier
-rw-r--r-- | src/java/com/android/internal/telephony/imsphone/ImsPhoneCallTracker.java | 151 | ||||
-rw-r--r-- | tests/telephonytests/src/com/android/internal/telephony/imsphone/ImsPhoneCallTrackerTest.java | 167 |
2 files changed, 252 insertions, 66 deletions
diff --git a/src/java/com/android/internal/telephony/imsphone/ImsPhoneCallTracker.java b/src/java/com/android/internal/telephony/imsphone/ImsPhoneCallTracker.java index 31156afe23..97696cdb29 100644 --- a/src/java/com/android/internal/telephony/imsphone/ImsPhoneCallTracker.java +++ b/src/java/com/android/internal/telephony/imsphone/ImsPhoneCallTracker.java @@ -132,6 +132,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Queue; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -188,13 +189,21 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall { private final Map<String, CallQualityMetrics> mCallQualityMetrics = new ConcurrentHashMap<>(); private final ConcurrentLinkedQueue<CallQualityMetrics> mCallQualityMetricsHistory = new ConcurrentLinkedQueue<>(); - private boolean mCarrierConfigLoaded = false; + // True if there is a carrier config loaded for a specific subscription (and not the default + // configuration). + private boolean mCarrierConfigLoadedForSubscription = false; + // Cache a carrier config for a subscription that is still pending a connection to the + // ImsService. + private Pair<Integer, PersistableBundle> mPendingCarrierConfigForSubId = null; + // The subId of the last ImsService attached to this tracker or empty if there has not been + // an attached ImsService yet. + private Optional<Integer> mCurrentlyConnectedSubId = Optional.empty(); private final MmTelFeatureListener mMmTelFeatureListener = new MmTelFeatureListener(); private class MmTelFeatureListener extends MmTelFeature.Listener { private void processIncomingCall(IImsCallSession c, Bundle extras) { - if (DBG) log("onReceive : incoming call intent"); + if (DBG) log("processIncomingCall: incoming call intent"); mOperationLocalLog.log("onIncomingCall Received"); if (extras == null) extras = new Bundle(); @@ -206,7 +215,7 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall { // For compatibility purposes with older vendor implmentations. isUssd |= extras.getBoolean(ImsManager.EXTRA_USSD, false); if (isUssd) { - if (DBG) log("onReceive : USSD"); + if (DBG) log("processIncomingCall: USSD"); mUssdSession = mImsManager.takeCall(c, mImsUssdListener); if (mUssdSession != null) { mUssdSession.accept(ImsCallProfile.CALL_TYPE_VOICE); @@ -218,7 +227,7 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall { // For compatibility purposes with older vendor implmentations. isUnknown |= extras.getBoolean(ImsManager.EXTRA_IS_UNKNOWN_CALL, false); if (DBG) { - log("onReceive : isUnknown = " + isUnknown + log("processIncomingCall: isUnknown = " + isUnknown + " fg = " + mForegroundCall.getState() + " bg = " + mBackgroundCall.getState()); } @@ -288,7 +297,7 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall { updatePhoneState(); mPhone.notifyPreciseCallStateChanged(); } catch (ImsException e) { - loge("onReceive : exception " + e); + loge("processIncomingCall: exception " + e); } catch (RemoteException e) { } } @@ -354,16 +363,31 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall { } } - private BroadcastReceiver mReceiver = new BroadcastReceiver() { + private final BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) { - int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY, + int subId = intent.getIntExtra(CarrierConfigManager.EXTRA_SUBSCRIPTION_INDEX, SubscriptionManager.INVALID_SUBSCRIPTION_ID); - if (subId == mPhone.getSubId()) { - updateCarrierConfiguration(subId); - log("onReceive : Updating mAllowEmergencyVideoCalls = " + - mAllowEmergencyVideoCalls); + int phoneId = intent.getIntExtra(CarrierConfigManager.EXTRA_SLOT_INDEX, + SubscriptionManager.INVALID_PHONE_INDEX); + if (mPhone.getPhoneId() != phoneId) { + log("onReceive: Skipping indication for other phoneId: " + phoneId); + return; + } + PersistableBundle carrierConfig = getCarrierConfigBundle(subId); + if (!mCurrentlyConnectedSubId.isEmpty() + && subId == mCurrentlyConnectedSubId.get()) { + log("onReceive: Applying carrier config for subId: " + subId); + // Reset pending config state + mPendingCarrierConfigForSubId = null; + updateCarrierConfiguration(subId, carrierConfig); + } else { + // cache the latest config update until ImsService connects for this subId. + // Once it has connected, startListeningForCalls will apply the pending config. + mPendingCarrierConfigForSubId = new Pair<>(subId, carrierConfig); + log("onReceive: caching carrier config until ImsService connects for subId: " + + subId); } } else if (TelecomManager.ACTION_DEFAULT_DIALER_CHANGED.equals(intent.getAction())) { mDefaultDialerUid.set(getPackageUid(context, intent.getStringExtra( @@ -948,7 +972,7 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall { intentfilter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED); intentfilter.addAction(TelecomManager.ACTION_DEFAULT_DIALER_CHANGED); mPhone.getContext().registerReceiver(mReceiver, intentfilter); - updateCarrierConfiguration(mPhone.getSubId()); + updateCarrierConfiguration(mPhone.getSubId(), getCarrierConfigBundle(mPhone.getSubId())); mPhone.getDefaultPhone().getDataEnabledSettings().registerForDataEnabledChanged( this, EVENT_DATA_ENABLED_CHANGED, null); @@ -970,7 +994,8 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall { LOG_TAG, new FeatureConnector.Listener<ImsManager>() { public void connectionReady(ImsManager manager, int subId) throws ImsException { mImsManager = manager; - startListeningForCalls(); + log("connectionReady for subId = " + subId); + startListeningForCalls(subId); } @Override @@ -1013,7 +1038,7 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall { } @VisibleForTesting - public void startListeningForCalls() throws ImsException { + public void startListeningForCalls(int subId) throws ImsException { log("startListeningForCalls"); mOperationLocalLog.log("startListeningForCalls - Connecting to ImsService"); ImsExternalCallTracker externalCallTracker = mPhone.getExternalCallTracker(); @@ -1048,10 +1073,17 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall { null); } - maybeConfigureRtpHeaderExtensions(); - updateImsServiceConfig(); + if (mPendingCarrierConfigForSubId != null && mPendingCarrierConfigForSubId.first == subId) { + // The carrier configuration was received by CarrierConfigManager before the indication + // that the ImsService was connected. + updateCarrierConfiguration(subId, mPendingCarrierConfigForSubId.second); + } else { + log("startListeningForCalls - waiting for the first carrier config indication for this " + + "subscription"); + } // For compatibility with apps that still use deprecated intent sendImsServiceStateIntent(ImsManager.ACTION_IMS_SERVICE_UP); + mCurrentlyConnectedSubId = Optional.of(subId); } /** @@ -1111,7 +1143,7 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall { mUtInterface.unregisterForSuppServiceIndication(this); mUtInterface = null; } - + mCurrentlyConnectedSubId = Optional.empty(); resetImsCapabilities(); hangupAllOrphanedConnections(DisconnectCause.LOST_SIGNAL); // For compatibility with apps that still use deprecated intent @@ -1464,14 +1496,27 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall { * @param subId The sub id to use to update configuration, may be invalid if a SIM has been * removed. */ - private void updateCarrierConfiguration(int subId) { - CarrierConfigManager carrierConfigManager = (CarrierConfigManager) - mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE); - if (carrierConfigManager == null - || !SubscriptionController.getInstance().isActiveSubId(subId)) { - loge("cacheCarrierConfiguration: No carrier config service found" + " " - + "or not active subId = " + subId); - mCarrierConfigLoaded = false; + private void updateCarrierConfiguration(int subId, PersistableBundle carrierConfig) { + // start by assuming the carrier config is not loaded for the provided subscription. + mCarrierConfigLoadedForSubscription = false; + + if (carrierConfig == null) { + loge("updateCarrierConfiguration: carrier config is null, skipping."); + return; + } + + // Ensure the local cache is up to date first (including default config for no SIM case) in + // ImsPhoneCallTracker to ensure we do not carry over settings from the previously inserted + // SIM for things like emergency calling. + updateCarrierConfigCache(carrierConfig); + log("updateCarrierConfiguration: Updating mAllowEmergencyVideoCalls = " + + mAllowEmergencyVideoCalls); + // Check for changes due to carrier config. + maybeConfigureRtpHeaderExtensions(); + + if (!SubscriptionController.getInstance().isActiveSubId(subId)) { + loge("updateCarrierConfiguration: skipping notification to ImsService, non" + + "active subId = " + subId); return; } @@ -1482,25 +1527,23 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall { // when the device is still locked. A CARRIER_CONFIG_CHANGED indication will be sent // once the device moves to ready. if (state != null && (!state.iccCardExist() || state.isPinLocked())) { - loge("cacheCarrierConfiguration: card state is not ready, skipping. State= " - + state); - mCarrierConfigLoaded = false; + loge("updateCarrierConfiguration: card state is not ready, skipping " + + "notification to ImsService. State= " + state); return; } } - PersistableBundle carrierConfig = carrierConfigManager.getConfigForSubId(subId); - if (carrierConfig == null) { - loge("cacheCarrierConfiguration: Empty carrier config."); - mCarrierConfigLoaded = false; + if (!CarrierConfigManager.isConfigForIdentifiedCarrier(carrierConfig)) { + logi("updateCarrierConfiguration: Empty or default carrier config, skipping " + + "notification to ImsService."); return; } - mCarrierConfigLoaded = true; - updateCarrierConfigCache(carrierConfig); + // Only update the ImsService configurations for the case where a new subscription has been + // loaded and is active. + logi("updateCarrierConfiguration: Updating ImsService configs."); + mCarrierConfigLoadedForSubscription = true; updateImsServiceConfig(); - // Check for changes due to carrier config. - maybeConfigureRtpHeaderExtensions(); } /** @@ -4622,6 +4665,27 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall { } /** + * + * @param subId The subId to get the carrier config for. + * @return The PersistableBundle containing the carrier config from + * {@link CarrierConfigManager} for the subId specified. + */ + private PersistableBundle getCarrierConfigBundle(int subId) { + CarrierConfigManager carrierConfigManager = (CarrierConfigManager) + mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE); + if (carrierConfigManager == null) { + loge("getCarrierConfigBundle: No carrier config service found"); + return null; + } + PersistableBundle carrierConfig = carrierConfigManager.getConfigForSubId(subId); + if (carrierConfig == null) { + loge("getCarrierConfigBundle: carrier config is null, skipping."); + return null; + } + return carrierConfig; + } + + /** * Given a call subject, removes any characters considered by the current carrier to be * invalid, as well as escaping (using \) any characters which the carrier requires to be * escaped. @@ -4634,15 +4698,7 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall { return callSubject; } - // Get the carrier config for the current sub. - CarrierConfigManager configMgr = (CarrierConfigManager) - mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE); - // Bail if we can't find the carrier config service. - if (configMgr == null) { - return callSubject; - } - - PersistableBundle carrierConfig = configMgr.getConfigForSubId(mPhone.getSubId()); + PersistableBundle carrierConfig = getCarrierConfigBundle(mPhone.getSubId()); // Bail if no carrier config found. if (carrierConfig == null) { return callSubject; @@ -4840,7 +4896,8 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall { // We do not want to update the ImsConfig for REASON_REGISTERED, since it can happen before // the carrier config has loaded and will deregister IMS. if (!mShouldUpdateImsConfigOnDisconnect - && reason != DataEnabledSettings.REASON_REGISTERED && mCarrierConfigLoaded) { + && reason != DataEnabledSettings.REASON_REGISTERED + && mCarrierConfigLoadedForSubscription) { // This will call into updateVideoCallFeatureValue and eventually all clients will be // asynchronously notified that the availability of VT over LTE has changed. updateImsServiceConfig(); @@ -4852,7 +4909,7 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall { * trigger the update of the configuration sent to the ImsService. */ private void updateImsServiceConfig() { - if (mImsManager != null && mCarrierConfigLoaded) { + if (mImsManager != null && mCarrierConfigLoadedForSubscription) { mImsManager.updateImsServiceConfig(); } } diff --git a/tests/telephonytests/src/com/android/internal/telephony/imsphone/ImsPhoneCallTrackerTest.java b/tests/telephonytests/src/com/android/internal/telephony/imsphone/ImsPhoneCallTrackerTest.java index cfb404cc13..a41d95035b 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/imsphone/ImsPhoneCallTrackerTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/imsphone/ImsPhoneCallTrackerTest.java @@ -50,7 +50,9 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.annotation.Nullable; +import android.content.BroadcastReceiver; import android.content.Context; +import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.net.NetworkStats; @@ -91,6 +93,7 @@ import com.android.internal.telephony.Call; import com.android.internal.telephony.CallStateException; import com.android.internal.telephony.CommandsInterface; import com.android.internal.telephony.Connection; +import com.android.internal.telephony.IccCardConstants; import com.android.internal.telephony.PhoneConstants; import com.android.internal.telephony.TelephonyTest; import com.android.internal.telephony.d2d.RtpTransport; @@ -121,6 +124,7 @@ public class ImsPhoneCallTrackerTest extends TelephonyTest { private ImsCall.Listener mImsCallListener; private ImsCall mImsCall; private ImsCall mSecondImsCall; + private BroadcastReceiver mBroadcastReceiver; private Bundle mBundle = new Bundle(); private static final int SUB_0 = 0; @Nullable private VtDataUsageProvider mVtDataUsageProvider; @@ -260,19 +264,6 @@ public class ImsPhoneCallTrackerTest extends TelephonyTest { }).when(mConnectorFactory).create(any(), anyInt(), anyString(), any(), any()); mCTUT = new ImsPhoneCallTracker(mImsPhone, mConnectorFactory, Runnable::run); - mCTUT.addReasonCodeRemapping(null, "Wifi signal lost.", ImsReasonInfo.CODE_WIFI_LOST); - mCTUT.addReasonCodeRemapping(501, "Call answered elsewhere.", - ImsReasonInfo.CODE_ANSWERED_ELSEWHERE); - mCTUT.addReasonCodeRemapping(510, "Call answered elsewhere.", - ImsReasonInfo.CODE_ANSWERED_ELSEWHERE); - mCTUT.addReasonCodeRemapping(ImsReasonInfo.CODE_USER_TERMINATED_BY_REMOTE, "", - ImsReasonInfo.CODE_SIP_FORBIDDEN); - mCTUT.addReasonCodeRemapping(ImsReasonInfo.CODE_SIP_SERVICE_UNAVAILABLE, - "emergency calls over wifi not allowed in this location", - ImsReasonInfo.CODE_EMERGENCY_CALL_OVER_WFC_NOT_AVAILABLE); - mCTUT.addReasonCodeRemapping(ImsReasonInfo.CODE_SIP_FORBIDDEN, - "service not allowed in this location", - ImsReasonInfo.CODE_WFC_SERVICE_NOT_AVAILABLE_IN_THIS_LOCATION); mCTUT.setDataEnabled(true); final ArgumentCaptor<VtDataUsageProvider> vtDataUsageProviderCaptor = @@ -282,6 +273,11 @@ public class ImsPhoneCallTrackerTest extends TelephonyTest { mVtDataUsageProvider = vtDataUsageProviderCaptor.getValue(); assertNotNull(mVtDataUsageProvider); mVtDataUsageProvider.setProviderCallbackBinder(mVtDataUsageProviderCb); + final ArgumentCaptor<BroadcastReceiver> receiverCaptor = + ArgumentCaptor.forClass(BroadcastReceiver.class); + verify(mContext).registerReceiver(receiverCaptor.capture(), any()); + mBroadcastReceiver = receiverCaptor.getValue(); + assertNotNull(mBroadcastReceiver); logd("ImsPhoneCallTracker initiated"); processAllMessages(); @@ -364,6 +360,96 @@ public class ImsPhoneCallTrackerTest extends TelephonyTest { @Test @SmallTest + public void testCarrierConfigLoadSubscription() throws Exception { + // Start with there being no subId loaded, so SubscriptionController#isActiveSubId is false + // as part of setup, connectionReady is called, which ends up calling + // updateCarrierConfiguration. Since the carrier config is not report carrier identified + // config, we should not see updateImsServiceConfig called yet. + verify(mImsManager, never()).updateImsServiceConfig(); + // Send disconnected indication + mConnectorListener.connectionUnavailable(FeatureConnector.UNAVAILABLE_REASON_DISCONNECTED); + + // Receive a subscription loaded and IMS connection ready indication. + doReturn(true).when(mSubscriptionController).isActiveSubId(anyInt()); + mContextFixture.getCarrierConfigBundle().putBoolean( + CarrierConfigManager.KEY_CARRIER_CONFIG_APPLIED_BOOL, true); + sendCarrierConfigChanged(); + // CarrierConfigLoader has signalled that the carrier config has been applied for a specific + // subscription. This will trigger unavailable -> ready indications. + mConnectorListener.connectionReady(mImsManager, SUB_0); + processAllMessages(); + verify(mImsManager).updateImsServiceConfig(); + } + + @Test + @SmallTest + public void testCarrierConfigSentLocked() throws Exception { + // move to ImsService unavailable state. + mConnectorListener.connectionUnavailable(FeatureConnector.UNAVAILABLE_REASON_DISCONNECTED); + doReturn(true).when(mSubscriptionController).isActiveSubId(anyInt()); + mContextFixture.getCarrierConfigBundle().putBoolean( + CarrierConfigManager.KEY_CARRIER_CONFIG_APPLIED_BOOL, true); + + sendCarrierConfigChanged(); + // No ImsService connected, so this will cache the config. + verify(mImsManager, never()).updateImsServiceConfig(); + + // Connect to ImsService, but sim is locked, so ensure we do not send configs yet + doReturn(mIccCard).when(mPhone).getIccCard(); + doReturn(IccCardConstants.State.PIN_REQUIRED).when(mIccCard).getState(); + mConnectorListener.connectionReady(mImsManager, SUB_0); + processAllMessages(); + verify(mImsManager, never()).updateImsServiceConfig(); + + // Now move to ready and simulate carrier config change in response to SIM state change. + doReturn(IccCardConstants.State.READY).when(mIccCard).getState(); + sendCarrierConfigChanged(); + verify(mImsManager).updateImsServiceConfig(); + } + + @Test + @SmallTest + public void testCarrierConfigSentAfterReady() throws Exception { + verify(mImsManager, never()).updateImsServiceConfig(); + + // Receive a subscription loaded and IMS connection ready indication. + doReturn(true).when(mSubscriptionController).isActiveSubId(anyInt()); + mContextFixture.getCarrierConfigBundle().putBoolean( + CarrierConfigManager.KEY_CARRIER_CONFIG_APPLIED_BOOL, true); + // CarrierConfigLoader has signalled that the carrier config has been applied for a specific + // subscription. This will trigger unavailable -> ready indications. + mConnectorListener.connectionUnavailable(FeatureConnector.UNAVAILABLE_REASON_DISCONNECTED); + mConnectorListener.connectionReady(mImsManager, SUB_0); + processAllMessages(); + // Did not receive carrier config changed yet + verify(mImsManager, never()).updateImsServiceConfig(); + sendCarrierConfigChanged(); + processAllMessages(); + verify(mImsManager).updateImsServiceConfig(); + } + + @Test + @SmallTest + public void testCarrierConfigSentBeforeReady() throws Exception { + // move to ImsService unavailable state. + mConnectorListener.connectionUnavailable(FeatureConnector.UNAVAILABLE_REASON_DISCONNECTED); + doReturn(true).when(mSubscriptionController).isActiveSubId(anyInt()); + mContextFixture.getCarrierConfigBundle().putBoolean( + CarrierConfigManager.KEY_CARRIER_CONFIG_APPLIED_BOOL, true); + + sendCarrierConfigChanged(); + // No ImsService connected, so this will cache the config. + verify(mImsManager, never()).updateImsServiceConfig(); + + // Connect to ImsService and ensure that the pending carrier config change is processed + // properly. + mConnectorListener.connectionReady(mImsManager, SUB_0); + processAllMessages(); + verify(mImsManager).updateImsServiceConfig(); + } + + @Test + @SmallTest public void testImsMTCall() { mImsCallProfile.setCallerNumberVerificationStatus( ImsCallProfile.VERIFICATION_STATUS_PASSED); @@ -405,6 +491,10 @@ public class ImsPhoneCallTrackerTest extends TelephonyTest { @Test @SmallTest public void testImsCepOnPeer() throws Exception { + PersistableBundle bundle = mContextFixture.getCarrierConfigBundle(); + bundle.putBoolean( + CarrierConfigManager.KEY_SUPPORT_IMS_CONFERENCE_EVENT_PACKAGE_ON_PEER_BOOL, true); + mCTUT.updateCarrierConfigCache(bundle); testImsMTCallAccept(); doReturn(false).when(mImsCall).isConferenceHost(); doReturn(true).when(mImsCall).isMultiparty(); @@ -764,6 +854,8 @@ public class ImsPhoneCallTrackerTest extends TelephonyTest { @Test @SmallTest public void testReasonCodeRemap() { + loadReasonCodeRemap(); + assertEquals(ImsReasonInfo.CODE_WIFI_LOST, mCTUT.maybeRemapReasonCode( new ImsReasonInfo(1, 1, "Wifi signal lost."))); assertEquals(ImsReasonInfo.CODE_WIFI_LOST, mCTUT.maybeRemapReasonCode( @@ -785,6 +877,22 @@ public class ImsPhoneCallTrackerTest extends TelephonyTest { mCTUT.updateCarrierConfigCache(bundle); } + private void loadReasonCodeRemap() { + mCTUT.addReasonCodeRemapping(null, "Wifi signal lost.", ImsReasonInfo.CODE_WIFI_LOST); + mCTUT.addReasonCodeRemapping(501, "Call answered elsewhere.", + ImsReasonInfo.CODE_ANSWERED_ELSEWHERE); + mCTUT.addReasonCodeRemapping(510, "Call answered elsewhere.", + ImsReasonInfo.CODE_ANSWERED_ELSEWHERE); + mCTUT.addReasonCodeRemapping(ImsReasonInfo.CODE_USER_TERMINATED_BY_REMOTE, "", + ImsReasonInfo.CODE_SIP_FORBIDDEN); + mCTUT.addReasonCodeRemapping(ImsReasonInfo.CODE_SIP_SERVICE_UNAVAILABLE, + "emergency calls over wifi not allowed in this location", + ImsReasonInfo.CODE_EMERGENCY_CALL_OVER_WFC_NOT_AVAILABLE); + mCTUT.addReasonCodeRemapping(ImsReasonInfo.CODE_SIP_FORBIDDEN, + "service not allowed in this location", + ImsReasonInfo.CODE_WFC_SERVICE_NOT_AVAILABLE_IN_THIS_LOCATION); + } + private void loadReasonCodeRemapCarrierConfig() { PersistableBundle bundle = new PersistableBundle(); String[] mappings = new String[] { @@ -1145,6 +1253,10 @@ public class ImsPhoneCallTrackerTest extends TelephonyTest { @Test @SmallTest public void testCantMakeCallTooMany() { + PersistableBundle bundle = mContextFixture.getCarrierConfigBundle(); + bundle.putBoolean(CarrierConfigManager.KEY_ALLOW_HOLD_VIDEO_CALL_BOOL, true); + mCTUT.updateCarrierConfigCache(bundle); + // Place a call. placeCallAndMakeActive(); @@ -1182,6 +1294,8 @@ public class ImsPhoneCallTrackerTest extends TelephonyTest { @Test @SmallTest public void testNumericOnlyRemap() { + loadReasonCodeRemap(); + assertEquals(ImsReasonInfo.CODE_SIP_FORBIDDEN, mCTUT.maybeRemapReasonCode( new ImsReasonInfo(ImsReasonInfo.CODE_USER_TERMINATED_BY_REMOTE, 0))); assertEquals(ImsReasonInfo.CODE_SIP_FORBIDDEN, mCTUT.maybeRemapReasonCode( @@ -1191,6 +1305,8 @@ public class ImsPhoneCallTrackerTest extends TelephonyTest { @Test @SmallTest public void testRemapEmergencyCallsOverWfc() { + loadReasonCodeRemap(); + assertEquals(ImsReasonInfo.CODE_SIP_SERVICE_UNAVAILABLE, mCTUT.maybeRemapReasonCode( new ImsReasonInfo(ImsReasonInfo.CODE_SIP_SERVICE_UNAVAILABLE, 0))); @@ -1207,6 +1323,8 @@ public class ImsPhoneCallTrackerTest extends TelephonyTest { @Test @SmallTest public void testRemapWfcNotAvailable() { + loadReasonCodeRemap(); + assertEquals(ImsReasonInfo.CODE_SIP_FORBIDDEN, mCTUT.maybeRemapReasonCode( new ImsReasonInfo(ImsReasonInfo.CODE_SIP_FORBIDDEN, 0))); @@ -1386,15 +1504,15 @@ public class ImsPhoneCallTrackerTest extends TelephonyTest { @Test @SmallTest public void testConfigureRtpHeaderExtensionTypes() throws Exception { - + mConnectorListener.connectionUnavailable(FeatureConnector.UNAVAILABLE_REASON_DISCONNECTED); + doReturn(true).when(mSubscriptionController).isActiveSubId(anyInt()); mContextFixture.getCarrierConfigBundle().putBoolean( CarrierConfigManager.KEY_SUPPORTS_DEVICE_TO_DEVICE_COMMUNICATION_USING_RTP_BOOL, true); mContextFixture.getCarrierConfigBundle().putBoolean( CarrierConfigManager.KEY_SUPPORTS_SDP_NEGOTIATION_OF_D2D_RTP_HEADER_EXTENSIONS_BOOL, true); - // Hacky but ImsPhoneCallTracker caches carrier config, so necessary. - mCTUT.updateCarrierConfigCache(mContextFixture.getCarrierConfigBundle()); + sendCarrierConfigChanged(); ImsPhoneCallTracker.Config config = new ImsPhoneCallTracker.Config(); config.isD2DCommunicationSupported = true; @@ -1417,15 +1535,15 @@ public class ImsPhoneCallTrackerTest extends TelephonyTest { @Test @SmallTest public void testRtpButNoSdp() throws Exception { - + mConnectorListener.connectionUnavailable(FeatureConnector.UNAVAILABLE_REASON_DISCONNECTED); + doReturn(true).when(mSubscriptionController).isActiveSubId(anyInt()); mContextFixture.getCarrierConfigBundle().putBoolean( CarrierConfigManager.KEY_SUPPORTS_DEVICE_TO_DEVICE_COMMUNICATION_USING_RTP_BOOL, true); mContextFixture.getCarrierConfigBundle().putBoolean( CarrierConfigManager.KEY_SUPPORTS_SDP_NEGOTIATION_OF_D2D_RTP_HEADER_EXTENSIONS_BOOL, false); - // Hacky but ImsPhoneCallTracker caches carrier config, so necessary. - mCTUT.updateCarrierConfigCache(mContextFixture.getCarrierConfigBundle()); + sendCarrierConfigChanged(); ImsPhoneCallTracker.Config config = new ImsPhoneCallTracker.Config(); config.isD2DCommunicationSupported = true; @@ -1447,6 +1565,9 @@ public class ImsPhoneCallTrackerTest extends TelephonyTest { @Test @SmallTest public void testDontConfigureRtpHeaderExtensionTypes() throws Exception { + mConnectorListener.connectionUnavailable(FeatureConnector.UNAVAILABLE_REASON_DISCONNECTED); + doReturn(true).when(mSubscriptionController).isActiveSubId(anyInt()); + sendCarrierConfigChanged(); ImsPhoneCallTracker.Config config = new ImsPhoneCallTracker.Config(); config.isD2DCommunicationSupported = false; mCTUT.setConfig(config); @@ -1456,6 +1577,14 @@ public class ImsPhoneCallTrackerTest extends TelephonyTest { verify(mImsManager, never()).setOfferedRtpHeaderExtensionTypes(any()); } + private void sendCarrierConfigChanged() { + Intent intent = new Intent(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED); + intent.putExtra(CarrierConfigManager.EXTRA_SUBSCRIPTION_INDEX, mPhone.getSubId()); + intent.putExtra(CarrierConfigManager.EXTRA_SLOT_INDEX, mPhone.getPhoneId()); + mBroadcastReceiver.onReceive(mContext, intent); + processAllMessages(); + } + private void assertVtDataUsageUpdated(int expectedToken, long rxBytes, long txBytes) throws RemoteException { final ArgumentCaptor<NetworkStats> ifaceStatsCaptor = ArgumentCaptor.forClass( |