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

Commit 443df8aa authored by Jack Yu's avatar Jack Yu
Browse files

Used single TCP configuration for devices

Starting from Android 13, the TCP buffer size is fixed after boot up,
and should never be changed based on carriers or the network types.
The value should be configured appropriately based on the device's
memory and performance. It is recommended to use lower values if the
device doesn't support high-speed network such like LTE, NR, or Wifi.

Bug: 213596972
Test: Manual
Merged-In: Ic529f184359fcf6623b85ce78527ddc94cdf7c1b
Change-Id: Ic529f184359fcf6623b85ce78527ddc94cdf7c1b
parent 18ffcab9
Loading
Loading
Loading
Loading
+10 −45
Original line number Original line Diff line number Diff line
@@ -17,7 +17,6 @@
package com.android.internal.telephony.data;
package com.android.internal.telephony.data;


import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.StringDef;
import android.annotation.StringDef;
import android.content.BroadcastReceiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Context;
@@ -43,7 +42,6 @@ import android.telephony.data.ApnSetting;
import android.text.TextUtils;
import android.text.TextUtils;
import android.util.IndentingPrintWriter;
import android.util.IndentingPrintWriter;


import com.android.internal.R;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.data.DataNetworkController.HandoverRule;
import com.android.internal.telephony.data.DataNetworkController.HandoverRule;
import com.android.internal.telephony.data.DataRetryManager.DataHandoverRetryRule;
import com.android.internal.telephony.data.DataRetryManager.DataHandoverRetryRule;
@@ -219,9 +217,6 @@ public class DataConfigManager extends Handler {
    /** A map of network types to the downlink and uplink bandwidth values for that network type */
    /** A map of network types to the downlink and uplink bandwidth values for that network type */
    private @NonNull final @DataConfigNetworkType Map<String, DataNetwork.NetworkBandwidth>
    private @NonNull final @DataConfigNetworkType Map<String, DataNetwork.NetworkBandwidth>
            mBandwidthMap = new ConcurrentHashMap<>();
            mBandwidthMap = new ConcurrentHashMap<>();
    /** A map of network types to the TCP buffer sizes for that network type */
    private @NonNull final @DataConfigNetworkType Map<String, String> mTcpBufferSizeMap =
            new ConcurrentHashMap<>();
    /** Rules for handover between IWLAN and cellular network. */
    /** Rules for handover between IWLAN and cellular network. */
    private @NonNull final List<HandoverRule> mHandoverRuleList = new ArrayList<>();
    private @NonNull final List<HandoverRule> mHandoverRuleList = new ArrayList<>();


@@ -298,7 +293,6 @@ public class DataConfigManager extends Handler {
        updateSingleDataNetworkTypeList();
        updateSingleDataNetworkTypeList();
        updateUnmeteredNetworkTypes();
        updateUnmeteredNetworkTypes();
        updateBandwidths();
        updateBandwidths();
        updateTcpBuffers();
        updateHandoverRules();
        updateHandoverRules();


        log("Data config updated. Config is " + (isConfigCarrierSpecific() ? "" : "not ")
        log("Data config updated. Config is " + (isConfigCarrierSpecific() ? "" : "not ")
@@ -605,46 +599,19 @@ public class DataConfigManager extends Handler {
        return mCarrierConfig.getInt(CarrierConfigManager.KEY_DEFAULT_MTU_INT);
        return mCarrierConfig.getInt(CarrierConfigManager.KEY_DEFAULT_MTU_INT);
    }
    }


    /**
     * Update the TCP buffer sizes from the carrier config.
     */
    private void updateTcpBuffers() {
        synchronized (this) {
            mTcpBufferSizeMap.clear();
            String[] buffers = mCarrierConfig.getStringArray(
                    CarrierConfigManager.KEY_TCP_BUFFERS_STRING_ARRAY);
            if (buffers != null) {
                for (String buffer : buffers) {
                    // split[0] = network type as string
                    // split[1] = rmem_min,rmem_def,rmem_max,wmem_min,wmem_def,wmem_max
                    String[] split = buffer.split(":");
                    if (split.length != 2) {
                        loge("Invalid TCP buffer sizes: " + buffer);
                        continue;
                    }
                    if (split[1].split(",").length != 6) {
                        loge("Invalid TCP buffer sizes for " + split[0] + ": " + split[1]);
                        continue;
                    }
                    mTcpBufferSizeMap.put(split[0], split[1]);
                }
            }
        }
    }

    /**
    /**
     * Get the TCP config string, used by {@link LinkProperties#setTcpBufferSizes(String)}.
     * Get the TCP config string, used by {@link LinkProperties#setTcpBufferSizes(String)}.
     * The config string will have the following form, with values in bytes:
     * The config string will have the following form, with values in bytes:
     * "read_min,read_default,read_max,write_min,write_default,write_max"
     * "read_min,read_default,read_max,write_min,write_default,write_max"
     *
     *
     * @param networkType The network type. Note that {@link TelephonyManager#NETWORK_TYPE_LTE_CA}
     * Note that starting from Android 13, the TCP buffer size is fixed after boot up, and should
     *                    can be used for LTE CA even though it's not a radio access technology.
     * never be changed based on carriers or the network types. The value should be configured
     * @param serviceState The service state, used to determine NR state.
     * appropriately based on the device's memory and performance.
     * @return The TCP configuration string for the given network type or null if unavailable.
     *
     * @return The TCP configuration string.
     */
     */
    public @Nullable String getTcpConfigString(@NetworkType int networkType,
    public @NonNull String getTcpConfigString() {
            @NonNull ServiceState serviceState) {
        return mResources.getString(com.android.internal.R.string.config_tcp_buffers);
        return mTcpBufferSizeMap.get(getDataConfigNetworkType(networkType, serviceState));
    }
    }


    /**
    /**
@@ -652,7 +619,8 @@ public class DataConfigManager extends Handler {
     * does not complete within the window, the data network will be torn down after timeout.
     * does not complete within the window, the data network will be torn down after timeout.
     */
     */
    public long getImsDeregistrationDelay() {
    public long getImsDeregistrationDelay() {
        return mResources.getInteger(R.integer.config_delay_for_ims_dereg_millis);
        return mResources.getInteger(
                com.android.internal.R.integer.config_delay_for_ims_dereg_millis);
    }
    }


    /**
    /**
@@ -903,10 +871,7 @@ public class DataConfigManager extends Handler {
                + shouldResetDataThrottlingWhenTacChanges());
                + shouldResetDataThrottlingWhenTacChanges());
        pw.println("Data service package name=" + getDataServicePackageName());
        pw.println("Data service package name=" + getDataServicePackageName());
        pw.println("Default MTU=" + getDefaultMtu());
        pw.println("Default MTU=" + getDefaultMtu());
        pw.println("TCP buffer sizes:");
        pw.println("TCP buffer sizes:" + getTcpConfigString());
        pw.increaseIndent();
        mTcpBufferSizeMap.forEach((key, value) -> pw.println(key + ":" + value));
        pw.decreaseIndent();
        pw.println("getImsDeregistrationDelay=" + getImsDeregistrationDelay());
        pw.println("getImsDeregistrationDelay=" + getImsDeregistrationDelay());
        pw.println("shouldPersistIwlanDataNetworksWhenDataServiceRestarted="
        pw.println("shouldPersistIwlanDataNetworksWhenDataServiceRestarted="
                + shouldPersistIwlanDataNetworksWhenDataServiceRestarted());
                + shouldPersistIwlanDataNetworksWhenDataServiceRestarted());
+1 −45
Original line number Original line Diff line number Diff line
@@ -404,9 +404,6 @@ public class DataNetwork extends StateMachine {
    /** The network bandwidth. */
    /** The network bandwidth. */
    private @NonNull NetworkBandwidth mNetworkBandwidth = new NetworkBandwidth(14, 14);
    private @NonNull NetworkBandwidth mNetworkBandwidth = new NetworkBandwidth(14, 14);


    /** The TCP buffer sizes config. */
    private @Nullable String mTcpBufferSizes = "";

    /** Whether {@link NetworkCapabilities#NET_CAPABILITY_TEMPORARILY_NOT_METERED} is supported. */
    /** Whether {@link NetworkCapabilities#NET_CAPABILITY_TEMPORARILY_NOT_METERED} is supported. */
    private boolean mTempNotMeteredSupported = false;
    private boolean mTempNotMeteredSupported = false;


@@ -756,7 +753,6 @@ public class DataNetwork extends StateMachine {
                    // TODO: Should update suspend state when CSS indicator changes.
                    // TODO: Should update suspend state when CSS indicator changes.
                    // TODO: Should update suspend state when call started/ended.
                    // TODO: Should update suspend state when call started/ended.
                    updateSuspendState();
                    updateSuspendState();
                    updateTcpBufferSizes();
                    updateBandwidthFromDataConfig();
                    updateBandwidthFromDataConfig();
                    break;
                    break;
                }
                }
@@ -1489,7 +1485,7 @@ public class DataNetwork extends StateMachine {
            linkProperties.setHttpProxy(proxy);
            linkProperties.setHttpProxy(proxy);
        }
        }


        linkProperties.setTcpBufferSizes(mTcpBufferSizes);
        linkProperties.setTcpBufferSizes(mDataConfigManager.getTcpConfigString());


        mNetworkSliceInfo = response.getSliceInfo();
        mNetworkSliceInfo = response.getSliceInfo();


@@ -1515,28 +1511,6 @@ public class DataNetwork extends StateMachine {
                        mCid.get(AccessNetworkConstants.TRANSPORT_TYPE_WWAN));
                        mCid.get(AccessNetworkConstants.TRANSPORT_TYPE_WWAN));
    }
    }


    /**
     * Get the TCP config string.
     *
     * @return The TCP config string used in {@link LinkProperties#setTcpBufferSizes(String)}.
     */
    private @Nullable String getTcpConfig() {
        ServiceState ss = mPhone.getServiceState();
        NetworkRegistrationInfo nrs = ss.getNetworkRegistrationInfo(
                NetworkRegistrationInfo.DOMAIN_PS, mTransport);
        int networkType = TelephonyManager.NETWORK_TYPE_UNKNOWN;
        if (nrs != null) {
            networkType = nrs.getAccessNetworkTechnology();
            if (networkType == TelephonyManager.NETWORK_TYPE_LTE
                    && nrs.isUsingCarrierAggregation()) {
                // Although LTE_CA is not a real RAT, but since LTE CA generally has higher speed
                // we use LTE_CA to get a different TCP config for LTE CA.
                networkType = TelephonyManager.NETWORK_TYPE_LTE_CA;
            }
        }
        return mDataConfigManager.getTcpConfigString(networkType, ss);
    }

    /**
    /**
     * Called when receiving setup data network response from the data service.
     * Called when receiving setup data network response from the data service.
     *
     *
@@ -1695,7 +1669,6 @@ public class DataNetwork extends StateMachine {
        log("onDataConfigUpdated");
        log("onDataConfigUpdated");


        updateBandwidthFromDataConfig();
        updateBandwidthFromDataConfig();
        updateTcpBufferSizes();
        updateMeteredAndCongested();
        updateMeteredAndCongested();
    }
    }


@@ -1761,7 +1734,6 @@ public class DataNetwork extends StateMachine {
     */
     */
    private void onDisplayInfoChanged() {
    private void onDisplayInfoChanged() {
        updateBandwidthFromDataConfig();
        updateBandwidthFromDataConfig();
        updateTcpBufferSizes();
        updateMeteredAndCongested();
        updateMeteredAndCongested();
    }
    }


