FileDocCategorySizeDatePackage
NetworkPolicy.javaAPI DocAndroid 5.1 API6820Thu Mar 12 22:22:10 GMT 2015android.net

NetworkPolicy

public class NetworkPolicy extends Object implements Comparable, android.os.Parcelable
Policy for networks matching a {@link NetworkTemplate}, including usage cycle and limits to be enforced.
hide

Fields Summary
public static final int
CYCLE_NONE
public static final long
WARNING_DISABLED
public static final long
LIMIT_DISABLED
public static final long
SNOOZE_NEVER
public NetworkTemplate
template
public int
cycleDay
public String
cycleTimezone
public long
warningBytes
public long
limitBytes
public long
lastWarningSnooze
public long
lastLimitSnooze
public boolean
metered
public boolean
inferred
private static final long
DEFAULT_MTU
public static final Creator
CREATOR
Constructors Summary
public NetworkPolicy(NetworkTemplate template, int cycleDay, String cycleTimezone, long warningBytes, long limitBytes, boolean metered)


    
          
                  
        this(template, cycleDay, cycleTimezone, warningBytes, limitBytes, SNOOZE_NEVER,
                SNOOZE_NEVER, metered, false);
    
public NetworkPolicy(NetworkTemplate template, int cycleDay, String cycleTimezone, long warningBytes, long limitBytes, long lastWarningSnooze, long lastLimitSnooze, boolean metered, boolean inferred)

        this.template = checkNotNull(template, "missing NetworkTemplate");
        this.cycleDay = cycleDay;
        this.cycleTimezone = checkNotNull(cycleTimezone, "missing cycleTimezone");
        this.warningBytes = warningBytes;
        this.limitBytes = limitBytes;
        this.lastWarningSnooze = lastWarningSnooze;
        this.lastLimitSnooze = lastLimitSnooze;
        this.metered = metered;
        this.inferred = inferred;
    
public NetworkPolicy(android.os.Parcel in)

        template = in.readParcelable(null);
        cycleDay = in.readInt();
        cycleTimezone = in.readString();
        warningBytes = in.readLong();
        limitBytes = in.readLong();
        lastWarningSnooze = in.readLong();
        lastLimitSnooze = in.readLong();
        metered = in.readInt() != 0;
        inferred = in.readInt() != 0;
    
Methods Summary
public voidclearSnooze()
Clear any existing snooze values, setting to {@link #SNOOZE_NEVER}.

        lastWarningSnooze = SNOOZE_NEVER;
        lastLimitSnooze = SNOOZE_NEVER;
    
public intcompareTo(android.net.NetworkPolicy another)

        if (another == null || another.limitBytes == LIMIT_DISABLED) {
            // other value is missing or disabled; we win
            return -1;
        }
        if (limitBytes == LIMIT_DISABLED || another.limitBytes < limitBytes) {
            // we're disabled or other limit is smaller; they win
            return 1;
        }
        return 0;
    
public intdescribeContents()

        return 0;
    
public booleanequals(java.lang.Object obj)

        if (obj instanceof NetworkPolicy) {
            final NetworkPolicy other = (NetworkPolicy) obj;
            return cycleDay == other.cycleDay && warningBytes == other.warningBytes
                    && limitBytes == other.limitBytes
                    && lastWarningSnooze == other.lastWarningSnooze
                    && lastLimitSnooze == other.lastLimitSnooze && metered == other.metered
                    && inferred == other.inferred
                    && Objects.equals(cycleTimezone, other.cycleTimezone)
                    && Objects.equals(template, other.template);
        }
        return false;
    
public booleanhasCycle()
Test if this policy has a cycle defined, after which usage should reset.

        return cycleDay != CYCLE_NONE;
    
public inthashCode()

        return Objects.hash(template, cycleDay, cycleTimezone, warningBytes, limitBytes,
                lastWarningSnooze, lastLimitSnooze, metered, inferred);
    
public booleanisOverLimit(long totalBytes)
Test if given measurement is near enough to {@link #limitBytes} to be considered over-limit.

        // over-estimate, since kernel will trigger limit once first packet
        // trips over limit.
        totalBytes += 2 * DEFAULT_MTU;
        return limitBytes != LIMIT_DISABLED && totalBytes >= limitBytes;
    
public booleanisOverWarning(long totalBytes)
Test if given measurement is over {@link #warningBytes}.

        return warningBytes != WARNING_DISABLED && totalBytes >= warningBytes;
    
public java.lang.StringtoString()

        final StringBuilder builder = new StringBuilder("NetworkPolicy");
        builder.append("[").append(template).append("]:");
        builder.append(" cycleDay=").append(cycleDay);
        builder.append(", cycleTimezone=").append(cycleTimezone);
        builder.append(", warningBytes=").append(warningBytes);
        builder.append(", limitBytes=").append(limitBytes);
        builder.append(", lastWarningSnooze=").append(lastWarningSnooze);
        builder.append(", lastLimitSnooze=").append(lastLimitSnooze);
        builder.append(", metered=").append(metered);
        builder.append(", inferred=").append(inferred);
        return builder.toString();
    
public voidwriteToParcel(android.os.Parcel dest, int flags)

        dest.writeParcelable(template, flags);
        dest.writeInt(cycleDay);
        dest.writeString(cycleTimezone);
        dest.writeLong(warningBytes);
        dest.writeLong(limitBytes);
        dest.writeLong(lastWarningSnooze);
        dest.writeLong(lastLimitSnooze);
        dest.writeInt(metered ? 1 : 0);
        dest.writeInt(inferred ? 1 : 0);