Average Internet speed varies wildly by region, so it’s important for developers to consider how their applications behave when connectivity is suboptimal. Unforeseen problems may arise when a device’s Internet connection is slow, and developers can get ahead of these issues by testing their apps under simulated network conditions. However, neither Android Studio nor Android itself offer an easy way to throttle Internet speeds, leaving developers to find solutions for themselves. This will change in Android 13, with the addition of a new setting to throttle network speeds.
Over the last few weeks, Google has introduced new code to Android’s network connectivity APIs that enables bandwidth limiting. According to this new code, Android 13 will support setting a rate limit on any Internet-capable network, including both Wi-Fi and cellular networks. The rate limit is defined in bytes per second and is stored in the Settings.Global value ‘ingress_rate_limit_bytes_per_second.’ For example, if the desired rate limit is 1Mbps, then the value of ‘ingress_rate_limit_bytes_per_second’ will be ‘125000.’ A value ≤ 0 will disable throttling entirely. The rate limit is applied on a per-network basis, so a device that’s connected to multiple networks simultaneously could exceed the limit.
Android 13’s new bandwidth rate limiting API won’t be supported on all devices, however. The kernel must support the feature, which can be accomplished by building Linux with the following config options: CONFIG_NET_SCHED, CONFIG_NET_SCH_INGRESS, CONFIG_NET_CLS_MATCHALL, CONFIG_NET_CLS_ACT, CONFIG_NET_ACT_POLICE, and CONFIG_NET_ACT_BPF. The configuration value ‘config_ingress_rate_limiting_supported’ of ServiceConnectivityResources should be set to ‘true’ (via a runtime resource overlay) if the kernel was built with support for network rate limiting.
Although the second developer preview build of Android 13 contains the new bandwidth limiting APIs, there is currently no user-facing way for developers to set a rate limit. A Google employee has confirmed that the company has implemented a setting in developer options to throttle Internet speeds, however. This setting is expected to be available in the first beta build of Android 13, which is scheduled to release sometime next month. Until the setting arrives, developers can simulate slow network connectivity by manually starting the Android Emulator via the command line with the -netspeed option.