diff --git a/framework/api/module-lib-current.txt b/framework/api/module-lib-current.txt index b65c0ce53f..751a1e2e5a 100644 --- a/framework/api/module-lib-current.txt +++ b/framework/api/module-lib-current.txt @@ -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>); 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); diff --git a/framework/src/android/net/ConnectivityManager.java b/framework/src/android/net/ConnectivityManager.java index e8e1efa09f..8651f34202 100644 --- a/framework/src/android/net/ConnectivityManager.java +++ b/framework/src/android/net/ConnectivityManager.java @@ -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(); - } - } } diff --git a/framework/src/android/net/IConnectivityManager.aidl b/framework/src/android/net/IConnectivityManager.aidl index 23a38506b4..1e1f653076 100644 --- a/framework/src/android/net/IConnectivityManager.aidl +++ b/framework/src/android/net/IConnectivityManager.aidl @@ -245,6 +245,4 @@ interface IConnectivityManager void setFirewallChainEnabled(int chain, boolean enable); void replaceFirewallChain(int chain, in int[] uids); - - void swapActiveStatsMap(); } diff --git a/service/src/com/android/server/BpfNetMaps.java b/service/src/com/android/server/BpfNetMaps.java index f2ca18b2cc..f3ac556218 100644 --- a/service/src/com/android/server/BpfNetMaps.java +++ b/service/src/com/android/server/BpfNetMaps.java @@ -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"); } diff --git a/service/src/com/android/server/ConnectivityService.java b/service/src/com/android/server/ConnectivityService.java index eabcd10c25..17a3428c41 100644 --- a/service/src/com/android/server/ConnectivityService.java +++ b/service/src/com/android/server/ConnectivityService.java @@ -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); - } - } } diff --git a/tests/unit/java/com/android/server/BpfNetMapsTest.java b/tests/unit/java/com/android/server/BpfNetMapsTest.java index ac21e77b77..345419b36f 100644 --- a/tests/unit/java/com/android/server/BpfNetMapsTest.java +++ b/tests/unit/java/com/android/server/BpfNetMapsTest.java @@ -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); } diff --git a/tests/unit/java/com/android/server/net/NetworkStatsFactoryTest.java b/tests/unit/java/com/android/server/net/NetworkStatsFactoryTest.java index 6872f8040c..79744b18c7 100644 --- a/tests/unit/java/com/android/server/net/NetworkStatsFactoryTest.java +++ b/tests/unit/java/com/android/server/net/NetworkStatsFactoryTest.java @@ -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]); }