Loading src/java/com/android/internal/telephony/nitz/NitzStateMachineImpl.java +10 −10 Original line number Diff line number Diff line Loading @@ -104,7 +104,7 @@ public final class NitzStateMachineImpl implements NitzStateMachine { */ private final TimeZoneSuggester mTimeZoneSuggester; /** A facade to the time / time zone detection services. */ private final NewTimeServiceHelper mNewTimeServiceHelper; private final TimeServiceHelper mTimeServiceHelper; // Shared detection state. Loading Loading @@ -136,7 +136,7 @@ public final class NitzStateMachineImpl implements NitzStateMachine { TimeZoneLookupHelper timeZoneLookupHelper = new TimeZoneLookupHelper(); TimeZoneSuggester timeZoneSuggester = new TimeZoneSuggesterImpl(deviceState, timeZoneLookupHelper); NewTimeServiceHelper newTimeServiceHelper = new NewTimeServiceHelperImpl(phone); TimeServiceHelper newTimeServiceHelper = new TimeServiceHelperImpl(phone); NitzSignalInputFilterPredicate nitzSignalFilter = NitzSignalInputFilterPredicateFactory.create(phone.getContext(), deviceState); return new NitzStateMachineImpl( Loading @@ -151,10 +151,10 @@ public final class NitzStateMachineImpl implements NitzStateMachine { public NitzStateMachineImpl(int slotIndex, @NonNull NitzSignalInputFilterPredicate nitzSignalInputFilter, @NonNull TimeZoneSuggester timeZoneSuggester, @NonNull NewTimeServiceHelper newTimeServiceHelper) { @NonNull TimeServiceHelper newTimeServiceHelper) { mSlotIndex = slotIndex; mTimeZoneSuggester = Objects.requireNonNull(timeZoneSuggester); mNewTimeServiceHelper = Objects.requireNonNull(newTimeServiceHelper); mTimeServiceHelper = Objects.requireNonNull(newTimeServiceHelper); mNitzSignalInputFilter = Objects.requireNonNull(nitzSignalInputFilter); } Loading Loading @@ -292,7 +292,7 @@ public final class NitzStateMachineImpl implements NitzStateMachine { + ", nitzSignal=" + nitzSignal + ", suggestion=" + suggestion + ", reason=" + reason); } mNewTimeServiceHelper.maybeSuggestDeviceTimeZone(suggestion); mTimeServiceHelper.maybeSuggestDeviceTimeZone(suggestion); } catch (RuntimeException ex) { Rlog.e(LOG_TAG, "doTimeZoneDetection: Exception thrown" + " mSlotIndex=" + mSlotIndex Loading Loading @@ -325,7 +325,7 @@ public final class NitzStateMachineImpl implements NitzStateMachine { + " nitzSignal=" + nitzSignal + ", reason=" + reason); } mNewTimeServiceHelper.suggestDeviceTime(builder.build()); mTimeServiceHelper.suggestDeviceTime(builder.build()); } catch (RuntimeException ex) { Rlog.e(LOG_TAG, "doTimeDetection: Exception thrown" + " mSlotIndex=" + mSlotIndex Loading @@ -337,15 +337,15 @@ public final class NitzStateMachineImpl implements NitzStateMachine { @Override public void dumpState(PrintWriter pw) { pw.println(" NewNitzStateMachineImpl.mLatestNitzSignal=" + mLatestNitzSignal); pw.println(" NewNitzStateMachineImpl.mCountryIsoCode=" + mCountryIsoCode); mNewTimeServiceHelper.dumpState(pw); pw.println(" NitzStateMachineImpl.mLatestNitzSignal=" + mLatestNitzSignal); pw.println(" NitzStateMachineImpl.mCountryIsoCode=" + mCountryIsoCode); mTimeServiceHelper.dumpState(pw); pw.flush(); } @Override public void dumpLogs(FileDescriptor fd, IndentingPrintWriter ipw, String[] args) { mNewTimeServiceHelper.dumpLogs(ipw); mTimeServiceHelper.dumpLogs(ipw); } @Nullable Loading src/java/com/android/internal/telephony/nitz/NewTimeServiceHelper.java→src/java/com/android/internal/telephony/nitz/TimeServiceHelper.java +10 −8 Original line number Diff line number Diff line Loading @@ -18,34 +18,36 @@ package com.android.internal.telephony.nitz; import android.annotation.NonNull; import android.app.timedetector.TelephonyTimeSuggestion; import android.app.timedetector.TimeDetector; import android.app.timezonedetector.TelephonyTimeZoneSuggestion; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.util.IndentingPrintWriter; import java.io.PrintWriter; /** * An interface to various time / time zone detection behaviors that should be centralized into * new services. * An interface to various time / time zone detection behaviors that are centralized into services. * This interface exists to separate out behavior to enable easier testing of the * {@link NitzStateMachineImpl}. */ public interface NewTimeServiceHelper { @VisibleForTesting public interface TimeServiceHelper { /** * Suggests the time to the {@link TimeDetector}. * Suggests the time to the time detector service. * * @param suggestion the time * @param suggestion the time suggestion */ void suggestDeviceTime(@NonNull TelephonyTimeSuggestion suggestion); /** * Suggests the time zone to the time zone detector. * Suggests the time zone to the time zone detector service. * * <p>NOTE: The {@link TelephonyTimeZoneSuggestion} cannot be null. The zoneId it contains can * be null to indicate there is no active suggestion; this can be used to clear a previous * suggestion. * * @param suggestion the time zone * @param suggestion the time zone suggestion */ void maybeSuggestDeviceTimeZone(@NonNull TelephonyTimeZoneSuggestion suggestion); Loading src/java/com/android/internal/telephony/nitz/NewTimeServiceHelperImpl.java→src/java/com/android/internal/telephony/nitz/TimeServiceHelperImpl.java +9 −5 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.app.timedetector.TimeDetector; import android.app.timezonedetector.TelephonyTimeZoneSuggestion; import android.app.timezonedetector.TimeZoneDetector; import android.content.Context; import android.os.SystemClock; import android.os.TimestampedValue; import android.util.LocalLog; Loading @@ -34,9 +35,9 @@ import java.io.PrintWriter; import java.util.Objects; /** * The real implementation of {@link NewTimeServiceHelper}. * The real implementation of {@link TimeServiceHelper}. */ public final class NewTimeServiceHelperImpl implements NewTimeServiceHelper { public final class TimeServiceHelperImpl implements TimeServiceHelper { private final int mSlotIndex; private final TimeDetector mTimeDetector; Loading @@ -53,7 +54,7 @@ public final class NewTimeServiceHelperImpl implements NewTimeServiceHelper { @NonNull private TelephonyTimeZoneSuggestion mLastSuggestedTimeZone; public NewTimeServiceHelperImpl(@NonNull Phone phone) { public TimeServiceHelperImpl(@NonNull Phone phone) { mSlotIndex = phone.getPhoneId(); Context context = Objects.requireNonNull(phone.getContext()); mTimeDetector = Objects.requireNonNull(context.getSystemService(TimeDetector.class)); Loading Loading @@ -99,8 +100,11 @@ public final class NewTimeServiceHelperImpl implements NewTimeServiceHelper { @Override public void dumpLogs(IndentingPrintWriter ipw) { ipw.println("NewTimeServiceHelperImpl:"); ipw.println("TimeServiceHelperImpl:"); ipw.increaseIndent(); ipw.println("SystemClock.elapsedRealtime()=" + SystemClock.elapsedRealtime()); ipw.println("System.currentTimeMillis()=" + System.currentTimeMillis()); ipw.println("Time Logs:"); ipw.increaseIndent(); mTimeLog.dump(ipw); Loading @@ -115,6 +119,6 @@ public final class NewTimeServiceHelperImpl implements NewTimeServiceHelper { @Override public void dumpState(PrintWriter pw) { pw.println(" NewTimeServiceHelperImpl.mLastSuggestedTimeZone=" + mLastSuggestedTimeZone); pw.println(" TimeServiceHelperImpl.mLastSuggestedTimeZone=" + mLastSuggestedTimeZone); } } tests/telephonytests/src/com/android/internal/telephony/nitz/NitzStateMachineImplTest.java +14 −14 Original line number Diff line number Diff line Loading @@ -60,7 +60,7 @@ public class NitzStateMachineImplTest extends TelephonyTest { private static final TelephonyTimeSuggestion EMPTY_TIME_SUGGESTION = createEmptyTimeSuggestion(SLOT_INDEX); private FakeNewTimeServiceHelper mFakeNewTimeServiceHelper; private FakeTimeServiceHelper mFakeTimeServiceHelper; private FakeDeviceState mFakeDeviceState; private TimeZoneSuggesterImpl mRealTimeZoneSuggester; Loading @@ -69,12 +69,12 @@ public class NitzStateMachineImplTest extends TelephonyTest { @Before public void setUp() throws Exception { TelephonyTest.logd("NewNitzStateMachineImplTest +Setup!"); super.setUp("NewNitzStateMachineImplTest"); TelephonyTest.logd("NitzStateMachineImplTest +Setup!"); super.setUp("NitzStateMachineImplTest"); // In tests we use a fake impls for NewTimeServiceHelper and DeviceState. mFakeDeviceState = new FakeDeviceState(); mFakeNewTimeServiceHelper = new FakeNewTimeServiceHelper(mFakeDeviceState); mFakeTimeServiceHelper = new FakeTimeServiceHelper(mFakeDeviceState); // In tests we disable NITZ signal input filtering. The real NITZ signal filter is tested // independently. This makes constructing test data simpler: we can be sure the signals Loading @@ -91,7 +91,7 @@ public class NitzStateMachineImplTest extends TelephonyTest { mNitzStateMachineImpl = new NitzStateMachineImpl( SLOT_INDEX, mFakeNitzSignalInputFilter, mRealTimeZoneSuggester, mFakeNewTimeServiceHelper); mFakeTimeServiceHelper); TelephonyTest.logd("NewNitzStateMachineImplTest -Setup!"); } Loading Loading @@ -574,22 +574,22 @@ public class NitzStateMachineImplTest extends TelephonyTest { } private void justVerifyTimeWasNotSuggested() { mFakeNewTimeServiceHelper.suggestedTimes.assertHasNotBeenSet(); mFakeTimeServiceHelper.suggestedTimes.assertHasNotBeenSet(); } private void justVerifyTimeZoneWasSuggested( TelephonyTimeZoneSuggestion timeZoneSuggestion) { mFakeNewTimeServiceHelper.suggestedTimeZones.assertHasBeenSet(); mFakeNewTimeServiceHelper.suggestedTimeZones.assertLatestEquals(timeZoneSuggestion); mFakeTimeServiceHelper.suggestedTimeZones.assertHasBeenSet(); mFakeTimeServiceHelper.suggestedTimeZones.assertLatestEquals(timeZoneSuggestion); } private void justVerifyTimeWasSuggested(TelephonyTimeSuggestion timeSuggestion) { mFakeNewTimeServiceHelper.suggestedTimes.assertChangeCount(1); mFakeNewTimeServiceHelper.suggestedTimes.assertLatestEquals(timeSuggestion); mFakeTimeServiceHelper.suggestedTimes.assertChangeCount(1); mFakeTimeServiceHelper.suggestedTimes.assertLatestEquals(timeSuggestion); } private void commitStateChanges() { mFakeNewTimeServiceHelper.commitState(); mFakeTimeServiceHelper.commitState(); } } Loading Loading @@ -643,10 +643,10 @@ public class NitzStateMachineImplTest extends TelephonyTest { } /** * A fake implementation of {@link NewTimeServiceHelper} that enables tests to detect what * A fake implementation of {@link TimeServiceHelper} that enables tests to detect what * {@link NitzStateMachineImpl} would do to a real device's state. */ private static class FakeNewTimeServiceHelper implements NewTimeServiceHelper { private static class FakeTimeServiceHelper implements TimeServiceHelper { private final FakeDeviceState mFakeDeviceState; Loading @@ -654,7 +654,7 @@ public class NitzStateMachineImplTest extends TelephonyTest { public final TestState<TelephonyTimeSuggestion> suggestedTimes = new TestState<>(); public final TestState<TelephonyTimeZoneSuggestion> suggestedTimeZones = new TestState<>(); FakeNewTimeServiceHelper(FakeDeviceState fakeDeviceState) { FakeTimeServiceHelper(FakeDeviceState fakeDeviceState) { mFakeDeviceState = fakeDeviceState; } Loading Loading
src/java/com/android/internal/telephony/nitz/NitzStateMachineImpl.java +10 −10 Original line number Diff line number Diff line Loading @@ -104,7 +104,7 @@ public final class NitzStateMachineImpl implements NitzStateMachine { */ private final TimeZoneSuggester mTimeZoneSuggester; /** A facade to the time / time zone detection services. */ private final NewTimeServiceHelper mNewTimeServiceHelper; private final TimeServiceHelper mTimeServiceHelper; // Shared detection state. Loading Loading @@ -136,7 +136,7 @@ public final class NitzStateMachineImpl implements NitzStateMachine { TimeZoneLookupHelper timeZoneLookupHelper = new TimeZoneLookupHelper(); TimeZoneSuggester timeZoneSuggester = new TimeZoneSuggesterImpl(deviceState, timeZoneLookupHelper); NewTimeServiceHelper newTimeServiceHelper = new NewTimeServiceHelperImpl(phone); TimeServiceHelper newTimeServiceHelper = new TimeServiceHelperImpl(phone); NitzSignalInputFilterPredicate nitzSignalFilter = NitzSignalInputFilterPredicateFactory.create(phone.getContext(), deviceState); return new NitzStateMachineImpl( Loading @@ -151,10 +151,10 @@ public final class NitzStateMachineImpl implements NitzStateMachine { public NitzStateMachineImpl(int slotIndex, @NonNull NitzSignalInputFilterPredicate nitzSignalInputFilter, @NonNull TimeZoneSuggester timeZoneSuggester, @NonNull NewTimeServiceHelper newTimeServiceHelper) { @NonNull TimeServiceHelper newTimeServiceHelper) { mSlotIndex = slotIndex; mTimeZoneSuggester = Objects.requireNonNull(timeZoneSuggester); mNewTimeServiceHelper = Objects.requireNonNull(newTimeServiceHelper); mTimeServiceHelper = Objects.requireNonNull(newTimeServiceHelper); mNitzSignalInputFilter = Objects.requireNonNull(nitzSignalInputFilter); } Loading Loading @@ -292,7 +292,7 @@ public final class NitzStateMachineImpl implements NitzStateMachine { + ", nitzSignal=" + nitzSignal + ", suggestion=" + suggestion + ", reason=" + reason); } mNewTimeServiceHelper.maybeSuggestDeviceTimeZone(suggestion); mTimeServiceHelper.maybeSuggestDeviceTimeZone(suggestion); } catch (RuntimeException ex) { Rlog.e(LOG_TAG, "doTimeZoneDetection: Exception thrown" + " mSlotIndex=" + mSlotIndex Loading Loading @@ -325,7 +325,7 @@ public final class NitzStateMachineImpl implements NitzStateMachine { + " nitzSignal=" + nitzSignal + ", reason=" + reason); } mNewTimeServiceHelper.suggestDeviceTime(builder.build()); mTimeServiceHelper.suggestDeviceTime(builder.build()); } catch (RuntimeException ex) { Rlog.e(LOG_TAG, "doTimeDetection: Exception thrown" + " mSlotIndex=" + mSlotIndex Loading @@ -337,15 +337,15 @@ public final class NitzStateMachineImpl implements NitzStateMachine { @Override public void dumpState(PrintWriter pw) { pw.println(" NewNitzStateMachineImpl.mLatestNitzSignal=" + mLatestNitzSignal); pw.println(" NewNitzStateMachineImpl.mCountryIsoCode=" + mCountryIsoCode); mNewTimeServiceHelper.dumpState(pw); pw.println(" NitzStateMachineImpl.mLatestNitzSignal=" + mLatestNitzSignal); pw.println(" NitzStateMachineImpl.mCountryIsoCode=" + mCountryIsoCode); mTimeServiceHelper.dumpState(pw); pw.flush(); } @Override public void dumpLogs(FileDescriptor fd, IndentingPrintWriter ipw, String[] args) { mNewTimeServiceHelper.dumpLogs(ipw); mTimeServiceHelper.dumpLogs(ipw); } @Nullable Loading
src/java/com/android/internal/telephony/nitz/NewTimeServiceHelper.java→src/java/com/android/internal/telephony/nitz/TimeServiceHelper.java +10 −8 Original line number Diff line number Diff line Loading @@ -18,34 +18,36 @@ package com.android.internal.telephony.nitz; import android.annotation.NonNull; import android.app.timedetector.TelephonyTimeSuggestion; import android.app.timedetector.TimeDetector; import android.app.timezonedetector.TelephonyTimeZoneSuggestion; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.util.IndentingPrintWriter; import java.io.PrintWriter; /** * An interface to various time / time zone detection behaviors that should be centralized into * new services. * An interface to various time / time zone detection behaviors that are centralized into services. * This interface exists to separate out behavior to enable easier testing of the * {@link NitzStateMachineImpl}. */ public interface NewTimeServiceHelper { @VisibleForTesting public interface TimeServiceHelper { /** * Suggests the time to the {@link TimeDetector}. * Suggests the time to the time detector service. * * @param suggestion the time * @param suggestion the time suggestion */ void suggestDeviceTime(@NonNull TelephonyTimeSuggestion suggestion); /** * Suggests the time zone to the time zone detector. * Suggests the time zone to the time zone detector service. * * <p>NOTE: The {@link TelephonyTimeZoneSuggestion} cannot be null. The zoneId it contains can * be null to indicate there is no active suggestion; this can be used to clear a previous * suggestion. * * @param suggestion the time zone * @param suggestion the time zone suggestion */ void maybeSuggestDeviceTimeZone(@NonNull TelephonyTimeZoneSuggestion suggestion); Loading
src/java/com/android/internal/telephony/nitz/NewTimeServiceHelperImpl.java→src/java/com/android/internal/telephony/nitz/TimeServiceHelperImpl.java +9 −5 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.app.timedetector.TimeDetector; import android.app.timezonedetector.TelephonyTimeZoneSuggestion; import android.app.timezonedetector.TimeZoneDetector; import android.content.Context; import android.os.SystemClock; import android.os.TimestampedValue; import android.util.LocalLog; Loading @@ -34,9 +35,9 @@ import java.io.PrintWriter; import java.util.Objects; /** * The real implementation of {@link NewTimeServiceHelper}. * The real implementation of {@link TimeServiceHelper}. */ public final class NewTimeServiceHelperImpl implements NewTimeServiceHelper { public final class TimeServiceHelperImpl implements TimeServiceHelper { private final int mSlotIndex; private final TimeDetector mTimeDetector; Loading @@ -53,7 +54,7 @@ public final class NewTimeServiceHelperImpl implements NewTimeServiceHelper { @NonNull private TelephonyTimeZoneSuggestion mLastSuggestedTimeZone; public NewTimeServiceHelperImpl(@NonNull Phone phone) { public TimeServiceHelperImpl(@NonNull Phone phone) { mSlotIndex = phone.getPhoneId(); Context context = Objects.requireNonNull(phone.getContext()); mTimeDetector = Objects.requireNonNull(context.getSystemService(TimeDetector.class)); Loading Loading @@ -99,8 +100,11 @@ public final class NewTimeServiceHelperImpl implements NewTimeServiceHelper { @Override public void dumpLogs(IndentingPrintWriter ipw) { ipw.println("NewTimeServiceHelperImpl:"); ipw.println("TimeServiceHelperImpl:"); ipw.increaseIndent(); ipw.println("SystemClock.elapsedRealtime()=" + SystemClock.elapsedRealtime()); ipw.println("System.currentTimeMillis()=" + System.currentTimeMillis()); ipw.println("Time Logs:"); ipw.increaseIndent(); mTimeLog.dump(ipw); Loading @@ -115,6 +119,6 @@ public final class NewTimeServiceHelperImpl implements NewTimeServiceHelper { @Override public void dumpState(PrintWriter pw) { pw.println(" NewTimeServiceHelperImpl.mLastSuggestedTimeZone=" + mLastSuggestedTimeZone); pw.println(" TimeServiceHelperImpl.mLastSuggestedTimeZone=" + mLastSuggestedTimeZone); } }
tests/telephonytests/src/com/android/internal/telephony/nitz/NitzStateMachineImplTest.java +14 −14 Original line number Diff line number Diff line Loading @@ -60,7 +60,7 @@ public class NitzStateMachineImplTest extends TelephonyTest { private static final TelephonyTimeSuggestion EMPTY_TIME_SUGGESTION = createEmptyTimeSuggestion(SLOT_INDEX); private FakeNewTimeServiceHelper mFakeNewTimeServiceHelper; private FakeTimeServiceHelper mFakeTimeServiceHelper; private FakeDeviceState mFakeDeviceState; private TimeZoneSuggesterImpl mRealTimeZoneSuggester; Loading @@ -69,12 +69,12 @@ public class NitzStateMachineImplTest extends TelephonyTest { @Before public void setUp() throws Exception { TelephonyTest.logd("NewNitzStateMachineImplTest +Setup!"); super.setUp("NewNitzStateMachineImplTest"); TelephonyTest.logd("NitzStateMachineImplTest +Setup!"); super.setUp("NitzStateMachineImplTest"); // In tests we use a fake impls for NewTimeServiceHelper and DeviceState. mFakeDeviceState = new FakeDeviceState(); mFakeNewTimeServiceHelper = new FakeNewTimeServiceHelper(mFakeDeviceState); mFakeTimeServiceHelper = new FakeTimeServiceHelper(mFakeDeviceState); // In tests we disable NITZ signal input filtering. The real NITZ signal filter is tested // independently. This makes constructing test data simpler: we can be sure the signals Loading @@ -91,7 +91,7 @@ public class NitzStateMachineImplTest extends TelephonyTest { mNitzStateMachineImpl = new NitzStateMachineImpl( SLOT_INDEX, mFakeNitzSignalInputFilter, mRealTimeZoneSuggester, mFakeNewTimeServiceHelper); mFakeTimeServiceHelper); TelephonyTest.logd("NewNitzStateMachineImplTest -Setup!"); } Loading Loading @@ -574,22 +574,22 @@ public class NitzStateMachineImplTest extends TelephonyTest { } private void justVerifyTimeWasNotSuggested() { mFakeNewTimeServiceHelper.suggestedTimes.assertHasNotBeenSet(); mFakeTimeServiceHelper.suggestedTimes.assertHasNotBeenSet(); } private void justVerifyTimeZoneWasSuggested( TelephonyTimeZoneSuggestion timeZoneSuggestion) { mFakeNewTimeServiceHelper.suggestedTimeZones.assertHasBeenSet(); mFakeNewTimeServiceHelper.suggestedTimeZones.assertLatestEquals(timeZoneSuggestion); mFakeTimeServiceHelper.suggestedTimeZones.assertHasBeenSet(); mFakeTimeServiceHelper.suggestedTimeZones.assertLatestEquals(timeZoneSuggestion); } private void justVerifyTimeWasSuggested(TelephonyTimeSuggestion timeSuggestion) { mFakeNewTimeServiceHelper.suggestedTimes.assertChangeCount(1); mFakeNewTimeServiceHelper.suggestedTimes.assertLatestEquals(timeSuggestion); mFakeTimeServiceHelper.suggestedTimes.assertChangeCount(1); mFakeTimeServiceHelper.suggestedTimes.assertLatestEquals(timeSuggestion); } private void commitStateChanges() { mFakeNewTimeServiceHelper.commitState(); mFakeTimeServiceHelper.commitState(); } } Loading Loading @@ -643,10 +643,10 @@ public class NitzStateMachineImplTest extends TelephonyTest { } /** * A fake implementation of {@link NewTimeServiceHelper} that enables tests to detect what * A fake implementation of {@link TimeServiceHelper} that enables tests to detect what * {@link NitzStateMachineImpl} would do to a real device's state. */ private static class FakeNewTimeServiceHelper implements NewTimeServiceHelper { private static class FakeTimeServiceHelper implements TimeServiceHelper { private final FakeDeviceState mFakeDeviceState; Loading @@ -654,7 +654,7 @@ public class NitzStateMachineImplTest extends TelephonyTest { public final TestState<TelephonyTimeSuggestion> suggestedTimes = new TestState<>(); public final TestState<TelephonyTimeZoneSuggestion> suggestedTimeZones = new TestState<>(); FakeNewTimeServiceHelper(FakeDeviceState fakeDeviceState) { FakeTimeServiceHelper(FakeDeviceState fakeDeviceState) { mFakeDeviceState = fakeDeviceState; } Loading