Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6ca5c25b authored by Les Lee's avatar Les Lee
Browse files

wifi data usage: replaced Wi-Fi SSID with a Wi-Fi network key

1. Used SSID to be a wifi network identity can't separate wifi
data usage when there are two different network with same SSID.
Use a new usage key from WifiInfo to replace wifi SSID to solve
this issue.

2. To support to query wifi usage per configured Wifi network.
Adding matchWifiNetworkKeys in NetworkTemplate to support querying
multi networkKeys wifi data usage since each configured Wifi
network configuration might be used to connect different Wifi
network. (Replace mNetworkId with mMatchWifiNetworkKeys)

3. Updated callers who were using NetworkTemplate constructor.

4. Fixed SortedSet null order case. The null subscriberId is a
valid input for matchSubscriberIds.

5. Replaced ArrayUtils with CollectionUtils.

Bug: 197520752
Bug: 126299427
Test: atest -c NetworkTemplateTest
Test: atest -c NetworkStatsServiceTest
Test: atest -c NetworkPolicyManagerServiceTest
Test: atest -c NetworkPolicyTest
Change-Id: Ie20e7fb56597817901be4ce1d2a7afcbc9ded0c6
parent b4ac36e2
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -369,11 +369,13 @@ public class NetworkPolicy implements Parcelable, Comparable<NetworkPolicy> {

        try {
            final NetworkTemplate.Builder builder = new NetworkTemplate.Builder(matchRule)
                    .setWifiNetworkKey(wifiNetworkKey)
                    .setMeteredness(metered);
            if (subscriberId != null) {
                builder.setSubscriberIds(Set.of(subscriberId));
            }
            if (wifiNetworkKey != null) {
                builder.setWifiNetworkKeys(Set.of(wifiNetworkKey));
            }
            return builder.build();
        } catch (IllegalArgumentException e) {
            throw new BackupUtils.BadVersionException(
@@ -393,7 +395,7 @@ public class NetworkPolicy implements Parcelable, Comparable<NetworkPolicy> {
            case MATCH_MOBILE:
                return !template.getSubscriberIds().isEmpty();
            case MATCH_WIFI:
                if (Objects.equals(template.getWifiNetworkKey(), null)
                if (template.getWifiNetworkKeys().isEmpty()
                        && template.getSubscriberIds().isEmpty()) {
                    return false;
                }
+4 −4
Original line number Diff line number Diff line
@@ -32,14 +32,14 @@ import kotlin.test.assertFalse
import kotlin.test.assertTrue

private const val TEST_IMSI1 = "TESTIMSI1"
private const val TEST_SSID1 = "TESTISSID1"
private const val TEST_WIFI_NETWORK_KEY1 = "TESTKEY1"

@RunWith(AndroidJUnit4::class)
class NetworkPolicyTest {
    @Test
    fun testTemplateBackupRestore() {
        assertPolicyBackupRestore(createTestPolicyForTemplate(
                NetworkTemplate.buildTemplateWifi(TEST_SSID1)))
                NetworkTemplate.buildTemplateWifi(TEST_WIFI_NETWORK_KEY1)))
        assertPolicyBackupRestore(createTestPolicyForTemplate(
                NetworkTemplate.buildTemplateMobileAll(TEST_IMSI1)))
        assertPolicyBackupRestore(createTestPolicyForTemplate(
@@ -79,6 +79,6 @@ class NetworkPolicyTest {

        // Verify wifi template can be persistable if the Wifi Network Key is supplied.
        assertTrue(NetworkPolicy.isTemplatePersistable(NetworkTemplate.Builder(MATCH_WIFI)
                .setWifiNetworkKey(TEST_SSID1).build()))
                .setWifiNetworkKeys(setOf(TEST_WIFI_NETWORK_KEY1)).build()))
    }
}
+5 −6
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import static android.net.ConnectivityManager.TYPE_WIFI;
import android.annotation.Nullable;
import android.content.Context;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.service.NetworkIdentityProto;
import android.telephony.Annotation.NetworkType;
import android.util.proto.ProtoOutputStream;
@@ -228,11 +227,11 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
        final int oemManaged = getOemBitfield(snapshot.getNetworkCapabilities());

        if (legacyType == TYPE_WIFI) {
            networkId = snapshot.getNetworkCapabilities().getSsid();
            if (networkId == null) {
                final WifiManager wifi = context.getSystemService(WifiManager.class);
                final WifiInfo info = wifi.getConnectionInfo();
                networkId = info != null ? info.getSSID() : null;
            final TransportInfo transportInfo = snapshot.getNetworkCapabilities()
                    .getTransportInfo();
            if (transportInfo instanceof WifiInfo) {
                final WifiInfo info = (WifiInfo) transportInfo;
                networkId = info != null ? info.getCurrentNetworkKey() : null;
            }
        }

+116 −67

File changed.

Preview size limit exceeded, changes collapsed.

+22 −16

File changed.

Preview size limit exceeded, changes collapsed.

Loading