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

Commit 42b4446b authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Iterate NetworkPolicy towards SubscriptionPlan."

parents 06820aa0 53313d7e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -146,6 +146,7 @@ package android {
    field public static final java.lang.String MANAGE_CA_CERTIFICATES = "android.permission.MANAGE_CA_CERTIFICATES";
    field public static final java.lang.String MANAGE_DEVICE_ADMINS = "android.permission.MANAGE_DEVICE_ADMINS";
    field public static final java.lang.String MANAGE_DOCUMENTS = "android.permission.MANAGE_DOCUMENTS";
    field public static final java.lang.String MANAGE_FALLBACK_SUBSCRIPTION_PLANS = "android.permission.MANAGE_FALLBACK_SUBSCRIPTION_PLANS";
    field public static final java.lang.String MANAGE_OWN_CALLS = "android.permission.MANAGE_OWN_CALLS";
    field public static final java.lang.String MANAGE_USB = "android.permission.MANAGE_USB";
    field public static final java.lang.String MANAGE_USERS = "android.permission.MANAGE_USERS";
+6 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.net.NetworkPolicy;
import android.net.NetworkQuotaInfo;
import android.net.NetworkState;
import android.net.NetworkTemplate;
import android.telephony.SubscriptionPlan;

/**
 * Interface that creates and modifies network policy rules.
@@ -67,5 +68,10 @@ interface INetworkPolicyManager {

    NetworkQuotaInfo getNetworkQuotaInfo(in NetworkState state);

    SubscriptionPlan[] getSubscriptionPlans(int subId, String callingPackage);
    void setSubscriptionPlans(int subId, in SubscriptionPlan[] plans, String callingPackage);

    String getSubscriptionPlanOwner(int subId);

    void factoryReset(String subscriber);
}
+11 −8
Original line number Diff line number Diff line
@@ -46,17 +46,20 @@ public class NetworkPolicy implements Parcelable, Comparable<NetworkPolicy> {
    public static final long SNOOZE_NEVER = -1;

    public NetworkTemplate template;
    public int cycleDay;
    public String cycleTimezone;
    public long warningBytes;
    public long limitBytes;
    public long lastWarningSnooze;
    public long lastLimitSnooze;
    @Deprecated public boolean metered;
    public boolean inferred;
    @Deprecated public int cycleDay = CYCLE_NONE;
    @Deprecated public String cycleTimezone = "UTC";
    public long warningBytes = WARNING_DISABLED;
    public long limitBytes = LIMIT_DISABLED;
    public long lastWarningSnooze = SNOOZE_NEVER;
    public long lastLimitSnooze = SNOOZE_NEVER;
    @Deprecated public boolean metered = true;
    public boolean inferred = false;

    private static final long DEFAULT_MTU = 1500;

    public NetworkPolicy() {
    }

    @Deprecated
    public NetworkPolicy(NetworkTemplate template, int cycleDay, String cycleTimezone,
            long warningBytes, long limitBytes, boolean metered) {
+6 −69
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
package android.net;

import static android.content.pm.PackageManager.GET_SIGNATURES;
import static android.net.NetworkPolicy.CYCLE_NONE;

import android.annotation.SystemService;
import android.app.ActivityManager;
@@ -30,13 +29,15 @@ import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo;
import android.os.RemoteException;
import android.os.UserHandle;
import android.telephony.SubscriptionPlan;
import android.util.DebugUtils;
import android.util.Pair;

import com.google.android.collect.Sets;

import java.util.Calendar;
import java.time.ZonedDateTime;
import java.util.HashSet;
import java.util.TimeZone;
import java.util.Iterator;

/**
 * Manager for creating and modifying network policy rules.
@@ -251,73 +252,9 @@ public class NetworkPolicyManager {
        }
    }

    /**
     * Compute the last cycle boundary for the given {@link NetworkPolicy}. For
     * example, if cycle day is 20th, and today is June 15th, it will return May
     * 20th. When cycle day doesn't exist in current month, it snaps to the 1st
     * of following month.
     *
     * @hide
     */
    public static long computeLastCycleBoundary(long currentTime, NetworkPolicy policy) {
        if (policy.cycleDay == CYCLE_NONE) {
            throw new IllegalArgumentException("Unable to compute boundary without cycleDay");
        }

        final Calendar cal = Calendar.getInstance(TimeZone.getTimeZone(policy.cycleTimezone));
        cal.setTimeInMillis(currentTime);
        snapToCycleDay(cal, policy.cycleDay);

        if (cal.getTimeInMillis() >= currentTime) {
            // Cycle boundary is beyond now, use last cycle boundary
            cal.set(Calendar.DAY_OF_MONTH, 1);
            cal.add(Calendar.MONTH, -1);
            snapToCycleDay(cal, policy.cycleDay);
        }

        return cal.getTimeInMillis();
    }

    /** {@hide} */
    public static long computeNextCycleBoundary(long currentTime, NetworkPolicy policy) {
        if (policy.cycleDay == CYCLE_NONE) {
            throw new IllegalArgumentException("Unable to compute boundary without cycleDay");
        }

        final Calendar cal = Calendar.getInstance(TimeZone.getTimeZone(policy.cycleTimezone));
        cal.setTimeInMillis(currentTime);
        snapToCycleDay(cal, policy.cycleDay);

        if (cal.getTimeInMillis() <= currentTime) {
            // Cycle boundary is before now, use next cycle boundary
            cal.set(Calendar.DAY_OF_MONTH, 1);
            cal.add(Calendar.MONTH, 1);
            snapToCycleDay(cal, policy.cycleDay);
        }

        return cal.getTimeInMillis();
    }

    /**
     * Snap to the cycle day for the current month given; when cycle day doesn't
     * exist, it snaps to last second of current month.
     *
     * @hide
     */
    public static void snapToCycleDay(Calendar cal, int cycleDay) {
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        if (cycleDay > cal.getActualMaximum(Calendar.DAY_OF_MONTH)) {
            cal.add(Calendar.MONTH, 1);
            cal.set(Calendar.DAY_OF_MONTH, 1);
            cal.set(Calendar.HOUR_OF_DAY, 0);
            cal.set(Calendar.MINUTE, 0);
            cal.set(Calendar.SECOND, 0);
            cal.add(Calendar.SECOND, -1);
        } else {
            cal.set(Calendar.DAY_OF_MONTH, cycleDay);
        }
    public static Iterator<Pair<ZonedDateTime, ZonedDateTime>> cycleIterator(NetworkPolicy policy) {
        return SubscriptionPlan.convert(policy).cycleIterator();
    }

    /**
+6 −0
Original line number Diff line number Diff line
@@ -3139,6 +3139,12 @@
    <permission android:name="android.permission.MANAGE_NETWORK_POLICY"
        android:protectionLevel="signature" />

    <!-- @SystemApi Allows an application to manage fallback subscription plans.
         Note that another app providing plans for an explicit HNI will always
         take precidence over these fallback plans. @hide -->
    <permission android:name="android.permission.MANAGE_FALLBACK_SUBSCRIPTION_PLANS"
        android:protectionLevel="signature|privileged" />

    <!-- @SystemApi Allows an application to account its network traffic against other UIDs. Used
         by system services like download manager and media server. Not for use by
         third party apps. @hide -->
Loading