[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
This commit is contained in:
@@ -26,6 +26,7 @@ import static android.net.NetworkRequest.Type.TRACK_SYSTEM_DEFAULT;
|
||||
import static android.net.QosCallback.QosCallbackRegistrationException;
|
||||
|
||||
import android.annotation.CallbackExecutor;
|
||||
import android.annotation.FlaggedApi;
|
||||
import android.annotation.IntDef;
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
@@ -115,6 +116,14 @@ public class ConnectivityManager {
|
||||
private static final String TAG = "ConnectivityManager";
|
||||
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
|
||||
|
||||
// TODO : remove this class when udc-mainline-prod is abandoned and android.net.flags.Flags is
|
||||
// available here
|
||||
/** @hide */
|
||||
public static class Flags {
|
||||
static final String SET_DATA_SAVER_VIA_CM =
|
||||
"com.android.net.flags.set_data_saver_via_cm";
|
||||
}
|
||||
|
||||
/**
|
||||
* A change in network connectivity has occurred. A default connection has either
|
||||
* been established or lost. The NetworkInfo for the affected network is
|
||||
@@ -5940,6 +5949,28 @@ public class ConnectivityManager {
|
||||
return new Range(TUN_INTF_NETID_START, TUN_INTF_NETID_START + TUN_INTF_NETID_RANGE - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets data saver switch.
|
||||
*
|
||||
* @param enable True if enable.
|
||||
* @throws IllegalStateException if failed.
|
||||
* @hide
|
||||
*/
|
||||
@FlaggedApi(Flags.SET_DATA_SAVER_VIA_CM)
|
||||
@SystemApi(client = MODULE_LIBRARIES)
|
||||
@RequiresPermission(anyOf = {
|
||||
android.Manifest.permission.NETWORK_SETTINGS,
|
||||
android.Manifest.permission.NETWORK_STACK,
|
||||
NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK
|
||||
})
|
||||
public void setDataSaverEnabled(final boolean enable) {
|
||||
try {
|
||||
mService.setDataSaverEnabled(enable);
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the specified UID to the list of UIds that are allowed to use data on metered networks
|
||||
* even when background data is restricted. The deny list takes precedence over the allow list.
|
||||
|
||||
Reference in New Issue
Block a user