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

Commit 9a5b90c6 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Add ingress rate limit to developer settings" into tm-dev am: d328f73e

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/17126083

Change-Id: Idd79df6e16c4345c03e2832f65551ee327837536
parents 5786613d d328f73e
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -1626,4 +1626,24 @@
        <item>300000</item>
    </string-array>

    <!-- Developer settings: ingress rate limit entries. [DO NOT TRANSLATE] -->
    <string-array name="ingress_rate_limit_entries">
        <item>@string/ingress_rate_limit_no_limit_entry</item>
        <item>128kbps</item>
        <item>256kbps</item>
        <item>1Mbps</item>
        <item>5Mbps</item>
        <item>15Mbps</item>
    </string-array>

    <!-- Developer settings: ingress rate limit values. [DO NOT TRANSLATE] -->
    <string-array name="ingress_rate_limit_values">
        <item>-1</item> <!-- -1 codes for disabled -->
        <item>16000</item> <!-- 128kbps == 16000B/s -->
        <item>32000</item> <!-- 256kbps == 32000B/s -->
        <item>125000</item> <!-- 1Mbps == 125000B/s -->
        <item>625000</item> <!-- 5Mbps == 625000/s -->
        <item>1875000</item> <!-- 15Mbps == 1875000/s -->
    </string-array>

</resources>
+9 −0
Original line number Diff line number Diff line
@@ -14037,4 +14037,13 @@
    <string name="bluetooth_details_head_tracking_title">Make audio more realistic</string>
    <!-- The summary of the head tracking [CHAR LIMIT=none] -->
    <string name="bluetooth_details_head_tracking_summary">Shift positioning of audio so it sounds more natural.</string>
    <!-- Developer Settings: Title for network bandwidth ingress rate limit [CHAR LIMIT=none] -->
    <string name="ingress_rate_limit_title">Network download rate limit</string>
    <!-- Developer Settings: Summary for network bandwidth ingress rate limit [CHAR LIMIT=none] -->
    <string name="ingress_rate_limit_summary">Configure the network bandwidth ingress rate limit which is applied to all networks that provide internet connectivity.</string>
    <!-- Developer Settings: Dialog for network bandwidth ingress rate limit [CHAR LIMIT=none] -->
    <string name="ingress_rate_limit_dialog_title">Configure network download rate limit</string>
    <!-- Developer Settings: Dialog ListPreference option to disable network bandwidth ingress rate limit [CHAR LIMIT=none] -->
    <string name="ingress_rate_limit_no_limit_entry">No limit</string>
</resources>
+8 −0
Original line number Diff line number Diff line
@@ -297,6 +297,14 @@
            android:title="@string/tethering_hardware_offload"
            android:summary="@string/tethering_hardware_offload_summary" />

        <ListPreference
            android:key="ingress_rate_limit"
            android:title="@string/ingress_rate_limit_title"
            android:summary="@string/ingress_rate_limit_summary"
            android:dialogTitle="@string/ingress_rate_limit_dialog_title"
            android:entries="@array/ingress_rate_limit_entries"
            android:entryValues="@array/ingress_rate_limit_values" />

        <com.android.settingslib.RestrictedPreference
            android:key="default_usb_configuration"
            android:fragment="com.android.settings.connecteddevice.usb.UsbDefaultFragment"
+1 −0
Original line number Diff line number Diff line
@@ -606,6 +606,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
        controllers.add(new SharedDataPreferenceController(context));
        controllers.add(new OverlaySettingsPreferenceController(context));
        controllers.add(new StylusHandwritingPreferenceController(context));
        controllers.add(new IngressRateLimitPreferenceController((context)));

        return controllers;
    }
+82 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settings.development;

import android.content.Context;
import android.net.ConnectivitySettingsManager;
import android.util.Log;

import androidx.preference.ListPreference;
import androidx.preference.Preference;

import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.development.DeveloperOptionsPreferenceController;

/**
 * Controller for ingress rate limit developer setting.
 */
public class IngressRateLimitPreferenceController extends DeveloperOptionsPreferenceController
        implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin {
    private static final String TAG = "IngressRateLimitPreferenceController";
    private static final String INGRESS_RATE_LIMIT_KEY = "ingress_rate_limit";
    private static final int RATE_LIMIT_DISABLED = -1;

    public IngressRateLimitPreferenceController(Context context) {
        super(context);
    }

    @Override
    public String getPreferenceKey() {
        return INGRESS_RATE_LIMIT_KEY;
    }

    @Override
    public boolean onPreferenceChange(Preference preference, Object newValue) {
        final long value = Long.parseLong(newValue.toString());
        try {
            ConnectivitySettingsManager.setIngressRateLimitInBytesPerSecond(mContext, value);
            return true;
        } catch (IllegalArgumentException e) {
            Log.e(TAG, "invalid rate limit", e);
            return false;
        }
    }

    @Override
    public void updateState(Preference preference) {
        final String ingressRateLimit = String.valueOf(
                ConnectivitySettingsManager.getIngressRateLimitInBytesPerSecond(mContext));

        // verify ingressRateLimit is valid / present in ListPreference; else do nothing.
        final CharSequence[] entryValues = ((ListPreference) preference).getEntryValues();
        for (int i = 0; i < entryValues.length; i++) {
            if (ingressRateLimit.contentEquals(entryValues[i])) {
                ((ListPreference) preference).setValue(ingressRateLimit);
                return;
            }
        }
    }

    @Override
    protected void onDeveloperOptionsSwitchDisabled() {
        super.onDeveloperOptionsSwitchDisabled();
        // disable rate limiting when developer options are disabled
        ConnectivitySettingsManager.setIngressRateLimitInBytesPerSecond(mContext,
                RATE_LIMIT_DISABLED);
        ((ListPreference) mPreference).setValue(String.valueOf(RATE_LIMIT_DISABLED));
    }
}
Loading