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

Commit 4f38234a authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Remove 5G only workaround for TNM"

parents b7a47e05 4c2ba07a
Loading
Loading
Loading
Loading
+7 −72
Original line number Diff line number Diff line
@@ -74,7 +74,6 @@ import android.telephony.AccessNetworkConstants.TransportType;
import android.telephony.Annotation.ApnType;
import android.telephony.Annotation.DataFailureCause;
import android.telephony.Annotation.NetworkType;
import android.telephony.AnomalyReporter;
import android.telephony.CarrierConfigManager;
import android.telephony.CellLocation;
import android.telephony.DataFailCause;
@@ -143,7 +142,6 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
@@ -358,7 +356,7 @@ public class DcTracker extends Handler {
    private boolean mLteEndcUsingUserDataForRrcDetection = false;

    /* List of SubscriptionPlans, updated when initialized and when plans are changed. */
    private List<SubscriptionPlan> mSubscriptionPlans = null;
    private List<SubscriptionPlan> mSubscriptionPlans = new ArrayList<>();
    /* List of network types an unmetered override applies to, set by onSubscriptionOverride
     * and cleared when the device is rebooted or the override expires. */
    private List<Integer> mUnmeteredNetworkTypes = null;
@@ -489,7 +487,7 @@ public class DcTracker extends Handler {
        public void onSubscriptionPlansChanged(int subId, SubscriptionPlan[] plans) {
            if (mPhone == null || mPhone.getSubId() != subId) return;

            mSubscriptionPlans = plans == null ? null : Arrays.asList(plans);
            mSubscriptionPlans = Arrays.asList(plans);
            if (DBG) log("SubscriptionPlans changed: " + mSubscriptionPlans);
            reevaluateUnmeteredConnections();
        }
@@ -2500,11 +2498,9 @@ public class DcTracker extends Handler {
        registerSettingsObserver();
        SubscriptionPlan[] plans = mNetworkPolicyManager.getSubscriptionPlans(
                mPhone.getSubId(), mPhone.getContext().getOpPackageName());
        if (plans != null) {
            mSubscriptionPlans = Arrays.asList(plans);
        mSubscriptionPlans = plans == null ? Collections.emptyList() : Arrays.asList(plans);
        if (DBG) log("SubscriptionPlans initialized: " + mSubscriptionPlans);
        reevaluateUnmeteredConnections();
        }
        mConfigReady = true;
    }

@@ -4448,27 +4444,10 @@ public class DcTracker extends Handler {
    }

    private void setDataConnectionUnmetered(boolean isUnmetered) {
        // TODO: Remove this after b/176119724 is fixed. This is just a workaround to prevent
        // NET_CAPABILITY_TEMPORARILY_NOT_METERED incorrectly set on devices that are not supposed
        // to use 5G unmetered network. Currently TEMPORARILY_NOT_METERED can only happen on few
        // devices and carriers.
        if (!isUnmetered || (isUnmetered && tempNotMeteredPossible())) {
        if (!isUnmetered || isTempNotMeteredSupportedByCarrier()) {
            for (DataConnection dataConnection : mDataConnections.values()) {
                dataConnection.onMeterednessChanged(isUnmetered);
            }
        } else {
            // isUnmetered=true but TEMP_NOT_METERED is not possible
            String message = "Unexpected temp not metered detected. carrier supported="
                    + isTempNotMeteredSupportedByCarrier() + ", device 5G capable="
                    + isDevice5GCapable() + ", camped on 5G=" + isCampedOn5G()
                    + ", timer active=" + mPhone.getDisplayInfoController().is5GHysteresisActive()
                    + ", display info="
                    + mPhone.getDisplayInfoController().getTelephonyDisplayInfo()
                    + ", subscription plans=" + mSubscriptionPlans
                    + ", Service state=" + mPhone.getServiceState();
            loge(message);
            AnomalyReporter.reportAnomaly(
                    UUID.fromString("9151f0fc-01df-4afb-b744-9c4529055250"), message);
        }
    }

@@ -4493,7 +4472,7 @@ public class DcTracker extends Handler {
    }

    private boolean isNetworkTypeUnmeteredViaSubscriptionPlan(@NetworkType int networkType) {
        if (mSubscriptionPlans == null || mSubscriptionPlans.size() == 0) {
        if (mSubscriptionPlans.isEmpty()) {
            // safe return false if unable to get subscription plans or plans don't exist
            return false;
        }
@@ -4590,18 +4569,6 @@ public class DcTracker extends Handler {
        return false;
    }

    // TODO: Remove this after b/176119724 is fixed. This is just a workaround to prevent
    // NET_CAPABILITY_TEMPORARILY_NOT_METERED incorrectly set on devices that are not supposed
    // to use 5G unmetered network. Currently TEMPORARILY_NOT_METERED can only happen on few devices
    // and carriers.
    private boolean isDevice5GCapable() {
        return (mPhone.getRadioAccessFamily() & TelephonyManager.NETWORK_TYPE_BITMASK_NR) != 0;
    }

    // TODO: Remove this after b/176119724 is fixed. This is just a workaround to prevent
    // NET_CAPABILITY_TEMPORARILY_NOT_METERED incorrectly set on devices that are not supposed
    // to use 5G unmetered network. Currently TEMPORARILY_NOT_METERED can only happen on few devices
    // and carriers.
    private boolean isTempNotMeteredSupportedByCarrier() {
        CarrierConfigManager configManager =
                mPhone.getContext().getSystemService(CarrierConfigManager.class);
@@ -4616,38 +4583,6 @@ public class DcTracker extends Handler {
        return false;
    }

    // TODO: Remove this after b/176119724 is fixed. This is just a workaround to prevent
    // NET_CAPABILITY_TEMPORARILY_NOT_METERED incorrectly set on devices that are not supposed
    // to use 5G unmetered network. Currently TEMPORARILY_NOT_METERED can only happen on few devices
    // and carriers.
    private boolean isCampedOn5G() {
        TelephonyDisplayInfo displayInfo = mPhone.getDisplayInfoController()
                .getTelephonyDisplayInfo();
        int overrideNetworkType = displayInfo.getOverrideNetworkType();
        NetworkRegistrationInfo nri =  mPhone.getServiceState().getNetworkRegistrationInfo(
                NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
        int networkType = nri == null ? TelephonyManager.NETWORK_TYPE_UNKNOWN
                : nri.getAccessNetworkTechnology();

        boolean isNrSa = networkType == TelephonyManager.NETWORK_TYPE_NR;
        boolean isNrNsa = (networkType == TelephonyManager.NETWORK_TYPE_LTE
                || networkType == TelephonyManager.NETWORK_TYPE_LTE_CA)
                && (overrideNetworkType == TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA
                || overrideNetworkType == TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_ADVANCED);
        boolean is5GHysteresisActive = mPhone.getDisplayInfoController().is5GHysteresisActive();

        // True if device is on NR SA or NR NSA, or neither but 5G hysteresis is active
        return isNrSa || isNrNsa || is5GHysteresisActive;
    }

    // TODO: Remove this after b/176119724 is fixed. This is just a workaround to prevent
    // NET_CAPABILITY_TEMPORARILY_NOT_METERED incorrectly set on devices that are not supposed
    // to use 5G unmetered network. Currently TEMPORARILY_NOT_METERED can only happen on few devices
    // and carriers.
    private boolean tempNotMeteredPossible() {
        return isDevice5GCapable() && isTempNotMeteredSupportedByCarrier() && isCampedOn5G();
    }

    protected void log(String s) {
        Rlog.d(mLogTag, s);
    }
+15 −4
Original line number Diff line number Diff line
@@ -708,6 +708,9 @@ public class DcTrackerTest extends TelephonyTest {
        doReturn("fake.action_attached").when(mPhone).getActionAttached();
        doReturn(ServiceState.RIL_RADIO_TECHNOLOGY_LTE).when(mServiceState)
                .getRilDataRadioTechnology();
        doReturn(new TelephonyDisplayInfo(TelephonyManager.NETWORK_TYPE_LTE,
                TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NONE))
                .when(mDisplayInfoController).getTelephonyDisplayInfo();

        mContextFixture.putStringArrayResource(com.android.internal.R.array
                .config_mobile_tcp_buffers, new String[]{
@@ -2321,6 +2324,8 @@ public class DcTrackerTest extends TelephonyTest {
                .setDataUsage(500_000_000, System.currentTimeMillis())
                .build());
        replaceInstance(DcTracker.class, "mSubscriptionPlans", mDct, plans);
        doReturn(plans.toArray(new SubscriptionPlan[0])).when(mNetworkPolicyManager)
                .getSubscriptionPlans(anyInt(), any());
    }

    private void resetSubscriptionPlans() throws Exception {
@@ -2475,6 +2480,7 @@ public class DcTrackerTest extends TelephonyTest {
                TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA))
                .when(mDisplayInfoController).getTelephonyDisplayInfo();
        setUpTempNotMetered();
        clearInvocations(mDataConnection);

        // NetCapability should be metered when connected to 5G with no unmetered plan or frequency
        mDct.sendMessage(mDct.obtainMessage(DctConstants.EVENT_TELEPHONY_DISPLAY_INFO_CHANGED));
@@ -2496,11 +2502,12 @@ public class DcTrackerTest extends TelephonyTest {
        intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, mPhone.getSubId());
        mContext.sendBroadcast(intent);
        waitForLastHandlerAction(mDcTrackerTestHandler.getThreadHandler());
        clearInvocations(mDataConnection);

        // NetCapability should switch to metered without fr=MMWAVE
        mDct.sendMessage(mDct.obtainMessage(DctConstants.EVENT_TELEPHONY_DISPLAY_INFO_CHANGED));
        waitForLastHandlerAction(mDcTrackerTestHandler.getThreadHandler());
        verify(mDataConnection, times(2)).onMeterednessChanged(false);
        verify(mDataConnection, times(1)).onMeterednessChanged(false);

        // NetCapability should switch to unmetered with fr=MMWAVE
        doReturn(new TelephonyDisplayInfo(TelephonyManager.NETWORK_TYPE_LTE,
@@ -2508,7 +2515,7 @@ public class DcTrackerTest extends TelephonyTest {
                .when(mDisplayInfoController).getTelephonyDisplayInfo();
        mDct.sendMessage(mDct.obtainMessage(DctConstants.EVENT_TELEPHONY_DISPLAY_INFO_CHANGED));
        waitForLastHandlerAction(mDcTrackerTestHandler.getThreadHandler());
        verify(mDataConnection, times(2)).onMeterednessChanged(true);
        verify(mDataConnection, times(1)).onMeterednessChanged(true);

        resetDataConnection(id);
        resetSubscriptionPlans();
@@ -2524,6 +2531,7 @@ public class DcTrackerTest extends TelephonyTest {
                TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA))
                .when(mDisplayInfoController).getTelephonyDisplayInfo();
        setUpTempNotMetered();
        clearInvocations(mDataConnection);

        // NetCapability should be metered when connected to 5G with no unmetered plan or frequency
        mDct.sendMessage(mDct.obtainMessage(DctConstants.EVENT_TELEPHONY_DISPLAY_INFO_CHANGED));
@@ -2538,6 +2546,7 @@ public class DcTrackerTest extends TelephonyTest {
        intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, mPhone.getSubId());
        mContext.sendBroadcast(intent);
        waitForLastHandlerAction(mDcTrackerTestHandler.getThreadHandler());
        clearInvocations(mDataConnection);

        // NetCapability should switch to unmetered when fr=MMWAVE and MMWAVE unmetered
        doReturn(new TelephonyDisplayInfo(TelephonyManager.NETWORK_TYPE_LTE,
@@ -2553,7 +2562,7 @@ public class DcTrackerTest extends TelephonyTest {
                .when(mDisplayInfoController).getTelephonyDisplayInfo();
        mDct.sendMessage(mDct.obtainMessage(DctConstants.EVENT_TELEPHONY_DISPLAY_INFO_CHANGED));
        waitForLastHandlerAction(mDcTrackerTestHandler.getThreadHandler());
        verify(mDataConnection, times(2)).onMeterednessChanged(false);
        verify(mDataConnection, times(1)).onMeterednessChanged(false);

        // Set SUB6 frequency to unmetered
        doReturn(2).when(mPhone).getSubId();
@@ -2564,13 +2573,14 @@ public class DcTrackerTest extends TelephonyTest {
        intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, mPhone.getSubId());
        mContext.sendBroadcast(intent);
        waitForLastHandlerAction(mDcTrackerTestHandler.getThreadHandler());
        clearInvocations(mDataConnection);

        // NetCapability should switch to unmetered when fr=SUB6 and SUB6 unmetered
        mDct.sendMessage(mDct.obtainMessage(DctConstants.EVENT_TELEPHONY_DISPLAY_INFO_CHANGED));
        waitForLastHandlerAction(mDcTrackerTestHandler.getThreadHandler());
        // Data connection is running on a different thread. Have to wait.
        waitForMs(200);
        verify(mDataConnection, times(2)).onMeterednessChanged(true);
        verify(mDataConnection, times(1)).onMeterednessChanged(true);

        resetDataConnection(id);
        resetSubscriptionPlans();
@@ -2583,6 +2593,7 @@ public class DcTrackerTest extends TelephonyTest {
        setUpSubscriptionPlans(true);
        setUpWatchdogTimer();
        setUpTempNotMetered();
        clearInvocations(mDataConnection);

        // NetCapability should be unmetered when connected to 5G
        doReturn(new TelephonyDisplayInfo(TelephonyManager.NETWORK_TYPE_LTE,