Loading packages/Tethering/res/values/config.xml +6 −0 Original line number Original line Diff line number Diff line Loading @@ -57,6 +57,12 @@ <item>"bt-pan"</item> <item>"bt-pan"</item> </string-array> </string-array> <!-- Use the BPF offload for tethering when the kernel has support. True by default. If the device doesn't want to support tether BPF offload, this should be false. Note that this setting could be override by device config. --> <bool translatable="false" name="config_tether_enable_bpf_offload">true</bool> <!-- Use the old dnsmasq DHCP server for tethering instead of the framework implementation. --> <!-- Use the old dnsmasq DHCP server for tethering instead of the framework implementation. --> <bool translatable="false" name="config_tether_enable_legacy_dhcp_server">false</bool> <bool translatable="false" name="config_tether_enable_legacy_dhcp_server">false</bool> Loading packages/Tethering/res/values/overlayable.xml +5 −0 Original line number Original line Diff line number Diff line Loading @@ -23,6 +23,11 @@ <item type="array" name="config_tether_wifi_p2p_regexs"/> <item type="array" name="config_tether_wifi_p2p_regexs"/> <item type="array" name="config_tether_bluetooth_regexs"/> <item type="array" name="config_tether_bluetooth_regexs"/> <item type="array" name="config_tether_dhcp_range"/> <item type="array" name="config_tether_dhcp_range"/> <!-- Use the BPF offload for tethering when the kernel has support. True by default. If the device doesn't want to support tether BPF offload, this should be false. Note that this setting could be override by device config. --> <item type="bool" name="config_tether_enable_bpf_offload"/> <item type="bool" name="config_tether_enable_legacy_dhcp_server"/> <item type="bool" name="config_tether_enable_legacy_dhcp_server"/> <item type="integer" name="config_tether_offload_poll_interval"/> <item type="integer" name="config_tether_offload_poll_interval"/> <item type="array" name="config_tether_upstream_types"/> <item type="array" name="config_tether_upstream_types"/> Loading packages/Tethering/src/android/net/ip/IpServer.java +27 −7 Original line number Original line Diff line number Diff line Loading @@ -227,6 +227,7 @@ public class IpServer extends StateMachine { private final int mInterfaceType; private final int mInterfaceType; private final LinkProperties mLinkProperties; private final LinkProperties mLinkProperties; private final boolean mUsingLegacyDhcp; private final boolean mUsingLegacyDhcp; private final boolean mUsingBpfOffload; private final Dependencies mDeps; private final Dependencies mDeps; Loading Loading @@ -304,7 +305,8 @@ public class IpServer extends StateMachine { public IpServer( public IpServer( String ifaceName, Looper looper, int interfaceType, SharedLog log, String ifaceName, Looper looper, int interfaceType, SharedLog log, INetd netd, Callback callback, boolean usingLegacyDhcp, Dependencies deps) { INetd netd, Callback callback, boolean usingLegacyDhcp, boolean usingBpfOffload, Dependencies deps) { super(ifaceName, looper); super(ifaceName, looper); mLog = log.forSubComponent(ifaceName); mLog = log.forSubComponent(ifaceName); mNetd = netd; mNetd = netd; Loading @@ -314,6 +316,7 @@ public class IpServer extends StateMachine { mInterfaceType = interfaceType; mInterfaceType = interfaceType; mLinkProperties = new LinkProperties(); mLinkProperties = new LinkProperties(); mUsingLegacyDhcp = usingLegacyDhcp; mUsingLegacyDhcp = usingLegacyDhcp; mUsingBpfOffload = usingBpfOffload; mDeps = deps; mDeps = deps; resetLinkProperties(); resetLinkProperties(); mLastError = TetheringManager.TETHER_ERROR_NO_ERROR; mLastError = TetheringManager.TETHER_ERROR_NO_ERROR; Loading @@ -321,9 +324,16 @@ public class IpServer extends StateMachine { mIpNeighborMonitor = mDeps.getIpNeighborMonitor(getHandler(), mLog, mIpNeighborMonitor = mDeps.getIpNeighborMonitor(getHandler(), mLog, new MyNeighborEventConsumer()); new MyNeighborEventConsumer()); // IP neighbor monitor monitors the neighbor event for adding/removing offload // forwarding rules per client. If BPF offload is not supported, don't start listening // neighbor events. See updateIpv6ForwardingRules, addIpv6ForwardingRule, // removeIpv6ForwardingRule. if (mUsingBpfOffload) { if (!mIpNeighborMonitor.start()) { if (!mIpNeighborMonitor.start()) { mLog.e("Failed to create IpNeighborMonitor on " + mIfaceName); mLog.e("Failed to create IpNeighborMonitor on " + mIfaceName); } } } mInitialState = new InitialState(); mInitialState = new InitialState(); mLocalHotspotState = new LocalHotspotState(); mLocalHotspotState = new LocalHotspotState(); Loading Loading @@ -715,12 +725,12 @@ public class IpServer extends StateMachine { final String upstreamIface = v6only.getInterfaceName(); final String upstreamIface = v6only.getInterfaceName(); params = new RaParams(); params = new RaParams(); // We advertise an mtu lower by 16, which is the closest multiple of 8 >= 14, // When BPF offload is enabled, we advertise an mtu lower by 16, which is the closest // the ethernet header size. This makes kernel ebpf tethering offload happy. // multiple of 8 >= 14, the ethernet header size. This makes kernel ebpf tethering // This hack should be reverted once we have the kernel fixed up. // offload happy. This hack should be reverted once we have the kernel fixed up. // Note: this will automatically clamp to at least 1280 (ipv6 minimum mtu) // Note: this will automatically clamp to at least 1280 (ipv6 minimum mtu) // see RouterAdvertisementDaemon.java putMtu() // see RouterAdvertisementDaemon.java putMtu() params.mtu = v6only.getMtu() - 16; params.mtu = mUsingBpfOffload ? v6only.getMtu() - 16 : v6only.getMtu(); params.hasDefaultRoute = v6only.hasIpv6DefaultRoute(); params.hasDefaultRoute = v6only.hasIpv6DefaultRoute(); if (params.hasDefaultRoute) params.hopLimit = getHopLimit(upstreamIface); if (params.hasDefaultRoute) params.hopLimit = getHopLimit(upstreamIface); Loading Loading @@ -844,6 +854,11 @@ public class IpServer extends StateMachine { } } private void addIpv6ForwardingRule(Ipv6ForwardingRule rule) { private void addIpv6ForwardingRule(Ipv6ForwardingRule rule) { // Theoretically, we don't need this check because IP neighbor monitor doesn't start if BPF // offload is disabled. Add this check just in case. // TODO: Perhaps remove this protection check. if (!mUsingBpfOffload) return; try { try { mNetd.tetherOffloadRuleAdd(rule.toTetherOffloadRuleParcel()); mNetd.tetherOffloadRuleAdd(rule.toTetherOffloadRuleParcel()); mIpv6ForwardingRules.put(rule.address, rule); mIpv6ForwardingRules.put(rule.address, rule); Loading @@ -853,6 +868,11 @@ public class IpServer extends StateMachine { } } private void removeIpv6ForwardingRule(Ipv6ForwardingRule rule, boolean removeFromMap) { private void removeIpv6ForwardingRule(Ipv6ForwardingRule rule, boolean removeFromMap) { // Theoretically, we don't need this check because IP neighbor monitor doesn't start if BPF // offload is disabled. Add this check just in case. // TODO: Perhaps remove this protection check. if (!mUsingBpfOffload) return; try { try { mNetd.tetherOffloadRuleRemove(rule.toTetherOffloadRuleParcel()); mNetd.tetherOffloadRuleRemove(rule.toTetherOffloadRuleParcel()); if (removeFromMap) { if (removeFromMap) { Loading packages/Tethering/src/com/android/networkstack/tethering/Tethering.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -2296,7 +2296,7 @@ public class Tethering { final TetherState tetherState = new TetherState( final TetherState tetherState = new TetherState( new IpServer(iface, mLooper, interfaceType, mLog, mNetd, new IpServer(iface, mLooper, interfaceType, mLog, mNetd, makeControlCallback(), mConfig.enableLegacyDhcpServer, makeControlCallback(), mConfig.enableLegacyDhcpServer, mDeps.getIpServerDependencies())); mConfig.enableBpfOffload, mDeps.getIpServerDependencies())); mTetherStates.put(iface, tetherState); mTetherStates.put(iface, tetherState); tetherState.ipServer.start(); tetherState.ipServer.start(); } } Loading packages/Tethering/src/com/android/networkstack/tethering/TetheringConfiguration.java +38 −4 Original line number Original line Diff line number Diff line Loading @@ -72,6 +72,12 @@ public class TetheringConfiguration { private static final String[] DEFAULT_IPV4_DNS = {"8.8.4.4", "8.8.8.8"}; private static final String[] DEFAULT_IPV4_DNS = {"8.8.4.4", "8.8.8.8"}; /** * Override enabling BPF offload configuration for tethering. */ public static final String OVERRIDE_TETHER_ENABLE_BPF_OFFLOAD = "override_tether_enable_bpf_offload"; /** /** * Use the old dnsmasq DHCP server for tethering instead of the framework implementation. * Use the old dnsmasq DHCP server for tethering instead of the framework implementation. */ */ Loading @@ -95,6 +101,8 @@ public class TetheringConfiguration { public final String[] legacyDhcpRanges; public final String[] legacyDhcpRanges; public final String[] defaultIPv4DNS; public final String[] defaultIPv4DNS; public final boolean enableLegacyDhcpServer; public final boolean enableLegacyDhcpServer; // TODO: Add to TetheringConfigurationParcel if required. public final boolean enableBpfOffload; public final String[] provisioningApp; public final String[] provisioningApp; public final String provisioningAppNoUi; public final String provisioningAppNoUi; Loading Loading @@ -124,11 +132,12 @@ public class TetheringConfiguration { isDunRequired = checkDunRequired(ctx); isDunRequired = checkDunRequired(ctx); chooseUpstreamAutomatically = getResourceBoolean( chooseUpstreamAutomatically = getResourceBoolean( res, R.bool.config_tether_upstream_automatic); res, R.bool.config_tether_upstream_automatic, false /** default value */); preferredUpstreamIfaceTypes = getUpstreamIfaceTypes(res, isDunRequired); preferredUpstreamIfaceTypes = getUpstreamIfaceTypes(res, isDunRequired); legacyDhcpRanges = getLegacyDhcpRanges(res); legacyDhcpRanges = getLegacyDhcpRanges(res); defaultIPv4DNS = copy(DEFAULT_IPV4_DNS); defaultIPv4DNS = copy(DEFAULT_IPV4_DNS); enableBpfOffload = getEnableBpfOffload(res); enableLegacyDhcpServer = getEnableLegacyDhcpServer(res); enableLegacyDhcpServer = getEnableLegacyDhcpServer(res); provisioningApp = getResourceStringArray(res, R.array.config_mobile_hotspot_provision_app); provisioningApp = getResourceStringArray(res, R.array.config_mobile_hotspot_provision_app); Loading Loading @@ -208,6 +217,9 @@ public class TetheringConfiguration { pw.print("provisioningAppNoUi: "); pw.print("provisioningAppNoUi: "); pw.println(provisioningAppNoUi); pw.println(provisioningAppNoUi); pw.print("enableBpfOffload: "); pw.println(enableBpfOffload); pw.print("enableLegacyDhcpServer: "); pw.print("enableLegacyDhcpServer: "); pw.println(enableLegacyDhcpServer); pw.println(enableLegacyDhcpServer); } } Loading @@ -228,6 +240,7 @@ public class TetheringConfiguration { toIntArray(preferredUpstreamIfaceTypes))); toIntArray(preferredUpstreamIfaceTypes))); sj.add(String.format("provisioningApp:%s", makeString(provisioningApp))); sj.add(String.format("provisioningApp:%s", makeString(provisioningApp))); sj.add(String.format("provisioningAppNoUi:%s", provisioningAppNoUi)); sj.add(String.format("provisioningAppNoUi:%s", provisioningAppNoUi)); sj.add(String.format("enableBpfOffload:%s", enableBpfOffload)); sj.add(String.format("enableLegacyDhcpServer:%s", enableLegacyDhcpServer)); sj.add(String.format("enableLegacyDhcpServer:%s", enableLegacyDhcpServer)); return String.format("TetheringConfiguration{%s}", sj.toString()); return String.format("TetheringConfiguration{%s}", sj.toString()); } } Loading Loading @@ -332,11 +345,11 @@ public class TetheringConfiguration { } } } } private static boolean getResourceBoolean(Resources res, int resId) { private static boolean getResourceBoolean(Resources res, int resId, boolean defaultValue) { try { try { return res.getBoolean(resId); return res.getBoolean(resId); } catch (Resources.NotFoundException e404) { } catch (Resources.NotFoundException e404) { return false; return defaultValue; } } } } Loading @@ -357,8 +370,29 @@ public class TetheringConfiguration { } } } } private boolean getEnableBpfOffload(final Resources res) { // Get BPF offload config // Priority 1: Device config // Priority 2: Resource config // Priority 3: Default value final boolean resourceValue = getResourceBoolean( res, R.bool.config_tether_enable_bpf_offload, true /** default value */); // Due to the limitation of static mock for testing, using #getProperty directly instead // of getDeviceConfigBoolean. getDeviceConfigBoolean is not invoked because it uses // #getBoolean to get the boolean device config. The test can't know that the returned // boolean value comes from device config or default value (because of null property // string). Because the test would like to verify null property boolean string case, // use DeviceConfig.getProperty here. See also the test case testBpfOffload{*} in // TetheringConfigurationTest.java. final String value = DeviceConfig.getProperty( NAMESPACE_CONNECTIVITY, OVERRIDE_TETHER_ENABLE_BPF_OFFLOAD); return (value != null) ? Boolean.parseBoolean(value) : resourceValue; } private boolean getEnableLegacyDhcpServer(final Resources res) { private boolean getEnableLegacyDhcpServer(final Resources res) { return getResourceBoolean(res, R.bool.config_tether_enable_legacy_dhcp_server) return getResourceBoolean( res, R.bool.config_tether_enable_legacy_dhcp_server, false /** default value */) || getDeviceConfigBoolean(TETHER_ENABLE_LEGACY_DHCP_SERVER); || getDeviceConfigBoolean(TETHER_ENABLE_LEGACY_DHCP_SERVER); } } Loading Loading
packages/Tethering/res/values/config.xml +6 −0 Original line number Original line Diff line number Diff line Loading @@ -57,6 +57,12 @@ <item>"bt-pan"</item> <item>"bt-pan"</item> </string-array> </string-array> <!-- Use the BPF offload for tethering when the kernel has support. True by default. If the device doesn't want to support tether BPF offload, this should be false. Note that this setting could be override by device config. --> <bool translatable="false" name="config_tether_enable_bpf_offload">true</bool> <!-- Use the old dnsmasq DHCP server for tethering instead of the framework implementation. --> <!-- Use the old dnsmasq DHCP server for tethering instead of the framework implementation. --> <bool translatable="false" name="config_tether_enable_legacy_dhcp_server">false</bool> <bool translatable="false" name="config_tether_enable_legacy_dhcp_server">false</bool> Loading
packages/Tethering/res/values/overlayable.xml +5 −0 Original line number Original line Diff line number Diff line Loading @@ -23,6 +23,11 @@ <item type="array" name="config_tether_wifi_p2p_regexs"/> <item type="array" name="config_tether_wifi_p2p_regexs"/> <item type="array" name="config_tether_bluetooth_regexs"/> <item type="array" name="config_tether_bluetooth_regexs"/> <item type="array" name="config_tether_dhcp_range"/> <item type="array" name="config_tether_dhcp_range"/> <!-- Use the BPF offload for tethering when the kernel has support. True by default. If the device doesn't want to support tether BPF offload, this should be false. Note that this setting could be override by device config. --> <item type="bool" name="config_tether_enable_bpf_offload"/> <item type="bool" name="config_tether_enable_legacy_dhcp_server"/> <item type="bool" name="config_tether_enable_legacy_dhcp_server"/> <item type="integer" name="config_tether_offload_poll_interval"/> <item type="integer" name="config_tether_offload_poll_interval"/> <item type="array" name="config_tether_upstream_types"/> <item type="array" name="config_tether_upstream_types"/> Loading
packages/Tethering/src/android/net/ip/IpServer.java +27 −7 Original line number Original line Diff line number Diff line Loading @@ -227,6 +227,7 @@ public class IpServer extends StateMachine { private final int mInterfaceType; private final int mInterfaceType; private final LinkProperties mLinkProperties; private final LinkProperties mLinkProperties; private final boolean mUsingLegacyDhcp; private final boolean mUsingLegacyDhcp; private final boolean mUsingBpfOffload; private final Dependencies mDeps; private final Dependencies mDeps; Loading Loading @@ -304,7 +305,8 @@ public class IpServer extends StateMachine { public IpServer( public IpServer( String ifaceName, Looper looper, int interfaceType, SharedLog log, String ifaceName, Looper looper, int interfaceType, SharedLog log, INetd netd, Callback callback, boolean usingLegacyDhcp, Dependencies deps) { INetd netd, Callback callback, boolean usingLegacyDhcp, boolean usingBpfOffload, Dependencies deps) { super(ifaceName, looper); super(ifaceName, looper); mLog = log.forSubComponent(ifaceName); mLog = log.forSubComponent(ifaceName); mNetd = netd; mNetd = netd; Loading @@ -314,6 +316,7 @@ public class IpServer extends StateMachine { mInterfaceType = interfaceType; mInterfaceType = interfaceType; mLinkProperties = new LinkProperties(); mLinkProperties = new LinkProperties(); mUsingLegacyDhcp = usingLegacyDhcp; mUsingLegacyDhcp = usingLegacyDhcp; mUsingBpfOffload = usingBpfOffload; mDeps = deps; mDeps = deps; resetLinkProperties(); resetLinkProperties(); mLastError = TetheringManager.TETHER_ERROR_NO_ERROR; mLastError = TetheringManager.TETHER_ERROR_NO_ERROR; Loading @@ -321,9 +324,16 @@ public class IpServer extends StateMachine { mIpNeighborMonitor = mDeps.getIpNeighborMonitor(getHandler(), mLog, mIpNeighborMonitor = mDeps.getIpNeighborMonitor(getHandler(), mLog, new MyNeighborEventConsumer()); new MyNeighborEventConsumer()); // IP neighbor monitor monitors the neighbor event for adding/removing offload // forwarding rules per client. If BPF offload is not supported, don't start listening // neighbor events. See updateIpv6ForwardingRules, addIpv6ForwardingRule, // removeIpv6ForwardingRule. if (mUsingBpfOffload) { if (!mIpNeighborMonitor.start()) { if (!mIpNeighborMonitor.start()) { mLog.e("Failed to create IpNeighborMonitor on " + mIfaceName); mLog.e("Failed to create IpNeighborMonitor on " + mIfaceName); } } } mInitialState = new InitialState(); mInitialState = new InitialState(); mLocalHotspotState = new LocalHotspotState(); mLocalHotspotState = new LocalHotspotState(); Loading Loading @@ -715,12 +725,12 @@ public class IpServer extends StateMachine { final String upstreamIface = v6only.getInterfaceName(); final String upstreamIface = v6only.getInterfaceName(); params = new RaParams(); params = new RaParams(); // We advertise an mtu lower by 16, which is the closest multiple of 8 >= 14, // When BPF offload is enabled, we advertise an mtu lower by 16, which is the closest // the ethernet header size. This makes kernel ebpf tethering offload happy. // multiple of 8 >= 14, the ethernet header size. This makes kernel ebpf tethering // This hack should be reverted once we have the kernel fixed up. // offload happy. This hack should be reverted once we have the kernel fixed up. // Note: this will automatically clamp to at least 1280 (ipv6 minimum mtu) // Note: this will automatically clamp to at least 1280 (ipv6 minimum mtu) // see RouterAdvertisementDaemon.java putMtu() // see RouterAdvertisementDaemon.java putMtu() params.mtu = v6only.getMtu() - 16; params.mtu = mUsingBpfOffload ? v6only.getMtu() - 16 : v6only.getMtu(); params.hasDefaultRoute = v6only.hasIpv6DefaultRoute(); params.hasDefaultRoute = v6only.hasIpv6DefaultRoute(); if (params.hasDefaultRoute) params.hopLimit = getHopLimit(upstreamIface); if (params.hasDefaultRoute) params.hopLimit = getHopLimit(upstreamIface); Loading Loading @@ -844,6 +854,11 @@ public class IpServer extends StateMachine { } } private void addIpv6ForwardingRule(Ipv6ForwardingRule rule) { private void addIpv6ForwardingRule(Ipv6ForwardingRule rule) { // Theoretically, we don't need this check because IP neighbor monitor doesn't start if BPF // offload is disabled. Add this check just in case. // TODO: Perhaps remove this protection check. if (!mUsingBpfOffload) return; try { try { mNetd.tetherOffloadRuleAdd(rule.toTetherOffloadRuleParcel()); mNetd.tetherOffloadRuleAdd(rule.toTetherOffloadRuleParcel()); mIpv6ForwardingRules.put(rule.address, rule); mIpv6ForwardingRules.put(rule.address, rule); Loading @@ -853,6 +868,11 @@ public class IpServer extends StateMachine { } } private void removeIpv6ForwardingRule(Ipv6ForwardingRule rule, boolean removeFromMap) { private void removeIpv6ForwardingRule(Ipv6ForwardingRule rule, boolean removeFromMap) { // Theoretically, we don't need this check because IP neighbor monitor doesn't start if BPF // offload is disabled. Add this check just in case. // TODO: Perhaps remove this protection check. if (!mUsingBpfOffload) return; try { try { mNetd.tetherOffloadRuleRemove(rule.toTetherOffloadRuleParcel()); mNetd.tetherOffloadRuleRemove(rule.toTetherOffloadRuleParcel()); if (removeFromMap) { if (removeFromMap) { Loading
packages/Tethering/src/com/android/networkstack/tethering/Tethering.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -2296,7 +2296,7 @@ public class Tethering { final TetherState tetherState = new TetherState( final TetherState tetherState = new TetherState( new IpServer(iface, mLooper, interfaceType, mLog, mNetd, new IpServer(iface, mLooper, interfaceType, mLog, mNetd, makeControlCallback(), mConfig.enableLegacyDhcpServer, makeControlCallback(), mConfig.enableLegacyDhcpServer, mDeps.getIpServerDependencies())); mConfig.enableBpfOffload, mDeps.getIpServerDependencies())); mTetherStates.put(iface, tetherState); mTetherStates.put(iface, tetherState); tetherState.ipServer.start(); tetherState.ipServer.start(); } } Loading
packages/Tethering/src/com/android/networkstack/tethering/TetheringConfiguration.java +38 −4 Original line number Original line Diff line number Diff line Loading @@ -72,6 +72,12 @@ public class TetheringConfiguration { private static final String[] DEFAULT_IPV4_DNS = {"8.8.4.4", "8.8.8.8"}; private static final String[] DEFAULT_IPV4_DNS = {"8.8.4.4", "8.8.8.8"}; /** * Override enabling BPF offload configuration for tethering. */ public static final String OVERRIDE_TETHER_ENABLE_BPF_OFFLOAD = "override_tether_enable_bpf_offload"; /** /** * Use the old dnsmasq DHCP server for tethering instead of the framework implementation. * Use the old dnsmasq DHCP server for tethering instead of the framework implementation. */ */ Loading @@ -95,6 +101,8 @@ public class TetheringConfiguration { public final String[] legacyDhcpRanges; public final String[] legacyDhcpRanges; public final String[] defaultIPv4DNS; public final String[] defaultIPv4DNS; public final boolean enableLegacyDhcpServer; public final boolean enableLegacyDhcpServer; // TODO: Add to TetheringConfigurationParcel if required. public final boolean enableBpfOffload; public final String[] provisioningApp; public final String[] provisioningApp; public final String provisioningAppNoUi; public final String provisioningAppNoUi; Loading Loading @@ -124,11 +132,12 @@ public class TetheringConfiguration { isDunRequired = checkDunRequired(ctx); isDunRequired = checkDunRequired(ctx); chooseUpstreamAutomatically = getResourceBoolean( chooseUpstreamAutomatically = getResourceBoolean( res, R.bool.config_tether_upstream_automatic); res, R.bool.config_tether_upstream_automatic, false /** default value */); preferredUpstreamIfaceTypes = getUpstreamIfaceTypes(res, isDunRequired); preferredUpstreamIfaceTypes = getUpstreamIfaceTypes(res, isDunRequired); legacyDhcpRanges = getLegacyDhcpRanges(res); legacyDhcpRanges = getLegacyDhcpRanges(res); defaultIPv4DNS = copy(DEFAULT_IPV4_DNS); defaultIPv4DNS = copy(DEFAULT_IPV4_DNS); enableBpfOffload = getEnableBpfOffload(res); enableLegacyDhcpServer = getEnableLegacyDhcpServer(res); enableLegacyDhcpServer = getEnableLegacyDhcpServer(res); provisioningApp = getResourceStringArray(res, R.array.config_mobile_hotspot_provision_app); provisioningApp = getResourceStringArray(res, R.array.config_mobile_hotspot_provision_app); Loading Loading @@ -208,6 +217,9 @@ public class TetheringConfiguration { pw.print("provisioningAppNoUi: "); pw.print("provisioningAppNoUi: "); pw.println(provisioningAppNoUi); pw.println(provisioningAppNoUi); pw.print("enableBpfOffload: "); pw.println(enableBpfOffload); pw.print("enableLegacyDhcpServer: "); pw.print("enableLegacyDhcpServer: "); pw.println(enableLegacyDhcpServer); pw.println(enableLegacyDhcpServer); } } Loading @@ -228,6 +240,7 @@ public class TetheringConfiguration { toIntArray(preferredUpstreamIfaceTypes))); toIntArray(preferredUpstreamIfaceTypes))); sj.add(String.format("provisioningApp:%s", makeString(provisioningApp))); sj.add(String.format("provisioningApp:%s", makeString(provisioningApp))); sj.add(String.format("provisioningAppNoUi:%s", provisioningAppNoUi)); sj.add(String.format("provisioningAppNoUi:%s", provisioningAppNoUi)); sj.add(String.format("enableBpfOffload:%s", enableBpfOffload)); sj.add(String.format("enableLegacyDhcpServer:%s", enableLegacyDhcpServer)); sj.add(String.format("enableLegacyDhcpServer:%s", enableLegacyDhcpServer)); return String.format("TetheringConfiguration{%s}", sj.toString()); return String.format("TetheringConfiguration{%s}", sj.toString()); } } Loading Loading @@ -332,11 +345,11 @@ public class TetheringConfiguration { } } } } private static boolean getResourceBoolean(Resources res, int resId) { private static boolean getResourceBoolean(Resources res, int resId, boolean defaultValue) { try { try { return res.getBoolean(resId); return res.getBoolean(resId); } catch (Resources.NotFoundException e404) { } catch (Resources.NotFoundException e404) { return false; return defaultValue; } } } } Loading @@ -357,8 +370,29 @@ public class TetheringConfiguration { } } } } private boolean getEnableBpfOffload(final Resources res) { // Get BPF offload config // Priority 1: Device config // Priority 2: Resource config // Priority 3: Default value final boolean resourceValue = getResourceBoolean( res, R.bool.config_tether_enable_bpf_offload, true /** default value */); // Due to the limitation of static mock for testing, using #getProperty directly instead // of getDeviceConfigBoolean. getDeviceConfigBoolean is not invoked because it uses // #getBoolean to get the boolean device config. The test can't know that the returned // boolean value comes from device config or default value (because of null property // string). Because the test would like to verify null property boolean string case, // use DeviceConfig.getProperty here. See also the test case testBpfOffload{*} in // TetheringConfigurationTest.java. final String value = DeviceConfig.getProperty( NAMESPACE_CONNECTIVITY, OVERRIDE_TETHER_ENABLE_BPF_OFFLOAD); return (value != null) ? Boolean.parseBoolean(value) : resourceValue; } private boolean getEnableLegacyDhcpServer(final Resources res) { private boolean getEnableLegacyDhcpServer(final Resources res) { return getResourceBoolean(res, R.bool.config_tether_enable_legacy_dhcp_server) return getResourceBoolean( res, R.bool.config_tether_enable_legacy_dhcp_server, false /** default value */) || getDeviceConfigBoolean(TETHER_ENABLE_LEGACY_DHCP_SERVER); || getDeviceConfigBoolean(TETHER_ENABLE_LEGACY_DHCP_SERVER); } } Loading