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

Commit 2e062ab8 authored by Jack Yu's avatar Jack Yu Committed by Android (Google) Code Review
Browse files

Merge "Excluded certain APNs (e.g. IMS) from mobile data usage." into nyc-dev

parents c9039e05 66a6be3a
Loading
Loading
Loading
Loading
+20 −4
Original line number Diff line number Diff line
@@ -55,19 +55,22 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
    final String mSubscriberId;
    final String mNetworkId;
    final boolean mRoaming;
    final boolean mMetered;

    public NetworkIdentity(
            int type, int subType, String subscriberId, String networkId, boolean roaming) {
            int type, int subType, String subscriberId, String networkId, boolean roaming,
            boolean metered) {
        mType = type;
        mSubType = COMBINE_SUBTYPE_ENABLED ? SUBTYPE_COMBINED : subType;
        mSubscriberId = subscriberId;
        mNetworkId = networkId;
        mRoaming = roaming;
        mMetered = metered;
    }

    @Override
    public int hashCode() {
        return Objects.hash(mType, mSubType, mSubscriberId, mNetworkId, mRoaming);
        return Objects.hash(mType, mSubType, mSubscriberId, mNetworkId, mRoaming, mMetered);
    }

    @Override
@@ -76,7 +79,8 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
            final NetworkIdentity ident = (NetworkIdentity) obj;
            return mType == ident.mType && mSubType == ident.mSubType && mRoaming == ident.mRoaming
                    && Objects.equals(mSubscriberId, ident.mSubscriberId)
                    && Objects.equals(mNetworkId, ident.mNetworkId);
                    && Objects.equals(mNetworkId, ident.mNetworkId)
                    && mMetered == ident.mMetered;
        }
        return false;
    }
@@ -102,6 +106,7 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
        if (mRoaming) {
            builder.append(", ROAMING");
        }
        builder.append(", metered=").append(mMetered);
        return builder.append("}").toString();
    }

@@ -125,6 +130,10 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
        return mRoaming;
    }

    public boolean getMetered() {
        return mMetered;
    }

    /**
     * Scrub given IMSI on production builds.
     */
@@ -162,6 +171,7 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
        String subscriberId = null;
        String networkId = null;
        boolean roaming = false;
        boolean metered = false;

        if (isNetworkTypeMobile(type)) {
            if (state.subscriberId == null) {
@@ -171,6 +181,9 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
            subscriberId = state.subscriberId;
            roaming = state.networkInfo.isRoaming();

            metered = !state.networkCapabilities.hasCapability(
                    NetworkCapabilities.NET_CAPABILITY_NOT_METERED);

        } else if (type == TYPE_WIFI) {
            if (state.networkId != null) {
                networkId = state.networkId;
@@ -182,7 +195,7 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
            }
        }

        return new NetworkIdentity(type, subType, subscriberId, networkId, roaming);
        return new NetworkIdentity(type, subType, subscriberId, networkId, roaming, metered);
    }

    @Override
@@ -200,6 +213,9 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
        if (res == 0) {
            res = Boolean.compare(mRoaming, another.mRoaming);
        }
        if (res == 0) {
            res = Boolean.compare(mMetered, another.mMetered);
        }
        return res;
    }
}
+4 −17
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.net;
import static android.net.ConnectivityManager.TYPE_BLUETOOTH;
import static android.net.ConnectivityManager.TYPE_ETHERNET;
import static android.net.ConnectivityManager.TYPE_PROXY;
import static android.net.ConnectivityManager.TYPE_MOBILE;
import static android.net.ConnectivityManager.TYPE_WIFI;
import static android.net.ConnectivityManager.TYPE_WIFI_P2P;
import static android.net.ConnectivityManager.TYPE_WIMAX;
@@ -30,9 +31,6 @@ import static android.telephony.TelephonyManager.NETWORK_CLASS_4_G;
import static android.telephony.TelephonyManager.NETWORK_CLASS_UNKNOWN;
import static android.telephony.TelephonyManager.getNetworkClass;

import static com.android.internal.util.ArrayUtils.contains;

