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

Commit df55bc39 authored by Xiangyu/Malcolm Chen's avatar Xiangyu/Malcolm Chen Committed by Android (Google) Code Review
Browse files

Merge "Refresh signal strength in CBRS case." into qt-qpr1-dev

parents 7bb45f1e 9bac356c
Loading
Loading
Loading
Loading
+40 −0
Original line number Diff line number Diff line
@@ -121,6 +121,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.TimeZone;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -136,6 +137,9 @@ public class ServiceStateTracker extends Handler {

    private static final String PROP_FORCE_ROAMING = "telephony.test.forceRoaming";

    private static final long SIGNAL_STRENGTH_REFRESH_THRESHOLD_IN_MS =
            TimeUnit.SECONDS.toMillis(10);

    @UnsupportedAppUsage
    private CommandsInterface mCi;
    @UnsupportedAppUsage
@@ -173,6 +177,7 @@ public class ServiceStateTracker extends Handler {

    @UnsupportedAppUsage
    private SignalStrength mSignalStrength;
    private long mSignalStrengthUpdatedTime;

    // TODO - this should not be public, right now used externally GsmConnetion.
    public RestrictedState mRestrictedState;
@@ -715,6 +720,7 @@ public class ServiceStateTracker extends Handler {
        mNitzState.handleNetworkCountryCodeUnavailable();
        mCellIdentity = null;
        mNewCellIdentity = null;
        mSignalStrengthUpdatedTime = System.currentTimeMillis();

        //cancel any pending pollstate request on voice tech switching
        cancelPollState();
@@ -4761,6 +4767,7 @@ public class ServiceStateTracker extends Handler {
            log("onSignalStrengthResult() Exception from RIL : " + ar.exception);
            mSignalStrength = new SignalStrength();
        }
        mSignalStrengthUpdatedTime = System.currentTimeMillis();

        boolean ssChanged = notifySignalStrength();

@@ -4893,9 +4900,41 @@ public class ServiceStateTracker extends Handler {
     * @return signal strength
     */
    public SignalStrength getSignalStrength() {
        if (shouldRefreshSignalStrength()) {
            log("SST.getSignalStrength() refreshing signal strength.");
            obtainMessage(EVENT_POLL_SIGNAL_STRENGTH).sendToTarget();
        }
        return mSignalStrength;
    }

    private boolean shouldRefreshSignalStrength() {
        long curTime = System.currentTimeMillis();

        // If last signal strength is older than 10 seconds, or somehow if curTime is smaller
        // than mSignalStrengthUpdatedTime (system time update), it's considered stale.
        boolean isStale = (mSignalStrengthUpdatedTime > curTime)
                || (curTime - mSignalStrengthUpdatedTime > SIGNAL_STRENGTH_REFRESH_THRESHOLD_IN_MS);
        if (!isStale) return false;

        List<SubscriptionInfo> subInfoList = SubscriptionController.getInstance()
                .getActiveSubscriptionInfoList(mPhone.getContext().getOpPackageName());
        for (SubscriptionInfo info : subInfoList) {
            // If we have an active opportunistic subscription whose data is IN_SERVICE, we needs
            // to get signal strength to decide data switching threshold. In this case, we poll
            // latest signal strength from modem.
            if (info.isOpportunistic()) {
                TelephonyManager tm = TelephonyManager.from(mPhone.getContext())
                        .createForSubscriptionId(info.getSubscriptionId());
                ServiceState ss = tm.getServiceState();
                if (ss != null && ss.getDataRegState() == ServiceState.STATE_IN_SERVICE) {
                    return true;
                }
            }
        }

        return false;
    }

    /**
     * Registration point for subscription info ready
     * @param h handler to notify
@@ -5248,6 +5287,7 @@ public class ServiceStateTracker extends Handler {
    @UnsupportedAppUsage
    private void setSignalStrengthDefaultValues() {
        mSignalStrength = new SignalStrength();
        mSignalStrengthUpdatedTime = System.currentTimeMillis();
    }

    protected String getHomeOperatorNumeric() {