Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fb71cac5 authored by Neil Fuller's avatar Neil Fuller
Browse files

Move currentTimeMillis() method to DeviceState

This moves the currentTimeMillis() method from TimeServiceHelper into
DeviceState: currentTimeMillis() is a method that will be used by both
NitzStateMachineImpl and the upcoming NewNitzStateMachineImpl and moving
it to NitzStateMachine.DeviceState means less duplication as it is
shared between both impls. TimeServiceHelper will not be used by
NewNitzStateMachineImpl.

Bug: 140712361
Test: treehugger
Change-Id: I375622be44bd8656b47b3602237ae6718fe8de92
parent 12ecd7e5
Loading
Loading
Loading
Loading
+10 −0
Original line number Original line Diff line number Diff line
@@ -112,6 +112,11 @@ public interface NitzStateMachine {
         * Returns the same value as {@link SystemClock#elapsedRealtime()}.
         * Returns the same value as {@link SystemClock#elapsedRealtime()}.
         */
         */
        long elapsedRealtime();
        long elapsedRealtime();

        /**
         * Returns the same value as {@link System#currentTimeMillis()}.
         */
        long currentTimeMillis();
    }
    }


    /**
    /**
@@ -169,5 +174,10 @@ public interface NitzStateMachine {
        public long elapsedRealtime() {
        public long elapsedRealtime() {
            return SystemClock.elapsedRealtime();
            return SystemClock.elapsedRealtime();
        }
        }

        @Override
        public long currentTimeMillis() {
            return System.currentTimeMillis();
        }
    }
    }
}
}
+1 −1
Original line number Original line Diff line number Diff line
@@ -493,7 +493,7 @@ public final class NitzStateMachineImpl implements NitzStateMachine {
     */
     */
    private void updateTimeZoneFromNetworkCountryCode(String iso) {
    private void updateTimeZoneFromNetworkCountryCode(String iso) {
        CountryResult lookupResult = mTimeZoneLookupHelper.lookupByCountry(
        CountryResult lookupResult = mTimeZoneLookupHelper.lookupByCountry(
                iso, mTimeServiceHelper.currentTimeMillis());
                iso, mDeviceState.currentTimeMillis());
        if (lookupResult != null && lookupResult.allZonesHaveSameOffset) {
        if (lookupResult != null && lookupResult.allZonesHaveSameOffset) {
            String logMsg = "updateTimeZoneFromNetworkCountryCode: tz result found"
            String logMsg = "updateTimeZoneFromNetworkCountryCode: tz result found"
                    + " iso=" + iso
                    + " iso=" + iso
+0 −5
Original line number Original line Diff line number Diff line
@@ -41,11 +41,6 @@ public interface TimeServiceHelper {
     */
     */
    void setListener(Listener listener);
    void setListener(Listener listener);


    /**
     * Returns the same value as {@link System#currentTimeMillis()}.
     */
    long currentTimeMillis();

    /**
    /**
     * Returns true if the device has an explicit time zone set.
     * Returns true if the device has an explicit time zone set.
     */
     */
+0 −5
Original line number Original line Diff line number Diff line
@@ -68,11 +68,6 @@ public final class TimeServiceHelperImpl implements TimeServiceHelper {
                });
                });
    }
    }


    @Override
    public long currentTimeMillis() {
        return System.currentTimeMillis();
    }

    @Override
    @Override
    public boolean isTimeZoneSettingInitialized() {
    public boolean isTimeZoneSettingInitialized() {
        return isTimeZoneSettingInitializedStatic();
        return isTimeZoneSettingInitializedStatic();
+9 −9
Original line number Original line Diff line number Diff line
@@ -88,8 +88,8 @@ public class NitzStateMachineImplTest extends TelephonyTest {
        super.setUp("NitzStateMachineTest");
        super.setUp("NitzStateMachineTest");


        // In tests we use a fake impls for TimeServiceHelper and DeviceState.
        // In tests we use a fake impls for TimeServiceHelper and DeviceState.
        mFakeTimeServiceHelper = new FakeTimeServiceHelper();
        mFakeDeviceState = new FakeDeviceState();
        mFakeDeviceState = new FakeDeviceState();
        mFakeTimeServiceHelper = new FakeTimeServiceHelper(mFakeDeviceState);


        // In tests we use the real TimeZoneLookupHelper.
        // In tests we use the real TimeZoneLookupHelper.
        mRealTimeZoneLookupHelper = new TimeZoneLookupHelper();
        mRealTimeZoneLookupHelper = new TimeZoneLookupHelper();
@@ -750,7 +750,7 @@ public class NitzStateMachineImplTest extends TelephonyTest {
        }
        }


        Script initializeSystemClock(long timeMillis) {
        Script initializeSystemClock(long timeMillis) {
            mFakeTimeServiceHelper.currentTimeMillis = timeMillis;
            mFakeDeviceState.currentTimeMillis = timeMillis;
            return this;
            return this;
        }
        }


@@ -892,22 +892,22 @@ public class NitzStateMachineImplTest extends TelephonyTest {


    private static class FakeTimeServiceHelper implements TimeServiceHelper {
    private static class FakeTimeServiceHelper implements TimeServiceHelper {


        private final FakeDeviceState mFakeDeviceState;

        public TimeServiceHelper.Listener listener;
        public TimeServiceHelper.Listener listener;
        public boolean timeZoneDetectionEnabled;
        public boolean timeZoneDetectionEnabled;
        public long currentTimeMillis;


        // State we want to track.
        // State we want to track.
        public TestState<String> deviceTimeZone = new TestState<>();
        public TestState<String> deviceTimeZone = new TestState<>();
        public TestState<TimestampedValue<Long>> suggestedTime = new TestState<>();
        public TestState<TimestampedValue<Long>> suggestedTime = new TestState<>();


        @Override
        FakeTimeServiceHelper(FakeDeviceState fakeDeviceState) {
        public void setListener(Listener listener) {
            mFakeDeviceState = fakeDeviceState;
            this.listener = listener;
        }
        }


        @Override
        @Override
        public long currentTimeMillis() {
        public void setListener(Listener listener) {
            return currentTimeMillis;
            this.listener = listener;
        }
        }


        @Override
        @Override
@@ -929,7 +929,7 @@ public class NitzStateMachineImplTest extends TelephonyTest {
        public void suggestDeviceTime(TimestampedValue<Long> deviceTime) {
        public void suggestDeviceTime(TimestampedValue<Long> deviceTime) {
            suggestedTime.set(deviceTime);
            suggestedTime.set(deviceTime);
            // The fake time service just uses the latest suggestion.
            // The fake time service just uses the latest suggestion.
            currentTimeMillis = deviceTime.getValue();
            mFakeDeviceState.currentTimeMillis = deviceTime.getValue();
        }
        }


        void commitState() {
        void commitState() {
Loading