import android.content.res.Resources;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.BackupUtils;
@@ -71,16 +69,6 @@ public class NetworkTemplate implements Parcelable {
    public static final int MATCH_BLUETOOTH = 8;
    public static final int MATCH_PROXY = 9;

    /**
     * Set of {@link NetworkInfo#getType()} that reflect data usage.
     */
    private static final int[] DATA_USAGE_NETWORK_TYPES;

    static {
        DATA_USAGE_NETWORK_TYPES = Resources.getSystem().getIntArray(
                com.android.internal.R.array.config_data_usage_network_types);
    }

    private static boolean sForceAllNetworkTypes = false;

    @VisibleForTesting
@@ -318,9 +306,8 @@ public class NetworkTemplate implements Parcelable {
            // TODO: consider matching against WiMAX subscriber identity
            return true;
        } else {
            final boolean matchesType = (sForceAllNetworkTypes
                    || contains(DATA_USAGE_NETWORK_TYPES, ident.mType));
            return matchesType && !ArrayUtils.isEmpty(mMatchSubscriberIds)
            return (sForceAllNetworkTypes || (ident.mType == TYPE_MOBILE && ident.mMetered))
                    && !ArrayUtils.isEmpty(mMatchSubscriberIds)
                    && ArrayUtils.contains(mMatchSubscriberIds, ident.mSubscriberId);
        }
    }
@@ -389,7 +376,7 @@ public class NetworkTemplate implements Parcelable {
        if (ident.mType == TYPE_WIMAX) {
            return true;
        } else {
            return sForceAllNetworkTypes || contains(DATA_USAGE_NETWORK_TYPES, ident.mType);
            return sForceAllNetworkTypes || (ident.mType == TYPE_MOBILE && ident.mMetered);
        }
    }

+0 −13
Original line number Diff line number Diff line
@@ -265,19 +265,6 @@
        <item>"0,1"</item>
    </string-array>

    <!-- Set of NetworkInfo.getType() that reflect data usage. -->
    <integer-array translatable="false" name="config_data_usage_network_types">
        <item>0</item> <!-- TYPE_MOBILE -->
        <item>2</item> <!-- TYPE_MOBILE_MMS -->
        <item>3</item> <!-- TYPE_MOBILE_SUPL -->
        <item>4</item> <!-- TYPE_MOBILE_DUN -->
        <item>5</item> <!-- TYPE_MOBILE_HIPRI -->
        <item>10</item> <!-- TYPE_MOBILE_FOTA -->
        <item>11</item> <!-- TYPE_MOBILE_IMS -->
        <item>12</item> <!-- TYPE_MOBILE_CBS -->
        <item>14</item> <!-- TYPE_MOBILE_IA -->
    </integer-array>

    <!-- The maximum duration (in milliseconds) we expect a network transition to take -->
    <integer name="config_networkTransitionTimeout">60000</integer>

+0 −1
Original line number Diff line number Diff line
@@ -1128,7 +1128,6 @@
  <java-symbol type="plurals" name="pinpuk_attempts" />

  <java-symbol type="array" name="carrier_properties" />
  <java-symbol type="array" name="config_data_usage_network_types" />
  <java-symbol type="array" name="config_sms_enabled_locking_shift_tables" />
  <java-symbol type="array" name="config_sms_enabled_single_shift_tables" />
  <java-symbol type="array" name="config_twoDigitNumberPattern" />
+16 −2
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ import java.io.DataOutputStream;
import java.io.IOException;
import java.util.HashSet;

import static android.net.ConnectivityManager.TYPE_MOBILE;

/**
 * Identity of a {@code iface}, defined by the set of {@link NetworkIdentity}
 * active on that interface.
@@ -34,6 +36,7 @@ public class NetworkIdentitySet extends HashSet<NetworkIdentity> implements
    private static final int VERSION_INIT = 1;
    private static final int VERSION_ADD_ROAMING = 2;
    private static final int VERSION_ADD_NETWORK_ID = 3;
    private static final int VERSION_ADD_METERED = 4;

    public NetworkIdentitySet() {
    }
@@ -61,12 +64,22 @@ public class NetworkIdentitySet extends HashSet<NetworkIdentity> implements
                roaming = false;
            }

            add(new NetworkIdentity(type, subType, subscriberId, networkId, roaming));
            final boolean metered;
            if (version >= VERSION_ADD_METERED) {
                metered = in.readBoolean();
            } else {
                // If this is the old data and the type is mobile, treat it as metered. (Note that
                // if this is a mobile network, TYPE_MOBILE is the only possible type that could be
                // used.)
                metered = (type == TYPE_MOBILE);
            }

            add(new NetworkIdentity(type, subType, subscriberId, networkId, roaming, metered));
        }
    }

    public void writeToStream(DataOutputStream out) throws IOException {
        out.writeInt(VERSION_ADD_NETWORK_ID);
        out.writeInt(VERSION_ADD_METERED);
        out.writeInt(size());
        for (NetworkIdentity ident : this) {
            out.writeInt(ident.getType());
@@ -74,6 +87,7 @@ public class NetworkIdentitySet extends HashSet<NetworkIdentity> implements
            writeOptionalString(out, ident.getSubscriberId());
            writeOptionalString(out, ident.getNetworkId());
            out.writeBoolean(ident.getRoaming());
            out.writeBoolean(ident.getMetered());
        }
    }

Loading