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

Commit df554bb5 authored by Junyu Lai's avatar Junyu Lai Committed by Android (Google) Code Review
Browse files

Merge changes from topic "am-99b870448c8c43b2815c42861ac6235c-rvc-dev" into rvc-dev

* changes:
  [SP18.6] Make offload controller poll interval configurable
  [SP18.5] Create offload controller poll interval to resource
  [SP18.4] Add unit test for polling network stats in OffloadController
  [SP18.3] Adapt TestableNetworkStatsProviderCbBinder
parents 0cbca1a2 833f4f6f
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -64,6 +64,13 @@
    <string-array translatable="false" name="config_tether_dhcp_range">
    </string-array>

    <!-- Used to config periodic polls tether offload stats from tethering offload HAL to make the
     data warnings work. 5000(ms) by default. If the device doesn't want to poll tether
     offload stats, this should be -1. Note that this setting could be override by
     runtime resource overlays.
    -->
    <integer translatable="false" name="config_tether_offload_poll_interval">5000</integer>

    <!-- Array of ConnectivityManager.TYPE_{BLUETOOTH, ETHERNET, MOBILE, MOBILE_DUN, MOBILE_HIPRI,
         WIFI} values allowable for tethering.

+1 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@
            <item type="array" name="config_tether_bluetooth_regexs"/>
            <item type="array" name="config_tether_dhcp_range"/>
            <item type="bool" name="config_tether_enable_legacy_dhcp_server"/>
            <item type="integer" name="config_tether_offload_poll_interval"/>
            <item type="array" name="config_tether_upstream_types"/>
            <item type="bool" name="config_tether_upstream_automatic"/>
            <!-- Configuration values for tethering entitlement check -->
+11 −8
Original line number Diff line number Diff line
@@ -26,6 +26,8 @@ import static android.net.NetworkStats.UID_TETHERING;
import static android.net.netstats.provider.NetworkStatsProvider.QUOTA_UNLIMITED;
import static android.provider.Settings.Global.TETHER_OFFLOAD_DISABLED;

