From 5069dbeaab3ae24fb6d366b16188b07e04055097 Mon Sep 17 00:00:00 2001 From: Malcolm Chen Date: Tue, 2 Jul 2019 22:29:35 -0700 Subject: [PATCH] Use new API to get mergedSubscriberIds based on grouping. In addition, make mMergedSubscriberIds a list to fit usage of multi-SIM devices. Bug: 135105735 Bug: 137137221 Test: manual Change-Id: I364262559789112f35b88f4c298463bf4af2e82a --- core/java/android/net/NetworkTemplate.java | 37 ++++++++++++++++++---- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/core/java/android/net/NetworkTemplate.java b/core/java/android/net/NetworkTemplate.java index ae421a4991..87c7118c0e 100644 --- a/core/java/android/net/NetworkTemplate.java +++ b/core/java/android/net/NetworkTemplate.java @@ -48,6 +48,7 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import java.util.Arrays; +import java.util.List; import java.util.Objects; /** @@ -481,17 +482,39 @@ public class NetworkTemplate implements Parcelable { * For example, given an incoming template matching B, and the currently * active merge set [A,B], we'd return a new template that primarily matches * A, but also matches B. + * TODO: remove and use {@link #normalize(NetworkTemplate, List)}. */ @UnsupportedAppUsage public static NetworkTemplate normalize(NetworkTemplate template, String[] merged) { - if (template.isMatchRuleMobile() && ArrayUtils.contains(merged, template.mSubscriberId)) { - // Requested template subscriber is part of the merge group; return - // a template that matches all merged subscribers. - return new NetworkTemplate(template.mMatchRule, merged[0], merged, - template.mNetworkId); - } else { - return template; + return normalize(template, Arrays.asList(merged)); + } + + /** + * Examine the given template and normalize if it refers to a "merged" + * mobile subscriber. We pick the "lowest" merged subscriber as the primary + * for key purposes, and expand the template to match all other merged + * subscribers. + * + * There can be multiple merged subscriberIds for multi-SIM devices. + * + *

+ * For example, given an incoming template matching B, and the currently + * active merge set [A,B], we'd return a new template that primarily matches + * A, but also matches B. + */ + public static NetworkTemplate normalize(NetworkTemplate template, List mergedList) { + if (!template.isMatchRuleMobile()) return template; + + for (String[] merged : mergedList) { + if (ArrayUtils.contains(merged, template.mSubscriberId)) { + // Requested template subscriber is part of the merge group; return + // a template that matches all merged subscribers. + return new NetworkTemplate(template.mMatchRule, merged[0], merged, + template.mNetworkId); + } } + + return template; } @UnsupportedAppUsage