[BR07.1] Expose setDataSaverEnabled from ConnectivityManager
Currently, data saver switch is controlled in NPMS, which
calls into NetworkManagementService and netd when switching
status. In netd, BandwidthController manipulates the
bw_data_saver chain to control the overall behavior.
However, this code are all platform implementation, which
are not updatable. In order to migrate data saver switch
from iptables to bpf, this API is needed for Connectivity to
change the implementation to directly write bpf in later
patches.
Test: atest CtsHostsideNetworkTests:com.android.cts.net.HostsideRestrictBackgroundNetworkTests
Test: atest FrameworksServicesTests:NetworkManagementServiceTest
Bug: 297836825
Change-Id: I71fa41ca739fef8e191fba91b02758ad5f732d5c
diff --git a/service/src/com/android/server/ConnectivityService.java b/service/src/com/android/server/ConnectivityService.java
index c19878c..967bcc8 100755
--- a/service/src/com/android/server/ConnectivityService.java
+++ b/service/src/com/android/server/ConnectivityService.java
@@ -12545,6 +12545,20 @@
}
@Override
+ public void setDataSaverEnabled(final boolean enable) {
+ enforceNetworkStackOrSettingsPermission();
+ try {
+ final boolean ret = mNetd.bandwidthEnableDataSaver(enable);
+ if (!ret) {
+ throw new IllegalStateException("Error when changing iptables: " + enable);
+ }
+ } catch (RemoteException e) {
+ // Lack of permission or binder errors.
+ throw new IllegalStateException(e);
+ }
+ }
+
+ @Override
public void updateMeteredNetworkAllowList(final int uid, final boolean add) {
enforceNetworkStackOrSettingsPermission();