NetworkTemplate.java revision 630a1712168f402653039e368259cb9480454fa8
11b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey/* 21b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * Copyright (C) 2011 The Android Open Source Project 31b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * 41b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * Licensed under the Apache License, Version 2.0 (the "License"); 51b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * you may not use this file except in compliance with the License. 61b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * You may obtain a copy of the License at 71b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * 81b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * http://www.apache.org/licenses/LICENSE-2.0 91b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * 101b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * Unless required by applicable law or agreed to in writing, software 111b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * distributed under the License is distributed on an "AS IS" BASIS, 121b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 131b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * See the License for the specific language governing permissions and 141b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * limitations under the License. 151b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey */ 161b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey 171b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkeypackage android.net; 181b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey 1902e21d6a5b5117d494777a36783909854854f751Jeff Sharkeyimport static android.net.ConnectivityManager.TYPE_ETHERNET; 201b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkeyimport static android.net.ConnectivityManager.TYPE_WIFI; 211b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkeyimport static android.net.ConnectivityManager.TYPE_WIMAX; 2202e21d6a5b5117d494777a36783909854854f751Jeff Sharkeyimport static android.net.NetworkIdentity.scrubSubscriberId; 231b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkeyimport static android.telephony.TelephonyManager.NETWORK_CLASS_2_G; 241b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkeyimport static android.telephony.TelephonyManager.NETWORK_CLASS_3_G; 251b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkeyimport static android.telephony.TelephonyManager.NETWORK_CLASS_4_G; 261b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkeyimport static android.telephony.TelephonyManager.NETWORK_CLASS_UNKNOWN; 271b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkeyimport static android.telephony.TelephonyManager.getNetworkClass; 28630a1712168f402653039e368259cb9480454fa8Jeff Sharkeyimport static com.android.internal.util.ArrayUtils.contains; 291b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey 30630a1712168f402653039e368259cb9480454fa8Jeff Sharkeyimport android.content.res.Resources; 311b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkeyimport android.os.Parcel; 321b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkeyimport android.os.Parcelable; 331b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey 341b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkeyimport com.android.internal.util.Objects; 351b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey 361b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey/** 371b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * Template definition used to generically match {@link NetworkIdentity}, 381b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * usually when collecting statistics. 391b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * 401b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * @hide 411b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey */ 421b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkeypublic class NetworkTemplate implements Parcelable { 431b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey 444e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey /** {@hide} */ 454e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey public static final int MATCH_MOBILE_ALL = 1; 464e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey /** {@hide} */ 474e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey public static final int MATCH_MOBILE_3G_LOWER = 2; 484e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey /** {@hide} */ 494e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey public static final int MATCH_MOBILE_4G = 3; 504e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey /** {@hide} */ 514e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey public static final int MATCH_WIFI = 4; 524e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey /** {@hide} */ 534e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey public static final int MATCH_ETHERNET = 5; 544e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey 551b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey /** 56630a1712168f402653039e368259cb9480454fa8Jeff Sharkey * Set of {@link NetworkInfo#getType()} that reflect data usage. 57630a1712168f402653039e368259cb9480454fa8Jeff Sharkey */ 58630a1712168f402653039e368259cb9480454fa8Jeff Sharkey private static final int[] DATA_USAGE_NETWORK_TYPES; 59630a1712168f402653039e368259cb9480454fa8Jeff Sharkey 60630a1712168f402653039e368259cb9480454fa8Jeff Sharkey static { 61630a1712168f402653039e368259cb9480454fa8Jeff Sharkey DATA_USAGE_NETWORK_TYPES = Resources.getSystem().getIntArray( 62630a1712168f402653039e368259cb9480454fa8Jeff Sharkey com.android.internal.R.array.config_data_usage_network_types); 63630a1712168f402653039e368259cb9480454fa8Jeff Sharkey } 64630a1712168f402653039e368259cb9480454fa8Jeff Sharkey 65630a1712168f402653039e368259cb9480454fa8Jeff Sharkey /** 661b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * Template to combine all {@link ConnectivityManager#TYPE_MOBILE} style 671b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * networks together. Only uses statistics for requested IMSI. 681b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey */ 694e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey public static NetworkTemplate buildTemplateMobileAll(String subscriberId) { 704e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey return new NetworkTemplate(MATCH_MOBILE_ALL, subscriberId); 714e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey } 721b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey 731b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey /** 741b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * Template to combine all {@link ConnectivityManager#TYPE_MOBILE} style 751b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * networks together that roughly meet a "3G" definition, or lower. Only 761b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * uses statistics for requested IMSI. 771b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey */ 784e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey public static NetworkTemplate buildTemplateMobile3gLower(String subscriberId) { 794e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey return new NetworkTemplate(MATCH_MOBILE_3G_LOWER, subscriberId); 804e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey } 811b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey 821b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey /** 831b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * Template to combine all {@link ConnectivityManager#TYPE_MOBILE} style 841b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * networks together that meet a "4G" definition. Only uses statistics for 851b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * requested IMSI. 861b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey */ 874e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey public static NetworkTemplate buildTemplateMobile4g(String subscriberId) { 884e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey return new NetworkTemplate(MATCH_MOBILE_4G, subscriberId); 894e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey } 901b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey 911b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey /** 921b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * Template to combine all {@link ConnectivityManager#TYPE_WIFI} style 931b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * networks together. 941b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey */ 954e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey public static NetworkTemplate buildTemplateWifi() { 964e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey return new NetworkTemplate(MATCH_WIFI, null); 974e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey } 981b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey 994e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey /** 1004e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey * Template to combine all {@link ConnectivityManager#TYPE_ETHERNET} style 1014e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey * networks together. 1024e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey */ 1034e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey public static NetworkTemplate buildTemplateEthernet() { 1044e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey return new NetworkTemplate(MATCH_ETHERNET, null); 1054e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey } 1064e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey 1074e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey private final int mMatchRule; 1084e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey private final String mSubscriberId; 1091b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey 1104e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey /** {@hide} */ 1111b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey public NetworkTemplate(int matchRule, String subscriberId) { 1121b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey this.mMatchRule = matchRule; 1131b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey this.mSubscriberId = subscriberId; 1141b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey } 1151b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey 1164e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey private NetworkTemplate(Parcel in) { 1171b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey mMatchRule = in.readInt(); 1181b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey mSubscriberId = in.readString(); 1191b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey } 1201b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey 1211b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey /** {@inheritDoc} */ 1221b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey public void writeToParcel(Parcel dest, int flags) { 1231b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey dest.writeInt(mMatchRule); 1241b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey dest.writeString(mSubscriberId); 1251b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey } 1261b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey 1271b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey /** {@inheritDoc} */ 1281b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey public int describeContents() { 1291b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey return 0; 1301b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey } 1311b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey 1321b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey @Override 1331b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey public String toString() { 13402e21d6a5b5117d494777a36783909854854f751Jeff Sharkey final String scrubSubscriberId = scrubSubscriberId(mSubscriberId); 1351b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey return "NetworkTemplate: matchRule=" + getMatchRuleName(mMatchRule) + ", subscriberId=" 1361b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey + scrubSubscriberId; 1371b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey } 1381b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey 1391b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey @Override 1401b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey public int hashCode() { 1411b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey return Objects.hashCode(mMatchRule, mSubscriberId); 1421b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey } 1431b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey 1441b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey @Override 1451b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey public boolean equals(Object obj) { 1461b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey if (obj instanceof NetworkTemplate) { 1471b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey final NetworkTemplate other = (NetworkTemplate) obj; 1481b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey return mMatchRule == other.mMatchRule 1491b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey && Objects.equal(mSubscriberId, other.mSubscriberId); 1501b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey } 1511b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey return false; 1521b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey } 1531b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey 1544e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey /** {@hide} */ 1551b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey public int getMatchRule() { 1561b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey return mMatchRule; 1571b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey } 1581b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey 1594e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey /** {@hide} */ 1601b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey public String getSubscriberId() { 1611b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey return mSubscriberId; 1621b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey } 1631b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey 1641b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey /** 165630a1712168f402653039e368259cb9480454fa8Jeff Sharkey * Test if given {@link NetworkIdentity} matches this template. 1661b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey */ 1671b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey public boolean matches(NetworkIdentity ident) { 1681b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey switch (mMatchRule) { 1691b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey case MATCH_MOBILE_ALL: 1701b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey return matchesMobile(ident); 1711b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey case MATCH_MOBILE_3G_LOWER: 1721b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey return matchesMobile3gLower(ident); 1731b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey case MATCH_MOBILE_4G: 1741b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey return matchesMobile4g(ident); 1751b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey case MATCH_WIFI: 1761b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey return matchesWifi(ident); 1774e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey case MATCH_ETHERNET: 1784e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey return matchesEthernet(ident); 1791b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey default: 1801b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey throw new IllegalArgumentException("unknown network template"); 1811b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey } 1821b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey } 1831b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey 1841b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey /** 185630a1712168f402653039e368259cb9480454fa8Jeff Sharkey * Check if mobile network with matching IMSI. 1861b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey */ 1871b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey private boolean matchesMobile(NetworkIdentity ident) { 188630a1712168f402653039e368259cb9480454fa8Jeff Sharkey if (ident.mType == TYPE_WIMAX) { 189630a1712168f402653039e368259cb9480454fa8Jeff Sharkey // TODO: consider matching against WiMAX subscriber identity 1901b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey return true; 191630a1712168f402653039e368259cb9480454fa8Jeff Sharkey } else { 192630a1712168f402653039e368259cb9480454fa8Jeff Sharkey return (contains(DATA_USAGE_NETWORK_TYPES, ident.mType) 193630a1712168f402653039e368259cb9480454fa8Jeff Sharkey && Objects.equal(mSubscriberId, ident.mSubscriberId)); 1941b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey } 1951b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey } 1961b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey 1971b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey /** 19802e21d6a5b5117d494777a36783909854854f751Jeff Sharkey * Check if mobile network classified 3G or lower with matching IMSI. 1991b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey */ 2001b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey private boolean matchesMobile3gLower(NetworkIdentity ident) { 201630a1712168f402653039e368259cb9480454fa8Jeff Sharkey if (ident.mType == TYPE_WIMAX) { 202630a1712168f402653039e368259cb9480454fa8Jeff Sharkey return false; 203630a1712168f402653039e368259cb9480454fa8Jeff Sharkey } else if (matchesMobile(ident)) { 2041b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey switch (getNetworkClass(ident.mSubType)) { 2051b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey case NETWORK_CLASS_UNKNOWN: 2061b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey case NETWORK_CLASS_2_G: 2071b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey case NETWORK_CLASS_3_G: 2081b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey return true; 2091b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey } 2101b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey } 2111b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey return false; 2121b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey } 2131b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey 2141b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey /** 215630a1712168f402653039e368259cb9480454fa8Jeff Sharkey * Check if mobile network classified 4G with matching IMSI. 2161b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey */ 2171b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey private boolean matchesMobile4g(NetworkIdentity ident) { 218630a1712168f402653039e368259cb9480454fa8Jeff Sharkey if (ident.mType == TYPE_WIMAX) { 219630a1712168f402653039e368259cb9480454fa8Jeff Sharkey // TODO: consider matching against WiMAX subscriber identity 220630a1712168f402653039e368259cb9480454fa8Jeff Sharkey return true; 221630a1712168f402653039e368259cb9480454fa8Jeff Sharkey } else if (matchesMobile(ident)) { 2221b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey switch (getNetworkClass(ident.mSubType)) { 2231b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey case NETWORK_CLASS_4_G: 2241b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey return true; 2251b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey } 2261b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey } 2271b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey return false; 2281b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey } 2291b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey 2301b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey /** 2311b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey * Check if matches Wi-Fi network template. 2321b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey */ 2331b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey private boolean matchesWifi(NetworkIdentity ident) { 2341b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey if (ident.mType == TYPE_WIFI) { 2351b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey return true; 2361b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey } 2371b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey return false; 2381b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey } 2391b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey 2404e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey /** 2414e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey * Check if matches Ethernet network template. 2424e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey */ 2434e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey private boolean matchesEthernet(NetworkIdentity ident) { 2444e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey if (ident.mType == TYPE_ETHERNET) { 2454e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey return true; 2464e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey } 2474e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey return false; 2484e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey } 2494e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey 2504e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey private static String getMatchRuleName(int matchRule) { 2511b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey switch (matchRule) { 2521b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey case MATCH_MOBILE_3G_LOWER: 2531b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey return "MOBILE_3G_LOWER"; 2541b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey case MATCH_MOBILE_4G: 2551b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey return "MOBILE_4G"; 2561b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey case MATCH_MOBILE_ALL: 2571b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey return "MOBILE_ALL"; 2581b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey case MATCH_WIFI: 2591b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey return "WIFI"; 2604e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey case MATCH_ETHERNET: 2614e814c348ce205fcc1a273427f95ef1d100ed60cJeff Sharkey return "ETHERNET"; 2621b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey default: 2631b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey return "UNKNOWN"; 2641b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey } 2651b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey } 2661b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey 2671b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey public static final Creator<NetworkTemplate> CREATOR = new Creator<NetworkTemplate>() { 2681b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey public NetworkTemplate createFromParcel(Parcel in) { 2691b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey return new NetworkTemplate(in); 2701b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey } 2711b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey 2721b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey public NetworkTemplate[] newArray(int size) { 2731b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey return new NetworkTemplate[size]; 2741b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey } 2751b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey }; 2761b5a2a96f793211bfbd39aa29cc41031dfa23950Jeff Sharkey} 277