Loading core/java/android/net/NetworkTemplate.java +27 −14 Original line number Diff line number Diff line Loading @@ -19,14 +19,15 @@ package android.net; import static android.net.ConnectivityManager.TYPE_ETHERNET; import static android.net.ConnectivityManager.TYPE_WIFI; import static android.net.ConnectivityManager.TYPE_WIMAX; import static android.net.ConnectivityManager.isNetworkTypeMobile; import static android.net.NetworkIdentity.scrubSubscriberId; 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 static com.android.internal.util.ArrayUtils.contains; import android.content.res.Resources; import android.os.Parcel; import android.os.Parcelable; Loading @@ -51,6 +52,16 @@ public class NetworkTemplate implements Parcelable { /** {@hide} */ public static final int MATCH_ETHERNET = 5; /** * 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); } /** * Template to combine all {@link ConnectivityManager#TYPE_MOBILE} style * networks together. Only uses statistics for requested IMSI. Loading Loading @@ -151,7 +162,7 @@ public class NetworkTemplate implements Parcelable { } /** * Test if this network matches the given template and IMSI. * Test if given {@link NetworkIdentity} matches this template. */ public boolean matches(NetworkIdentity ident) { switch (mMatchRule) { Loading @@ -171,23 +182,25 @@ public class NetworkTemplate implements Parcelable { } /** * Check if mobile network with matching IMSI. Also matches * {@link #TYPE_WIMAX}. * Check if mobile network with matching IMSI. */ private boolean matchesMobile(NetworkIdentity ident) { if (isNetworkTypeMobile(ident.mType) && Objects.equal(mSubscriberId, ident.mSubscriberId)) { return true; } else if (ident.mType == TYPE_WIMAX) { if (ident.mType == TYPE_WIMAX) { // TODO: consider matching against WiMAX subscriber identity return true; } else { return (contains(DATA_USAGE_NETWORK_TYPES, ident.mType) && Objects.equal(mSubscriberId, ident.mSubscriberId)); } return false; } /** * Check if mobile network classified 3G or lower with matching IMSI. */ private boolean matchesMobile3gLower(NetworkIdentity ident) { if (isNetworkTypeMobile(ident.mType) && Objects.equal(mSubscriberId, ident.mSubscriberId)) { if (ident.mType == TYPE_WIMAX) { return false; } else if (matchesMobile(ident)) { switch (getNetworkClass(ident.mSubType)) { case NETWORK_CLASS_UNKNOWN: case NETWORK_CLASS_2_G: Loading @@ -199,17 +212,17 @@ public class NetworkTemplate implements Parcelable { } /** * Check if mobile network classified 4G with matching IMSI. Also matches * {@link #TYPE_WIMAX}. * Check if mobile network classified 4G with matching IMSI. */ private boolean matchesMobile4g(NetworkIdentity ident) { if (isNetworkTypeMobile(ident.mType) && Objects.equal(mSubscriberId, ident.mSubscriberId)) { if (ident.mType == TYPE_WIMAX) { // TODO: consider matching against WiMAX subscriber identity return true; } else if (matchesMobile(ident)) { switch (getNetworkClass(ident.mSubType)) { case NETWORK_CLASS_4_G: return true; } } else if (ident.mType == TYPE_WIMAX) { return true; } return false; } Loading core/java/com/android/internal/util/ArrayUtils.java +9 −0 Original line number Diff line number Diff line Loading @@ -133,4 +133,13 @@ public class ArrayUtils } return false; } public static boolean contains(int[] array, int value) { for (int element : array) { if (element == value) { return true; } } return false; } } core/res/res/values/config.xml +12 −0 Original line number Diff line number Diff line Loading @@ -138,6 +138,18 @@ <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 --> </integer-array> <!-- The maximum duration (in milliseconds) we expect a network transition to take --> <integer name="config_networkTransitionTimeout">60000</integer> Loading Loading
core/java/android/net/NetworkTemplate.java +27 −14 Original line number Diff line number Diff line Loading @@ -19,14 +19,15 @@ package android.net; import static android.net.ConnectivityManager.TYPE_ETHERNET; import static android.net.ConnectivityManager.TYPE_WIFI; import static android.net.ConnectivityManager.TYPE_WIMAX; import static android.net.ConnectivityManager.isNetworkTypeMobile; import static android.net.NetworkIdentity.scrubSubscriberId; 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 static com.android.internal.util.ArrayUtils.contains; import android.content.res.Resources; import android.os.Parcel; import android.os.Parcelable; Loading @@ -51,6 +52,16 @@ public class NetworkTemplate implements Parcelable { /** {@hide} */ public static final int MATCH_ETHERNET = 5; /** * 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); } /** * Template to combine all {@link ConnectivityManager#TYPE_MOBILE} style * networks together. Only uses statistics for requested IMSI. Loading Loading @@ -151,7 +162,7 @@ public class NetworkTemplate implements Parcelable { } /** * Test if this network matches the given template and IMSI. * Test if given {@link NetworkIdentity} matches this template. */ public boolean matches(NetworkIdentity ident) { switch (mMatchRule) { Loading @@ -171,23 +182,25 @@ public class NetworkTemplate implements Parcelable { } /** * Check if mobile network with matching IMSI. Also matches * {@link #TYPE_WIMAX}. * Check if mobile network with matching IMSI. */ private boolean matchesMobile(NetworkIdentity ident) { if (isNetworkTypeMobile(ident.mType) && Objects.equal(mSubscriberId, ident.mSubscriberId)) { return true; } else if (ident.mType == TYPE_WIMAX) { if (ident.mType == TYPE_WIMAX) { // TODO: consider matching against WiMAX subscriber identity return true; } else { return (contains(DATA_USAGE_NETWORK_TYPES, ident.mType) && Objects.equal(mSubscriberId, ident.mSubscriberId)); } return false; } /** * Check if mobile network classified 3G or lower with matching IMSI. */ private boolean matchesMobile3gLower(NetworkIdentity ident) { if (isNetworkTypeMobile(ident.mType) && Objects.equal(mSubscriberId, ident.mSubscriberId)) { if (ident.mType == TYPE_WIMAX) { return false; } else if (matchesMobile(ident)) { switch (getNetworkClass(ident.mSubType)) { case NETWORK_CLASS_UNKNOWN: case NETWORK_CLASS_2_G: Loading @@ -199,17 +212,17 @@ public class NetworkTemplate implements Parcelable { } /** * Check if mobile network classified 4G with matching IMSI. Also matches * {@link #TYPE_WIMAX}. * Check if mobile network classified 4G with matching IMSI. */ private boolean matchesMobile4g(NetworkIdentity ident) { if (isNetworkTypeMobile(ident.mType) && Objects.equal(mSubscriberId, ident.mSubscriberId)) { if (ident.mType == TYPE_WIMAX) { // TODO: consider matching against WiMAX subscriber identity return true; } else if (matchesMobile(ident)) { switch (getNetworkClass(ident.mSubType)) { case NETWORK_CLASS_4_G: return true; } } else if (ident.mType == TYPE_WIMAX) { return true; } return false; } Loading
core/java/com/android/internal/util/ArrayUtils.java +9 −0 Original line number Diff line number Diff line Loading @@ -133,4 +133,13 @@ public class ArrayUtils } return false; } public static boolean contains(int[] array, int value) { for (int element : array) { if (element == value) { return true; } } return false; } }
core/res/res/values/config.xml +12 −0 Original line number Diff line number Diff line Loading @@ -138,6 +138,18 @@ <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 --> </integer-array> <!-- The maximum duration (in milliseconds) we expect a network transition to take --> <integer name="config_networkTransitionTimeout">60000</integer> Loading