From 1acacc8f867faabb16d40d1917e98a177668040f Mon Sep 17 00:00:00 2001 From: Les Lee Date: Wed, 3 Nov 2021 19:57:54 +0800 Subject: [PATCH] Fix normalize doesn't work on carrier template From android 12, the subscriberId is being used for different network types. For instances: The TYPE_WIFI with subscriberId means that it is a merged wifi network. The TYPE_CARRIER means that the network associate to specific carrier network (subscriberId). So remove the check "isMatchRuleMobile" and only check whether subscriberId is being used in NetworkTemplate or not. Bug: 194939211 Test: atest -c NetworkTemplateTest Change-Id: I80c9f887cf8b4714716d657da92ed273a532ce27 Merged-In: I80c9f887cf8b4714716d657da92ed273a532ce27 (cherry picked from commit 46cc261aa90305bdfec668af5d5ed25a27032cda) Merged-In:I80c9f887cf8b4714716d657da92ed273a532ce27 --- core/java/android/net/NetworkTemplate.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/core/java/android/net/NetworkTemplate.java b/core/java/android/net/NetworkTemplate.java index 249154aa91..762816dd9f 100644 --- a/core/java/android/net/NetworkTemplate.java +++ b/core/java/android/net/NetworkTemplate.java @@ -782,8 +782,8 @@ public class NetworkTemplate implements Parcelable { } /** - * Examine the given template and normalize if it refers to a "merged" - * mobile subscriber. We pick the "lowest" merged subscriber as the primary + * Examine the given template and normalize it. + * We pick the "lowest" merged subscriber as the primary * for key purposes, and expand the template to match all other merged * subscribers. *

@@ -798,8 +798,8 @@ public class NetworkTemplate implements Parcelable { } /** - * Examine the given template and normalize if it refers to a "merged" - * mobile subscriber. We pick the "lowest" merged subscriber as the primary + * Examine the given template and normalize it. + * We pick the "lowest" merged subscriber as the primary * for key purposes, and expand the template to match all other merged * subscribers. * @@ -811,7 +811,12 @@ public class NetworkTemplate implements Parcelable { * A, but also matches B. */ public static NetworkTemplate normalize(NetworkTemplate template, List mergedList) { - if (!template.isMatchRuleMobile()) return template; + // Now there are several types of network which uses SubscriberId to store network + // information. For instances: + // The TYPE_WIFI with subscriberId means that it is a merged carrier wifi network. + // The TYPE_CARRIER means that the network associate to specific carrier network. + + if (template.mSubscriberId == null) return template; for (String[] merged : mergedList) { if (ArrayUtils.contains(merged, template.mSubscriberId)) {