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

Commit 7f9b980f authored by Malcolm Chen's avatar Malcolm Chen
Browse files

Refresh signal strength in CBRS case.

When there's an active CBRS subscription and it's in Service, we
allow a max rate of 10 seconds of refresh signal strength if there
are external signal strength queries.

Bug: 141371697
Test: manual

Change-Id: Ie6881b1fe9d33c1496e7b13d298a5296abafc54a
Merged-In: Ie6881b1fe9d33c1496e7b13d298a5296abafc54a
parent c7cb9361
Loading
Loading
Loading
Loading
+40 −0
Original line number Diff line number Diff line
@@ -119,6 +119,7 @@ import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -134,6 +135,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
@@ -171,6 +175,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;
@@ -712,6 +717,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();
@@ -4700,6 +4706,7 @@ public class ServiceStateTracker extends Handler {
            log("onSignalStrengthResult() Exception from RIL : " + ar.exception);
            mSignalStrength = new SignalStrength();
        }
        mSignalStrengthUpdatedTime = System.currentTimeMillis();

        boolean ssChanged = notifySignalStrength();

@@ -4832,9 +4839,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
@@ -5187,6 +5226,7 @@ public class ServiceStateTracker extends Handler {
    @UnsupportedAppUsage
    private void setSignalStrengthDefaultValues() {
        mSignalStrength = new SignalStrength();
        mSignalStrengthUpdatedTime = System.currentTimeMillis();
    }

    protected String getHomeOperatorNumeric() {