Merge "Remove unused augmentWithStackedInterfaces"

This commit is contained in:
Treehugger Robot
2023-03-09 06:55:24 +00:00
committed by Gerrit Code Review
3 changed files with 1 additions and 42 deletions

View File

@@ -34,8 +34,6 @@ import com.android.server.BpfNetMaps;
import java.io.IOException; import java.io.IOException;
import java.net.ProtocolException; import java.net.ProtocolException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@@ -146,36 +144,6 @@ public class NetworkStatsFactory {
mUnderlyingNetworkInfos = vpnArray.clone(); mUnderlyingNetworkInfos = vpnArray.clone();
} }
/**
* Get a set of interfaces containing specified ifaces and stacked interfaces.
*
* <p>The added stacked interfaces are ifaces stacked on top of the specified ones, or ifaces
* on which the specified ones are stacked. Stacked interfaces are those noted with
* {@link #noteStackedIface(String, String)}, but only interfaces noted before this method
* is called are guaranteed to be included.
*/
public String[] augmentWithStackedInterfaces(@Nullable String[] requiredIfaces) {
if (requiredIfaces == NetworkStats.INTERFACES_ALL) {
return null;
}
HashSet<String> relatedIfaces = new HashSet<>(Arrays.asList(requiredIfaces));
// ConcurrentHashMap's EntrySet iterators are "guaranteed to traverse
// elements as they existed upon construction exactly once, and may
// (but are not guaranteed to) reflect any modifications subsequent to construction".
// This is enough here.
for (Map.Entry<String, String> entry : mStackedIfaces.entrySet()) {
if (relatedIfaces.contains(entry.getKey())) {
relatedIfaces.add(entry.getValue());
} else if (relatedIfaces.contains(entry.getValue())) {
relatedIfaces.add(entry.getKey());
}
}
String[] outArray = new String[relatedIfaces.size()];
return relatedIfaces.toArray(outArray);
}
/** /**
* Applies 464xlat adjustments with ifaces noted with {@link #noteStackedIface(String, String)}. * Applies 464xlat adjustments with ifaces noted with {@link #noteStackedIface(String, String)}.
* @see NetworkStats#apply464xlatAdjustments(NetworkStats, NetworkStats, Map) * @see NetworkStats#apply464xlatAdjustments(NetworkStats, NetworkStats, Map)

View File

@@ -1730,11 +1730,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
PermissionUtils.enforceNetworkStackPermission(mContext); PermissionUtils.enforceNetworkStackPermission(mContext);
try { try {
final String[] ifaceArray = getAllIfacesSinceBoot(transport); final String[] ifaceArray = getAllIfacesSinceBoot(transport);
// TODO(b/215633405) : mMobileIfaces and mWifiIfaces already contain the stacked final NetworkStats stats = getNetworkStatsUidDetail(ifaceArray);
// interfaces, so this is not useful, remove it.
final String[] ifacesToQuery =
mStatsFactory.augmentWithStackedInterfaces(ifaceArray);
final NetworkStats stats = getNetworkStatsUidDetail(ifacesToQuery);
// Clear the interfaces of the stats before returning, so callers won't get this // Clear the interfaces of the stats before returning, so callers won't get this
// information. This is because no caller needs this information for now, and it // information. This is because no caller needs this information for now, and it
// makes it easier to change the implementation later by using the histories in the // makes it easier to change the implementation later by using the histories in the

View File

@@ -82,7 +82,6 @@ import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Matchers.eq; import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
@@ -395,10 +394,6 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
verify(mNetd).registerUnsolicitedEventListener(alertObserver.capture()); verify(mNetd).registerUnsolicitedEventListener(alertObserver.capture());
mAlertObserver = alertObserver.getValue(); mAlertObserver = alertObserver.getValue();
// Make augmentWithStackedInterfaces returns the interfaces that was passed to it.
doAnswer(inv -> ((String[]) inv.getArgument(0)).clone())
.when(mStatsFactory).augmentWithStackedInterfaces(any());
// Catch TetheringEventCallback during systemReady(). // Catch TetheringEventCallback during systemReady().
ArgumentCaptor<TetheringManager.TetheringEventCallback> tetheringEventCbCaptor = ArgumentCaptor<TetheringManager.TetheringEventCallback> tetheringEventCbCaptor =
ArgumentCaptor.forClass(TetheringManager.TetheringEventCallback.class); ArgumentCaptor.forClass(TetheringManager.TetheringEventCallback.class);