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

Commit 8b941766 authored by Neil Fuller's avatar Neil Fuller Committed by Gerrit Code Review
Browse files

Merge "Add NitzStateMachine.handleNetworkUnavailable()"

parents f50d3955 9c84c926
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -53,6 +53,11 @@ public interface NitzStateMachine {
     */
    void handleNetworkAvailable();

    /**
     * Informs the {@link NitzStateMachine} that the network has become unavailable.
     */
    void handleNetworkUnavailable();

    /**
     * Informs the {@link NitzStateMachine} that the country code from network has become
     * unavailable.
+39 −20
Original line number Diff line number Diff line
@@ -81,11 +81,12 @@ public final class NitzStateMachineImpl implements NitzStateMachine {

    /**
     * Boolean is {@code true} if NITZ has been used to determine a time zone (which may not
     * ultimately have been used due to user settings). Cleared by {@link #handleNetworkAvailable()}
     * and {@link #handleNetworkCountryCodeUnavailable()}. The flag can be used when historic NITZ
     * data may no longer be valid. {@code false} indicates it is reasonable to try to set the time
     * zone using less reliable algorithms than NITZ-based detection such as by just using network
     * country code.
     * ultimately have been used due to user settings). Cleared by {@link
     * #handleNetworkAvailable()}, {@link #handleNetworkCountryCodeUnavailable()},
     * {@link #handleNetworkUnavailable()}, and {@link #handleAirplaneModeChanged(boolean)}. The
     * flag can be used when historic NITZ data may no longer be valid. {@code false} indicates it
     * is reasonable to try to set the time zone using less reliable algorithms than NITZ-based
     * detection such as by just using network country code.
     */
    private boolean mNitzTimeZoneDetectionSuccessful = false;

@@ -311,12 +312,37 @@ public final class NitzStateMachineImpl implements NitzStateMachine {
        mNitzTimeZoneDetectionSuccessful = false;
    }

    @Override
    public void handleNetworkUnavailable() {
        if (DBG) {
            Rlog.d(LOG_TAG, "handleNetworkUnavailable: Clearing NITZ and detection state");
        }
        // Clear state related to NITZ.
        mSavedNitzTime = null;
        mTimeLog.log("handleNetworkUnavailable: NITZ state cleared.");

        mLatestNitzSignal = null;
        mNitzTimeZoneDetectionSuccessful = false;
        mSavedTimeZoneId = null;
        mTimeZoneLog.log("handleNetworkUnavailable: NITZ state cleared.");

        // mSavedTimeZoneId has been cleared but it might be sufficient to detect the time zone
        // using only the country information that is left.
        if (mGotCountryCode) {
            String isoCountryCode = mDeviceState.getNetworkCountryIsoForPhone();
            if (!TextUtils.isEmpty(isoCountryCode)) {
                updateTimeZoneFromNetworkCountryCode(isoCountryCode);
            }
        }
    }

    @Override
    public void handleNetworkCountryCodeUnavailable() {
        if (DBG) {
            Rlog.d(LOG_TAG, "handleNetworkCountryCodeUnavailable");
        }

        mSavedTimeZoneId = null;
        mGotCountryCode = false;
        mNitzTimeZoneDetectionSuccessful = false;
    }
@@ -348,8 +374,14 @@ public final class NitzStateMachineImpl implements NitzStateMachine {
        // principles what the time / time zone is. This assumes calls like handleNetworkAvailable()
        // will be made after airplane mode is re-enabled as the device re-establishes network
        // connectivity.
        clearTimeDetectionState();
        clearTimeZoneDetectionState();
        mSavedNitzTime = null;
        mTimeLog.log("handleAirplaneModeChanged(" + on + "): Time state cleared.");

        mGotCountryCode = false;
        mLatestNitzSignal = null;
        mNitzTimeZoneDetectionSuccessful = false;
        mSavedTimeZoneId = null;
        mTimeZoneLog.log("handleAirplaneModeChanged(" + on + "): Time zone state cleared.");
    }

    private void updateTimeFromNitz() {
@@ -446,11 +478,6 @@ public final class NitzStateMachineImpl implements NitzStateMachine {
        }
    }

    private void clearTimeDetectionState() {
        mSavedNitzTime = null;
        mTimeZoneLog.log("clearTimeZoneDetectionState: All time detection state cleared.");
    }

    private void setAndBroadcastNetworkSetTimeZone(String zoneId, String logMessage) {
        logMessage += " [Setting device time zone to zoneId=" + zoneId + "]";
        if (DBG) {
@@ -554,14 +581,6 @@ public final class NitzStateMachineImpl implements NitzStateMachine {
        }
    }

    private void clearTimeZoneDetectionState() {
        mLatestNitzSignal = null;
        mGotCountryCode = false;
        mSavedTimeZoneId = null;
        mNitzTimeZoneDetectionSuccessful = false;
        mTimeZoneLog.log("clearTimeZoneDetectionState: All time zone detection state cleared.");
    }

    // VisibleForTesting
    public boolean getNitzTimeZoneDetectionSuccessful() {
        return mNitzTimeZoneDetectionSuccessful;
+1 −0
Original line number Diff line number Diff line
@@ -3320,6 +3320,7 @@ public class ServiceStateTracker extends Handler {

        if (hasDeregistered) {
            mNetworkDetachedRegistrants.notifyRegistrants();
            mNitzState.handleNetworkUnavailable();
        }

        if (hasRejectCauseChanged) {
+13 −19
Original line number Diff line number Diff line
@@ -166,6 +166,17 @@ public final class NewNitzStateMachineImpl implements NitzStateMachine {

    @Override
    public void handleNetworkAvailable() {
        // We no longer do any useful work here: we assume handleNetworkUnavailable() is reliable.
        // TODO: Remove this method when all implementations do nothing.
    }

    @Override
    public void handleNetworkUnavailable() {
        String reason = "handleNetworkUnavailable()";
        clearNetworkStateAndRerunDetection(reason);
    }

    private void clearNetworkStateAndRerunDetection(String reason) {
        // Assume any previous NITZ signals received are now invalid.
        mLatestNitzSignal = null;

@@ -173,12 +184,9 @@ public final class NewNitzStateMachineImpl implements NitzStateMachine {
                mGotCountryCode ? mDeviceState.getNetworkCountryIsoForPhone() : null;

        if (DBG) {
            Rlog.d(LOG_TAG, "handleNetworkAvailable: countryIsoCode=" + countryIsoCode
                    + ", mLatestNitzSignal=" + mLatestNitzSignal);
            Rlog.d(LOG_TAG, reason + ": countryIsoCode=" + countryIsoCode);
        }

        String reason = "handleNetworkAvailable()";

        // Generate a new time zone suggestion and update the service as needed.
        doTimeZoneDetection(countryIsoCode, null /* nitzSignal */, reason);

@@ -192,7 +200,6 @@ public final class NewNitzStateMachineImpl implements NitzStateMachine {
            Rlog.d(LOG_TAG, "handleNetworkCountryCodeSet: countryChanged=" + countryChanged
                    + ", mLatestNitzSignal=" + mLatestNitzSignal);
        }

        mGotCountryCode = true;

        // Generate a new time zone suggestion and update the service as needed.
@@ -243,10 +250,6 @@ public final class NewNitzStateMachineImpl implements NitzStateMachine {

    @Override
    public void handleAirplaneModeChanged(boolean on) {
        if (DBG) {
            Rlog.d(LOG_TAG, "handleAirplaneModeChanged: on=" + on);
        }

        // Treat entry / exit from airplane mode as a strong signal that the user wants to clear
        // cached state. If the user really is boarding a plane they won't want cached state from
        // before their flight influencing behavior.
@@ -260,20 +263,11 @@ public final class NewNitzStateMachineImpl implements NitzStateMachine {
        // will be made after airplane mode is re-enabled as the device re-establishes network
        // connectivity.

        // Clear shared state.
        mLatestNitzSignal = null;

        // Clear time zone detection state.
        mGotCountryCode = false;

        String reason = "handleAirplaneModeChanged(" + on + ")";

        // Generate a new time zone suggestion and update the service as needed.
        doTimeZoneDetection(null /* countryIsoCode */, null /* nitzSignal */,
                reason);

        // Generate a new time suggestion and update the service as needed.
        doTimeDetection(null /* nitzSignal */, reason);
        clearNetworkStateAndRerunDetection(reason);
    }

    /**
+237 −20

File changed.

Preview size limit exceeded, changes collapsed.

Loading