blob: 6cfab92360f6d86d5a5b4914c6e64991598729d8 [file] [log] [blame]
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -07001/*
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
17package android.net;
18
Jeff Sharkey55a442e2014-11-18 18:22:21 -080019import static android.net.ConnectivityManager.TYPE_BLUETOOTH;
Jeff Sharkey02e21d62011-07-17 15:53:33 -070020import static android.net.ConnectivityManager.TYPE_ETHERNET;
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -070021import static android.net.ConnectivityManager.TYPE_WIFI;
Jeff Sharkey3ca74812012-01-24 15:37:07 -080022import static android.net.ConnectivityManager.TYPE_WIFI_P2P;
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -070023import static android.net.ConnectivityManager.TYPE_WIMAX;
Jeff Sharkeyd4dd7712012-03-16 11:11:54 -070024import static android.net.NetworkIdentity.COMBINE_SUBTYPE_ENABLED;
Jeff Sharkey2e4dce02012-12-18 17:06:06 -080025import static android.net.wifi.WifiInfo.removeDoubleQuotes;
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -070026import static android.telephony.TelephonyManager.NETWORK_CLASS_2_G;
27import static android.telephony.TelephonyManager.NETWORK_CLASS_3_G;
28import static android.telephony.TelephonyManager.NETWORK_CLASS_4_G;
29import static android.telephony.TelephonyManager.NETWORK_CLASS_UNKNOWN;
30import static android.telephony.TelephonyManager.getNetworkClass;
Jeff Sharkey630a1712011-09-26 10:47:10 -070031import static com.android.internal.util.ArrayUtils.contains;
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -070032
Jeff Sharkey630a1712011-09-26 10:47:10 -070033import android.content.res.Resources;
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -070034import android.os.Parcel;
35import android.os.Parcelable;
36
Jeff Sharkey8b2c3a142012-11-12 11:45:05 -080037import com.android.internal.annotations.VisibleForTesting;
Jeff Sharkey32566012014-12-02 18:30:14 -080038import com.android.internal.util.ArrayUtils;
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -070039
Jeff Sharkey32566012014-12-02 18:30:14 -080040import java.util.Arrays;
Jeff Sharkey55a442e2014-11-18 18:22:21 -080041import java.util.Objects;
42
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -070043/**
44 * Template definition used to generically match {@link NetworkIdentity},
45 * usually when collecting statistics.
46 *
47 * @hide
48 */
49public class NetworkTemplate implements Parcelable {
50
Jeff Sharkey4e814c32011-07-14 20:37:37 -070051 public static final int MATCH_MOBILE_ALL = 1;
Jeff Sharkey4e814c32011-07-14 20:37:37 -070052 public static final int MATCH_MOBILE_3G_LOWER = 2;
Jeff Sharkey4e814c32011-07-14 20:37:37 -070053 public static final int MATCH_MOBILE_4G = 3;
Jeff Sharkey4e814c32011-07-14 20:37:37 -070054 public static final int MATCH_WIFI = 4;
Jeff Sharkey4e814c32011-07-14 20:37:37 -070055 public static final int MATCH_ETHERNET = 5;
Jeff Sharkey234766a2012-04-10 19:48:07 -070056 public static final int MATCH_MOBILE_WILDCARD = 6;
57 public static final int MATCH_WIFI_WILDCARD = 7;
Jeff Sharkey55a442e2014-11-18 18:22:21 -080058 public static final int MATCH_BLUETOOTH = 8;
Jeff Sharkey4e814c32011-07-14 20:37:37 -070059
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -070060 /**
Jeff Sharkey630a1712011-09-26 10:47:10 -070061 * Set of {@link NetworkInfo#getType()} that reflect data usage.
62 */
63 private static final int[] DATA_USAGE_NETWORK_TYPES;
64
65 static {
66 DATA_USAGE_NETWORK_TYPES = Resources.getSystem().getIntArray(
67 com.android.internal.R.array.config_data_usage_network_types);
68 }
69
Jeff Sharkey70c70532012-05-16 14:51:19 -070070 private static boolean sForceAllNetworkTypes = false;
71
Jeff Sharkey8b2c3a142012-11-12 11:45:05 -080072 @VisibleForTesting
Jeff Sharkey70c70532012-05-16 14:51:19 -070073 public static void forceAllNetworkTypes() {
74 sForceAllNetworkTypes = true;
75 }
76
Jeff Sharkey630a1712011-09-26 10:47:10 -070077 /**
Jeff Sharkey8fc27e82012-04-04 20:40:58 -070078 * Template to match {@link ConnectivityManager#TYPE_MOBILE} networks with
79 * the given IMSI.
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -070080 */
Jeff Sharkey4e814c32011-07-14 20:37:37 -070081 public static NetworkTemplate buildTemplateMobileAll(String subscriberId) {
Jeff Sharkey8fc27e82012-04-04 20:40:58 -070082 return new NetworkTemplate(MATCH_MOBILE_ALL, subscriberId, null);
Jeff Sharkey4e814c32011-07-14 20:37:37 -070083 }
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -070084
85 /**
Jeff Sharkey8fc27e82012-04-04 20:40:58 -070086 * Template to match {@link ConnectivityManager#TYPE_MOBILE} networks with
87 * the given IMSI that roughly meet a "3G" definition, or lower.
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -070088 */
Jeff Sharkey8fc27e82012-04-04 20:40:58 -070089 @Deprecated
Jeff Sharkey4e814c32011-07-14 20:37:37 -070090 public static NetworkTemplate buildTemplateMobile3gLower(String subscriberId) {
Jeff Sharkey8fc27e82012-04-04 20:40:58 -070091 return new NetworkTemplate(MATCH_MOBILE_3G_LOWER, subscriberId, null);
Jeff Sharkey4e814c32011-07-14 20:37:37 -070092 }
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -070093
94 /**
Jeff Sharkey8fc27e82012-04-04 20:40:58 -070095 * Template to match {@link ConnectivityManager#TYPE_MOBILE} networks with
96 * the given IMSI that roughly meet a "4G" definition.
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -070097 */
Jeff Sharkey8fc27e82012-04-04 20:40:58 -070098 @Deprecated
Jeff Sharkey4e814c32011-07-14 20:37:37 -070099 public static NetworkTemplate buildTemplateMobile4g(String subscriberId) {
Jeff Sharkey8fc27e82012-04-04 20:40:58 -0700100 return new NetworkTemplate(MATCH_MOBILE_4G, subscriberId, null);
Jeff Sharkey4e814c32011-07-14 20:37:37 -0700101 }
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -0700102
103 /**
Jeff Sharkey234766a2012-04-10 19:48:07 -0700104 * Template to match {@link ConnectivityManager#TYPE_MOBILE} networks,
105 * regardless of IMSI.
106 */
107 public static NetworkTemplate buildTemplateMobileWildcard() {
108 return new NetworkTemplate(MATCH_MOBILE_WILDCARD, null, null);
109 }
110
111 /**
Jeff Sharkey8fc27e82012-04-04 20:40:58 -0700112 * Template to match all {@link ConnectivityManager#TYPE_WIFI} networks,
113 * regardless of SSID.
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -0700114 */
Jeff Sharkey8fc27e82012-04-04 20:40:58 -0700115 public static NetworkTemplate buildTemplateWifiWildcard() {
Jeff Sharkey234766a2012-04-10 19:48:07 -0700116 return new NetworkTemplate(MATCH_WIFI_WILDCARD, null, null);
Jeff Sharkey8fc27e82012-04-04 20:40:58 -0700117 }
118
119 @Deprecated
Jeff Sharkey4e814c32011-07-14 20:37:37 -0700120 public static NetworkTemplate buildTemplateWifi() {
Jeff Sharkey8fc27e82012-04-04 20:40:58 -0700121 return buildTemplateWifiWildcard();
122 }
123
124 /**
125 * Template to match {@link ConnectivityManager#TYPE_WIFI} networks with the
126 * given SSID.
127 */
128 public static NetworkTemplate buildTemplateWifi(String networkId) {
129 return new NetworkTemplate(MATCH_WIFI, null, networkId);
Jeff Sharkey4e814c32011-07-14 20:37:37 -0700130 }
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -0700131
Jeff Sharkey4e814c32011-07-14 20:37:37 -0700132 /**
133 * Template to combine all {@link ConnectivityManager#TYPE_ETHERNET} style
134 * networks together.
135 */
136 public static NetworkTemplate buildTemplateEthernet() {
Jeff Sharkey8fc27e82012-04-04 20:40:58 -0700137 return new NetworkTemplate(MATCH_ETHERNET, null, null);
Jeff Sharkey4e814c32011-07-14 20:37:37 -0700138 }
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -0700139
Jeff Sharkey55a442e2014-11-18 18:22:21 -0800140 /**
141 * Template to combine all {@link ConnectivityManager#TYPE_BLUETOOTH} style
142 * networks together.
143 */
144 public static NetworkTemplate buildTemplateBluetooth() {
145 return new NetworkTemplate(MATCH_BLUETOOTH, null, null);
146 }
147
Jeff Sharkey4e814c32011-07-14 20:37:37 -0700148 private final int mMatchRule;
149 private final String mSubscriberId;
Jeff Sharkey32566012014-12-02 18:30:14 -0800150
151 /**
152 * Ugh, templates are designed to target a single subscriber, but we might
153 * need to match several "merged" subscribers. These are the subscribers
154 * that should be considered to match this template.
155 * <p>
156 * Since the merge set is dynamic, it should <em>not</em> be persisted or
157 * used for determining equality.
158 */
159 private final String[] mMatchSubscriberIds;
160
Jeff Sharkey8fc27e82012-04-04 20:40:58 -0700161 private final String mNetworkId;
Jeff Sharkey4e814c32011-07-14 20:37:37 -0700162
Jeff Sharkey8fc27e82012-04-04 20:40:58 -0700163 public NetworkTemplate(int matchRule, String subscriberId, String networkId) {
Jeff Sharkey32566012014-12-02 18:30:14 -0800164 this(matchRule, subscriberId, new String[] { subscriberId }, networkId);
165 }
166
167 public NetworkTemplate(int matchRule, String subscriberId, String[] matchSubscriberIds,
168 String networkId) {
Jeff Sharkey8fc27e82012-04-04 20:40:58 -0700169 mMatchRule = matchRule;
170 mSubscriberId = subscriberId;
Jeff Sharkey32566012014-12-02 18:30:14 -0800171 mMatchSubscriberIds = matchSubscriberIds;
Jeff Sharkey8fc27e82012-04-04 20:40:58 -0700172 mNetworkId = networkId;
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -0700173 }
174
Jeff Sharkey4e814c32011-07-14 20:37:37 -0700175 private NetworkTemplate(Parcel in) {
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -0700176 mMatchRule = in.readInt();
177 mSubscriberId = in.readString();
Jeff Sharkey32566012014-12-02 18:30:14 -0800178 mMatchSubscriberIds = in.createStringArray();
Jeff Sharkey8fc27e82012-04-04 20:40:58 -0700179 mNetworkId = in.readString();
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -0700180 }
181
Jeff Sharkey8fc27e82012-04-04 20:40:58 -0700182 @Override
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -0700183 public void writeToParcel(Parcel dest, int flags) {
184 dest.writeInt(mMatchRule);
185 dest.writeString(mSubscriberId);
Jeff Sharkey32566012014-12-02 18:30:14 -0800186 dest.writeStringArray(mMatchSubscriberIds);
Jeff Sharkey8fc27e82012-04-04 20:40:58 -0700187 dest.writeString(mNetworkId);
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -0700188 }
189
Jeff Sharkey8fc27e82012-04-04 20:40:58 -0700190 @Override
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -0700191 public int describeContents() {
192 return 0;
193 }
194
195 @Override
196 public String toString() {
Jeff Sharkey8fc27e82012-04-04 20:40:58 -0700197 final StringBuilder builder = new StringBuilder("NetworkTemplate: ");
198 builder.append("matchRule=").append(getMatchRuleName(mMatchRule));
199 if (mSubscriberId != null) {
Jeff Sharkey32566012014-12-02 18:30:14 -0800200 builder.append(", subscriberId=").append(
201 NetworkIdentity.scrubSubscriberId(mSubscriberId));
202 }
203 if (mMatchSubscriberIds != null) {
204 builder.append(", matchSubscriberIds=").append(
205 Arrays.toString(NetworkIdentity.scrubSubscriberId(mMatchSubscriberIds)));
Jeff Sharkey8fc27e82012-04-04 20:40:58 -0700206 }
207 if (mNetworkId != null) {
208 builder.append(", networkId=").append(mNetworkId);
209 }
210 return builder.toString();
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -0700211 }
212
213 @Override
214 public int hashCode() {
Kenny Roote6585b32013-12-13 12:00:26 -0800215 return Objects.hash(mMatchRule, mSubscriberId, mNetworkId);
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -0700216 }
217
218 @Override
219 public boolean equals(Object obj) {
220 if (obj instanceof NetworkTemplate) {
221 final NetworkTemplate other = (NetworkTemplate) obj;
222 return mMatchRule == other.mMatchRule
Kenny Roote6585b32013-12-13 12:00:26 -0800223 && Objects.equals(mSubscriberId, other.mSubscriberId)
224 && Objects.equals(mNetworkId, other.mNetworkId);
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -0700225 }
226 return false;
227 }
228
Jeff Sharkey32566012014-12-02 18:30:14 -0800229 public boolean isMatchRuleMobile() {
230 switch (mMatchRule) {
231 case MATCH_MOBILE_3G_LOWER:
232 case MATCH_MOBILE_4G:
233 case MATCH_MOBILE_ALL:
234 case MATCH_MOBILE_WILDCARD:
235 return true;
236 default:
237 return false;
238 }
239 }
240
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -0700241 public int getMatchRule() {
242 return mMatchRule;
243 }
244
245 public String getSubscriberId() {
246 return mSubscriberId;
247 }
248
Jeff Sharkey8fc27e82012-04-04 20:40:58 -0700249 public String getNetworkId() {
250 return mNetworkId;
251 }
252
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -0700253 /**
Jeff Sharkey630a1712011-09-26 10:47:10 -0700254 * Test if given {@link NetworkIdentity} matches this template.
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -0700255 */
256 public boolean matches(NetworkIdentity ident) {
257 switch (mMatchRule) {
258 case MATCH_MOBILE_ALL:
259 return matchesMobile(ident);
260 case MATCH_MOBILE_3G_LOWER:
261 return matchesMobile3gLower(ident);
262 case MATCH_MOBILE_4G:
263 return matchesMobile4g(ident);
264 case MATCH_WIFI:
265 return matchesWifi(ident);
Jeff Sharkey4e814c32011-07-14 20:37:37 -0700266 case MATCH_ETHERNET:
267 return matchesEthernet(ident);
Jeff Sharkey234766a2012-04-10 19:48:07 -0700268 case MATCH_MOBILE_WILDCARD:
269 return matchesMobileWildcard(ident);
270 case MATCH_WIFI_WILDCARD:
271 return matchesWifiWildcard(ident);
Jeff Sharkey55a442e2014-11-18 18:22:21 -0800272 case MATCH_BLUETOOTH:
273 return matchesBluetooth(ident);
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -0700274 default:
275 throw new IllegalArgumentException("unknown network template");
276 }
277 }
278
279 /**
Jeff Sharkey630a1712011-09-26 10:47:10 -0700280 * Check if mobile network with matching IMSI.
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -0700281 */
282 private boolean matchesMobile(NetworkIdentity ident) {
Jeff Sharkey630a1712011-09-26 10:47:10 -0700283 if (ident.mType == TYPE_WIMAX) {
284 // TODO: consider matching against WiMAX subscriber identity
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -0700285 return true;
Jeff Sharkey630a1712011-09-26 10:47:10 -0700286 } else {
Jeff Sharkey32566012014-12-02 18:30:14 -0800287 final boolean matchesType = (sForceAllNetworkTypes
288 || contains(DATA_USAGE_NETWORK_TYPES, ident.mType));
289 return matchesType && ArrayUtils.contains(mMatchSubscriberIds, ident.mSubscriberId);
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -0700290 }
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -0700291 }
292
293 /**
Jeff Sharkey02e21d62011-07-17 15:53:33 -0700294 * Check if mobile network classified 3G or lower with matching IMSI.
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -0700295 */
296 private boolean matchesMobile3gLower(NetworkIdentity ident) {
Jeff Sharkeyd4dd7712012-03-16 11:11:54 -0700297 ensureSubtypeAvailable();
Jeff Sharkey630a1712011-09-26 10:47:10 -0700298 if (ident.mType == TYPE_WIMAX) {
299 return false;
300 } else if (matchesMobile(ident)) {
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -0700301 switch (getNetworkClass(ident.mSubType)) {
302 case NETWORK_CLASS_UNKNOWN:
303 case NETWORK_CLASS_2_G:
304 case NETWORK_CLASS_3_G:
305 return true;
306 }
307 }
308 return false;
309 }
310
311 /**
Jeff Sharkey630a1712011-09-26 10:47:10 -0700312 * Check if mobile network classified 4G with matching IMSI.
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -0700313 */
314 private boolean matchesMobile4g(NetworkIdentity ident) {
Jeff Sharkeyd4dd7712012-03-16 11:11:54 -0700315 ensureSubtypeAvailable();
Jeff Sharkey630a1712011-09-26 10:47:10 -0700316 if (ident.mType == TYPE_WIMAX) {
317 // TODO: consider matching against WiMAX subscriber identity
318 return true;
319 } else if (matchesMobile(ident)) {
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -0700320 switch (getNetworkClass(ident.mSubType)) {
321 case NETWORK_CLASS_4_G:
322 return true;
323 }
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -0700324 }
325 return false;
326 }
327
328 /**
329 * Check if matches Wi-Fi network template.
330 */
331 private boolean matchesWifi(NetworkIdentity ident) {
Jeff Sharkey3ca74812012-01-24 15:37:07 -0800332 switch (ident.mType) {
333 case TYPE_WIFI:
Kenny Roote6585b32013-12-13 12:00:26 -0800334 return Objects.equals(
Jeff Sharkey2e4dce02012-12-18 17:06:06 -0800335 removeDoubleQuotes(mNetworkId), removeDoubleQuotes(ident.mNetworkId));
Jeff Sharkey3ca74812012-01-24 15:37:07 -0800336 default:
337 return false;
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -0700338 }
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -0700339 }
340
Jeff Sharkey4e814c32011-07-14 20:37:37 -0700341 /**
342 * Check if matches Ethernet network template.
343 */
344 private boolean matchesEthernet(NetworkIdentity ident) {
345 if (ident.mType == TYPE_ETHERNET) {
346 return true;
347 }
348 return false;
349 }
350
Jeff Sharkey234766a2012-04-10 19:48:07 -0700351 private boolean matchesMobileWildcard(NetworkIdentity ident) {
352 if (ident.mType == TYPE_WIMAX) {
353 return true;
354 } else {
Jeff Sharkey70c70532012-05-16 14:51:19 -0700355 return sForceAllNetworkTypes || contains(DATA_USAGE_NETWORK_TYPES, ident.mType);
Jeff Sharkey234766a2012-04-10 19:48:07 -0700356 }
357 }
358
359 private boolean matchesWifiWildcard(NetworkIdentity ident) {
360 switch (ident.mType) {
361 case TYPE_WIFI:
362 case TYPE_WIFI_P2P:
363 return true;
364 default:
365 return false;
366 }
367 }
368
Jeff Sharkey55a442e2014-11-18 18:22:21 -0800369 /**
370 * Check if matches Bluetooth network template.
371 */
372 private boolean matchesBluetooth(NetworkIdentity ident) {
373 if (ident.mType == TYPE_BLUETOOTH) {
374 return true;
375 }
376 return false;
377 }
378
Jeff Sharkey4e814c32011-07-14 20:37:37 -0700379 private static String getMatchRuleName(int matchRule) {
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -0700380 switch (matchRule) {
381 case MATCH_MOBILE_3G_LOWER:
382 return "MOBILE_3G_LOWER";
383 case MATCH_MOBILE_4G:
384 return "MOBILE_4G";
385 case MATCH_MOBILE_ALL:
386 return "MOBILE_ALL";
387 case MATCH_WIFI:
388 return "WIFI";
Jeff Sharkey4e814c32011-07-14 20:37:37 -0700389 case MATCH_ETHERNET:
390 return "ETHERNET";
Jeff Sharkey234766a2012-04-10 19:48:07 -0700391 case MATCH_MOBILE_WILDCARD:
392 return "MOBILE_WILDCARD";
393 case MATCH_WIFI_WILDCARD:
394 return "WIFI_WILDCARD";
Jeff Sharkey55a442e2014-11-18 18:22:21 -0800395 case MATCH_BLUETOOTH:
396 return "BLUETOOTH";
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -0700397 default:
398 return "UNKNOWN";
399 }
400 }
401
Jeff Sharkeyd4dd7712012-03-16 11:11:54 -0700402 private static void ensureSubtypeAvailable() {
403 if (COMBINE_SUBTYPE_ENABLED) {
404 throw new IllegalArgumentException(
405 "Unable to enforce 3G_LOWER template on combined data.");
406 }
407 }
408
Jeff Sharkey32566012014-12-02 18:30:14 -0800409 /**
410 * Examine the given template and normalize if it refers to a "merged"
411 * mobile subscriber. We pick the "lowest" merged subscriber as the primary
412 * for key purposes, and expand the template to match all other merged
413 * subscribers.
414 * <p>
415 * For example, given an incoming template matching B, and the currently
416 * active merge set [A,B], we'd return a new template that primarily matches
417 * A, but also matches B.
418 */
419 public static NetworkTemplate normalize(NetworkTemplate template, String[] merged) {
420 if (template.isMatchRuleMobile() && ArrayUtils.contains(merged, template.mSubscriberId)) {
421 // Requested template subscriber is part of the merge group; return
422 // a template that matches all merged subscribers.
423 return new NetworkTemplate(template.mMatchRule, merged[0], merged,
424 template.mNetworkId);
425 } else {
426 return template;
427 }
428 }
429
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -0700430 public static final Creator<NetworkTemplate> CREATOR = new Creator<NetworkTemplate>() {
Jeff Sharkey8fc27e82012-04-04 20:40:58 -0700431 @Override
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -0700432 public NetworkTemplate createFromParcel(Parcel in) {
433 return new NetworkTemplate(in);
434 }
435
Jeff Sharkey8fc27e82012-04-04 20:40:58 -0700436 @Override
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -0700437 public NetworkTemplate[] newArray(int size) {
438 return new NetworkTemplate[size];
439 }
440 };
441}