Remove ConnectivityManager swapActiveStatsMap API
swapActiveStatsMap is temporary added for the NetworkStatsFactory to
call BpfNetMaps#swapActiveStatsMap in tethering mainline module. Now
NetworkStatsFactory already be mainlined, calling BpfNetMaps#swapActiveStatsMap
directly.
Bug: 218494448
Test: atest ConnectivityCoverageTests
atest FrameworksNetTests
Change-Id: I3358e4ac5fb7ed0964273afdbccd1b4128ca7645
This commit is contained in:
@@ -28,7 +28,6 @@ package android.net {
|
||||
method @RequiresPermission(anyOf={android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, android.Manifest.permission.NETWORK_STACK, android.Manifest.permission.NETWORK_SETTINGS}) public void setRequireVpnForUids(boolean, @NonNull java.util.Collection<android.util.Range<java.lang.Integer>>);
|
||||
method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_TEST_NETWORKS, android.Manifest.permission.NETWORK_STACK}) public void simulateDataStall(int, long, @NonNull android.net.Network, @NonNull android.os.PersistableBundle);
|
||||
method @RequiresPermission(anyOf={android.Manifest.permission.NETWORK_SETTINGS, android.Manifest.permission.NETWORK_STACK, android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK}) public void startCaptivePortalApp(@NonNull android.net.Network);
|
||||
method @RequiresPermission(anyOf={android.Manifest.permission.NETWORK_SETTINGS, android.Manifest.permission.NETWORK_STACK, android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK}) public void swapActiveStatsMap();
|
||||
method public void systemReady();
|
||||
method @RequiresPermission(anyOf={android.Manifest.permission.NETWORK_SETTINGS, android.Manifest.permission.NETWORK_STACK, android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK}) public void updateFirewallRule(int, int, boolean);
|
||||
method @RequiresPermission(anyOf={android.Manifest.permission.NETWORK_SETTINGS, android.Manifest.permission.NETWORK_STACK, android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK}) public void updateMeteredNetworkAllowList(int, boolean);
|
||||
|
||||
@@ -5818,27 +5818,4 @@ public class ConnectivityManager {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Request to change the current active network stats map.
|
||||
* STOPSHIP: Remove this API before T sdk finalized, this API is temporary added for the
|
||||
* NetworkStatsFactory which is platform code but will be moved into connectivity (tethering)
|
||||
* mainline module.
|
||||
*
|
||||
* @throws IllegalStateException if swapping active stats map failed.
|
||||
* @hide
|
||||
*/
|
||||
@SystemApi(client = MODULE_LIBRARIES)
|
||||
@RequiresPermission(anyOf = {
|
||||
android.Manifest.permission.NETWORK_SETTINGS,
|
||||
android.Manifest.permission.NETWORK_STACK,
|
||||
NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK
|
||||
})
|
||||
public void swapActiveStatsMap() {
|
||||
try {
|
||||
mService.swapActiveStatsMap();
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -245,6 +245,4 @@ interface IConnectivityManager
|
||||
void setFirewallChainEnabled(int chain, boolean enable);
|
||||
|
||||
void replaceFirewallChain(int chain, in int[] uids);
|
||||
|
||||
void swapActiveStatsMap();
|
||||
}
|
||||
|
||||
@@ -54,6 +54,13 @@ public class BpfNetMaps {
|
||||
sInitialized = true;
|
||||
}
|
||||
|
||||
/** Constructor used after T that doesn't need to use netd anymore. */
|
||||
public BpfNetMaps() {
|
||||
this(null);
|
||||
|
||||
if (USE_NETD) throw new IllegalArgumentException("BpfNetMaps need to use netd before T");
|
||||
}
|
||||
|
||||
public BpfNetMaps(INetd netd) {
|
||||
ensureInitialized();
|
||||
mNetd = netd;
|
||||
@@ -247,15 +254,10 @@ public class BpfNetMaps {
|
||||
/**
|
||||
* Request netd to change the current active network stats map.
|
||||
*
|
||||
* @throws RemoteException when netd has crashed.
|
||||
* @throws ServiceSpecificException in case of failure, with an error code indicating the
|
||||
* cause of the failure.
|
||||
*/
|
||||
public void swapActiveStatsMap() throws RemoteException {
|
||||
if (USE_NETD) {
|
||||
mNetd.trafficSwapActiveStatsMap();
|
||||
return;
|
||||
}
|
||||
public void swapActiveStatsMap() {
|
||||
final int err = native_swapActiveStatsMap();
|
||||
maybeThrow(err, "Unable to swap active stats map");
|
||||
}
|
||||
|
||||
@@ -11129,14 +11129,4 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void swapActiveStatsMap() {
|
||||
enforceNetworkStackOrSettingsPermission();
|
||||
try {
|
||||
mBpfNetMaps.swapActiveStatsMap();
|
||||
} catch (RemoteException | ServiceSpecificException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,8 +78,6 @@ public final class BpfNetMapsTest {
|
||||
verify(mNetd).firewallAddUidInterfaceRules(IFNAME, TEST_UIDS);
|
||||
mBpfNetMaps.removeUidInterfaceRules(TEST_UIDS);
|
||||
verify(mNetd).firewallRemoveUidInterfaceRules(TEST_UIDS);
|
||||
mBpfNetMaps.swapActiveStatsMap();
|
||||
verify(mNetd).trafficSwapActiveStatsMap();
|
||||
mBpfNetMaps.setNetPermForUids(PERMISSION_INTERNET, TEST_UIDS);
|
||||
verify(mNetd).trafficSetNetPermForUids(PERMISSION_INTERNET, TEST_UIDS);
|
||||
}
|
||||
|
||||
@@ -32,12 +32,9 @@ import static com.android.server.net.NetworkStatsFactory.kernelToTag;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkStats;
|
||||
import android.net.TrafficStats;
|
||||
import android.net.UnderlyingNetworkInfo;
|
||||
@@ -77,7 +74,6 @@ public class NetworkStatsFactoryTest extends NetworkStatsBaseTest {
|
||||
private File mTestProc;
|
||||
private NetworkStatsFactory mFactory;
|
||||
@Mock private Context mContext;
|
||||
@Mock private ConnectivityManager mCm;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@@ -88,9 +84,6 @@ public class NetworkStatsFactoryTest extends NetworkStatsBaseTest {
|
||||
// applications. So in order to have a test support native library, the native code
|
||||
// related to networkStatsFactory is compiled to a minimal native library and loaded here.
|
||||
System.loadLibrary("networkstatsfactorytestjni");
|
||||
doReturn(Context.CONNECTIVITY_SERVICE).when(mContext).getSystemServiceName(
|
||||
eq(ConnectivityManager.class));
|
||||
doReturn(mCm).when(mContext).getSystemService(eq(Context.CONNECTIVITY_SERVICE));
|
||||
mFactory = new NetworkStatsFactory(mContext, mTestProc, false);
|
||||
mFactory.updateUnderlyingNetworkInfos(new UnderlyingNetworkInfo[0]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user