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

Commit 22c055e6 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

External mutation of full NetworkPolicy set.

Instead of embedding complex template coexistence rules into policy
service, rely on external editors to enforce, and offer atomic
get/set operations for full policy sets.

Generate default mobile policy when none exists, using default of 4GB
warning and cycle reset of current day.  Dispatch listener events
through Handler when holding internal lock, and catch CLASS_UNKNOWN
networks in 3G_LOWER template.

Change-Id: I063cf1eaf330e32b75d0697b89fc04488e6dfaea
parent 4a97122e
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ interface INetworkPolicyManager {
    void registerListener(INetworkPolicyListener listener);
    void unregisterListener(INetworkPolicyListener listener);

    void setNetworkPolicy(int networkType, String subscriberId, in NetworkPolicy policy);
    NetworkPolicy getNetworkPolicy(int networkType, String subscriberId);
    void setNetworkPolicies(in NetworkPolicy[] policies);
    NetworkPolicy[] getNetworkPolicies();

}
+24 −8
Original line number Diff line number Diff line
@@ -26,17 +26,27 @@ import android.os.Parcelable;
 * @hide
 */
public class NetworkPolicy implements Parcelable, Comparable<NetworkPolicy> {
    public final int cycleDay;
    public final long warningBytes;
    public final long limitBytes;
    public final int networkTemplate;
    public final String subscriberId;
    public int cycleDay;
    public long warningBytes;
    public long limitBytes;

    public NetworkPolicy(int cycleDay, long warningBytes, long limitBytes) {
    public static final long WARNING_DISABLED = -1;
    public static final long LIMIT_DISABLED = -1;

    public NetworkPolicy(int networkTemplate, String subscriberId, int cycleDay, long warningBytes,
            long limitBytes) {
        this.networkTemplate = networkTemplate;
        this.subscriberId = subscriberId;
        this.cycleDay = cycleDay;
        this.warningBytes = warningBytes;
        this.limitBytes = limitBytes;
    }

    public NetworkPolicy(Parcel in) {
        networkTemplate = in.readInt();
        subscriberId = in.readString();
        cycleDay = in.readInt();
        warningBytes = in.readLong();
        limitBytes = in.readLong();
@@ -44,6 +54,8 @@ public class NetworkPolicy implements Parcelable, Comparable<NetworkPolicy> {

    /** {@inheritDoc} */
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(networkTemplate);
        dest.writeString(subscriberId);
        dest.writeInt(cycleDay);
        dest.writeLong(warningBytes);
        dest.writeLong(limitBytes);
@@ -56,17 +68,21 @@ public class NetworkPolicy implements Parcelable, Comparable<NetworkPolicy> {

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

    @Override
    public String toString() {
        return "NetworkPolicy: cycleDay=" + cycleDay + ", warningBytes=" + warningBytes
                + ", limitBytes=" + limitBytes;
        return "NetworkPolicy: networkTemplate=" + networkTemplate + ", cycleDay=" + cycleDay
                + ", warningBytes=" + warningBytes + ", limitBytes=" + limitBytes;
    }

    public static final Creator<NetworkPolicy> CREATOR = new Creator<NetworkPolicy>() {
+4 −4
Original line number Diff line number Diff line
@@ -55,17 +55,17 @@ public class NetworkPolicyManager {
    }

    /** {@hide} */
    public void setNetworkPolicy(int networkType, String subscriberId, NetworkPolicy policy) {
    public void setNetworkPolicies(NetworkPolicy[] policies) {
        try {
            mService.setNetworkPolicy(networkType, subscriberId, policy);
            mService.setNetworkPolicies(policies);
        } catch (RemoteException e) {
        }
    }

    /** {@hide} */
    public NetworkPolicy getNetworkPolicy(int networkType, String subscriberId) {
    public NetworkPolicy[] getNetworkPolicies() {
        try {
            return mService.getNetworkPolicy(networkType, subscriberId);
            return mService.getNetworkPolicies();
        } catch (RemoteException e) {
            return null;
        }
+14 −5
Original line number Diff line number Diff line
@@ -41,11 +41,9 @@ public class TrafficStats {
     */
    public final static int UNSUPPORTED = -1;

    // TODO: find better home for these template constants

    /**
     * Template to combine all {@link ConnectivityManager#TYPE_MOBILE} style
     * networks together. Only uses statistics for currently active IMSI.
     * networks together. Only uses statistics for requested IMSI.
     *
     * @hide
     */
@@ -54,7 +52,7 @@ public class TrafficStats {
    /**
     * Template to combine all {@link ConnectivityManager#TYPE_MOBILE} style
     * networks together that roughly meet a "3G" definition, or lower. Only
     * uses statistics for currently active IMSI.
     * uses statistics for requested IMSI.
     *
     * @hide
     */
@@ -63,7 +61,7 @@ public class TrafficStats {
    /**
     * Template to combine all {@link ConnectivityManager#TYPE_MOBILE} style
     * networks together that meet a "4G" definition. Only uses statistics for
     * currently active IMSI.
     * requested IMSI.
     *
     * @hide
     */
@@ -184,6 +182,17 @@ public class TrafficStats {
        }
    }

    /** {@hide} */
    public static boolean isNetworkTemplateMobile(int networkTemplate) {
        switch (networkTemplate) {
            case TEMPLATE_MOBILE_3G_LOWER:
            case TEMPLATE_MOBILE_4G:
            case TEMPLATE_MOBILE_ALL:
                return true;
        }
        return false;
    }

    /**
     * Get the total number of packets transmitted through the mobile interface.
     *
+2 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import static android.net.TrafficStats.TEMPLATE_WIFI;
import static android.telephony.TelephonyManager.NETWORK_CLASS_2_G;
import static android.telephony.TelephonyManager.NETWORK_CLASS_3_G;
import static android.telephony.TelephonyManager.NETWORK_CLASS_4_G;
import static android.telephony.TelephonyManager.NETWORK_CLASS_UNKNOWN;
import static android.telephony.TelephonyManager.getNetworkClass;

import android.content.Context;
@@ -148,6 +149,7 @@ public class NetworkIdentity {
        if (isNetworkTypeMobile(type)
                && Objects.equal(this.subscriberId, subscriberId)) {
            switch (getNetworkClass(subType)) {
                case NETWORK_CLASS_UNKNOWN:
                case NETWORK_CLASS_2_G:
                case NETWORK_CLASS_3_G:
                    return true;
Loading