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

Commit 1dcb1b8a authored by Jack Yu's avatar Jack Yu Committed by Sarah Chin
Browse files

Temporary fix to prevent TEMPORARILY_NOT_METERED leak

Currently we are seeing TEMPORARILY_NOT_METERED occurs on non-5G
devices. This fix adds more checks to prevent incorrect
TEMPORARILY_NOT_METERED being set. Before we root cause the issue,
we only allow this bit when all of the following conditions met.

1. Devices should support 5G.
2. Carriers should support 5G unmetered data.
3. Device should camp on 5G network.

This temporary fix should be removed after we root cause the issue.

Bug: 176119724
Test: Manual
Change-Id: I762fbe81329858c9057270fadf10713a9029d6da
Merged-In: I762fbe81329858c9057270fadf10713a9029d6da
parent 3a87d97a
Loading
Loading
Loading
Loading
+68 −8
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ import android.telephony.NetworkRegistrationInfo;
import android.telephony.PreciseDataConnectionState;
import android.telephony.ServiceState;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyDisplayInfo;
import android.telephony.TelephonyManager;
import android.telephony.data.ApnSetting;
import android.telephony.data.DataCallResponse;
@@ -1557,6 +1558,55 @@ public class DataConnection extends StateMachine {
        return true;
    }

    // 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);
        if (configManager != null) {
            PersistableBundle bundle = configManager.getConfigForSubId(mSubId);
            if (bundle != null) {
                return bundle.getBoolean(
                        CarrierConfigManager.KEY_NETWORK_TEMP_NOT_METERED_SUPPORTED_BOOL);
            }
        }

        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 isCampedOn5GNsa() {
        TelephonyDisplayInfo displayInfo = mPhone.getDisplayInfoController()
                .getTelephonyDisplayInfo();
        int overrideNetworkType = displayInfo.getOverrideNetworkType();
        int networkType = mPhone.getServiceState().getDataNetworkType();
        return (networkType == TelephonyManager.NETWORK_TYPE_LTE
                || networkType == TelephonyManager.NETWORK_TYPE_LTE_CA)
                && (overrideNetworkType == TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA
                || overrideNetworkType == TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA_MMWAVE);
    }

    // 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() && isCampedOn5GNsa();
    }

    /**
     * Get the network capabilities for this data connection.
     *
@@ -1676,15 +1726,25 @@ public class DataConnection extends StateMachine {
            result.removeCapability(NetworkCapabilities.NET_CAPABILITY_NOT_CONGESTED);
        }

        // 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 (tempNotMeteredPossible()) {
            result.setCapability(NetworkCapabilities.NET_CAPABILITY_TEMPORARILY_NOT_METERED,
                    mUnmeteredOverride);

        if (mUnmeteredOverride && result.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
                && (mPhone.getRadioAccessFamily() & TelephonyManager.NETWORK_TYPE_BITMASK_NR)
                == 0) {
            String message = "Unexpected TEMPORARILY_NOT_METERED on devices not supporting NR.";
        } else if (mUnmeteredOverride) {
            // If temp not metered is not possible, but mUnmeteredOverride got set, that means we
            // hit the bug.
            SubscriptionManager subscriptionManager = mPhone.getContext()
                    .getSystemService(SubscriptionManager.class);
            String message = "Unexpected temp not metered detected. carrier supported="
                    + isTempNotMeteredSupportedByCarrier() + ", device 5G capable="
                    + isDevice5GCapable() + ", display info="
                    + mPhone.getDisplayInfoController().getTelephonyDisplayInfo()
                    + ", subscription plans=" + subscriptionManager.getSubscriptionPlans(mSubId);
            loge(message);
            // Using fixed UUID to avoid duplicate bugreport notification
            loge("Service state=" + mPhone.getServiceState());
            AnomalyReporter.reportAnomaly(
                    UUID.fromString("9151f0fc-01df-4afb-b744-9c4529055248"), message);
        }