Loading src/java/com/android/internal/telephony/DisplayInfoController.java +25 −1 Original line number Diff line number Diff line Loading @@ -18,11 +18,13 @@ package com.android.internal.telephony; import android.annotation.NonNull; import android.os.Handler; import android.os.Message; import android.os.Registrant; import android.os.RegistrantList; import android.telephony.AccessNetworkConstants; import android.telephony.AnomalyReporter; import android.telephony.NetworkRegistrationInfo; import android.telephony.ServiceState; import android.telephony.TelephonyDisplayInfo; import android.telephony.TelephonyManager; import android.util.IndentingPrintWriter; Loading Loading @@ -66,10 +68,14 @@ public class DisplayInfoController extends Handler { TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_ADVANCED) ); /** Event for service state changed (roaming). */ private static final int EVENT_SERVICE_STATE_CHANGED = 1; private final Phone mPhone; private final NetworkTypeController mNetworkTypeController; private final RegistrantList mTelephonyDisplayInfoChangedRegistrants = new RegistrantList(); private @NonNull TelephonyDisplayInfo mTelephonyDisplayInfo; private @NonNull ServiceState mServiceState; public DisplayInfoController(Phone phone) { mPhone = phone; Loading @@ -79,6 +85,13 @@ public class DisplayInfoController extends Handler { TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NONE); mNetworkTypeController = new NetworkTypeController(phone, this); mNetworkTypeController.sendMessage(NetworkTypeController.EVENT_UPDATE); mServiceState = mPhone.getServiceStateTracker().getServiceState(); post(() -> { mPhone.getServiceStateTracker() .registerForServiceStateChanged(this, EVENT_SERVICE_STATE_CHANGED, null); updateTelephonyDisplayInfo(); }); } /** Loading @@ -98,7 +111,7 @@ public class DisplayInfoController extends Handler { int dataNetworkType = nri == null ? TelephonyManager.NETWORK_TYPE_UNKNOWN : nri.getAccessNetworkTechnology(); TelephonyDisplayInfo newDisplayInfo = new TelephonyDisplayInfo(dataNetworkType, mNetworkTypeController.getOverrideNetworkType()); mNetworkTypeController.getOverrideNetworkType(), mServiceState.getRoaming()); if (!newDisplayInfo.equals(mTelephonyDisplayInfo)) { logl("TelephonyDisplayInfo changed from " + mTelephonyDisplayInfo + " to " + newDisplayInfo); Loading Loading @@ -160,6 +173,17 @@ public class DisplayInfoController extends Handler { mTelephonyDisplayInfoChangedRegistrants.remove(h); } @Override public void handleMessage(@NonNull Message msg) { switch (msg.what) { case EVENT_SERVICE_STATE_CHANGED: mServiceState = mPhone.getServiceStateTracker().getServiceState(); log("ServiceState updated, isRoaming=" + mServiceState.getRoaming()); updateTelephonyDisplayInfo(); break; } } /** * Log debug messages. * @param s debug messages Loading src/java/com/android/internal/telephony/ServiceStateTracker.java +7 −7 Original line number Diff line number Diff line Loading @@ -910,7 +910,7 @@ public class ServiceStateTracker extends Handler { if (nrs != null) { int rat = ServiceState.networkTypeToRilRadioTechnology( nrs.getAccessNetworkTechnology()); int drs = regCodeToServiceState(nrs.getInitialRegistrationState()); int drs = regCodeToServiceState(nrs.getNetworkRegistrationState()); return new Pair<>(drs, rat); } return null; Loading Loading @@ -2171,14 +2171,14 @@ public class ServiceStateTracker extends Handler { if (wlanPsRegState != null && wlanPsRegState.getAccessNetworkTechnology() == TelephonyManager.NETWORK_TYPE_IWLAN && wlanPsRegState.getInitialRegistrationState() && wlanPsRegState.getNetworkRegistrationState() == NetworkRegistrationInfo.REGISTRATION_STATE_HOME && isIwlanPreferred) { serviceState.setDataRegState(ServiceState.STATE_IN_SERVICE); } else if (wwanPsRegState != null) { // If the device is not camped on IWLAN, then we use cellular PS registration state // to compute reg state and rat. int regState = wwanPsRegState.getInitialRegistrationState(); int regState = wwanPsRegState.getNetworkRegistrationState(); serviceState.setDataRegState(regCodeToServiceState(regState)); } if (DBG) { Loading @@ -2194,7 +2194,7 @@ public class ServiceStateTracker extends Handler { VoiceSpecificRegistrationInfo voiceSpecificStates = networkRegState.getVoiceSpecificInfo(); int registrationState = networkRegState.getInitialRegistrationState(); int registrationState = networkRegState.getNetworkRegistrationState(); int cssIndicator = voiceSpecificStates.cssSupported ? 1 : 0; int newVoiceRat = ServiceState.networkTypeToRilRadioTechnology( networkRegState.getAccessNetworkTechnology()); Loading Loading @@ -2276,7 +2276,7 @@ public class ServiceStateTracker extends Handler { mNewSS.addNetworkRegistrationInfo(networkRegState); DataSpecificRegistrationInfo dataSpecificStates = networkRegState.getDataSpecificInfo(); int registrationState = networkRegState.getInitialRegistrationState(); int registrationState = networkRegState.getNetworkRegistrationState(); int serviceState = regCodeToServiceState(registrationState); int newDataRat = ServiceState.networkTypeToRilRadioTechnology( networkRegState.getAccessNetworkTechnology()); Loading Loading @@ -3526,9 +3526,9 @@ public class ServiceStateTracker extends Handler { anyDataRatChanged = true; } int oldRegState = oldNrs != null ? oldNrs.getInitialRegistrationState() int oldRegState = oldNrs != null ? oldNrs.getNetworkRegistrationState() : NetworkRegistrationInfo.REGISTRATION_STATE_UNKNOWN; int newRegState = newNrs != null ? newNrs.getInitialRegistrationState() int newRegState = newNrs != null ? newNrs.getNetworkRegistrationState() : NetworkRegistrationInfo.REGISTRATION_STATE_UNKNOWN; hasDataRegStateChanged.put(transport, oldRegState != newRegState); if (oldRegState != newRegState) { Loading tests/telephonytests/src/com/android/internal/telephony/DisplayInfoControllerTest.java 0 → 100644 +280 −0 Original line number Diff line number Diff line /* * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.internal.telephony; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.when; import android.content.Context; import android.content.Intent; import android.os.AsyncResult; import android.os.HandlerThread; import android.os.PersistableBundle; import android.telephony.AccessNetworkConstants; import android.telephony.CarrierConfigManager; import android.telephony.CellIdentity; import android.telephony.CellIdentityCdma; import android.telephony.CellIdentityLte; import android.telephony.LteVopsSupportInfo; import android.telephony.NetworkRegistrationInfo; import android.telephony.ServiceState; import android.telephony.TelephonyDisplayInfo; import android.telephony.TelephonyManager; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; import android.text.TextUtils; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mockito; import java.util.Collections; @RunWith(AndroidTestingRunner.class) @TestableLooper.RunWithLooper public class DisplayInfoControllerTest extends TelephonyTest { private static final int PHONE_ID = 0; private static final String MCC = "600"; private static final String MNC = "01"; private static final String NUMERIC = MCC + MNC; private static final String NETWORK = "TestNet"; private DisplayInfoController mDic; private ServiceStateTracker mSst; private ServiceStateTrackerTestHandler mSstHandler; private SignalStrengthController mSsc; private PersistableBundle mBundle; private class ServiceStateTrackerTestHandler extends HandlerThread { private ServiceStateTrackerTestHandler(String name) { super(name); } @Override public void onLooperPrepared() { mSsc = new SignalStrengthController(mPhone); doReturn(mSsc).when(mPhone).getSignalStrengthController(); doReturn(new ServiceState()).when(mPhone).getServiceState(); doReturn(NUMERIC).when(mTelephonyManager).getSimOperatorNumericForPhone(eq(PHONE_ID)); doReturn(NETWORK).when(mTelephonyManager).getSimOperatorNameForPhone(eq(PHONE_ID)); mSst = new ServiceStateTracker(mPhone, mSimulatedCommands); doReturn(mSst).when(mPhone).getServiceStateTracker(); setReady(true); } } @Before public void setUp() throws Exception { logd("DisplayInfoControllerTest setup!"); super.setUp(getClass().getSimpleName()); mSstHandler = new ServiceStateTrackerTestHandler(getClass().getSimpleName()); mSstHandler.start(); waitUntilReady(); waitForLastHandlerAction(mSstHandler.getThreadHandler()); } @After public void tearDown() throws Exception { mSst.removeCallbacksAndMessages(null); mSst = null; mSstHandler.quit(); mSstHandler.join(); mSstHandler = null; mBundle = null; super.tearDown(); } private void sendCarrierConfigUpdate() { CarrierConfigManager mockConfigManager = Mockito.mock(CarrierConfigManager.class); when(mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE)) .thenReturn(mockConfigManager); when(mockConfigManager.getConfigForSubId(anyInt())).thenReturn(mBundle); Intent intent = new Intent().setAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED); intent.putExtra(CarrierConfigManager.EXTRA_SLOT_INDEX, PHONE_ID); mContext.sendBroadcast(intent); waitForLastHandlerAction(mSstHandler.getThreadHandler()); } private static String getPlmnFromCellIdentity(final CellIdentity ci) { if (ci == null || ci instanceof CellIdentityCdma) return ""; final String mcc = ci.getMccString(); final String mnc = ci.getMncString(); if (TextUtils.isEmpty(mcc) || TextUtils.isEmpty(mnc)) return ""; return mcc + mnc; } private void changeRegState(int state) { int voiceRat = TelephonyManager.NETWORK_TYPE_LTE; int dataRat = TelephonyManager.NETWORK_TYPE_LTE; CellIdentityLte cid = new CellIdentityLte(1, 1, 5, 1, new int[] {1, 2}, 5000, MCC, MNC, NETWORK, NETWORK, Collections.emptyList(), null); LteVopsSupportInfo lteVopsSupportInfo = new LteVopsSupportInfo( LteVopsSupportInfo.LTE_STATUS_SUPPORTED, LteVopsSupportInfo.LTE_STATUS_SUPPORTED); waitForLastHandlerAction(mSstHandler.getThreadHandler()); NetworkRegistrationInfo dataResult = new NetworkRegistrationInfo( NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN, state, dataRat, 0, false, null, cid, getPlmnFromCellIdentity(cid), 1, false, false, false, lteVopsSupportInfo); mSst.mPollingContext[0] = 3; final String[] oldOpNamesResult = new String[] {"test", "test", NUMERIC}; mSst.sendMessage( mSst.obtainMessage( ServiceStateTracker.EVENT_POLL_STATE_OPERATOR, new AsyncResult(mSst.mPollingContext, oldOpNamesResult, null))); waitForLastHandlerAction(mSstHandler.getThreadHandler()); // update data reg state to be in service mSst.sendMessage( mSst.obtainMessage( ServiceStateTracker.EVENT_POLL_STATE_PS_CELLULAR_REGISTRATION, new AsyncResult(mSst.mPollingContext, dataResult, null))); waitForLastHandlerAction(mSstHandler.getThreadHandler()); NetworkRegistrationInfo voiceResult = new NetworkRegistrationInfo( NetworkRegistrationInfo.DOMAIN_CS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN, state, voiceRat, 0, false, null, cid, getPlmnFromCellIdentity(cid), false, 0, 0, 0); mSst.sendMessage( mSst.obtainMessage( ServiceStateTracker.EVENT_POLL_STATE_CS_CELLULAR_REGISTRATION, new AsyncResult(mSst.mPollingContext, voiceResult, null))); waitForLastHandlerAction(mSstHandler.getThreadHandler()); } @Test public void testIsRoamingOverride_NonRoamingOperator() { doReturn(true).when(mPhone).isPhoneTypeGsm(); mBundle = mContextFixture.getCarrierConfigBundle(); mBundle.putStringArray( CarrierConfigManager.KEY_NON_ROAMING_OPERATOR_STRING_ARRAY, new String[] {NUMERIC}); sendCarrierConfigUpdate(); changeRegState(NetworkRegistrationInfo.REGISTRATION_STATE_ROAMING); ServiceState ss = mSst.getServiceState(); assertFalse(ss.getRoaming()); // home doReturn(mSst).when(mPhone).getServiceStateTracker(); mDic = new DisplayInfoController(mPhone); mDic.updateTelephonyDisplayInfo(); TelephonyDisplayInfo tdi = mDic.getTelephonyDisplayInfo(); assertFalse(tdi.isRoaming()); } @Test public void testIsRoamingOverride_ForceHomeNetwork() { doReturn(true).when(mPhone).isPhoneTypeGsm(); mBundle = mContextFixture.getCarrierConfigBundle(); mBundle.putBoolean(CarrierConfigManager.KEY_FORCE_HOME_NETWORK_BOOL, true); sendCarrierConfigUpdate(); changeRegState(NetworkRegistrationInfo.REGISTRATION_STATE_ROAMING); ServiceState ss = mSst.getServiceState(); assertFalse(ss.getRoaming()); // home doReturn(mSst).when(mPhone).getServiceStateTracker(); mDic = new DisplayInfoController(mPhone); mDic.updateTelephonyDisplayInfo(); TelephonyDisplayInfo tdi = mDic.getTelephonyDisplayInfo(); assertFalse(tdi.isRoaming()); } @Test public void testIsRoamingOverride_RoamingOperator() { doReturn(true).when(mPhone).isPhoneTypeGsm(); mBundle = mContextFixture.getCarrierConfigBundle(); mBundle.putStringArray( CarrierConfigManager.KEY_ROAMING_OPERATOR_STRING_ARRAY, new String[] {"60101"}); sendCarrierConfigUpdate(); changeRegState(NetworkRegistrationInfo.REGISTRATION_STATE_ROAMING); ServiceState ss1 = mSst.getServiceState(); assertTrue(ss1.getRoaming()); // roam doReturn(mSst).when(mPhone).getServiceStateTracker(); mDic = new DisplayInfoController(mPhone); mDic.updateTelephonyDisplayInfo(); TelephonyDisplayInfo tdi = mDic.getTelephonyDisplayInfo(); assertTrue(tdi.isRoaming()); } @Test public void testIsRoamingOverride_NonRoamingGsmOperator() { doReturn(true).when(mPhone).isPhoneTypeGsm(); mBundle = mContextFixture.getCarrierConfigBundle(); mBundle.putStringArray( CarrierConfigManager.KEY_GSM_NONROAMING_NETWORKS_STRING_ARRAY, new String[] {NUMERIC}); sendCarrierConfigUpdate(); changeRegState(NetworkRegistrationInfo.REGISTRATION_STATE_ROAMING); ServiceState ss = mSst.getServiceState(); assertFalse(ss.getRoaming()); // home doReturn(mSst).when(mPhone).getServiceStateTracker(); mDic = new DisplayInfoController(mPhone); mDic.updateTelephonyDisplayInfo(); TelephonyDisplayInfo tdi = mDic.getTelephonyDisplayInfo(); assertFalse(tdi.isRoaming()); } @Test public void testIsRoamingOverride_RoamingGsmOperator() { doReturn(true).when(mPhone).isPhoneTypeGsm(); mBundle = mContextFixture.getCarrierConfigBundle(); mBundle.putStringArray( CarrierConfigManager.KEY_GSM_ROAMING_NETWORKS_STRING_ARRAY, new String[] {NUMERIC}); sendCarrierConfigUpdate(); changeRegState(NetworkRegistrationInfo.REGISTRATION_STATE_HOME); ServiceState ss1 = mSst.getServiceState(); assertTrue(ss1.getRoaming()); // roam doReturn(mSst).when(mPhone).getServiceStateTracker(); mDic = new DisplayInfoController(mPhone); mDic.updateTelephonyDisplayInfo(); TelephonyDisplayInfo tdi = mDic.getTelephonyDisplayInfo(); assertTrue(tdi.isRoaming()); } } tests/telephonytests/src/com/android/internal/telephony/NetworkRegistrationInfoTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -85,6 +85,6 @@ public class NetworkRegistrationInfoTest { nri.setRoamingType(ServiceState.ROAMING_TYPE_NOT_ROAMING); assertEquals(NetworkRegistrationInfo.REGISTRATION_STATE_HOME, nri.getRegistrationState()); assertEquals(NetworkRegistrationInfo.REGISTRATION_STATE_ROAMING, nri.getInitialRegistrationState()); nri.getNetworkRegistrationState()); } } tests/telephonytests/src/com/android/internal/telephony/TelephonyRegistryTest.java +10 −5 Original line number Diff line number Diff line Loading @@ -1070,7 +1070,8 @@ public class TelephonyRegistryTest extends TelephonyTest { anyString(), any())).thenReturn(true); TelephonyDisplayInfo displayInfo = new TelephonyDisplayInfo( TelephonyManager.NETWORK_TYPE_LTE, TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_ADVANCED); TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_ADVANCED, false); // Notify with invalid subId on default phone. Should NOT trigger callback. mTelephonyRegistry.notifyDisplayInfoChanged(0, INVALID_SUBSCRIPTION_ID, displayInfo); Loading @@ -1096,10 +1097,12 @@ public class TelephonyRegistryTest extends TelephonyTest { anyString(), any())).thenReturn(false); TelephonyDisplayInfo displayInfo = new TelephonyDisplayInfo( TelephonyManager.NETWORK_TYPE_LTE, TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_ADVANCED); TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_ADVANCED, false); TelephonyDisplayInfo expectDisplayInfo = new TelephonyDisplayInfo( TelephonyManager.NETWORK_TYPE_LTE, TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA_MMWAVE); TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA_MMWAVE, false); // Notify with invalid subId on default phone. Should NOT trigger callback. mTelephonyRegistry.notifyDisplayInfoChanged(0, INVALID_SUBSCRIPTION_ID, displayInfo); Loading @@ -1121,10 +1124,12 @@ public class TelephonyRegistryTest extends TelephonyTest { int[] events = {TelephonyCallback.EVENT_DISPLAY_INFO_CHANGED}; TelephonyDisplayInfo displayInfo = new TelephonyDisplayInfo( TelephonyManager.NETWORK_TYPE_LTE, TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_ADVANCED); TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_ADVANCED, false); TelephonyDisplayInfo expectDisplayInfo = new TelephonyDisplayInfo( TelephonyManager.NETWORK_TYPE_LTE, TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA_MMWAVE); TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA_MMWAVE, false); TelephonyCallback telephonyCallback2 = new TelephonyCallbackWrapper() { @Override public void onDisplayInfoChanged(TelephonyDisplayInfo displayInfoNotify) { Loading Loading
src/java/com/android/internal/telephony/DisplayInfoController.java +25 −1 Original line number Diff line number Diff line Loading @@ -18,11 +18,13 @@ package com.android.internal.telephony; import android.annotation.NonNull; import android.os.Handler; import android.os.Message; import android.os.Registrant; import android.os.RegistrantList; import android.telephony.AccessNetworkConstants; import android.telephony.AnomalyReporter; import android.telephony.NetworkRegistrationInfo; import android.telephony.ServiceState; import android.telephony.TelephonyDisplayInfo; import android.telephony.TelephonyManager; import android.util.IndentingPrintWriter; Loading Loading @@ -66,10 +68,14 @@ public class DisplayInfoController extends Handler { TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_ADVANCED) ); /** Event for service state changed (roaming). */ private static final int EVENT_SERVICE_STATE_CHANGED = 1; private final Phone mPhone; private final NetworkTypeController mNetworkTypeController; private final RegistrantList mTelephonyDisplayInfoChangedRegistrants = new RegistrantList(); private @NonNull TelephonyDisplayInfo mTelephonyDisplayInfo; private @NonNull ServiceState mServiceState; public DisplayInfoController(Phone phone) { mPhone = phone; Loading @@ -79,6 +85,13 @@ public class DisplayInfoController extends Handler { TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NONE); mNetworkTypeController = new NetworkTypeController(phone, this); mNetworkTypeController.sendMessage(NetworkTypeController.EVENT_UPDATE); mServiceState = mPhone.getServiceStateTracker().getServiceState(); post(() -> { mPhone.getServiceStateTracker() .registerForServiceStateChanged(this, EVENT_SERVICE_STATE_CHANGED, null); updateTelephonyDisplayInfo(); }); } /** Loading @@ -98,7 +111,7 @@ public class DisplayInfoController extends Handler { int dataNetworkType = nri == null ? TelephonyManager.NETWORK_TYPE_UNKNOWN : nri.getAccessNetworkTechnology(); TelephonyDisplayInfo newDisplayInfo = new TelephonyDisplayInfo(dataNetworkType, mNetworkTypeController.getOverrideNetworkType()); mNetworkTypeController.getOverrideNetworkType(), mServiceState.getRoaming()); if (!newDisplayInfo.equals(mTelephonyDisplayInfo)) { logl("TelephonyDisplayInfo changed from " + mTelephonyDisplayInfo + " to " + newDisplayInfo); Loading Loading @@ -160,6 +173,17 @@ public class DisplayInfoController extends Handler { mTelephonyDisplayInfoChangedRegistrants.remove(h); } @Override public void handleMessage(@NonNull Message msg) { switch (msg.what) { case EVENT_SERVICE_STATE_CHANGED: mServiceState = mPhone.getServiceStateTracker().getServiceState(); log("ServiceState updated, isRoaming=" + mServiceState.getRoaming()); updateTelephonyDisplayInfo(); break; } } /** * Log debug messages. * @param s debug messages Loading
src/java/com/android/internal/telephony/ServiceStateTracker.java +7 −7 Original line number Diff line number Diff line Loading @@ -910,7 +910,7 @@ public class ServiceStateTracker extends Handler { if (nrs != null) { int rat = ServiceState.networkTypeToRilRadioTechnology( nrs.getAccessNetworkTechnology()); int drs = regCodeToServiceState(nrs.getInitialRegistrationState()); int drs = regCodeToServiceState(nrs.getNetworkRegistrationState()); return new Pair<>(drs, rat); } return null; Loading Loading @@ -2171,14 +2171,14 @@ public class ServiceStateTracker extends Handler { if (wlanPsRegState != null && wlanPsRegState.getAccessNetworkTechnology() == TelephonyManager.NETWORK_TYPE_IWLAN && wlanPsRegState.getInitialRegistrationState() && wlanPsRegState.getNetworkRegistrationState() == NetworkRegistrationInfo.REGISTRATION_STATE_HOME && isIwlanPreferred) { serviceState.setDataRegState(ServiceState.STATE_IN_SERVICE); } else if (wwanPsRegState != null) { // If the device is not camped on IWLAN, then we use cellular PS registration state // to compute reg state and rat. int regState = wwanPsRegState.getInitialRegistrationState(); int regState = wwanPsRegState.getNetworkRegistrationState(); serviceState.setDataRegState(regCodeToServiceState(regState)); } if (DBG) { Loading @@ -2194,7 +2194,7 @@ public class ServiceStateTracker extends Handler { VoiceSpecificRegistrationInfo voiceSpecificStates = networkRegState.getVoiceSpecificInfo(); int registrationState = networkRegState.getInitialRegistrationState(); int registrationState = networkRegState.getNetworkRegistrationState(); int cssIndicator = voiceSpecificStates.cssSupported ? 1 : 0; int newVoiceRat = ServiceState.networkTypeToRilRadioTechnology( networkRegState.getAccessNetworkTechnology()); Loading Loading @@ -2276,7 +2276,7 @@ public class ServiceStateTracker extends Handler { mNewSS.addNetworkRegistrationInfo(networkRegState); DataSpecificRegistrationInfo dataSpecificStates = networkRegState.getDataSpecificInfo(); int registrationState = networkRegState.getInitialRegistrationState(); int registrationState = networkRegState.getNetworkRegistrationState(); int serviceState = regCodeToServiceState(registrationState); int newDataRat = ServiceState.networkTypeToRilRadioTechnology( networkRegState.getAccessNetworkTechnology()); Loading Loading @@ -3526,9 +3526,9 @@ public class ServiceStateTracker extends Handler { anyDataRatChanged = true; } int oldRegState = oldNrs != null ? oldNrs.getInitialRegistrationState() int oldRegState = oldNrs != null ? oldNrs.getNetworkRegistrationState() : NetworkRegistrationInfo.REGISTRATION_STATE_UNKNOWN; int newRegState = newNrs != null ? newNrs.getInitialRegistrationState() int newRegState = newNrs != null ? newNrs.getNetworkRegistrationState() : NetworkRegistrationInfo.REGISTRATION_STATE_UNKNOWN; hasDataRegStateChanged.put(transport, oldRegState != newRegState); if (oldRegState != newRegState) { Loading
tests/telephonytests/src/com/android/internal/telephony/DisplayInfoControllerTest.java 0 → 100644 +280 −0 Original line number Diff line number Diff line /* * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.internal.telephony; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.when; import android.content.Context; import android.content.Intent; import android.os.AsyncResult; import android.os.HandlerThread; import android.os.PersistableBundle; import android.telephony.AccessNetworkConstants; import android.telephony.CarrierConfigManager; import android.telephony.CellIdentity; import android.telephony.CellIdentityCdma; import android.telephony.CellIdentityLte; import android.telephony.LteVopsSupportInfo; import android.telephony.NetworkRegistrationInfo; import android.telephony.ServiceState; import android.telephony.TelephonyDisplayInfo; import android.telephony.TelephonyManager; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; import android.text.TextUtils; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mockito; import java.util.Collections; @RunWith(AndroidTestingRunner.class) @TestableLooper.RunWithLooper public class DisplayInfoControllerTest extends TelephonyTest { private static final int PHONE_ID = 0; private static final String MCC = "600"; private static final String MNC = "01"; private static final String NUMERIC = MCC + MNC; private static final String NETWORK = "TestNet"; private DisplayInfoController mDic; private ServiceStateTracker mSst; private ServiceStateTrackerTestHandler mSstHandler; private SignalStrengthController mSsc; private PersistableBundle mBundle; private class ServiceStateTrackerTestHandler extends HandlerThread { private ServiceStateTrackerTestHandler(String name) { super(name); } @Override public void onLooperPrepared() { mSsc = new SignalStrengthController(mPhone); doReturn(mSsc).when(mPhone).getSignalStrengthController(); doReturn(new ServiceState()).when(mPhone).getServiceState(); doReturn(NUMERIC).when(mTelephonyManager).getSimOperatorNumericForPhone(eq(PHONE_ID)); doReturn(NETWORK).when(mTelephonyManager).getSimOperatorNameForPhone(eq(PHONE_ID)); mSst = new ServiceStateTracker(mPhone, mSimulatedCommands); doReturn(mSst).when(mPhone).getServiceStateTracker(); setReady(true); } } @Before public void setUp() throws Exception { logd("DisplayInfoControllerTest setup!"); super.setUp(getClass().getSimpleName()); mSstHandler = new ServiceStateTrackerTestHandler(getClass().getSimpleName()); mSstHandler.start(); waitUntilReady(); waitForLastHandlerAction(mSstHandler.getThreadHandler()); } @After public void tearDown() throws Exception { mSst.removeCallbacksAndMessages(null); mSst = null; mSstHandler.quit(); mSstHandler.join(); mSstHandler = null; mBundle = null; super.tearDown(); } private void sendCarrierConfigUpdate() { CarrierConfigManager mockConfigManager = Mockito.mock(CarrierConfigManager.class); when(mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE)) .thenReturn(mockConfigManager); when(mockConfigManager.getConfigForSubId(anyInt())).thenReturn(mBundle); Intent intent = new Intent().setAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED); intent.putExtra(CarrierConfigManager.EXTRA_SLOT_INDEX, PHONE_ID); mContext.sendBroadcast(intent); waitForLastHandlerAction(mSstHandler.getThreadHandler()); } private static String getPlmnFromCellIdentity(final CellIdentity ci) { if (ci == null || ci instanceof CellIdentityCdma) return ""; final String mcc = ci.getMccString(); final String mnc = ci.getMncString(); if (TextUtils.isEmpty(mcc) || TextUtils.isEmpty(mnc)) return ""; return mcc + mnc; } private void changeRegState(int state) { int voiceRat = TelephonyManager.NETWORK_TYPE_LTE; int dataRat = TelephonyManager.NETWORK_TYPE_LTE; CellIdentityLte cid = new CellIdentityLte(1, 1, 5, 1, new int[] {1, 2}, 5000, MCC, MNC, NETWORK, NETWORK, Collections.emptyList(), null); LteVopsSupportInfo lteVopsSupportInfo = new LteVopsSupportInfo( LteVopsSupportInfo.LTE_STATUS_SUPPORTED, LteVopsSupportInfo.LTE_STATUS_SUPPORTED); waitForLastHandlerAction(mSstHandler.getThreadHandler()); NetworkRegistrationInfo dataResult = new NetworkRegistrationInfo( NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN, state, dataRat, 0, false, null, cid, getPlmnFromCellIdentity(cid), 1, false, false, false, lteVopsSupportInfo); mSst.mPollingContext[0] = 3; final String[] oldOpNamesResult = new String[] {"test", "test", NUMERIC}; mSst.sendMessage( mSst.obtainMessage( ServiceStateTracker.EVENT_POLL_STATE_OPERATOR, new AsyncResult(mSst.mPollingContext, oldOpNamesResult, null))); waitForLastHandlerAction(mSstHandler.getThreadHandler()); // update data reg state to be in service mSst.sendMessage( mSst.obtainMessage( ServiceStateTracker.EVENT_POLL_STATE_PS_CELLULAR_REGISTRATION, new AsyncResult(mSst.mPollingContext, dataResult, null))); waitForLastHandlerAction(mSstHandler.getThreadHandler()); NetworkRegistrationInfo voiceResult = new NetworkRegistrationInfo( NetworkRegistrationInfo.DOMAIN_CS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN, state, voiceRat, 0, false, null, cid, getPlmnFromCellIdentity(cid), false, 0, 0, 0); mSst.sendMessage( mSst.obtainMessage( ServiceStateTracker.EVENT_POLL_STATE_CS_CELLULAR_REGISTRATION, new AsyncResult(mSst.mPollingContext, voiceResult, null))); waitForLastHandlerAction(mSstHandler.getThreadHandler()); } @Test public void testIsRoamingOverride_NonRoamingOperator() { doReturn(true).when(mPhone).isPhoneTypeGsm(); mBundle = mContextFixture.getCarrierConfigBundle(); mBundle.putStringArray( CarrierConfigManager.KEY_NON_ROAMING_OPERATOR_STRING_ARRAY, new String[] {NUMERIC}); sendCarrierConfigUpdate(); changeRegState(NetworkRegistrationInfo.REGISTRATION_STATE_ROAMING); ServiceState ss = mSst.getServiceState(); assertFalse(ss.getRoaming()); // home doReturn(mSst).when(mPhone).getServiceStateTracker(); mDic = new DisplayInfoController(mPhone); mDic.updateTelephonyDisplayInfo(); TelephonyDisplayInfo tdi = mDic.getTelephonyDisplayInfo(); assertFalse(tdi.isRoaming()); } @Test public void testIsRoamingOverride_ForceHomeNetwork() { doReturn(true).when(mPhone).isPhoneTypeGsm(); mBundle = mContextFixture.getCarrierConfigBundle(); mBundle.putBoolean(CarrierConfigManager.KEY_FORCE_HOME_NETWORK_BOOL, true); sendCarrierConfigUpdate(); changeRegState(NetworkRegistrationInfo.REGISTRATION_STATE_ROAMING); ServiceState ss = mSst.getServiceState(); assertFalse(ss.getRoaming()); // home doReturn(mSst).when(mPhone).getServiceStateTracker(); mDic = new DisplayInfoController(mPhone); mDic.updateTelephonyDisplayInfo(); TelephonyDisplayInfo tdi = mDic.getTelephonyDisplayInfo(); assertFalse(tdi.isRoaming()); } @Test public void testIsRoamingOverride_RoamingOperator() { doReturn(true).when(mPhone).isPhoneTypeGsm(); mBundle = mContextFixture.getCarrierConfigBundle(); mBundle.putStringArray( CarrierConfigManager.KEY_ROAMING_OPERATOR_STRING_ARRAY, new String[] {"60101"}); sendCarrierConfigUpdate(); changeRegState(NetworkRegistrationInfo.REGISTRATION_STATE_ROAMING); ServiceState ss1 = mSst.getServiceState(); assertTrue(ss1.getRoaming()); // roam doReturn(mSst).when(mPhone).getServiceStateTracker(); mDic = new DisplayInfoController(mPhone); mDic.updateTelephonyDisplayInfo(); TelephonyDisplayInfo tdi = mDic.getTelephonyDisplayInfo(); assertTrue(tdi.isRoaming()); } @Test public void testIsRoamingOverride_NonRoamingGsmOperator() { doReturn(true).when(mPhone).isPhoneTypeGsm(); mBundle = mContextFixture.getCarrierConfigBundle(); mBundle.putStringArray( CarrierConfigManager.KEY_GSM_NONROAMING_NETWORKS_STRING_ARRAY, new String[] {NUMERIC}); sendCarrierConfigUpdate(); changeRegState(NetworkRegistrationInfo.REGISTRATION_STATE_ROAMING); ServiceState ss = mSst.getServiceState(); assertFalse(ss.getRoaming()); // home doReturn(mSst).when(mPhone).getServiceStateTracker(); mDic = new DisplayInfoController(mPhone); mDic.updateTelephonyDisplayInfo(); TelephonyDisplayInfo tdi = mDic.getTelephonyDisplayInfo(); assertFalse(tdi.isRoaming()); } @Test public void testIsRoamingOverride_RoamingGsmOperator() { doReturn(true).when(mPhone).isPhoneTypeGsm(); mBundle = mContextFixture.getCarrierConfigBundle(); mBundle.putStringArray( CarrierConfigManager.KEY_GSM_ROAMING_NETWORKS_STRING_ARRAY, new String[] {NUMERIC}); sendCarrierConfigUpdate(); changeRegState(NetworkRegistrationInfo.REGISTRATION_STATE_HOME); ServiceState ss1 = mSst.getServiceState(); assertTrue(ss1.getRoaming()); // roam doReturn(mSst).when(mPhone).getServiceStateTracker(); mDic = new DisplayInfoController(mPhone); mDic.updateTelephonyDisplayInfo(); TelephonyDisplayInfo tdi = mDic.getTelephonyDisplayInfo(); assertTrue(tdi.isRoaming()); } }
tests/telephonytests/src/com/android/internal/telephony/NetworkRegistrationInfoTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -85,6 +85,6 @@ public class NetworkRegistrationInfoTest { nri.setRoamingType(ServiceState.ROAMING_TYPE_NOT_ROAMING); assertEquals(NetworkRegistrationInfo.REGISTRATION_STATE_HOME, nri.getRegistrationState()); assertEquals(NetworkRegistrationInfo.REGISTRATION_STATE_ROAMING, nri.getInitialRegistrationState()); nri.getNetworkRegistrationState()); } }
tests/telephonytests/src/com/android/internal/telephony/TelephonyRegistryTest.java +10 −5 Original line number Diff line number Diff line Loading @@ -1070,7 +1070,8 @@ public class TelephonyRegistryTest extends TelephonyTest { anyString(), any())).thenReturn(true); TelephonyDisplayInfo displayInfo = new TelephonyDisplayInfo( TelephonyManager.NETWORK_TYPE_LTE, TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_ADVANCED); TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_ADVANCED, false); // Notify with invalid subId on default phone. Should NOT trigger callback. mTelephonyRegistry.notifyDisplayInfoChanged(0, INVALID_SUBSCRIPTION_ID, displayInfo); Loading @@ -1096,10 +1097,12 @@ public class TelephonyRegistryTest extends TelephonyTest { anyString(), any())).thenReturn(false); TelephonyDisplayInfo displayInfo = new TelephonyDisplayInfo( TelephonyManager.NETWORK_TYPE_LTE, TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_ADVANCED); TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_ADVANCED, false); TelephonyDisplayInfo expectDisplayInfo = new TelephonyDisplayInfo( TelephonyManager.NETWORK_TYPE_LTE, TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA_MMWAVE); TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA_MMWAVE, false); // Notify with invalid subId on default phone. Should NOT trigger callback. mTelephonyRegistry.notifyDisplayInfoChanged(0, INVALID_SUBSCRIPTION_ID, displayInfo); Loading @@ -1121,10 +1124,12 @@ public class TelephonyRegistryTest extends TelephonyTest { int[] events = {TelephonyCallback.EVENT_DISPLAY_INFO_CHANGED}; TelephonyDisplayInfo displayInfo = new TelephonyDisplayInfo( TelephonyManager.NETWORK_TYPE_LTE, TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_ADVANCED); TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_ADVANCED, false); TelephonyDisplayInfo expectDisplayInfo = new TelephonyDisplayInfo( TelephonyManager.NETWORK_TYPE_LTE, TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA_MMWAVE); TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA_MMWAVE, false); TelephonyCallback telephonyCallback2 = new TelephonyCallbackWrapper() { @Override public void onDisplayInfoChanged(TelephonyDisplayInfo displayInfoNotify) { Loading