Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.net; |
| 18 | |
Jeff Sharkey | 02e21d6 | 2011-07-17 15:53:33 -0700 | [diff] [blame] | 19 | import static android.net.ConnectivityManager.TYPE_ETHERNET; |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 20 | import static android.net.ConnectivityManager.TYPE_WIFI; |
Jeff Sharkey | 3ca7481 | 2012-01-24 15:37:07 -0800 | [diff] [blame] | 21 | import static android.net.ConnectivityManager.TYPE_WIFI_P2P; |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 22 | import static android.net.ConnectivityManager.TYPE_WIMAX; |
Jeff Sharkey | d4dd771 | 2012-03-16 11:11:54 -0700 | [diff] [blame] | 23 | import static android.net.NetworkIdentity.COMBINE_SUBTYPE_ENABLED; |
Jeff Sharkey | 02e21d6 | 2011-07-17 15:53:33 -0700 | [diff] [blame] | 24 | import static android.net.NetworkIdentity.scrubSubscriberId; |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 25 | import static android.telephony.TelephonyManager.NETWORK_CLASS_2_G; |
| 26 | import static android.telephony.TelephonyManager.NETWORK_CLASS_3_G; |
| 27 | import static android.telephony.TelephonyManager.NETWORK_CLASS_4_G; |
| 28 | import static android.telephony.TelephonyManager.NETWORK_CLASS_UNKNOWN; |
| 29 | import static android.telephony.TelephonyManager.getNetworkClass; |
Jeff Sharkey | 630a171 | 2011-09-26 10:47:10 -0700 | [diff] [blame] | 30 | import static com.android.internal.util.ArrayUtils.contains; |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 31 | |
Jeff Sharkey | 630a171 | 2011-09-26 10:47:10 -0700 | [diff] [blame] | 32 | import android.content.res.Resources; |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 33 | import android.os.Parcel; |
| 34 | import android.os.Parcelable; |
| 35 | |
| 36 | import com.android.internal.util.Objects; |
| 37 | |
| 38 | /** |
| 39 | * Template definition used to generically match {@link NetworkIdentity}, |
| 40 | * usually when collecting statistics. |
| 41 | * |
| 42 | * @hide |
| 43 | */ |
| 44 | public class NetworkTemplate implements Parcelable { |
| 45 | |
Jeff Sharkey | 4e814c3 | 2011-07-14 20:37:37 -0700 | [diff] [blame] | 46 | public static final int MATCH_MOBILE_ALL = 1; |
Jeff Sharkey | 4e814c3 | 2011-07-14 20:37:37 -0700 | [diff] [blame] | 47 | public static final int MATCH_MOBILE_3G_LOWER = 2; |
Jeff Sharkey | 4e814c3 | 2011-07-14 20:37:37 -0700 | [diff] [blame] | 48 | public static final int MATCH_MOBILE_4G = 3; |
Jeff Sharkey | 4e814c3 | 2011-07-14 20:37:37 -0700 | [diff] [blame] | 49 | public static final int MATCH_WIFI = 4; |
Jeff Sharkey | 4e814c3 | 2011-07-14 20:37:37 -0700 | [diff] [blame] | 50 | public static final int MATCH_ETHERNET = 5; |
Jeff Sharkey | 234766a | 2012-04-10 19:48:07 -0700 | [diff] [blame^] | 51 | public static final int MATCH_MOBILE_WILDCARD = 6; |
| 52 | public static final int MATCH_WIFI_WILDCARD = 7; |
Jeff Sharkey | 4e814c3 | 2011-07-14 20:37:37 -0700 | [diff] [blame] | 53 | |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 54 | /** |
Jeff Sharkey | 630a171 | 2011-09-26 10:47:10 -0700 | [diff] [blame] | 55 | * Set of {@link NetworkInfo#getType()} that reflect data usage. |
| 56 | */ |
| 57 | private static final int[] DATA_USAGE_NETWORK_TYPES; |
| 58 | |
| 59 | static { |
| 60 | DATA_USAGE_NETWORK_TYPES = Resources.getSystem().getIntArray( |
| 61 | com.android.internal.R.array.config_data_usage_network_types); |
| 62 | } |
| 63 | |
| 64 | /** |
Jeff Sharkey | 8fc27e8 | 2012-04-04 20:40:58 -0700 | [diff] [blame] | 65 | * Template to match {@link ConnectivityManager#TYPE_MOBILE} networks with |
| 66 | * the given IMSI. |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 67 | */ |
Jeff Sharkey | 4e814c3 | 2011-07-14 20:37:37 -0700 | [diff] [blame] | 68 | public static NetworkTemplate buildTemplateMobileAll(String subscriberId) { |
Jeff Sharkey | 8fc27e8 | 2012-04-04 20:40:58 -0700 | [diff] [blame] | 69 | return new NetworkTemplate(MATCH_MOBILE_ALL, subscriberId, null); |
Jeff Sharkey | 4e814c3 | 2011-07-14 20:37:37 -0700 | [diff] [blame] | 70 | } |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 71 | |
| 72 | /** |
Jeff Sharkey | 8fc27e8 | 2012-04-04 20:40:58 -0700 | [diff] [blame] | 73 | * Template to match {@link ConnectivityManager#TYPE_MOBILE} networks with |
| 74 | * the given IMSI that roughly meet a "3G" definition, or lower. |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 75 | */ |
Jeff Sharkey | 8fc27e8 | 2012-04-04 20:40:58 -0700 | [diff] [blame] | 76 | @Deprecated |
Jeff Sharkey | 4e814c3 | 2011-07-14 20:37:37 -0700 | [diff] [blame] | 77 | public static NetworkTemplate buildTemplateMobile3gLower(String subscriberId) { |
Jeff Sharkey | 8fc27e8 | 2012-04-04 20:40:58 -0700 | [diff] [blame] | 78 | return new NetworkTemplate(MATCH_MOBILE_3G_LOWER, subscriberId, null); |
Jeff Sharkey | 4e814c3 | 2011-07-14 20:37:37 -0700 | [diff] [blame] | 79 | } |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 80 | |
| 81 | /** |
Jeff Sharkey | 8fc27e8 | 2012-04-04 20:40:58 -0700 | [diff] [blame] | 82 | * Template to match {@link ConnectivityManager#TYPE_MOBILE} networks with |
| 83 | * the given IMSI that roughly meet a "4G" definition. |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 84 | */ |
Jeff Sharkey | 8fc27e8 | 2012-04-04 20:40:58 -0700 | [diff] [blame] | 85 | @Deprecated |
Jeff Sharkey | 4e814c3 | 2011-07-14 20:37:37 -0700 | [diff] [blame] | 86 | public static NetworkTemplate buildTemplateMobile4g(String subscriberId) { |
Jeff Sharkey | 8fc27e8 | 2012-04-04 20:40:58 -0700 | [diff] [blame] | 87 | return new NetworkTemplate(MATCH_MOBILE_4G, subscriberId, null); |
Jeff Sharkey | 4e814c3 | 2011-07-14 20:37:37 -0700 | [diff] [blame] | 88 | } |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 89 | |
| 90 | /** |
Jeff Sharkey | 234766a | 2012-04-10 19:48:07 -0700 | [diff] [blame^] | 91 | * Template to match {@link ConnectivityManager#TYPE_MOBILE} networks, |
| 92 | * regardless of IMSI. |
| 93 | */ |
| 94 | public static NetworkTemplate buildTemplateMobileWildcard() { |
| 95 | return new NetworkTemplate(MATCH_MOBILE_WILDCARD, null, null); |
| 96 | } |
| 97 | |
| 98 | /** |
Jeff Sharkey | 8fc27e8 | 2012-04-04 20:40:58 -0700 | [diff] [blame] | 99 | * Template to match all {@link ConnectivityManager#TYPE_WIFI} networks, |
| 100 | * regardless of SSID. |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 101 | */ |
Jeff Sharkey | 8fc27e8 | 2012-04-04 20:40:58 -0700 | [diff] [blame] | 102 | public static NetworkTemplate buildTemplateWifiWildcard() { |
Jeff Sharkey | 234766a | 2012-04-10 19:48:07 -0700 | [diff] [blame^] | 103 | return new NetworkTemplate(MATCH_WIFI_WILDCARD, null, null); |
Jeff Sharkey | 8fc27e8 | 2012-04-04 20:40:58 -0700 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | @Deprecated |
Jeff Sharkey | 4e814c3 | 2011-07-14 20:37:37 -0700 | [diff] [blame] | 107 | public static NetworkTemplate buildTemplateWifi() { |
Jeff Sharkey | 8fc27e8 | 2012-04-04 20:40:58 -0700 | [diff] [blame] | 108 | return buildTemplateWifiWildcard(); |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Template to match {@link ConnectivityManager#TYPE_WIFI} networks with the |
| 113 | * given SSID. |
| 114 | */ |
| 115 | public static NetworkTemplate buildTemplateWifi(String networkId) { |
| 116 | return new NetworkTemplate(MATCH_WIFI, null, networkId); |
Jeff Sharkey | 4e814c3 | 2011-07-14 20:37:37 -0700 | [diff] [blame] | 117 | } |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 118 | |
Jeff Sharkey | 4e814c3 | 2011-07-14 20:37:37 -0700 | [diff] [blame] | 119 | /** |
| 120 | * Template to combine all {@link ConnectivityManager#TYPE_ETHERNET} style |
| 121 | * networks together. |
| 122 | */ |
| 123 | public static NetworkTemplate buildTemplateEthernet() { |
Jeff Sharkey | 8fc27e8 | 2012-04-04 20:40:58 -0700 | [diff] [blame] | 124 | return new NetworkTemplate(MATCH_ETHERNET, null, null); |
Jeff Sharkey | 4e814c3 | 2011-07-14 20:37:37 -0700 | [diff] [blame] | 125 | } |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 126 | |
Jeff Sharkey | 4e814c3 | 2011-07-14 20:37:37 -0700 | [diff] [blame] | 127 | private final int mMatchRule; |
| 128 | private final String mSubscriberId; |
Jeff Sharkey | 8fc27e8 | 2012-04-04 20:40:58 -0700 | [diff] [blame] | 129 | private final String mNetworkId; |
Jeff Sharkey | 4e814c3 | 2011-07-14 20:37:37 -0700 | [diff] [blame] | 130 | |
Jeff Sharkey | 8fc27e8 | 2012-04-04 20:40:58 -0700 | [diff] [blame] | 131 | public NetworkTemplate(int matchRule, String subscriberId, String networkId) { |
| 132 | mMatchRule = matchRule; |
| 133 | mSubscriberId = subscriberId; |
| 134 | mNetworkId = networkId; |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 135 | } |
| 136 | |
Jeff Sharkey | 4e814c3 | 2011-07-14 20:37:37 -0700 | [diff] [blame] | 137 | private NetworkTemplate(Parcel in) { |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 138 | mMatchRule = in.readInt(); |
| 139 | mSubscriberId = in.readString(); |
Jeff Sharkey | 8fc27e8 | 2012-04-04 20:40:58 -0700 | [diff] [blame] | 140 | mNetworkId = in.readString(); |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 141 | } |
| 142 | |
Jeff Sharkey | 8fc27e8 | 2012-04-04 20:40:58 -0700 | [diff] [blame] | 143 | @Override |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 144 | public void writeToParcel(Parcel dest, int flags) { |
| 145 | dest.writeInt(mMatchRule); |
| 146 | dest.writeString(mSubscriberId); |
Jeff Sharkey | 8fc27e8 | 2012-04-04 20:40:58 -0700 | [diff] [blame] | 147 | dest.writeString(mNetworkId); |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 148 | } |
| 149 | |
Jeff Sharkey | 8fc27e8 | 2012-04-04 20:40:58 -0700 | [diff] [blame] | 150 | @Override |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 151 | public int describeContents() { |
| 152 | return 0; |
| 153 | } |
| 154 | |
| 155 | @Override |
| 156 | public String toString() { |
Jeff Sharkey | 8fc27e8 | 2012-04-04 20:40:58 -0700 | [diff] [blame] | 157 | final StringBuilder builder = new StringBuilder("NetworkTemplate: "); |
| 158 | builder.append("matchRule=").append(getMatchRuleName(mMatchRule)); |
| 159 | if (mSubscriberId != null) { |
| 160 | builder.append(", subscriberId=").append(scrubSubscriberId(mSubscriberId)); |
| 161 | } |
| 162 | if (mNetworkId != null) { |
| 163 | builder.append(", networkId=").append(mNetworkId); |
| 164 | } |
| 165 | return builder.toString(); |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | @Override |
| 169 | public int hashCode() { |
Jeff Sharkey | 8fc27e8 | 2012-04-04 20:40:58 -0700 | [diff] [blame] | 170 | return Objects.hashCode(mMatchRule, mSubscriberId, mNetworkId); |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | @Override |
| 174 | public boolean equals(Object obj) { |
| 175 | if (obj instanceof NetworkTemplate) { |
| 176 | final NetworkTemplate other = (NetworkTemplate) obj; |
| 177 | return mMatchRule == other.mMatchRule |
Jeff Sharkey | 8fc27e8 | 2012-04-04 20:40:58 -0700 | [diff] [blame] | 178 | && Objects.equal(mSubscriberId, other.mSubscriberId) |
| 179 | && Objects.equal(mNetworkId, other.mNetworkId); |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 180 | } |
| 181 | return false; |
| 182 | } |
| 183 | |
| 184 | public int getMatchRule() { |
| 185 | return mMatchRule; |
| 186 | } |
| 187 | |
| 188 | public String getSubscriberId() { |
| 189 | return mSubscriberId; |
| 190 | } |
| 191 | |
Jeff Sharkey | 8fc27e8 | 2012-04-04 20:40:58 -0700 | [diff] [blame] | 192 | public String getNetworkId() { |
| 193 | return mNetworkId; |
| 194 | } |
| 195 | |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 196 | /** |
Jeff Sharkey | 630a171 | 2011-09-26 10:47:10 -0700 | [diff] [blame] | 197 | * Test if given {@link NetworkIdentity} matches this template. |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 198 | */ |
| 199 | public boolean matches(NetworkIdentity ident) { |
| 200 | switch (mMatchRule) { |
| 201 | case MATCH_MOBILE_ALL: |
| 202 | return matchesMobile(ident); |
| 203 | case MATCH_MOBILE_3G_LOWER: |
| 204 | return matchesMobile3gLower(ident); |
| 205 | case MATCH_MOBILE_4G: |
| 206 | return matchesMobile4g(ident); |
| 207 | case MATCH_WIFI: |
| 208 | return matchesWifi(ident); |
Jeff Sharkey | 4e814c3 | 2011-07-14 20:37:37 -0700 | [diff] [blame] | 209 | case MATCH_ETHERNET: |
| 210 | return matchesEthernet(ident); |
Jeff Sharkey | 234766a | 2012-04-10 19:48:07 -0700 | [diff] [blame^] | 211 | case MATCH_MOBILE_WILDCARD: |
| 212 | return matchesMobileWildcard(ident); |
| 213 | case MATCH_WIFI_WILDCARD: |
| 214 | return matchesWifiWildcard(ident); |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 215 | default: |
| 216 | throw new IllegalArgumentException("unknown network template"); |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | /** |
Jeff Sharkey | 630a171 | 2011-09-26 10:47:10 -0700 | [diff] [blame] | 221 | * Check if mobile network with matching IMSI. |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 222 | */ |
| 223 | private boolean matchesMobile(NetworkIdentity ident) { |
Jeff Sharkey | 630a171 | 2011-09-26 10:47:10 -0700 | [diff] [blame] | 224 | if (ident.mType == TYPE_WIMAX) { |
| 225 | // TODO: consider matching against WiMAX subscriber identity |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 226 | return true; |
Jeff Sharkey | 630a171 | 2011-09-26 10:47:10 -0700 | [diff] [blame] | 227 | } else { |
| 228 | return (contains(DATA_USAGE_NETWORK_TYPES, ident.mType) |
| 229 | && Objects.equal(mSubscriberId, ident.mSubscriberId)); |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 230 | } |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | /** |
Jeff Sharkey | 02e21d6 | 2011-07-17 15:53:33 -0700 | [diff] [blame] | 234 | * Check if mobile network classified 3G or lower with matching IMSI. |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 235 | */ |
| 236 | private boolean matchesMobile3gLower(NetworkIdentity ident) { |
Jeff Sharkey | d4dd771 | 2012-03-16 11:11:54 -0700 | [diff] [blame] | 237 | ensureSubtypeAvailable(); |
Jeff Sharkey | 630a171 | 2011-09-26 10:47:10 -0700 | [diff] [blame] | 238 | if (ident.mType == TYPE_WIMAX) { |
| 239 | return false; |
| 240 | } else if (matchesMobile(ident)) { |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 241 | switch (getNetworkClass(ident.mSubType)) { |
| 242 | case NETWORK_CLASS_UNKNOWN: |
| 243 | case NETWORK_CLASS_2_G: |
| 244 | case NETWORK_CLASS_3_G: |
| 245 | return true; |
| 246 | } |
| 247 | } |
| 248 | return false; |
| 249 | } |
| 250 | |
| 251 | /** |
Jeff Sharkey | 630a171 | 2011-09-26 10:47:10 -0700 | [diff] [blame] | 252 | * Check if mobile network classified 4G with matching IMSI. |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 253 | */ |
| 254 | private boolean matchesMobile4g(NetworkIdentity ident) { |
Jeff Sharkey | d4dd771 | 2012-03-16 11:11:54 -0700 | [diff] [blame] | 255 | ensureSubtypeAvailable(); |
Jeff Sharkey | 630a171 | 2011-09-26 10:47:10 -0700 | [diff] [blame] | 256 | if (ident.mType == TYPE_WIMAX) { |
| 257 | // TODO: consider matching against WiMAX subscriber identity |
| 258 | return true; |
| 259 | } else if (matchesMobile(ident)) { |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 260 | switch (getNetworkClass(ident.mSubType)) { |
| 261 | case NETWORK_CLASS_4_G: |
| 262 | return true; |
| 263 | } |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 264 | } |
| 265 | return false; |
| 266 | } |
| 267 | |
| 268 | /** |
| 269 | * Check if matches Wi-Fi network template. |
| 270 | */ |
| 271 | private boolean matchesWifi(NetworkIdentity ident) { |
Jeff Sharkey | 3ca7481 | 2012-01-24 15:37:07 -0800 | [diff] [blame] | 272 | switch (ident.mType) { |
| 273 | case TYPE_WIFI: |
Jeff Sharkey | 234766a | 2012-04-10 19:48:07 -0700 | [diff] [blame^] | 274 | return Objects.equal(mNetworkId, ident.mNetworkId); |
Jeff Sharkey | 3ca7481 | 2012-01-24 15:37:07 -0800 | [diff] [blame] | 275 | default: |
| 276 | return false; |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 277 | } |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 278 | } |
| 279 | |
Jeff Sharkey | 4e814c3 | 2011-07-14 20:37:37 -0700 | [diff] [blame] | 280 | /** |
| 281 | * Check if matches Ethernet network template. |
| 282 | */ |
| 283 | private boolean matchesEthernet(NetworkIdentity ident) { |
| 284 | if (ident.mType == TYPE_ETHERNET) { |
| 285 | return true; |
| 286 | } |
| 287 | return false; |
| 288 | } |
| 289 | |
Jeff Sharkey | 234766a | 2012-04-10 19:48:07 -0700 | [diff] [blame^] | 290 | private boolean matchesMobileWildcard(NetworkIdentity ident) { |
| 291 | if (ident.mType == TYPE_WIMAX) { |
| 292 | return true; |
| 293 | } else { |
| 294 | return contains(DATA_USAGE_NETWORK_TYPES, ident.mType); |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | private boolean matchesWifiWildcard(NetworkIdentity ident) { |
| 299 | switch (ident.mType) { |
| 300 | case TYPE_WIFI: |
| 301 | case TYPE_WIFI_P2P: |
| 302 | return true; |
| 303 | default: |
| 304 | return false; |
| 305 | } |
| 306 | } |
| 307 | |
Jeff Sharkey | 4e814c3 | 2011-07-14 20:37:37 -0700 | [diff] [blame] | 308 | private static String getMatchRuleName(int matchRule) { |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 309 | switch (matchRule) { |
| 310 | case MATCH_MOBILE_3G_LOWER: |
| 311 | return "MOBILE_3G_LOWER"; |
| 312 | case MATCH_MOBILE_4G: |
| 313 | return "MOBILE_4G"; |
| 314 | case MATCH_MOBILE_ALL: |
| 315 | return "MOBILE_ALL"; |
| 316 | case MATCH_WIFI: |
| 317 | return "WIFI"; |
Jeff Sharkey | 4e814c3 | 2011-07-14 20:37:37 -0700 | [diff] [blame] | 318 | case MATCH_ETHERNET: |
| 319 | return "ETHERNET"; |
Jeff Sharkey | 234766a | 2012-04-10 19:48:07 -0700 | [diff] [blame^] | 320 | case MATCH_MOBILE_WILDCARD: |
| 321 | return "MOBILE_WILDCARD"; |
| 322 | case MATCH_WIFI_WILDCARD: |
| 323 | return "WIFI_WILDCARD"; |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 324 | default: |
| 325 | return "UNKNOWN"; |
| 326 | } |
| 327 | } |
| 328 | |
Jeff Sharkey | d4dd771 | 2012-03-16 11:11:54 -0700 | [diff] [blame] | 329 | private static void ensureSubtypeAvailable() { |
| 330 | if (COMBINE_SUBTYPE_ENABLED) { |
| 331 | throw new IllegalArgumentException( |
| 332 | "Unable to enforce 3G_LOWER template on combined data."); |
| 333 | } |
| 334 | } |
| 335 | |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 336 | public static final Creator<NetworkTemplate> CREATOR = new Creator<NetworkTemplate>() { |
Jeff Sharkey | 8fc27e8 | 2012-04-04 20:40:58 -0700 | [diff] [blame] | 337 | @Override |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 338 | public NetworkTemplate createFromParcel(Parcel in) { |
| 339 | return new NetworkTemplate(in); |
| 340 | } |
| 341 | |
Jeff Sharkey | 8fc27e8 | 2012-04-04 20:40:58 -0700 | [diff] [blame] | 342 | @Override |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 343 | public NetworkTemplate[] newArray(int size) { |
| 344 | return new NetworkTemplate[size]; |
| 345 | } |
| 346 | }; |
| 347 | } |