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

Commit 6364c19f authored by Sarah Chin's avatar Sarah Chin Committed by Gerrit Code Review
Browse files

Merge "Temporary fix to prevent TEMPORARILY_NOT_METERED leak"

parents 08389c7c 1dcb1b8a
Loading
Loading
Loading
Loading
+68 −8
Original line number Original line Diff line number Diff line
@@ -59,6 +59,7 @@ import android.telephony.NetworkRegistrationInfo;
import android.telephony.PreciseDataConnectionState;
import android.telephony.PreciseDataConnectionState;
import android.telephony.ServiceState;
import android.telephony.ServiceState;
import android.telephony.SubscriptionManager;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyDisplayInfo;
import android.telephony.TelephonyManager;
import android.telephony.TelephonyManager;
import android.telephony.data.ApnSetting;
import android.telephony.data.ApnSetting;
import android.telephony.data.DataCallResponse;
import android.telephony.data.DataCallResponse;
@@ -1557,6 +1558,55 @@ public class DataConnection extends StateMachine {
        return true;
        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.
     * Get the network capabilities for this data connection.
     *
     *
@@ -1676,15 +1726,25 @@ public class DataConnection extends StateMachine {
            result.removeCapability(NetworkCapabilities.NET_CAPABILITY_NOT_CONGESTED);
            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,
            result.setCapability(NetworkCapabilities.NET_CAPABILITY_TEMPORARILY_NOT_METERED,
                    mUnmeteredOverride);
                    mUnmeteredOverride);

        } else if (mUnmeteredOverride) {
        if (mUnmeteredOverride && result.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
            // If temp not metered is not possible, but mUnmeteredOverride got set, that means we
                && (mPhone.getRadioAccessFamily() & TelephonyManager.NETWORK_TYPE_BITMASK_NR)
            // hit the bug.
                == 0) {
            SubscriptionManager subscriptionManager = mPhone.getContext()
            String message = "Unexpected TEMPORARILY_NOT_METERED on devices not supporting NR.";
                    .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);
            loge(message);
            // Using fixed UUID to avoid duplicate bugreport notification
            loge("Service state=" + mPhone.getServiceState());
            AnomalyReporter.reportAnomaly(
            AnomalyReporter.reportAnomaly(
                    UUID.fromString("9151f0fc-01df-4afb-b744-9c4529055248"), message);
                    UUID.fromString("9151f0fc-01df-4afb-b744-9c4529055248"), message);
        }
        }