Loading src/java/com/android/internal/telephony/ServiceStateTracker.java +32 −1 Original line number Diff line number Diff line Loading @@ -124,6 +124,7 @@ import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; Loading Loading @@ -274,6 +275,7 @@ public class ServiceStateTracker extends Handler { private static final int EVENT_POLL_STATE_REQUEST = 58; // Timeout event used when delaying radio power off to wait for IMS deregistration to happen. private static final int EVENT_POWER_OFF_RADIO_IMS_DEREG_TIMEOUT = 62; protected static final int EVENT_RESET_LAST_KNOWN_CELL_IDENTITY = 63; /** * The current service state. Loading Loading @@ -455,6 +457,7 @@ public class ServiceStateTracker extends Handler { protected final GsmCdmaPhone mPhone; private CellIdentity mCellIdentity; @Nullable private CellIdentity mLastKnownCellIdentity; private static final int MS_PER_HOUR = 60 * 60 * 1000; private final NitzStateMachine mNitzState; Loading Loading @@ -748,6 +751,7 @@ public class ServiceStateTracker extends Handler { mNitzState.handleNetworkUnavailable(); mCellIdentity = null; mPhone.getSignalStrengthController().setSignalStrengthDefaultValues(); mLastKnownCellIdentity = null; //cancel any pending pollstate request on voice tech switching cancelPollState(); Loading Loading @@ -1672,6 +1676,12 @@ public class ServiceStateTracker extends Handler { break; } case EVENT_RESET_LAST_KNOWN_CELL_IDENTITY: { if (DBG) log("EVENT_RESET_LAST_KNOWN_CELL_IDENTITY triggered"); mLastKnownCellIdentity = null; break; } default: log("Unhandled message with number: " + msg.what); break; Loading Loading @@ -3568,6 +3578,15 @@ public class ServiceStateTracker extends Handler { mNewSS.setStateOutOfService(); mCellIdentity = primaryCellIdentity; if (mSS.getState() == ServiceState.STATE_IN_SERVICE && primaryCellIdentity != null) { mLastKnownCellIdentity = mCellIdentity; removeMessages(EVENT_RESET_LAST_KNOWN_CELL_IDENTITY); } if (hasDeregistered && !hasMessages(EVENT_RESET_LAST_KNOWN_CELL_IDENTITY)) { sendEmptyMessageDelayed(EVENT_RESET_LAST_KNOWN_CELL_IDENTITY, TimeUnit.DAYS.toMillis(1)); } int areaCode = getAreaCodeFromCellIdentity(mCellIdentity); if (areaCode != mLastKnownAreaCode && areaCode != CellInfo.UNAVAILABLE) { Loading Loading @@ -5852,4 +5871,16 @@ public class ServiceStateTracker extends Handler { public void unregisterForAreaCodeChanged(Handler h) { mAreaCodeChangedRegistrants.remove(h); } /** * get last known cell identity * If there is current registered network this value will be same as the registered cell * identity. If the device goes out of service the previous cell identity is cached and * will be returned. If the cache age of the cell identity is more than 24 hours * it will be cleared and null will be returned. * @return last known cell identity. */ public @Nullable CellIdentity getLastKnownCellIdentity() { return mLastKnownCellIdentity; } } tests/telephonytests/src/com/android/internal/telephony/ServiceStateTrackerTest.java +47 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyLong; Loading Loading @@ -2121,6 +2122,30 @@ public class ServiceStateTrackerTest extends TelephonyTest { waitForLastHandlerAction(mSSTTestHandler.getThreadHandler()); } private void sendRegStateUpdateForLteOnOos() throws Exception { LteVopsSupportInfo lteVopsSupportInfo = new LteVopsSupportInfo(LteVopsSupportInfo.LTE_STATUS_NOT_AVAILABLE, LteVopsSupportInfo.LTE_STATUS_NOT_AVAILABLE); NetworkRegistrationInfo dataResult = new NetworkRegistrationInfo( NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN, NetworkRegistrationInfo.REGISTRATION_STATE_NOT_REGISTERED_OR_SEARCHING, TelephonyManager.NETWORK_TYPE_UNKNOWN, 0, false, null, null, "", 1, false, false, false, lteVopsSupportInfo); NetworkRegistrationInfo voiceResult = new NetworkRegistrationInfo( NetworkRegistrationInfo.DOMAIN_CS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN, NetworkRegistrationInfo.REGISTRATION_STATE_NOT_REGISTERED_OR_SEARCHING, TelephonyManager.NETWORK_TYPE_UNKNOWN, 0, false, null, null, "", false, 0, 0, 0); sst.mPollingContext[0] = 2; sst.sendMessage(sst.obtainMessage( ServiceStateTracker.EVENT_POLL_STATE_PS_CELLULAR_REGISTRATION, new AsyncResult(sst.mPollingContext, dataResult, null))); waitForLastHandlerAction(mSSTTestHandler.getThreadHandler()); sst.sendMessage(sst.obtainMessage( ServiceStateTracker.EVENT_POLL_STATE_CS_CELLULAR_REGISTRATION, new AsyncResult(sst.mPollingContext, voiceResult, null))); waitForLastHandlerAction(mSSTTestHandler.getThreadHandler()); } @Test public void testPhyChanBandwidthUpdatedOnDataRegState() throws Exception { // Cell ID change should trigger hasLocationChanged. Loading Loading @@ -2501,6 +2526,28 @@ public class ServiceStateTrackerTest extends TelephonyTest { verify(mEriManager, times(1)).loadEriFile(); } @Test public void testLastKnownCellIdentity() throws Exception { CellIdentityLte cellIdentity = new CellIdentityLte(1, 1, 5, 1, new int[] {1, 2}, 5000, "001", "01", "test", "tst", Collections.emptyList(), null); sendPhyChanConfigChange(new int[] {10000}, TelephonyManager.NETWORK_TYPE_LTE, 1); sendRegStateUpdateForLteCellId(cellIdentity); assertEquals(ServiceState.STATE_IN_SERVICE, sst.mSS.getState()); assertEquals(cellIdentity, sst.getLastKnownCellIdentity()); assertFalse(sst.hasMessages(sst.EVENT_RESET_LAST_KNOWN_CELL_IDENTITY)); sendRegStateUpdateForLteOnOos(); assertEquals(ServiceState.STATE_OUT_OF_SERVICE, sst.mSS.getState()); assertEquals(cellIdentity, sst.getLastKnownCellIdentity()); assertTrue(sst.hasMessages(sst.EVENT_RESET_LAST_KNOWN_CELL_IDENTITY)); sst.obtainMessage(sst.EVENT_RESET_LAST_KNOWN_CELL_IDENTITY, null).sendToTarget(); waitForLastHandlerAction(mSSTTestHandler.getThreadHandler()); assertNull(sst.getLastKnownCellIdentity()); } @Test public void testUpdateSpnDisplay_noService_displayEmergencyCallOnly() { // GSM phone Loading Loading
src/java/com/android/internal/telephony/ServiceStateTracker.java +32 −1 Original line number Diff line number Diff line Loading @@ -124,6 +124,7 @@ import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; Loading Loading @@ -274,6 +275,7 @@ public class ServiceStateTracker extends Handler { private static final int EVENT_POLL_STATE_REQUEST = 58; // Timeout event used when delaying radio power off to wait for IMS deregistration to happen. private static final int EVENT_POWER_OFF_RADIO_IMS_DEREG_TIMEOUT = 62; protected static final int EVENT_RESET_LAST_KNOWN_CELL_IDENTITY = 63; /** * The current service state. Loading Loading @@ -455,6 +457,7 @@ public class ServiceStateTracker extends Handler { protected final GsmCdmaPhone mPhone; private CellIdentity mCellIdentity; @Nullable private CellIdentity mLastKnownCellIdentity; private static final int MS_PER_HOUR = 60 * 60 * 1000; private final NitzStateMachine mNitzState; Loading Loading @@ -748,6 +751,7 @@ public class ServiceStateTracker extends Handler { mNitzState.handleNetworkUnavailable(); mCellIdentity = null; mPhone.getSignalStrengthController().setSignalStrengthDefaultValues(); mLastKnownCellIdentity = null; //cancel any pending pollstate request on voice tech switching cancelPollState(); Loading Loading @@ -1672,6 +1676,12 @@ public class ServiceStateTracker extends Handler { break; } case EVENT_RESET_LAST_KNOWN_CELL_IDENTITY: { if (DBG) log("EVENT_RESET_LAST_KNOWN_CELL_IDENTITY triggered"); mLastKnownCellIdentity = null; break; } default: log("Unhandled message with number: " + msg.what); break; Loading Loading @@ -3568,6 +3578,15 @@ public class ServiceStateTracker extends Handler { mNewSS.setStateOutOfService(); mCellIdentity = primaryCellIdentity; if (mSS.getState() == ServiceState.STATE_IN_SERVICE && primaryCellIdentity != null) { mLastKnownCellIdentity = mCellIdentity; removeMessages(EVENT_RESET_LAST_KNOWN_CELL_IDENTITY); } if (hasDeregistered && !hasMessages(EVENT_RESET_LAST_KNOWN_CELL_IDENTITY)) { sendEmptyMessageDelayed(EVENT_RESET_LAST_KNOWN_CELL_IDENTITY, TimeUnit.DAYS.toMillis(1)); } int areaCode = getAreaCodeFromCellIdentity(mCellIdentity); if (areaCode != mLastKnownAreaCode && areaCode != CellInfo.UNAVAILABLE) { Loading Loading @@ -5852,4 +5871,16 @@ public class ServiceStateTracker extends Handler { public void unregisterForAreaCodeChanged(Handler h) { mAreaCodeChangedRegistrants.remove(h); } /** * get last known cell identity * If there is current registered network this value will be same as the registered cell * identity. If the device goes out of service the previous cell identity is cached and * will be returned. If the cache age of the cell identity is more than 24 hours * it will be cleared and null will be returned. * @return last known cell identity. */ public @Nullable CellIdentity getLastKnownCellIdentity() { return mLastKnownCellIdentity; } }
tests/telephonytests/src/com/android/internal/telephony/ServiceStateTrackerTest.java +47 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyLong; Loading Loading @@ -2121,6 +2122,30 @@ public class ServiceStateTrackerTest extends TelephonyTest { waitForLastHandlerAction(mSSTTestHandler.getThreadHandler()); } private void sendRegStateUpdateForLteOnOos() throws Exception { LteVopsSupportInfo lteVopsSupportInfo = new LteVopsSupportInfo(LteVopsSupportInfo.LTE_STATUS_NOT_AVAILABLE, LteVopsSupportInfo.LTE_STATUS_NOT_AVAILABLE); NetworkRegistrationInfo dataResult = new NetworkRegistrationInfo( NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN, NetworkRegistrationInfo.REGISTRATION_STATE_NOT_REGISTERED_OR_SEARCHING, TelephonyManager.NETWORK_TYPE_UNKNOWN, 0, false, null, null, "", 1, false, false, false, lteVopsSupportInfo); NetworkRegistrationInfo voiceResult = new NetworkRegistrationInfo( NetworkRegistrationInfo.DOMAIN_CS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN, NetworkRegistrationInfo.REGISTRATION_STATE_NOT_REGISTERED_OR_SEARCHING, TelephonyManager.NETWORK_TYPE_UNKNOWN, 0, false, null, null, "", false, 0, 0, 0); sst.mPollingContext[0] = 2; sst.sendMessage(sst.obtainMessage( ServiceStateTracker.EVENT_POLL_STATE_PS_CELLULAR_REGISTRATION, new AsyncResult(sst.mPollingContext, dataResult, null))); waitForLastHandlerAction(mSSTTestHandler.getThreadHandler()); sst.sendMessage(sst.obtainMessage( ServiceStateTracker.EVENT_POLL_STATE_CS_CELLULAR_REGISTRATION, new AsyncResult(sst.mPollingContext, voiceResult, null))); waitForLastHandlerAction(mSSTTestHandler.getThreadHandler()); } @Test public void testPhyChanBandwidthUpdatedOnDataRegState() throws Exception { // Cell ID change should trigger hasLocationChanged. Loading Loading @@ -2501,6 +2526,28 @@ public class ServiceStateTrackerTest extends TelephonyTest { verify(mEriManager, times(1)).loadEriFile(); } @Test public void testLastKnownCellIdentity() throws Exception { CellIdentityLte cellIdentity = new CellIdentityLte(1, 1, 5, 1, new int[] {1, 2}, 5000, "001", "01", "test", "tst", Collections.emptyList(), null); sendPhyChanConfigChange(new int[] {10000}, TelephonyManager.NETWORK_TYPE_LTE, 1); sendRegStateUpdateForLteCellId(cellIdentity); assertEquals(ServiceState.STATE_IN_SERVICE, sst.mSS.getState()); assertEquals(cellIdentity, sst.getLastKnownCellIdentity()); assertFalse(sst.hasMessages(sst.EVENT_RESET_LAST_KNOWN_CELL_IDENTITY)); sendRegStateUpdateForLteOnOos(); assertEquals(ServiceState.STATE_OUT_OF_SERVICE, sst.mSS.getState()); assertEquals(cellIdentity, sst.getLastKnownCellIdentity()); assertTrue(sst.hasMessages(sst.EVENT_RESET_LAST_KNOWN_CELL_IDENTITY)); sst.obtainMessage(sst.EVENT_RESET_LAST_KNOWN_CELL_IDENTITY, null).sendToTarget(); waitForLastHandlerAction(mSSTTestHandler.getThreadHandler()); assertNull(sst.getLastKnownCellIdentity()); } @Test public void testUpdateSpnDisplay_noService_displayEmergencyCallOnly() { // GSM phone Loading