Commit 3eb6f0e8 by tonihei Committed by Ian Baker

Remove network type test restrictions for API 29/30

Network type detection on these API levels couldn't be tested
yet because of a missing Robolectric feature. This was fixed by
the recent Robolectric upgrade and the restrictions can be removed.

This also requires to replicate the platform hack we rely on on
these API levels.

PiperOrigin-RevId: 448240431
parent 010a00e4
......@@ -25,6 +25,7 @@ import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.NetworkInfo.DetailedState;
import android.net.Uri;
import android.telephony.ServiceState;
import android.telephony.TelephonyDisplayInfo;
import android.telephony.TelephonyManager;
import androidx.test.core.app.ApplicationProvider;
......@@ -187,13 +188,6 @@ public final class DefaultBandwidthMeterTest {
@Test
public void defaultInitialBitrateEstimate_for4G_isGreaterThanEstimateFor2G() {
if (Util.SDK_INT == 29 || Util.SDK_INT == 30) {
// Robolectric doesn't support listening to service state changes, which we need on APIs 29
// and 30 to run this test successfully.
// TODO(b/190021699): Update once Robolectric released support for this.
return;
}
setActiveNetworkInfo(networkInfo4g);
DefaultBandwidthMeter bandwidthMeter4g =
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
......@@ -209,13 +203,6 @@ public final class DefaultBandwidthMeterTest {
@Test
public void defaultInitialBitrateEstimate_for4G_isGreaterThanEstimateFor3G() {
if (Util.SDK_INT == 29 || Util.SDK_INT == 30) {
// Robolectric doesn't support listening to service state changes, which we need on APIs 29
// and 30 to run this test successfully.
// TODO(b/190021699): Update once Robolectric released support for this.
return;
}
setActiveNetworkInfo(networkInfo4g);
DefaultBandwidthMeter bandwidthMeter4g =
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
......@@ -247,13 +234,6 @@ public final class DefaultBandwidthMeterTest {
@Test
@Config(minSdk = 29) // 5G detection support was added in API 29.
public void defaultInitialBitrateEstimate_for5gNsa_isGreaterThanEstimateFor4g() {
if (Util.SDK_INT == 29 || Util.SDK_INT == 30) {
// Robolectric doesn't support listening to service state changes, which we need on APIs 29
// and 30 to run this test successfully.
// TODO(b/190021699): Update once Robolectric released support for this.
return;
}
setActiveNetworkInfo(networkInfo4g);
DefaultBandwidthMeter bandwidthMeter4g =
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build();
......@@ -365,13 +345,6 @@ public final class DefaultBandwidthMeterTest {
@Test
public void
defaultInitialBitrateEstimate_for4g_forFastCountry_isGreaterThanEstimateForSlowCountry() {
if (Util.SDK_INT == 29 || Util.SDK_INT == 30) {
// Robolectric doesn't support listening to service state changes, which we need on APIs 29
// and 30 to run this test successfully.
// TODO(b/190021699): Update once Robolectric released support for this.
return;
}
setActiveNetworkInfo(networkInfo4g);
setNetworkCountryIso(FAST_COUNTRY_ISO);
DefaultBandwidthMeter bandwidthMeterFast =
......@@ -390,13 +363,6 @@ public final class DefaultBandwidthMeterTest {
@Config(minSdk = 29) // 5G detection support was added in API 29.
public void
defaultInitialBitrateEstimate_for5gNsa_forFastCountry_isGreaterThanEstimateForSlowCountry() {
if (Util.SDK_INT == 29 || Util.SDK_INT == 30) {
// Robolectric doesn't support listening to service state changes, which we need on APIs 29
// and 30 to run this test successfully.
// TODO(b/190021699): Update once Robolectric released support for this.
return;
}
setActiveNetworkInfo(networkInfo4g, TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA);
setNetworkCountryIso(FAST_COUNTRY_ISO);
DefaultBandwidthMeter bandwidthMeterFast =
......@@ -556,13 +522,6 @@ public final class DefaultBandwidthMeterTest {
@Test
public void initialBitrateEstimateOverwrite_for4G_whileConnectedTo4G_setsInitialEstimate() {
if (Util.SDK_INT == 29 || Util.SDK_INT == 30) {
// Robolectric doesn't support listening to service state changes, which we need on APIs 29
// and 30 to run this test successfully.
// TODO(b/190021699): Update once Robolectric released support for this.
return;
}
setActiveNetworkInfo(networkInfo4g);
DefaultBandwidthMeter bandwidthMeter =
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext())
......@@ -589,13 +548,6 @@ public final class DefaultBandwidthMeterTest {
@Test
@Config(minSdk = 29) // 5G detection support was added in API 29.
public void initialBitrateEstimateOverwrite_for5gNsa_whileConnectedTo5gNsa_setsInitialEstimate() {
if (Util.SDK_INT == 29 || Util.SDK_INT == 30) {
// Robolectric doesn't support listening to service state changes, which we need on APIs 29
// and 30 to run this test successfully.
// TODO(b/190021699): Update once Robolectric released support for this.
return;
}
setActiveNetworkInfo(networkInfo4g, TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA);
DefaultBandwidthMeter bandwidthMeter =
new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext())
......@@ -760,6 +712,19 @@ public final class DefaultBandwidthMeterTest {
ShadowTelephonyManager.createTelephonyDisplayInfo(
networkInfo.getType(), networkTypeOverride);
Shadows.shadowOf(telephonyManager).setTelephonyDisplayInfo(displayInfo);
} else if (Util.SDK_INT >= 29) {
ServiceState serviceState = new ServiceState();
if (networkTypeOverride == TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA) {
// Replicate known platform hack that includes special string indicating 5G-NSA.
serviceState =
new ServiceState() {
@Override
public String toString() {
return "...nrState=CONNECTED...";
}
};
}
Shadows.shadowOf(telephonyManager).setServiceState(serviceState);
}
// Create a sticky broadcast for the connectivity action because Robolectric isn't replying with
// the current network state if a receiver for this intent is registered.
......@@ -787,7 +752,7 @@ public final class DefaultBandwidthMeterTest {
dataSource,
dataSpec,
/* isNetwork= */ true,
/* bytes= */ random.nextInt(5 * 1024 * 1024));
/* bytesTransferred= */ random.nextInt(5 * 1024 * 1024));
bandwidthMeter.onTransferEnd(dataSource, dataSpec, /* isNetwork= */ true);
bitrateEstimates[i] = bandwidthMeter.getBitrateEstimate();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment