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

Commit 9dbd544e authored by Sarah Chin's avatar Sarah Chin Committed by Automerger Merge Worker
Browse files

Merge "Update getNetworkTypes() call" am: 97c1100f

Change-Id: I7c48911f1cfa059fb522e91a207ad731bd5d0948
parents 676275ab 97c1100f
Loading
Loading
Loading
Loading
+11 −8
Original line number Original line Diff line number Diff line
@@ -135,7 +135,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Matcher;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.Pattern;
import java.util.stream.IntStream;
import java.util.stream.Collectors;


/**
/**
 * {@hide}
 * {@hide}
@@ -4143,24 +4143,27 @@ public class DcTracker extends Handler {
        }
        }


        boolean isGeneralUnmetered = true;
        boolean isGeneralUnmetered = true;
        Set<Integer> allNetworkTypes = Arrays.stream(TelephonyManager.getAllNetworkTypes())
                .boxed().collect(Collectors.toSet());
        for (SubscriptionPlan plan : mSubscriptionPlans) {
        for (SubscriptionPlan plan : mSubscriptionPlans) {
            // check plan is general or specific
            // check plan is general (applies to all network types) or specific
            if (plan.getNetworkTypes() == null) {
            if (Arrays.stream(plan.getNetworkTypes()).boxed().collect(Collectors.toSet())
                    .containsAll(allNetworkTypes)) {
                if (!isPlanUnmetered(plan)) {
                if (!isPlanUnmetered(plan)) {
                    // metered takes precedence over unmetered for safety
                    // metered takes precedence over unmetered for safety
                    isGeneralUnmetered = false;
                    isGeneralUnmetered = false;
                }
                }
            } else {
            } else {
                // check plan applies to given network type
                // check plan applies to given network type
                if (IntStream.of(plan.getNetworkTypes()).anyMatch(n -> n == networkType)) {
                    // ensure network type unknown returns general value
                if (networkType != TelephonyManager.NETWORK_TYPE_UNKNOWN) {
                if (networkType != TelephonyManager.NETWORK_TYPE_UNKNOWN) {
                        // there is only 1 specific plan per network type, so return value if found
                    for (int planNetworkType : plan.getNetworkTypes()) {
                        if (planNetworkType == networkType) {
                            return isPlanUnmetered(plan);
                            return isPlanUnmetered(plan);
                        }
                        }
                    }
                    }
                }
                }
            }
            }
        }
        return isGeneralUnmetered;
        return isGeneralUnmetered;
    }
    }


+0 −2
Original line number Original line Diff line number Diff line
@@ -1821,7 +1821,6 @@ public class DcTrackerTest extends TelephonyTest {
            plans.add(SubscriptionPlan.Builder
            plans.add(SubscriptionPlan.Builder
                    .createRecurring(ZonedDateTime.parse("2007-03-14T00:00:00.000Z"),
                    .createRecurring(ZonedDateTime.parse("2007-03-14T00:00:00.000Z"),
                            Period.ofMonths(1))
                            Period.ofMonths(1))
                    .setTitle("Some NR 5G unmetered workaround plan")
                    .setDataLimit(SubscriptionPlan.BYTES_UNLIMITED,
                    .setDataLimit(SubscriptionPlan.BYTES_UNLIMITED,
                            SubscriptionPlan.LIMIT_BEHAVIOR_THROTTLED)
                            SubscriptionPlan.LIMIT_BEHAVIOR_THROTTLED)
                    .setNetworkTypes(new int[] {TelephonyManager.NETWORK_TYPE_NR})
                    .setNetworkTypes(new int[] {TelephonyManager.NETWORK_TYPE_NR})
@@ -1830,7 +1829,6 @@ public class DcTrackerTest extends TelephonyTest {
        plans.add(SubscriptionPlan.Builder
        plans.add(SubscriptionPlan.Builder
                .createRecurring(ZonedDateTime.parse("2007-03-14T00:00:00.000Z"),
                .createRecurring(ZonedDateTime.parse("2007-03-14T00:00:00.000Z"),
                        Period.ofMonths(1))
                        Period.ofMonths(1))
                .setTitle("Some 5GB Plan")
                .setDataLimit(1_000_000_000, SubscriptionPlan.LIMIT_BEHAVIOR_DISABLED)
                .setDataLimit(1_000_000_000, SubscriptionPlan.LIMIT_BEHAVIOR_DISABLED)
                .setDataUsage(500_000_000, System.currentTimeMillis())
                .setDataUsage(500_000_000, System.currentTimeMillis())
                .build());
                .build());