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

Commit fc1bde92 authored by Erik Kline's avatar Erik Kline Committed by android-build-merger
Browse files

Merge "Prefer default Internet network for upstream tethering."

am: 3580a6a9

Change-Id: I0990d077627aed71b03e7aa40a8acc460448a774
parents 5ae46260 3580a6a9
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -498,6 +498,14 @@
        <item>0</item>
    </integer-array>

    <!-- When true, the tethering upstream network follows the current default
         Internet network (except when the current default network is mobile,
         in which case a DUN network will be used if required).

         When true, overrides the config_tether_upstream_types setting above.
    -->
    <bool translatable="false" name="config_tether_upstream_automatic">false</bool>

    <!-- If the DUN connection for this CDMA device supports more than just DUN -->
    <!-- traffic you should list them here. -->
    <!-- If this device is not CDMA this is ignored.  If this list is empty on -->
+1 −0
Original line number Diff line number Diff line
@@ -1822,6 +1822,7 @@
  <java-symbol type="array" name="config_tether_bluetooth_regexs" />
  <java-symbol type="array" name="config_tether_dhcp_range" />
  <java-symbol type="array" name="config_tether_upstream_types" />
  <java-symbol type="bool" name="config_tether_upstream_automatic" />
  <java-symbol type="array" name="config_tether_apndata" />
  <java-symbol type="array" name="config_tether_usb_regexs" />
  <java-symbol type="array" name="config_tether_wifi_regexs" />
