From 6ee73daa0aa90620e4b2cb13ead4b53d16f45010 Mon Sep 17 00:00:00 2001 From: Erik Kline Date: Sat, 8 Jul 2017 20:36:37 +0900 Subject: [PATCH] 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 Change-Id: Ia6276ada690aa3e4870bb83dc4bf3ddcddc35e7b --- .../com/android/server/connectivity/Tethering.java | 10 +++++++++- .../connectivity/tethering/TetheringConfiguration.java | 5 +++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/services/core/java/com/android/server/connectivity/Tethering.java b/services/core/java/com/android/server/connectivity/Tethering.java index 1bee594de9f1b..0a9dba72ce82b 100644 --- a/services/core/java/com/android/server/connectivity/Tethering.java +++ b/services/core/java/com/android/server/connectivity/Tethering.java @@ -255,6 +255,12 @@ public class Tethering extends BaseNetworkObserver { mUpstreamNetworkMonitor.updateMobileRequiresDun(mConfig.isDunRequired); } + private void maybeUpdateConfiguration() { + final int dunCheck = TetheringConfiguration.checkDunRequired(mContext); + if (dunCheck == mConfig.dunCheck) return; + updateConfiguration(); + } + @Override public void interfaceStatusChanged(String iface, boolean up) { // Never called directly: only called from interfaceLinkStateChanged. @@ -1283,7 +1289,9 @@ public class Tethering extends BaseNetworkObserver { } 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( mConfig.preferredUpstreamIfaceTypes); diff --git a/services/core/java/com/android/server/connectivity/tethering/TetheringConfiguration.java b/services/core/java/com/android/server/connectivity/tethering/TetheringConfiguration.java index 7efa1664788cb..acbc10b9dc43d 100644 --- a/services/core/java/com/android/server/connectivity/tethering/TetheringConfiguration.java +++ b/services/core/java/com/android/server/connectivity/tethering/TetheringConfiguration.java @@ -70,6 +70,7 @@ public class TetheringConfiguration { public final String[] tetherableUsbRegexs; public final String[] tetherableWifiRegexs; public final String[] tetherableBluetoothRegexs; + public final int dunCheck; public final boolean isDunRequired; public final Collection preferredUpstreamIfaceTypes; public final String[] dhcpRanges; @@ -88,7 +89,7 @@ public class TetheringConfiguration { tetherableBluetoothRegexs = ctx.getResources().getStringArray( com.android.internal.R.array.config_tether_bluetooth_regexs); - final int dunCheck = checkDunRequired(ctx); + dunCheck = checkDunRequired(ctx); configLog.log("DUN check returned: " + dunCheckString(dunCheck)); preferredUpstreamIfaceTypes = getUpstreamIfaceTypes(ctx, dunCheck); @@ -175,7 +176,7 @@ public class TetheringConfiguration { return upstreamNames; } - private static int checkDunRequired(Context ctx) { + public static int checkDunRequired(Context ctx) { final TelephonyManager tm = (TelephonyManager) ctx.getSystemService(TELEPHONY_SERVICE); return (tm != null) ? tm.getTetherApnRequired() : DUN_UNSPECIFIED; }