Merge "[BOT.12] Add unit test for disabling BpfCoordinator by config" am: 6241525504 am: d36e818816
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1313802 Change-Id: Ica3e4752091c3460296f7d06ccb1e0827aec29f6
This commit is contained in:
@@ -94,7 +94,7 @@ public class BpfCoordinator {
|
||||
// in the constructor because it is hard to unwind all existing change once device
|
||||
// configuration is changed. Especially the forwarding rules. Keep the same setting
|
||||
// to make it simpler. See also TetheringConfiguration.
|
||||
private final boolean mUsingBpf;
|
||||
private final boolean mIsBpfEnabled;
|
||||
|
||||
// Tracks whether BPF tethering is started or not. This is set by tethering before it
|
||||
// starts the first IpServer and is cleared by tethering shortly before the last IpServer
|
||||
@@ -184,7 +184,7 @@ public class BpfCoordinator {
|
||||
mHandler = mDeps.getHandler();
|
||||
mNetd = mDeps.getNetd();
|
||||
mLog = mDeps.getSharedLog().forSubComponent(TAG);
|
||||
mUsingBpf = isOffloadEnabled();
|
||||
mIsBpfEnabled = isBpfEnabled();
|
||||
BpfTetherStatsProvider provider = new BpfTetherStatsProvider();
|
||||
try {
|
||||
mDeps.getNetworkStatsManager().registerNetworkStatsProvider(
|
||||
@@ -207,7 +207,7 @@ public class BpfCoordinator {
|
||||
public void startPolling() {
|
||||
if (mPollingStarted) return;
|
||||
|
||||
if (!mUsingBpf) {
|
||||
if (!mIsBpfEnabled) {
|
||||
mLog.i("Offload disabled");
|
||||
return;
|
||||
}
|
||||
@@ -246,7 +246,7 @@ public class BpfCoordinator {
|
||||
*/
|
||||
public void tetherOffloadRuleAdd(
|
||||
@NonNull final IpServer ipServer, @NonNull final Ipv6ForwardingRule rule) {
|
||||
if (!mUsingBpf) return;
|
||||
if (!mIsBpfEnabled) return;
|
||||
|
||||
try {
|
||||
// TODO: Perhaps avoid to add a duplicate rule.
|
||||
@@ -287,7 +287,7 @@ public class BpfCoordinator {
|
||||
*/
|
||||
public void tetherOffloadRuleRemove(
|
||||
@NonNull final IpServer ipServer, @NonNull final Ipv6ForwardingRule rule) {
|
||||
if (!mUsingBpf) return;
|
||||
if (!mIsBpfEnabled) return;
|
||||
|
||||
try {
|
||||
// TODO: Perhaps avoid to remove a non-existent rule.
|
||||
@@ -332,7 +332,7 @@ public class BpfCoordinator {
|
||||
* Note that this can be only called on handler thread.
|
||||
*/
|
||||
public void tetherOffloadRuleClear(@NonNull final IpServer ipServer) {
|
||||
if (!mUsingBpf) return;
|
||||
if (!mIsBpfEnabled) return;
|
||||
|
||||
final LinkedHashMap<Inet6Address, Ipv6ForwardingRule> rules = mIpv6ForwardingRules.get(
|
||||
ipServer);
|
||||
@@ -349,7 +349,7 @@ public class BpfCoordinator {
|
||||
* Note that this can be only called on handler thread.
|
||||
*/
|
||||
public void tetherOffloadRuleUpdate(@NonNull final IpServer ipServer, int newUpstreamIfindex) {
|
||||
if (!mUsingBpf) return;
|
||||
if (!mIsBpfEnabled) return;
|
||||
|
||||
final LinkedHashMap<Inet6Address, Ipv6ForwardingRule> rules = mIpv6ForwardingRules.get(
|
||||
ipServer);
|
||||
@@ -373,7 +373,7 @@ public class BpfCoordinator {
|
||||
* Note that this can be only called on handler thread.
|
||||
*/
|
||||
public void addUpstreamNameToLookupTable(int upstreamIfindex, @NonNull String upstreamIface) {
|
||||
if (!mUsingBpf) return;
|
||||
if (!mIsBpfEnabled) return;
|
||||
|
||||
if (upstreamIfindex == 0 || TextUtils.isEmpty(upstreamIface)) return;
|
||||
|
||||
@@ -398,7 +398,7 @@ public class BpfCoordinator {
|
||||
public void dump(@NonNull IndentingPrintWriter pw) {
|
||||
final ConditionVariable dumpDone = new ConditionVariable();
|
||||
mHandler.post(() -> {
|
||||
pw.println("mUsingBpf: " + mUsingBpf);
|
||||
pw.println("mIsBpfEnabled: " + mIsBpfEnabled);
|
||||
pw.println("Polling " + (mPollingStarted ? "started" : "not started"));
|
||||
pw.println("Stats provider " + (mStatsProvider != null
|
||||
? "registered" : "not registered"));
|
||||
@@ -589,9 +589,9 @@ public class BpfCoordinator {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isOffloadEnabled() {
|
||||
private boolean isBpfEnabled() {
|
||||
final TetheringConfiguration config = mDeps.getTetherConfig();
|
||||
return (config != null) ? config.enableBpfOffload : true /* default value */;
|
||||
return (config != null) ? config.isBpfOffloadEnabled() : true /* default value */;
|
||||
}
|
||||
|
||||
private int getInterfaceIndexFromRules(@NonNull String ifName) {
|
||||
@@ -754,4 +754,21 @@ public class BpfCoordinator {
|
||||
|
||||
mHandler.postDelayed(mScheduledPollingTask, mDeps.getPerformPollInterval());
|
||||
}
|
||||
|
||||
// Return forwarding rule map. This is used for testing only.
|
||||
// Note that this can be only called on handler thread.
|
||||
@NonNull
|
||||
@VisibleForTesting
|
||||
final HashMap<IpServer, LinkedHashMap<Inet6Address, Ipv6ForwardingRule>>
|
||||
getForwardingRulesForTesting() {
|
||||
return mIpv6ForwardingRules;
|
||||
}
|
||||
|
||||
// Return upstream interface name map. This is used for testing only.
|
||||
// Note that this can be only called on handler thread.
|
||||
@NonNull
|
||||
@VisibleForTesting
|
||||
final SparseArray<String> getInterfaceNamesForTesting() {
|
||||
return mInterfaceNames;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -340,8 +340,7 @@ public class Tethering {
|
||||
|
||||
@NonNull
|
||||
public NetworkStatsManager getNetworkStatsManager() {
|
||||
return (NetworkStatsManager) mContext.getSystemService(
|
||||
Context.NETWORK_STATS_SERVICE);
|
||||
return mContext.getSystemService(NetworkStatsManager.class);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@@ -2406,7 +2405,7 @@ public class Tethering {
|
||||
final TetherState tetherState = new TetherState(
|
||||
new IpServer(iface, mLooper, interfaceType, mLog, mNetd, mBpfCoordinator,
|
||||
makeControlCallback(), mConfig.enableLegacyDhcpServer,
|
||||
mConfig.enableBpfOffload, mPrivateAddressCoordinator,
|
||||
mConfig.isBpfOffloadEnabled(), mPrivateAddressCoordinator,
|
||||
mDeps.getIpServerDependencies()));
|
||||
mTetherStates.put(iface, tetherState);
|
||||
tetherState.ipServer.start();
|
||||
|
||||
@@ -101,8 +101,6 @@ public class TetheringConfiguration {
|
||||
public final String[] legacyDhcpRanges;
|
||||
public final String[] defaultIPv4DNS;
|
||||
public final boolean enableLegacyDhcpServer;
|
||||
// TODO: Add to TetheringConfigurationParcel if required.
|
||||
public final boolean enableBpfOffload;
|
||||
|
||||
public final String[] provisioningApp;
|
||||
public final String provisioningAppNoUi;
|
||||
@@ -112,6 +110,8 @@ public class TetheringConfiguration {
|
||||
public final int activeDataSubId;
|
||||
|
||||
private final int mOffloadPollInterval;
|
||||
// TODO: Add to TetheringConfigurationParcel if required.
|
||||
private final boolean mEnableBpfOffload;
|
||||
|
||||
public TetheringConfiguration(Context ctx, SharedLog log, int id) {
|
||||
final SharedLog configLog = log.forSubComponent("config");
|
||||
@@ -138,7 +138,7 @@ public class TetheringConfiguration {
|
||||
|
||||
legacyDhcpRanges = getLegacyDhcpRanges(res);
|
||||
defaultIPv4DNS = copy(DEFAULT_IPV4_DNS);
|
||||
enableBpfOffload = getEnableBpfOffload(res);
|
||||
mEnableBpfOffload = getEnableBpfOffload(res);
|
||||
enableLegacyDhcpServer = getEnableLegacyDhcpServer(res);
|
||||
|
||||
provisioningApp = getResourceStringArray(res, R.array.config_mobile_hotspot_provision_app);
|
||||
@@ -222,7 +222,7 @@ public class TetheringConfiguration {
|
||||
pw.println(provisioningAppNoUi);
|
||||
|
||||
pw.print("enableBpfOffload: ");
|
||||
pw.println(enableBpfOffload);
|
||||
pw.println(mEnableBpfOffload);
|
||||
|
||||
pw.print("enableLegacyDhcpServer: ");
|
||||
pw.println(enableLegacyDhcpServer);
|
||||
@@ -244,7 +244,7 @@ public class TetheringConfiguration {
|
||||
toIntArray(preferredUpstreamIfaceTypes)));
|
||||
sj.add(String.format("provisioningApp:%s", makeString(provisioningApp)));
|
||||
sj.add(String.format("provisioningAppNoUi:%s", provisioningAppNoUi));
|
||||
sj.add(String.format("enableBpfOffload:%s", enableBpfOffload));
|
||||
sj.add(String.format("enableBpfOffload:%s", mEnableBpfOffload));
|
||||
sj.add(String.format("enableLegacyDhcpServer:%s", enableLegacyDhcpServer));
|
||||
return String.format("TetheringConfiguration{%s}", sj.toString());
|
||||
}
|
||||
@@ -283,6 +283,10 @@ public class TetheringConfiguration {
|
||||
return mOffloadPollInterval;
|
||||
}
|
||||
|
||||
public boolean isBpfOffloadEnabled() {
|
||||
return mEnableBpfOffload;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user