+5 −1
Original line number Diff line number Diff line
@@ -898,6 +898,10 @@ public class ConnectivityService extends IConnectivityManager.Stub
            public boolean isTetheringSupported() {
                return ConnectivityService.this.isTetheringSupported();
            }
            @Override
            public NetworkRequest getDefaultNetworkRequest() {
                return mDefaultRequest;
            }
        };
        return new Tethering(mContext, mNetd, mStatsService, mPolicyManager,
                IoThread.get().getLooper(), new MockableSystemProperties(),
@@ -915,7 +919,7 @@ public class ConnectivityService extends IConnectivityManager.Stub

    private NetworkRequest createDefaultInternetRequestForTransport(
            int transportType, NetworkRequest.Type type) {
        NetworkCapabilities netCap = new NetworkCapabilities();
        final NetworkCapabilities netCap = new NetworkCapabilities();
        netCap.addCapability(NET_CAPABILITY_INTERNET);
        netCap.addCapability(NET_CAPABILITY_NOT_RESTRICTED);
        if (transportType > -1) {
+7 −15
Original line number Diff line number Diff line
@@ -1350,8 +1350,11 @@ public class Tethering extends BaseNetworkObserver {
            // do not currently know how to watch for changes in DUN settings.
            maybeUpdateConfiguration();

            final NetworkState ns = mUpstreamNetworkMonitor.selectPreferredUpstreamType(
                    mConfig.preferredUpstreamIfaceTypes);
            final TetheringConfiguration config = mConfig;
            final NetworkState ns = (config.chooseUpstreamAutomatically)
                    ? mUpstreamNetworkMonitor.getCurrentPreferredUpstream()
                    : mUpstreamNetworkMonitor.selectPreferredUpstreamType(
                            config.preferredUpstreamIfaceTypes);
            if (ns == null) {
                if (tryCell) {
                    mUpstreamNetworkMonitor.registerMobileNetworkRequest();
@@ -1380,9 +1383,7 @@ public class Tethering extends BaseNetworkObserver {
            }
            notifyDownstreamsOfNewUpstreamIface(ifaces);
            if (ns != null && pertainsToCurrentUpstream(ns)) {
                // If we already have NetworkState for this network examine
                // it immediately, because there likely will be no second
                // EVENT_ON_AVAILABLE (it was already received).
                // If we already have NetworkState for this network update it immediately.
                handleNewUpstreamNetworkState(ns);
            } else if (mCurrentUpstreamIfaceSet == null) {
                // There are no available upstream networks.
@@ -1498,15 +1499,6 @@ public class Tethering extends BaseNetworkObserver {
            }

            switch (arg1) {
                case UpstreamNetworkMonitor.EVENT_ON_AVAILABLE:
                    // The default network changed, or DUN connected
                    // before this callback was processed. Updates
                    // for the current NetworkCapabilities and
                    // LinkProperties have been requested (default
                    // request) or are being sent shortly (DUN). Do
                    // nothing until they arrive; if no updates
                    // arrive there's nothing to do.
                    break;
                case UpstreamNetworkMonitor.EVENT_ON_CAPABILITIES:
                    handleNewUpstreamNetworkState(ns);
                    break;
@@ -1539,7 +1531,7 @@ public class Tethering extends BaseNetworkObserver {
                }

                mSimChange.startListening();
                mUpstreamNetworkMonitor.start();
                mUpstreamNetworkMonitor.start(mDeps.getDefaultNetworkRequest());

                // TODO: De-duplicate with updateUpstreamWanted() below.
                if (upstreamWanted()) {
+14 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import static com.android.internal.R.array.config_tether_dhcp_range;
import static com.android.internal.R.array.config_tether_usb_regexs;
import static com.android.internal.R.array.config_tether_upstream_types;
import static com.android.internal.R.array.config_tether_wifi_regexs;
import static com.android.internal.R.bool.config_tether_upstream_automatic;
import static com.android.internal.R.string.config_mobile_hotspot_provision_app_no_ui;

import android.content.Context;
@@ -86,6 +87,7 @@ public class TetheringConfiguration {
    public final String[] tetherableBluetoothRegexs;
    public final int dunCheck;
    public final boolean isDunRequired;
    public final boolean chooseUpstreamAutomatically;
    public final Collection<Integer> preferredUpstreamIfaceTypes;
    public final String[] dhcpRanges;
    public final String[] defaultIPv4DNS;
@@ -106,6 +108,7 @@ public class TetheringConfiguration {
        dunCheck = checkDunRequired(ctx);
        configLog.log("DUN check returned: " + dunCheckString(dunCheck));

        chooseUpstreamAutomatically = getResourceBoolean(ctx, config_tether_upstream_automatic);
        preferredUpstreamIfaceTypes = getUpstreamIfaceTypes(ctx, dunCheck);
        isDunRequired = preferredUpstreamIfaceTypes.contains(TYPE_MOBILE_DUN);

@@ -142,6 +145,8 @@ public class TetheringConfiguration {
        pw.print("isDunRequired: ");
        pw.println(isDunRequired);

        pw.print("chooseUpstreamAutomatically: ");
        pw.println(chooseUpstreamAutomatically);
        dumpStringArray(pw, "preferredUpstreamIfaceTypes",
                preferredUpstreamNames(preferredUpstreamIfaceTypes));

@@ -160,6 +165,7 @@ public class TetheringConfiguration {
        sj.add(String.format("tetherableBluetoothRegexs:%s",
                makeString(tetherableBluetoothRegexs)));
        sj.add(String.format("isDunRequired:%s", isDunRequired));
        sj.add(String.format("chooseUpstreamAutomatically:%s", chooseUpstreamAutomatically));
        sj.add(String.format("preferredUpstreamIfaceTypes:%s",
                makeString(preferredUpstreamNames(preferredUpstreamIfaceTypes))));
        sj.add(String.format("provisioningApp:%s", makeString(provisioningApp)));
@@ -286,6 +292,14 @@ public class TetheringConfiguration {
        }
    }

    private static boolean getResourceBoolean(Context ctx, int resId) {
        try {
            return ctx.getResources().getBoolean(resId);
        } catch (Resources.NotFoundException e404) {
            return false;
        }
    }

    private static String[] getResourceStringArray(Context ctx, int resId) {
        try {
            final String[] strArray = ctx.getResources().getStringArray(resId);
Loading