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

Commit 8092933a authored by Sarah Chin's avatar Sarah Chin
Browse files

Add support for RAT-based TCP buffer sizes

If the RAT-based resource overlay is not set,
config_tcp_buffers will be used instead.

Test: atest FrameworksTelephonyTests
Bug: 222323543
Change-Id: I1418518289a0d37c33dbadfbd9561df710e67105
parent d3f3058c
Loading
Loading
Loading
Loading
+54 −7
Original line number Diff line number Diff line
@@ -217,6 +217,9 @@ public class DataConfigManager extends Handler {
    /** A map of network types to the downlink and uplink bandwidth values for that network type */
    private @NonNull final @DataConfigNetworkType Map<String, DataNetwork.NetworkBandwidth>
            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. */
    private @NonNull final List<HandoverRule> mHandoverRuleList = new ArrayList<>();

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

        log("Data config updated. Config is " + (isConfigCarrierSpecific() ? "" : "not ")
@@ -625,18 +629,57 @@ public class DataConfigManager extends Handler {
        return mCarrierConfig.getInt(CarrierConfigManager.KEY_DEFAULT_MTU_INT);
    }

    /**
     * Update the TCP buffer sizes from the resource overlays.
     */
    private void updateTcpBuffers() {
        synchronized (this) {
            mTcpBufferSizeMap.clear();
            String[] configs = mResources.getStringArray(
                    com.android.internal.R.array.config_network_type_tcp_buffers);
            if (configs != null) {
                for (String config : configs) {
                    // split[0] = network type as string
                    // split[1] = rmem_min,rmem_def,rmem_max,wmem_min,wmem_def,wmem_max
                    String[] split = config.split(":");
                    if (split.length != 2) {
                        loge("Invalid TCP buffer sizes entry: " + config);
                        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)}.
     * The config string will have the following form, with values in bytes:
     * "read_min,read_default,read_max,write_min,write_default,write_max"
     *
     * Note that 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.
     *
     * @return The TCP configuration string.
     * @param networkType The network type. Note that {@link TelephonyManager#NETWORK_TYPE_LTE_CA}
     *                    can be used for LTE CA even though it's not a radio access technology.
     * @param serviceState The service state, used to determine NR state.
     * @return The TCP configuration string for the given network type or the default value from
     *         config_tcp_buffers if unavailable.
     */
    public @NonNull String getTcpConfigString() {
    public @NonNull String getTcpConfigString(@NetworkType int networkType,
            @NonNull ServiceState serviceState) {
        String config = mTcpBufferSizeMap.get(getDataConfigNetworkType(networkType, serviceState));
        if (TextUtils.isEmpty(config)) {
            config = getDefaultTcpConfigString();
        }
        return config;
    }

    /**
     * @return The fixed TCP buffer size configured based on the device's memory and performance.
     */
    public @NonNull String getDefaultTcpConfigString() {
        return mResources.getString(com.android.internal.R.string.config_tcp_buffers);
    }

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

    /** The TCP buffer sizes config. */
    private @NonNull String mTcpBufferSizes;

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

@@ -826,6 +829,7 @@ public class DataNetwork extends StateMachine {
        mAttachedNetworkRequestList.addAll(networkRequestList);
        mCid.put(AccessNetworkConstants.TRANSPORT_TYPE_WWAN, INVALID_CID);
        mCid.put(AccessNetworkConstants.TRANSPORT_TYPE_WLAN, INVALID_CID);
        mTcpBufferSizes = mDataConfigManager.getDefaultTcpConfigString();

        for (TelephonyNetworkRequest networkRequest : networkRequestList) {
            networkRequest.setAttachedNetwork(DataNetwork.this);
@@ -974,6 +978,7 @@ public class DataNetwork extends StateMachine {
                    // TODO: Should update suspend state when CSS indicator changes.
                    // TODO: Should update suspend state when call started/ended.
                    updateSuspendState();
                    updateTcpBufferSizes();
                    updateBandwidthFromDataConfig();
                    updateDataCallSessionStatsOfDrsOrRatChange((AsyncResult) msg.obj);
                    break;
@@ -2063,7 +2068,7 @@ public class DataNetwork extends StateMachine {
            linkProperties.setHttpProxy(proxy);
        }

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

        mNetworkSliceInfo = response.getSliceInfo();

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

    /**
     * Get the TCP buffer sizes config string.
     *
     * @return The TCP buffer sizes config 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.
     *
@@ -2293,6 +2320,7 @@ public class DataNetwork extends StateMachine {
        log("onDataConfigUpdated");

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

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

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

    /**
     * Update the TCP buffer sizes from resource overlays.
     */
    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
     */
@@ -3015,6 +3059,7 @@ public class DataNetwork extends StateMachine {
        pw.println("mLinkProperties=" + mLinkProperties);
        pw.println("mNetworkSliceInfo=" + mNetworkSliceInfo);
        pw.println("mNetworkBandwidth=" + mNetworkBandwidth);
        pw.println("mTcpBufferSizes=" + mTcpBufferSizes);
        pw.println("mTempNotMeteredSupported=" + mTempNotMeteredSupported);
        pw.println("mTempNotMetered=" + mTempNotMetered);
        pw.println("mCongested=" + mCongested);