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

Commit 48234d27 authored by Erik Kline's avatar Erik Kline
Browse files

Stop unnecessary tethering reconfigurations

The TetheringConfiguraiton is retrieved at startup and on every
ACTION_CONFIGURATION_CHANGED broadcast.  Re-retrieving the config
at every upstream selection is unnecessary and fills up the logs.

Test: as follows
    - built
    - flashed
    - booted
    - "runtest frameworks-net" passes
Bug: 32163131
Bug: 63250751
Merged-In: Id089375a5699ac1157fc5f445876fee558d7bc7e
Merged-In: I1fc87f9c2a31f7fd16889275e6ba197b2b48a264
Merged-In: Ia6276ada690aa3e4870bb83dc4bf3ddcddc35e7b
(cherry picked from commit 6ee73daa)

Change-Id: Ic51123e173cc29cfcb52210707f2a0f8d2ab2e3b
parent 5bb30496
Loading
Loading
Loading
Loading
+9 −1
Original line number Original line Diff line number Diff line
@@ -252,6 +252,12 @@ public class Tethering extends BaseNetworkObserver {
        mUpstreamNetworkMonitor.updateMobileRequiresDun(mConfig.isDunRequired);
        mUpstreamNetworkMonitor.updateMobileRequiresDun(mConfig.isDunRequired);
    }
    }


    private void maybeUpdateConfiguration() {
        final int dunCheck = TetheringConfiguration.checkDunRequired(mContext);
        if (dunCheck == mConfig.dunCheck) return;
        updateConfiguration();
    }

    @Override
    @Override
    public void interfaceStatusChanged(String iface, boolean up) {
    public void interfaceStatusChanged(String iface, boolean up) {
        // Never called directly: only called from interfaceLinkStateChanged.
        // Never called directly: only called from interfaceLinkStateChanged.
@@ -1273,7 +1279,9 @@ public class Tethering extends BaseNetworkObserver {
        }
        }


        protected void chooseUpstreamType(boolean tryCell) {
        protected void chooseUpstreamType(boolean tryCell) {
            updateConfiguration(); // TODO - remove?
            // We rebuild configuration on ACTION_CONFIGURATION_CHANGED, but we
            // do not currently know how to watch for changes in DUN settings.
            maybeUpdateConfiguration();


            final NetworkState ns = mUpstreamNetworkMonitor.selectPreferredUpstreamType(
            final NetworkState ns = mUpstreamNetworkMonitor.selectPreferredUpstreamType(
                    mConfig.preferredUpstreamIfaceTypes);
                    mConfig.preferredUpstreamIfaceTypes);
+3 −2
Original line number Original line Diff line number Diff line
@@ -70,6 +70,7 @@ public class TetheringConfiguration {
    public final String[] tetherableUsbRegexs;
    public final String[] tetherableUsbRegexs;
    public final String[] tetherableWifiRegexs;
    public final String[] tetherableWifiRegexs;
    public final String[] tetherableBluetoothRegexs;
    public final String[] tetherableBluetoothRegexs;
    public final int dunCheck;
    public final boolean isDunRequired;
    public final boolean isDunRequired;
    public final Collection<Integer> preferredUpstreamIfaceTypes;
    public final Collection<Integer> preferredUpstreamIfaceTypes;
    public final String[] dhcpRanges;
    public final String[] dhcpRanges;
@@ -85,7 +86,7 @@ public class TetheringConfiguration {
        tetherableBluetoothRegexs = ctx.getResources().getStringArray(
        tetherableBluetoothRegexs = ctx.getResources().getStringArray(
                com.android.internal.R.array.config_tether_bluetooth_regexs);
                com.android.internal.R.array.config_tether_bluetooth_regexs);


        final int dunCheck = checkDunRequired(ctx);
        dunCheck = checkDunRequired(ctx);
        configLog.log("DUN check returned: " + dunCheckString(dunCheck));
        configLog.log("DUN check returned: " + dunCheckString(dunCheck));


        preferredUpstreamIfaceTypes = getUpstreamIfaceTypes(ctx, dunCheck);
        preferredUpstreamIfaceTypes = getUpstreamIfaceTypes(ctx, dunCheck);
@@ -172,7 +173,7 @@ public class TetheringConfiguration {
        return upstreamNames;
        return upstreamNames;
    }
    }


    private static int checkDunRequired(Context ctx) {
    public static int checkDunRequired(Context ctx) {
        final TelephonyManager tm = (TelephonyManager) ctx.getSystemService(TELEPHONY_SERVICE);
        final TelephonyManager tm = (TelephonyManager) ctx.getSystemService(TELEPHONY_SERVICE);
        return (tm != null) ? tm.getTetherApnRequired() : DUN_UNSPECIFIED;
        return (tm != null) ? tm.getTetherApnRequired() : DUN_UNSPECIFIED;
    }
    }