@@ -1779,21 +1751,6 @@ public class DataNetwork extends StateMachine {
        updateNetworkCapabilities();
        updateNetworkCapabilities();
    }
    }


    /**
     * Update the TCP buffer sizes from carrier configs.
     */
    private void updateTcpBufferSizes() {
        log("updateTcpBufferSizes");
        mTcpBufferSizes = getTcpConfig();
        LinkProperties linkProperties = new LinkProperties(mLinkProperties);
        linkProperties.setTcpBufferSizes(mTcpBufferSizes);
        if (!linkProperties.equals(mLinkProperties)) {
            mLinkProperties = linkProperties;
            log("sendLinkProperties " + mLinkProperties);
            mNetworkAgent.sendLinkProperties(mLinkProperties);
        }
    }

    /**
    /**
     * Update the metered and congested values from carrier configs and subscription overrides
     * Update the metered and congested values from carrier configs and subscription overrides
     */
     */
@@ -2322,7 +2279,6 @@ public class DataNetwork extends StateMachine {
        pw.println("mLinkProperties=" + mLinkProperties);
        pw.println("mLinkProperties=" + mLinkProperties);
        pw.println("mNetworkSliceInfo=" + mNetworkSliceInfo);
        pw.println("mNetworkSliceInfo=" + mNetworkSliceInfo);
        pw.println("mNetworkBandwidth=" + mNetworkBandwidth);
        pw.println("mNetworkBandwidth=" + mNetworkBandwidth);
        pw.println("mTcpBufferSizes=" + mTcpBufferSizes);
        pw.println("mTempNotMeteredSupported=" + mTempNotMeteredSupported);
        pw.println("mTempNotMeteredSupported=" + mTempNotMeteredSupported);
        pw.println("mTempNotMetered=" + mTempNotMetered);
        pw.println("mTempNotMetered=" + mTempNotMetered);
        pw.println("mCongested=" + mCongested);
        pw.println("mCongested=" + mCongested);