Loading src/java/com/android/internal/telephony/MccTable.java +2 −4 Original line number Diff line number Diff line Loading @@ -358,13 +358,11 @@ public final class MccTable { * @param mcc Mobile Country Code of the SIM or SIM-like entity (build prop on CDMA) */ private static void setTimezoneFromMccIfNeeded(Context context, int mcc) { TimeServiceHelper timeServiceHelper = TelephonyComponentFactory.getInstance().makeTimeServiceHelper(context); if (!timeServiceHelper.isTimeZoneSettingInitialized()) { if (!TimeServiceHelper.isTimeZoneSettingInitializedStatic()) { String zoneId = defaultTimeZoneForMcc(mcc); if (zoneId != null && zoneId.length() > 0) { // Set time zone based on MCC timeServiceHelper.setDeviceTimeZone(zoneId); TimeServiceHelper.setDeviceTimeZoneStatic(context, zoneId); Slog.d(LOG_TAG, "timezone set to " + zoneId); } } Loading src/java/com/android/internal/telephony/NitzStateMachine.java +2 −24 Original line number Diff line number Diff line Loading @@ -98,22 +98,6 @@ public class NitzStateMachine { return ignoreNitz != null && ignoreNitz.equals("yes"); } /** * Returns true if the {@code telephony.test.ignore.nitz} system property is set to * 'y', 'yes', '1', 'true' or 'on' AND the current uptime is an odd number. */ public boolean getIgnoreNitzForTests() { return SystemProperties.getBoolean(TelephonyProperties.PROPERTY_IGNORE_NITZ, false) && ((SystemClock.uptimeMillis() & 1) == 0); } /** * Sets the {@code gsm.nitz.time} system property. */ public void setNitzTimeProperty(long timeMillis) { SystemProperties.set("gsm.nitz.time", String.valueOf(timeMillis)); } /** * Returns the same value as {@link SystemClock#elapsedRealtime()}. */ Loading Loading @@ -504,7 +488,6 @@ public class NitzStateMachine { } private void saveNitzTime(long time) { mDeviceState.setNitzTimeProperty(time); mSavedTime = time; mSavedAtTime = mDeviceState.elapsedRealtime(); mNitzUpdatedTime = true; Loading Loading @@ -595,17 +578,13 @@ public class NitzStateMachine { * @param iso Country code from network MCC */ public void updateTimeZoneByNetworkCountryCode(String iso) { // Test both paths if ignore nitz for tests is true boolean testOneUniqueOffsetPath = mDeviceState.getIgnoreNitzForTests(); List<String> uniqueZoneIds = TimeUtils.getTimeZoneIdsWithUniqueOffsets(iso); if ((uniqueZoneIds.size() == 1) || testOneUniqueOffsetPath) { if (uniqueZoneIds.size() == 1) { String zoneId = uniqueZoneIds.get(0); if (DBG) { Rlog.d(LOG_TAG, "updateTimeZoneByNetworkCountryCode: no nitz but one TZ for iso-cc=" + iso + " with zone.getID=" + zoneId + " testOneUniqueOffsetPath=" + testOneUniqueOffsetPath); + " with zone.getID=" + zoneId); } mTimeZoneLog.log("updateTimeZoneByNetworkCountryCode: set time zone=" + zoneId + " iso=" + iso); Loading @@ -615,7 +594,6 @@ public class NitzStateMachine { Rlog.d(LOG_TAG, "updateTimeZoneByNetworkCountryCode: there are " + uniqueZoneIds.size() + " unique offsets for iso-cc='" + iso + " testOneUniqueOffsetPath=" + testOneUniqueOffsetPath + "', do nothing"); } } Loading src/java/com/android/internal/telephony/TimeServiceHelper.java +35 −15 Original line number Diff line number Diff line Loading @@ -94,16 +94,8 @@ public class TimeServiceHelper { * Returns true if the device has an explicit time zone set. */ public boolean isTimeZoneSettingInitialized() { // timezone.equals("GMT") will be true and only true if the timezone was // set to a default value by the system server (when starting, system server // sets the persist.sys.timezone to "GMT" if it's not set). "GMT" is not used by // any code that sets it explicitly (in case where something sets GMT explicitly, // "Etc/GMT" Olsen ID would be used). // TODO(b/64056758): Remove "timezone.equals("GMT")" hack when there's a // better way of telling if the value has been defaulted. return isTimeZoneSettingInitializedStatic(); String timeZoneId = SystemProperties.get(TIMEZONE_PROPERTY); return timeZoneId != null && timeZoneId.length() > 0 && !timeZoneId.equals("GMT"); } /** Loading Loading @@ -135,12 +127,7 @@ public class TimeServiceHelper { * @param zoneId timezone set by carrier */ public void setDeviceTimeZone(String zoneId) { AlarmManager alarm = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); alarm.setTimeZone(zoneId); Intent intent = new Intent(TelephonyIntents.ACTION_NETWORK_SET_TIMEZONE); intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); intent.putExtra("time-zone", zoneId); mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); setDeviceTimeZoneStatic(mContext, zoneId); } /** Loading @@ -156,4 +143,37 @@ public class TimeServiceHelper { intent.putExtra("time", time); mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); } /** * Static implementation of isTimeZoneSettingInitialized() for use from {@link MccTable}. This * is a hack to deflake TelephonyTests when running on a device with a real SIM: in that * situation real service events may come in while a TelephonyTest is running, leading to flakes * as the real / fake instance of TimeServiceHelper is swapped in and out from * {@link TelephonyComponentFactory}. */ static boolean isTimeZoneSettingInitializedStatic() { // timezone.equals("GMT") will be true and only true if the timezone was // set to a default value by the system server (when starting, system server // sets the persist.sys.timezone to "GMT" if it's not set). "GMT" is not used by // any code that sets it explicitly (in case where something sets GMT explicitly, // "Etc/GMT" Olsen ID would be used). // TODO(b/64056758): Remove "timezone.equals("GMT")" hack when there's a // better way of telling if the value has been defaulted. String timeZoneId = SystemProperties.get(TIMEZONE_PROPERTY); return timeZoneId != null && timeZoneId.length() > 0 && !timeZoneId.equals("GMT"); } /** * Static method for use by MccTable. See {@link #isTimeZoneSettingInitializedStatic()} for * explanation. */ static void setDeviceTimeZoneStatic(Context context, String zoneId) { AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmManager.setTimeZone(zoneId); Intent intent = new Intent(TelephonyIntents.ACTION_NETWORK_SET_TIMEZONE); intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); intent.putExtra("time-zone", zoneId); context.sendStickyBroadcastAsUser(intent, UserHandle.ALL); } } tests/telephonytests/src/com/android/internal/telephony/NitzStateMachineTest.java +0 −23 Original line number Diff line number Diff line Loading @@ -53,7 +53,6 @@ public class NitzStateMachineTest extends TelephonyTest { // Configure device state when(mDeviceState.getIgnoreNitz()).thenReturn(false); when(mDeviceState.getIgnoreNitzForTests()).thenReturn(false); when(mDeviceState.getNitzUpdateDiffMillis()).thenReturn(2000); when(mDeviceState.getNitzUpdateSpacingMillis()).thenReturn(1000 * 60 * 10); when(mDeviceState.elapsedRealtime()).thenReturn(123456789L); Loading @@ -68,7 +67,6 @@ public class NitzStateMachineTest extends TelephonyTest { // Confirm all mDeviceState side effects were verified. We don't care about retrievals of // device state. verify(mDeviceState, atLeast(0)).getIgnoreNitz(); verify(mDeviceState, atLeast(0)).getIgnoreNitzForTests(); verify(mDeviceState, atLeast(0)).getNitzUpdateDiffMillis(); verify(mDeviceState, atLeast(0)).getNitzUpdateSpacingMillis(); verify(mDeviceState, atLeast(0)).elapsedRealtime(); Loading Loading @@ -112,8 +110,6 @@ public class NitzStateMachineTest extends TelephonyTest { verifyTimeServiceTimeZoneWasSet(usNitzSignal.getTimeZoneId()); verifyTimeServiceTimeWasSet(expectedAdjustedCurrentTimeMillis); verifyNitzTimePropertyWasSet(expectedAdjustedCurrentTimeMillis); assertTrue(mNitzStateMachine.getNitzUpdatedTime()); assertEquals(usNitzSignal.getNitzData(), mNitzStateMachine.getCachedNitzData()); assertEquals(usNitzSignal.getTimeZoneId(), mNitzStateMachine.getSavedTimeZoneId()); Loading Loading @@ -147,8 +143,6 @@ public class NitzStateMachineTest extends TelephonyTest { verifyTimeServiceTimeZoneWasNotSet(); verifyTimeServiceTimeWasSet(expectedAdjustedCurrentTimeMillis); verifyNitzTimePropertyWasSet(expectedAdjustedCurrentTimeMillis); assertTrue(mNitzStateMachine.getNitzUpdatedTime()); assertEquals(usNitzSignal.getNitzData(), mNitzStateMachine.getCachedNitzData()); assertEquals(usNitzSignal.getTimeZoneId(), mNitzStateMachine.getSavedTimeZoneId()); Loading @@ -175,14 +169,9 @@ public class NitzStateMachineTest extends TelephonyTest { usNitzSignal.getNitzData(), usNitzSignal.getReceivedRealtimeMillis()); // Check resulting state and side effects. long expectedAdjustedCurrentTimeMillis = usNitzSignal.getAdjustedCurrentTimeMillis(mDeviceState.elapsedRealtime()); verifyTimeServiceTimeZoneWasSet(usNitzSignal.getTimeZoneId()); verifyTimeServiceTimeWasNotSet(); verifyNitzTimePropertyWasSet(expectedAdjustedCurrentTimeMillis); assertTrue(mNitzStateMachine.getNitzUpdatedTime()); assertEquals(usNitzSignal.getNitzData(), mNitzStateMachine.getCachedNitzData()); assertEquals(usNitzSignal.getTimeZoneId(), mNitzStateMachine.getSavedTimeZoneId()); Loading @@ -209,15 +198,9 @@ public class NitzStateMachineTest extends TelephonyTest { mNitzStateMachine.setTimeAndTimeZoneFromNitz( usNitzSignal.getNitzData(), usNitzSignal.getReceivedRealtimeMillis()); // Check resulting state and side effects. long expectedAdjustedCurrentTimeMillis = usNitzSignal.getAdjustedCurrentTimeMillis(mDeviceState.elapsedRealtime()); verifyTimeServiceTimeZoneWasNotSet(); verifyTimeServiceTimeWasNotSet(); verifyNitzTimePropertyWasSet(expectedAdjustedCurrentTimeMillis); assertTrue(mNitzStateMachine.getNitzUpdatedTime()); assertEquals(usNitzSignal.getNitzData(), mNitzStateMachine.getCachedNitzData()); assertEquals(usNitzSignal.getTimeZoneId(), mNitzStateMachine.getSavedTimeZoneId()); Loading @@ -241,12 +224,6 @@ public class NitzStateMachineTest extends TelephonyTest { assertEquals(expectedTimeMillis, (long) timeServiceTimeCaptor.getValue()); } private void verifyNitzTimePropertyWasSet(long expectedTimeMillis) { ArgumentCaptor<Long> propertyCaptor = ArgumentCaptor.forClass(Long.TYPE); verify(mDeviceState, times(1)).setNitzTimeProperty(propertyCaptor.capture()); assertEquals(expectedTimeMillis, (long) propertyCaptor.getValue()); } private void incrementSimulatedDeviceClock(int incMillis) { long currentElapsedRealtime = mDeviceState.elapsedRealtime(); when(mDeviceState.elapsedRealtime()).thenReturn(currentElapsedRealtime + incMillis); Loading tests/telephonytests/src/com/android/internal/telephony/TelephonyTest.java +22 −23 Original line number Diff line number Diff line Loading @@ -299,26 +299,6 @@ public abstract class TelephonyTest { TAG = tag; MockitoAnnotations.initMocks(this); //Use reflection to mock singletons replaceInstance(CallManager.class, "INSTANCE", null, mCallManager); replaceInstance(TelephonyComponentFactory.class, "sInstance", null, mTelephonyComponentFactory); replaceInstance(UiccController.class, "mInstance", null, mUiccController); replaceInstance(CdmaSubscriptionSourceManager.class, "sInstance", null, mCdmaSSM); replaceInstance(ImsManager.class, "sImsManagerInstances", null, mImsManagerInstances); replaceInstance(SubscriptionController.class, "sInstance", null, mSubscriptionController); replaceInstance(ProxyController.class, "sProxyController", null, mProxyController); replaceInstance(ActivityManager.class, "IActivityManagerSingleton", null, mIActivityManagerSingleton); replaceInstance(CdmaSubscriptionSourceManager.class, "mCdmaSubscriptionSourceChangedRegistrants", mCdmaSSM, mRegistrantList); replaceInstance(SimulatedCommandsVerifier.class, "sInstance", null, mSimulatedCommandsVerifier); replaceInstance(Singleton.class, "mInstance", mIActivityManagerSingleton, mIActivityManager); replaceInstance(ServiceManager.class, "sCache", null, mServiceManagerMockedServices); replaceInstance(IntentBroadcaster.class, "sIntentBroadcaster", null, mIntentBroadcaster); mSimulatedCommands = new SimulatedCommands(); mContextFixture = new ContextFixture(); mContext = mContextFixture.getTestDouble(); Loading @@ -333,9 +313,6 @@ public abstract class TelephonyTest { mEuiccManager = (EuiccManager) mContext.getSystemService(Context.EUICC_SERVICE); mPackageManager = mContext.getPackageManager(); replaceInstance(TelephonyManager.class, "sInstance", null, mContext.getSystemService(Context.TELEPHONY_SERVICE)); //mTelephonyComponentFactory doReturn(mSST).when(mTelephonyComponentFactory) .makeServiceStateTracker(nullable(GsmCdmaPhone.class), Loading Loading @@ -464,6 +441,28 @@ public abstract class TelephonyTest { //SIM doReturn(1).when(mTelephonyManager).getSimCount(); //Use reflection to mock singletons replaceInstance(CallManager.class, "INSTANCE", null, mCallManager); replaceInstance(TelephonyComponentFactory.class, "sInstance", null, mTelephonyComponentFactory); replaceInstance(UiccController.class, "mInstance", null, mUiccController); replaceInstance(CdmaSubscriptionSourceManager.class, "sInstance", null, mCdmaSSM); replaceInstance(ImsManager.class, "sImsManagerInstances", null, mImsManagerInstances); replaceInstance(SubscriptionController.class, "sInstance", null, mSubscriptionController); replaceInstance(ProxyController.class, "sProxyController", null, mProxyController); replaceInstance(ActivityManager.class, "IActivityManagerSingleton", null, mIActivityManagerSingleton); replaceInstance(CdmaSubscriptionSourceManager.class, "mCdmaSubscriptionSourceChangedRegistrants", mCdmaSSM, mRegistrantList); replaceInstance(SimulatedCommandsVerifier.class, "sInstance", null, mSimulatedCommandsVerifier); replaceInstance(Singleton.class, "mInstance", mIActivityManagerSingleton, mIActivityManager); replaceInstance(ServiceManager.class, "sCache", null, mServiceManagerMockedServices); replaceInstance(IntentBroadcaster.class, "sIntentBroadcaster", null, mIntentBroadcaster); replaceInstance(TelephonyManager.class, "sInstance", null, mContext.getSystemService(Context.TELEPHONY_SERVICE)); setReady(false); } Loading Loading
src/java/com/android/internal/telephony/MccTable.java +2 −4 Original line number Diff line number Diff line Loading @@ -358,13 +358,11 @@ public final class MccTable { * @param mcc Mobile Country Code of the SIM or SIM-like entity (build prop on CDMA) */ private static void setTimezoneFromMccIfNeeded(Context context, int mcc) { TimeServiceHelper timeServiceHelper = TelephonyComponentFactory.getInstance().makeTimeServiceHelper(context); if (!timeServiceHelper.isTimeZoneSettingInitialized()) { if (!TimeServiceHelper.isTimeZoneSettingInitializedStatic()) { String zoneId = defaultTimeZoneForMcc(mcc); if (zoneId != null && zoneId.length() > 0) { // Set time zone based on MCC timeServiceHelper.setDeviceTimeZone(zoneId); TimeServiceHelper.setDeviceTimeZoneStatic(context, zoneId); Slog.d(LOG_TAG, "timezone set to " + zoneId); } } Loading
src/java/com/android/internal/telephony/NitzStateMachine.java +2 −24 Original line number Diff line number Diff line Loading @@ -98,22 +98,6 @@ public class NitzStateMachine { return ignoreNitz != null && ignoreNitz.equals("yes"); } /** * Returns true if the {@code telephony.test.ignore.nitz} system property is set to * 'y', 'yes', '1', 'true' or 'on' AND the current uptime is an odd number. */ public boolean getIgnoreNitzForTests() { return SystemProperties.getBoolean(TelephonyProperties.PROPERTY_IGNORE_NITZ, false) && ((SystemClock.uptimeMillis() & 1) == 0); } /** * Sets the {@code gsm.nitz.time} system property. */ public void setNitzTimeProperty(long timeMillis) { SystemProperties.set("gsm.nitz.time", String.valueOf(timeMillis)); } /** * Returns the same value as {@link SystemClock#elapsedRealtime()}. */ Loading Loading @@ -504,7 +488,6 @@ public class NitzStateMachine { } private void saveNitzTime(long time) { mDeviceState.setNitzTimeProperty(time); mSavedTime = time; mSavedAtTime = mDeviceState.elapsedRealtime(); mNitzUpdatedTime = true; Loading Loading @@ -595,17 +578,13 @@ public class NitzStateMachine { * @param iso Country code from network MCC */ public void updateTimeZoneByNetworkCountryCode(String iso) { // Test both paths if ignore nitz for tests is true boolean testOneUniqueOffsetPath = mDeviceState.getIgnoreNitzForTests(); List<String> uniqueZoneIds = TimeUtils.getTimeZoneIdsWithUniqueOffsets(iso); if ((uniqueZoneIds.size() == 1) || testOneUniqueOffsetPath) { if (uniqueZoneIds.size() == 1) { String zoneId = uniqueZoneIds.get(0); if (DBG) { Rlog.d(LOG_TAG, "updateTimeZoneByNetworkCountryCode: no nitz but one TZ for iso-cc=" + iso + " with zone.getID=" + zoneId + " testOneUniqueOffsetPath=" + testOneUniqueOffsetPath); + " with zone.getID=" + zoneId); } mTimeZoneLog.log("updateTimeZoneByNetworkCountryCode: set time zone=" + zoneId + " iso=" + iso); Loading @@ -615,7 +594,6 @@ public class NitzStateMachine { Rlog.d(LOG_TAG, "updateTimeZoneByNetworkCountryCode: there are " + uniqueZoneIds.size() + " unique offsets for iso-cc='" + iso + " testOneUniqueOffsetPath=" + testOneUniqueOffsetPath + "', do nothing"); } } Loading
src/java/com/android/internal/telephony/TimeServiceHelper.java +35 −15 Original line number Diff line number Diff line Loading @@ -94,16 +94,8 @@ public class TimeServiceHelper { * Returns true if the device has an explicit time zone set. */ public boolean isTimeZoneSettingInitialized() { // timezone.equals("GMT") will be true and only true if the timezone was // set to a default value by the system server (when starting, system server // sets the persist.sys.timezone to "GMT" if it's not set). "GMT" is not used by // any code that sets it explicitly (in case where something sets GMT explicitly, // "Etc/GMT" Olsen ID would be used). // TODO(b/64056758): Remove "timezone.equals("GMT")" hack when there's a // better way of telling if the value has been defaulted. return isTimeZoneSettingInitializedStatic(); String timeZoneId = SystemProperties.get(TIMEZONE_PROPERTY); return timeZoneId != null && timeZoneId.length() > 0 && !timeZoneId.equals("GMT"); } /** Loading Loading @@ -135,12 +127,7 @@ public class TimeServiceHelper { * @param zoneId timezone set by carrier */ public void setDeviceTimeZone(String zoneId) { AlarmManager alarm = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); alarm.setTimeZone(zoneId); Intent intent = new Intent(TelephonyIntents.ACTION_NETWORK_SET_TIMEZONE); intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); intent.putExtra("time-zone", zoneId); mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); setDeviceTimeZoneStatic(mContext, zoneId); } /** Loading @@ -156,4 +143,37 @@ public class TimeServiceHelper { intent.putExtra("time", time); mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); } /** * Static implementation of isTimeZoneSettingInitialized() for use from {@link MccTable}. This * is a hack to deflake TelephonyTests when running on a device with a real SIM: in that * situation real service events may come in while a TelephonyTest is running, leading to flakes * as the real / fake instance of TimeServiceHelper is swapped in and out from * {@link TelephonyComponentFactory}. */ static boolean isTimeZoneSettingInitializedStatic() { // timezone.equals("GMT") will be true and only true if the timezone was // set to a default value by the system server (when starting, system server // sets the persist.sys.timezone to "GMT" if it's not set). "GMT" is not used by // any code that sets it explicitly (in case where something sets GMT explicitly, // "Etc/GMT" Olsen ID would be used). // TODO(b/64056758): Remove "timezone.equals("GMT")" hack when there's a // better way of telling if the value has been defaulted. String timeZoneId = SystemProperties.get(TIMEZONE_PROPERTY); return timeZoneId != null && timeZoneId.length() > 0 && !timeZoneId.equals("GMT"); } /** * Static method for use by MccTable. See {@link #isTimeZoneSettingInitializedStatic()} for * explanation. */ static void setDeviceTimeZoneStatic(Context context, String zoneId) { AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmManager.setTimeZone(zoneId); Intent intent = new Intent(TelephonyIntents.ACTION_NETWORK_SET_TIMEZONE); intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); intent.putExtra("time-zone", zoneId); context.sendStickyBroadcastAsUser(intent, UserHandle.ALL); } }
tests/telephonytests/src/com/android/internal/telephony/NitzStateMachineTest.java +0 −23 Original line number Diff line number Diff line Loading @@ -53,7 +53,6 @@ public class NitzStateMachineTest extends TelephonyTest { // Configure device state when(mDeviceState.getIgnoreNitz()).thenReturn(false); when(mDeviceState.getIgnoreNitzForTests()).thenReturn(false); when(mDeviceState.getNitzUpdateDiffMillis()).thenReturn(2000); when(mDeviceState.getNitzUpdateSpacingMillis()).thenReturn(1000 * 60 * 10); when(mDeviceState.elapsedRealtime()).thenReturn(123456789L); Loading @@ -68,7 +67,6 @@ public class NitzStateMachineTest extends TelephonyTest { // Confirm all mDeviceState side effects were verified. We don't care about retrievals of // device state. verify(mDeviceState, atLeast(0)).getIgnoreNitz(); verify(mDeviceState, atLeast(0)).getIgnoreNitzForTests(); verify(mDeviceState, atLeast(0)).getNitzUpdateDiffMillis(); verify(mDeviceState, atLeast(0)).getNitzUpdateSpacingMillis(); verify(mDeviceState, atLeast(0)).elapsedRealtime(); Loading Loading @@ -112,8 +110,6 @@ public class NitzStateMachineTest extends TelephonyTest { verifyTimeServiceTimeZoneWasSet(usNitzSignal.getTimeZoneId()); verifyTimeServiceTimeWasSet(expectedAdjustedCurrentTimeMillis); verifyNitzTimePropertyWasSet(expectedAdjustedCurrentTimeMillis); assertTrue(mNitzStateMachine.getNitzUpdatedTime()); assertEquals(usNitzSignal.getNitzData(), mNitzStateMachine.getCachedNitzData()); assertEquals(usNitzSignal.getTimeZoneId(), mNitzStateMachine.getSavedTimeZoneId()); Loading Loading @@ -147,8 +143,6 @@ public class NitzStateMachineTest extends TelephonyTest { verifyTimeServiceTimeZoneWasNotSet(); verifyTimeServiceTimeWasSet(expectedAdjustedCurrentTimeMillis); verifyNitzTimePropertyWasSet(expectedAdjustedCurrentTimeMillis); assertTrue(mNitzStateMachine.getNitzUpdatedTime()); assertEquals(usNitzSignal.getNitzData(), mNitzStateMachine.getCachedNitzData()); assertEquals(usNitzSignal.getTimeZoneId(), mNitzStateMachine.getSavedTimeZoneId()); Loading @@ -175,14 +169,9 @@ public class NitzStateMachineTest extends TelephonyTest { usNitzSignal.getNitzData(), usNitzSignal.getReceivedRealtimeMillis()); // Check resulting state and side effects. long expectedAdjustedCurrentTimeMillis = usNitzSignal.getAdjustedCurrentTimeMillis(mDeviceState.elapsedRealtime()); verifyTimeServiceTimeZoneWasSet(usNitzSignal.getTimeZoneId()); verifyTimeServiceTimeWasNotSet(); verifyNitzTimePropertyWasSet(expectedAdjustedCurrentTimeMillis); assertTrue(mNitzStateMachine.getNitzUpdatedTime()); assertEquals(usNitzSignal.getNitzData(), mNitzStateMachine.getCachedNitzData()); assertEquals(usNitzSignal.getTimeZoneId(), mNitzStateMachine.getSavedTimeZoneId()); Loading @@ -209,15 +198,9 @@ public class NitzStateMachineTest extends TelephonyTest { mNitzStateMachine.setTimeAndTimeZoneFromNitz( usNitzSignal.getNitzData(), usNitzSignal.getReceivedRealtimeMillis()); // Check resulting state and side effects. long expectedAdjustedCurrentTimeMillis = usNitzSignal.getAdjustedCurrentTimeMillis(mDeviceState.elapsedRealtime()); verifyTimeServiceTimeZoneWasNotSet(); verifyTimeServiceTimeWasNotSet(); verifyNitzTimePropertyWasSet(expectedAdjustedCurrentTimeMillis); assertTrue(mNitzStateMachine.getNitzUpdatedTime()); assertEquals(usNitzSignal.getNitzData(), mNitzStateMachine.getCachedNitzData()); assertEquals(usNitzSignal.getTimeZoneId(), mNitzStateMachine.getSavedTimeZoneId()); Loading @@ -241,12 +224,6 @@ public class NitzStateMachineTest extends TelephonyTest { assertEquals(expectedTimeMillis, (long) timeServiceTimeCaptor.getValue()); } private void verifyNitzTimePropertyWasSet(long expectedTimeMillis) { ArgumentCaptor<Long> propertyCaptor = ArgumentCaptor.forClass(Long.TYPE); verify(mDeviceState, times(1)).setNitzTimeProperty(propertyCaptor.capture()); assertEquals(expectedTimeMillis, (long) propertyCaptor.getValue()); } private void incrementSimulatedDeviceClock(int incMillis) { long currentElapsedRealtime = mDeviceState.elapsedRealtime(); when(mDeviceState.elapsedRealtime()).thenReturn(currentElapsedRealtime + incMillis); Loading
tests/telephonytests/src/com/android/internal/telephony/TelephonyTest.java +22 −23 Original line number Diff line number Diff line Loading @@ -299,26 +299,6 @@ public abstract class TelephonyTest { TAG = tag; MockitoAnnotations.initMocks(this); //Use reflection to mock singletons replaceInstance(CallManager.class, "INSTANCE", null, mCallManager); replaceInstance(TelephonyComponentFactory.class, "sInstance", null, mTelephonyComponentFactory); replaceInstance(UiccController.class, "mInstance", null, mUiccController); replaceInstance(CdmaSubscriptionSourceManager.class, "sInstance", null, mCdmaSSM); replaceInstance(ImsManager.class, "sImsManagerInstances", null, mImsManagerInstances); replaceInstance(SubscriptionController.class, "sInstance", null, mSubscriptionController); replaceInstance(ProxyController.class, "sProxyController", null, mProxyController); replaceInstance(ActivityManager.class, "IActivityManagerSingleton", null, mIActivityManagerSingleton); replaceInstance(CdmaSubscriptionSourceManager.class, "mCdmaSubscriptionSourceChangedRegistrants", mCdmaSSM, mRegistrantList); replaceInstance(SimulatedCommandsVerifier.class, "sInstance", null, mSimulatedCommandsVerifier); replaceInstance(Singleton.class, "mInstance", mIActivityManagerSingleton, mIActivityManager); replaceInstance(ServiceManager.class, "sCache", null, mServiceManagerMockedServices); replaceInstance(IntentBroadcaster.class, "sIntentBroadcaster", null, mIntentBroadcaster); mSimulatedCommands = new SimulatedCommands(); mContextFixture = new ContextFixture(); mContext = mContextFixture.getTestDouble(); Loading @@ -333,9 +313,6 @@ public abstract class TelephonyTest { mEuiccManager = (EuiccManager) mContext.getSystemService(Context.EUICC_SERVICE); mPackageManager = mContext.getPackageManager(); replaceInstance(TelephonyManager.class, "sInstance", null, mContext.getSystemService(Context.TELEPHONY_SERVICE)); //mTelephonyComponentFactory doReturn(mSST).when(mTelephonyComponentFactory) .makeServiceStateTracker(nullable(GsmCdmaPhone.class), Loading Loading @@ -464,6 +441,28 @@ public abstract class TelephonyTest { //SIM doReturn(1).when(mTelephonyManager).getSimCount(); //Use reflection to mock singletons replaceInstance(CallManager.class, "INSTANCE", null, mCallManager); replaceInstance(TelephonyComponentFactory.class, "sInstance", null, mTelephonyComponentFactory); replaceInstance(UiccController.class, "mInstance", null, mUiccController); replaceInstance(CdmaSubscriptionSourceManager.class, "sInstance", null, mCdmaSSM); replaceInstance(ImsManager.class, "sImsManagerInstances", null, mImsManagerInstances); replaceInstance(SubscriptionController.class, "sInstance", null, mSubscriptionController); replaceInstance(ProxyController.class, "sProxyController", null, mProxyController); replaceInstance(ActivityManager.class, "IActivityManagerSingleton", null, mIActivityManagerSingleton); replaceInstance(CdmaSubscriptionSourceManager.class, "mCdmaSubscriptionSourceChangedRegistrants", mCdmaSSM, mRegistrantList); replaceInstance(SimulatedCommandsVerifier.class, "sInstance", null, mSimulatedCommandsVerifier); replaceInstance(Singleton.class, "mInstance", mIActivityManagerSingleton, mIActivityManager); replaceInstance(ServiceManager.class, "sCache", null, mServiceManagerMockedServices); replaceInstance(IntentBroadcaster.class, "sIntentBroadcaster", null, mIntentBroadcaster); replaceInstance(TelephonyManager.class, "sInstance", null, mContext.getSystemService(Context.TELEPHONY_SERVICE)); setReady(false); } Loading