import static com.android.networkstack.tethering.TetheringConfiguration.DEFAULT_TETHER_OFFLOAD_POLL_INTERVAL_MS;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.usage.NetworkStatsManager;
@@ -77,7 +79,6 @@ public class OffloadController {
    private static final boolean DBG = false;
    private static final String ANYIP = "0.0.0.0";
    private static final ForwardedStats EMPTY_STATS = new ForwardedStats();
    private static final int DEFAULT_PERFORM_POLL_INTERVAL_MS = 5000;

    @VisibleForTesting
    enum StatsType {
@@ -134,11 +135,9 @@ public class OffloadController {
    private final Dependencies mDeps;

    // TODO: Put more parameters in constructor into dependency object.
    static class Dependencies {
        int getPerformPollInterval() {
            // TODO: Consider make this configurable.
            return DEFAULT_PERFORM_POLL_INTERVAL_MS;
        }
    interface Dependencies {
        @NonNull
        TetheringConfiguration getTetherConfig();
    }

    public OffloadController(Handler h, OffloadHardwareInterface hwi,
@@ -452,12 +451,16 @@ public class OffloadController {
        if (mHandler.hasCallbacks(mScheduledPollingTask)) {
            mHandler.removeCallbacks(mScheduledPollingTask);
        }
        mHandler.postDelayed(mScheduledPollingTask, mDeps.getPerformPollInterval());
        mHandler.postDelayed(mScheduledPollingTask,
                mDeps.getTetherConfig().getOffloadPollInterval());
    }

    private boolean isPollingStatsNeeded() {
        return started() && mRemainingAlertQuota > 0
                && !TextUtils.isEmpty(currentUpstreamInterface());
                && !TextUtils.isEmpty(currentUpstreamInterface())
                && mDeps.getTetherConfig() != null
                && mDeps.getTetherConfig().getOffloadPollInterval()
                >= DEFAULT_TETHER_OFFLOAD_POLL_INTERVAL_MS;
    }

    private boolean maybeUpdateDataLimit(String iface) {
+7 −1
Original line number Diff line number Diff line
@@ -273,7 +273,13 @@ public class Tethering {
        mHandler = mTetherMasterSM.getHandler();
        mOffloadController = new OffloadController(mHandler,
                mDeps.getOffloadHardwareInterface(mHandler, mLog), mContext.getContentResolver(),
                statsManager, mLog, new OffloadController.Dependencies());
                statsManager, mLog, new OffloadController.Dependencies() {

                    @Override
                    public TetheringConfiguration getTetherConfig() {
                        return mConfig;
                    }
                });
        mUpstreamNetworkMonitor = mDeps.getUpstreamNetworkMonitor(mContext, mTetherMasterSM, mLog,
                TetherMasterSM.EVENT_UPSTREAM_CALLBACK);
        mForwardedDownstreams = new LinkedHashSet<>();
+20 −0
Original line number Diff line number Diff line
@@ -78,6 +78,12 @@ public class TetheringConfiguration {
    public static final String TETHER_ENABLE_LEGACY_DHCP_SERVER =
            "tether_enable_legacy_dhcp_server";

    /**
     * Default value that used to periodic polls tether offload stats from tethering offload HAL
     * to make the data warnings work.
     */
    public static final int DEFAULT_TETHER_OFFLOAD_POLL_INTERVAL_MS = 5000;

    public final String[] tetherableUsbRegexs;
    public final String[] tetherableWifiRegexs;
    public final String[] tetherableWifiP2pRegexs;
@@ -96,6 +102,8 @@ public class TetheringConfiguration {

    public final int activeDataSubId;

    private final int mOffloadPollInterval;

    public TetheringConfiguration(Context ctx, SharedLog log, int id) {
        final SharedLog configLog = log.forSubComponent("config");

@@ -129,6 +137,10 @@ public class TetheringConfiguration {
                R.integer.config_mobile_hotspot_provision_check_period,
                0 /* No periodic re-check */);

        mOffloadPollInterval = getResourceInteger(res,
                R.integer.config_tether_offload_poll_interval,
                DEFAULT_TETHER_OFFLOAD_POLL_INTERVAL_MS);

        configLog.log(toString());
    }

@@ -189,6 +201,9 @@ public class TetheringConfiguration {
        dumpStringArray(pw, "legacyDhcpRanges", legacyDhcpRanges);
        dumpStringArray(pw, "defaultIPv4DNS", defaultIPv4DNS);

        pw.print("offloadPollInterval: ");
        pw.println(mOffloadPollInterval);

        dumpStringArray(pw, "provisioningApp", provisioningApp);
        pw.print("provisioningAppNoUi: ");
        pw.println(provisioningAppNoUi);
@@ -208,6 +223,7 @@ public class TetheringConfiguration {
                makeString(tetherableBluetoothRegexs)));
        sj.add(String.format("isDunRequired:%s", isDunRequired));
        sj.add(String.format("chooseUpstreamAutomatically:%s", chooseUpstreamAutomatically));
        sj.add(String.format("offloadPollInterval:%d", mOffloadPollInterval));
        sj.add(String.format("preferredUpstreamIfaceTypes:%s",
                toIntArray(preferredUpstreamIfaceTypes)));
        sj.add(String.format("provisioningApp:%s", makeString(provisioningApp)));
@@ -246,6 +262,10 @@ public class TetheringConfiguration {
        return (tm != null) ? tm.isTetheringApnRequired() : false;
    }

    public int getOffloadPollInterval() {
        return mOffloadPollInterval;
    }

    private static Collection<Integer> getUpstreamIfaceTypes(Resources res, boolean dunRequired) {
        final int[] ifaceTypes = res.getIntArray(R.array.config_tether_upstream_types);
        final ArrayList<Integer> upstreamIfaceTypes = new ArrayList<>(ifaceTypes.length);
Loading