Merge "Revert consider TEMPORARILY_NOT_METERED as unmetered in data usage"

This commit is contained in:
Treehugger Robot
2022-12-02 11:27:27 +00:00
committed by Gerrit Code Review
5 changed files with 11 additions and 17 deletions

View File

@@ -400,10 +400,8 @@ public class NetworkIdentity {
setSubscriberId(snapshot.getSubscriberId());
setRoaming(!snapshot.getNetworkCapabilities().hasCapability(
NetworkCapabilities.NET_CAPABILITY_NOT_ROAMING));
setMetered(!(snapshot.getNetworkCapabilities().hasCapability(
NetworkCapabilities.NET_CAPABILITY_NOT_METERED)
|| snapshot.getNetworkCapabilities().hasCapability(
NetworkCapabilities.NET_CAPABILITY_TEMPORARILY_NOT_METERED)));
setMetered(!snapshot.getNetworkCapabilities().hasCapability(
NetworkCapabilities.NET_CAPABILITY_NOT_METERED));
setOemManaged(getOemBitfield(snapshot.getNetworkCapabilities()));

View File

@@ -75,7 +75,6 @@ import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_VPN;
import static android.net.NetworkCapabilities.NET_CAPABILITY_OEM_PAID;
import static android.net.NetworkCapabilities.NET_CAPABILITY_OEM_PRIVATE;
import static android.net.NetworkCapabilities.NET_CAPABILITY_PARTIAL_CONNECTIVITY;
import static android.net.NetworkCapabilities.NET_CAPABILITY_TEMPORARILY_NOT_METERED;
import static android.net.NetworkCapabilities.NET_CAPABILITY_VALIDATED;
import static android.net.NetworkCapabilities.NET_ENTERPRISE_ID_1;
import static android.net.NetworkCapabilities.NET_ENTERPRISE_ID_5;
@@ -8062,10 +8061,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
final boolean oldMetered = prevNc.isMetered();
final boolean newMetered = newNc.isMetered();
final boolean meteredChanged = oldMetered != newMetered;
final boolean oldTempMetered = prevNc.hasCapability(NET_CAPABILITY_TEMPORARILY_NOT_METERED);
final boolean newTempMetered = newNc.hasCapability(NET_CAPABILITY_TEMPORARILY_NOT_METERED);
final boolean tempMeteredChanged = oldTempMetered != newTempMetered;
if (meteredChanged) {
maybeNotifyNetworkBlocked(nai, oldMetered, newMetered,
@@ -8076,7 +8071,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
!= newNc.hasCapability(NET_CAPABILITY_NOT_ROAMING);
// Report changes that are interesting for network statistics tracking.
if (meteredChanged || roamingChanged || tempMeteredChanged) {
if (meteredChanged || roamingChanged) {
notifyIfacesChangedForNetworkStats();
}

View File

@@ -101,15 +101,15 @@ class NetworkIdentityTest {
false /* defaultNetwork */, TelephonyManager.NETWORK_TYPE_UMTS)
assertFalse(netIdent2.isMetered())
// Verify network is not metered because it has NET_CAPABILITY_TEMPORARILY_NOT_METERED
// capability .
// In current design, a network that has NET_CAPABILITY_TEMPORARILY_NOT_METERED
// capability will be treated as metered.
val capsTempNotMetered = NetworkCapabilities().apply {
setCapability(NetworkCapabilities.NET_CAPABILITY_TEMPORARILY_NOT_METERED, true)
}
val netIdent3 = NetworkIdentity.buildNetworkIdentity(mockContext,
buildMobileNetworkStateSnapshot(capsTempNotMetered, TEST_IMSI1),
false /* defaultNetwork */, TelephonyManager.NETWORK_TYPE_UMTS)
assertFalse(netIdent3.isMetered())
assertTrue(netIdent3.isMetered())
}
@Test

View File

@@ -7336,10 +7336,11 @@ public class ConnectivityServiceTest {
expectNotifyNetworkStatus(onlyCell(), onlyCell(), MOBILE_IFNAME);
reset(mStatsManager);
// Temp metered change should update ifaces
// Temp metered change shouldn't update ifaces
mCellNetworkAgent.addCapability(NET_CAPABILITY_TEMPORARILY_NOT_METERED);
waitForIdle();
expectNotifyNetworkStatus(onlyCell(), onlyCell(), MOBILE_IFNAME);
verify(mStatsManager, never()).notifyNetworkStatus(eq(onlyCell()),
any(List.class), eq(MOBILE_IFNAME), any(List.class));
reset(mStatsManager);
// Congested change shouldn't update ifaces

View File

@@ -995,8 +995,8 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
forcePollAndWaitForIdle();
// Verify service recorded history.
assertUidTotal(templateMetered5g, UID_RED, 128L, 2L, 128L, 2L, 0);
assertUidTotal(templateNonMetered5g, UID_RED, 256, 3L, 128L, 5L, 0);
assertUidTotal(templateMetered5g, UID_RED, 384L, 5L, 256L, 7L, 0);
assertUidTotal(templateNonMetered5g, UID_RED, 0L, 0L, 0L, 0L, 0);
}
@Test