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

Commit 168b46e8 authored by Jack Yu's avatar Jack Yu Committed by android-build-merger
Browse files

Merge "Fixed time zone detection not working when SIM is absent"

am: 69fcd032

Change-Id: I57640d950f66937682654a869dec1bb1faad9a68
parents a3e7f8cb 69fcd032
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -89,6 +89,8 @@ public class LocaleTracker extends Handler {

    private final Phone mPhone;

    private final NitzStateMachine mNitzStateMachine;

    /** SIM card state. Must be one of TelephonyManager.SIM_STATE_XXX */
    private int mSimState;

@@ -172,11 +174,13 @@ public class LocaleTracker extends Handler {
     * Constructor
     *
     * @param phone The phone object
     * @param nitzStateMachine NITZ state machine
     * @param looper The looper message handler
     */
    public LocaleTracker(Phone phone, Looper looper)  {
    public LocaleTracker(Phone phone, NitzStateMachine nitzStateMachine, Looper looper)  {
        super(looper);
        mPhone = phone;
        mNitzStateMachine = nitzStateMachine;
        mSimState = TelephonyManager.SIM_STATE_UNKNOWN;

        final IntentFilter filter = new IntentFilter();
@@ -391,6 +395,7 @@ public class LocaleTracker extends Handler {
        String msg = "updateLocale: mcc = " + mcc + ", country = " + countryIso;
        log(msg);
        mLocalLog.log(msg);
        boolean countryChanged = false;
        if (!Objects.equals(countryIso, mCurrentCountryIso)) {
            msg = "updateLocale: Change the current country to " + countryIso;
            log(msg);
@@ -405,6 +410,13 @@ public class LocaleTracker extends Handler {
            // broadcast on forbidden channels.
            ((WifiManager) mPhone.getContext().getSystemService(Context.WIFI_SERVICE))
                    .setCountryCode(countryIso);
            countryChanged = true;
        }

        if (TextUtils.isEmpty(countryIso)) {
            mNitzStateMachine.handleNetworkCountryCodeUnavailable();
        } else {
            mNitzStateMachine.handleNetworkCountryCodeSet(countryChanged);
        }
    }

+6 −6
Original line number Diff line number Diff line
@@ -72,10 +72,10 @@ public final class NewNitzStateMachine 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 #handleNetworkUnavailable()}. 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.
     * 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.
     */
    private boolean mNitzTimeZoneDetectionSuccessful = false;

@@ -282,9 +282,9 @@ public final class NewNitzStateMachine implements NitzStateMachine {
    }

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

        mGotCountryCode = false;
+3 −2
Original line number Diff line number Diff line
@@ -48,9 +48,10 @@ public interface NitzStateMachine {
    void handleNetworkAvailable();

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

    /**
     * Handle a new NITZ signal being received.
+6 −6
Original line number Diff line number Diff line
@@ -73,10 +73,10 @@ public final class OldNitzStateMachine 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 #handleNetworkUnavailable()}. 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.
     * 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.
     */
    private boolean mNitzTimeZoneDetectionSuccessful = false;

@@ -290,9 +290,9 @@ public final class OldNitzStateMachine implements NitzStateMachine {
    }

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

        mGotCountryCode = false;
+4 −29
Original line number Diff line number Diff line
@@ -76,7 +76,6 @@ import android.util.LocalLog;
import android.util.Pair;
import android.util.SparseArray;
import android.util.StatsLog;
import android.util.TimeUtils;
import android.util.TimestampedValue;

import com.android.internal.annotations.VisibleForTesting;
@@ -521,7 +520,7 @@ public class ServiceStateTracker extends Handler {
        }

        mLocaleTracker = TelephonyComponentFactory.getInstance().makeLocaleTracker(
                mPhone, getLooper());
                mPhone, mNitzState, getLooper());

        mCi.registerForImsNetworkStateChanged(this, EVENT_IMS_STATE_CHANGED, null);
        mCi.registerForRadioStateChanged(this, EVENT_RADIO_STATE_CHANGED, null);
@@ -608,7 +607,7 @@ public class ServiceStateTracker extends Handler {
        mMin = null;
        mPrlVersion = null;
        mIsMinInfoReady = false;
        mNitzState.handleNetworkUnavailable();
        mNitzState.handleNetworkCountryCodeUnavailable();
        mCellIdentity = null;
        mNewCellIdentity = null;

@@ -2697,7 +2696,7 @@ public class ServiceStateTracker extends Handler {
                mNewSS.setStateOutOfService();
                mNewCellIdentity = null;
                setSignalStrengthDefaultValues();
                mNitzState.handleNetworkUnavailable();
                mNitzState.handleNetworkCountryCodeUnavailable();
                pollStateDone();
                break;

@@ -2705,7 +2704,7 @@ public class ServiceStateTracker extends Handler {
                mNewSS.setStateOff();
                mNewCellIdentity = null;
                setSignalStrengthDefaultValues();
                mNitzState.handleNetworkUnavailable();
                mNitzState.handleNetworkCountryCodeUnavailable();
                // don't poll when device is shutting down or the poll was not modemTrigged
                // (they sent us new radio data) and current network is not IWLAN
                if (mDeviceShuttingDown ||
@@ -2950,7 +2949,6 @@ public class ServiceStateTracker extends Handler {

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

        if (hasRejectCauseChanged) {
@@ -2982,7 +2980,6 @@ public class ServiceStateTracker extends Handler {
                // operator numeric in locale tracker is null. The async update will allow getting
                // cell info from the modem instead of using the cached one.
                mLocaleTracker.updateOperatorNumeric("");
                mNitzState.handleNetworkUnavailable();
            } else if (mSS.getRilDataRadioTechnology() != ServiceState.RIL_RADIO_TECHNOLOGY_IWLAN) {
                // If the device is on IWLAN, modems manufacture a ServiceState with the MCC/MNC of
                // the SIM as if we were talking to towers. Telephony code then uses that with
@@ -2994,28 +2991,6 @@ public class ServiceStateTracker extends Handler {
                }

                mLocaleTracker.updateOperatorNumeric(operatorNumeric);
                String countryIsoCode = mLocaleTracker.getCurrentCountry();

                // Update Time Zone.
                boolean iccCardExists = iccCardExists();
                boolean networkIsoChanged =
                        networkCountryIsoChanged(countryIsoCode, prevCountryIsoCode);

                // Determine countryChanged: networkIso is only reliable if there's an ICC card.
                boolean countryChanged = iccCardExists && networkIsoChanged;
                if (DBG) {
                    long ctm = System.currentTimeMillis();
                    log("Before handleNetworkCountryCodeKnown:"
                            + " countryChanged=" + countryChanged
                            + " iccCardExist=" + iccCardExists
                            + " countryIsoChanged=" + networkIsoChanged
                            + " operatorNumeric=" + operatorNumeric
                            + " prevOperatorNumeric=" + prevOperatorNumeric
                            + " countryIsoCode=" + countryIsoCode
                            + " prevCountryIsoCode=" + prevCountryIsoCode
                            + " ltod=" + TimeUtils.logTimeOfDay(ctm));
                }
                mNitzState.handleNetworkCountryCodeSet(countryChanged);
            }

            tm.setNetworkRoamingForPhone(mPhone.getPhoneId(),
Loading