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
This commit is contained in:
@@ -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.<String[]>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.
|
||||
*
|
||||
* <p>
|
||||
* 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<String[]> 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
|
||||
|
||||
@@ -232,7 +232,6 @@ import com.android.server.ServiceThread;
|
||||
import com.android.server.SystemConfig;
|
||||
|
||||
import libcore.io.IoUtils;
|
||||
import libcore.util.EmptyArray;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlSerializer;
|
||||
@@ -540,7 +539,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
private final SparseArray<String> mSubIdToSubscriberId = new SparseArray<>();
|
||||
/** Set of all merged subscriberId as of last update */
|
||||
@GuardedBy("mNetworkPoliciesSecondLock")
|
||||
private String[] mMergedSubscriberIds = EmptyArray.STRING;
|
||||
private List<String[]> mMergedSubscriberIds = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Indicates the uids restricted by admin from accessing metered data. It's a mapping from
|
||||
@@ -1801,7 +1800,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
final SubscriptionManager sm = mContext.getSystemService(SubscriptionManager.class);
|
||||
|
||||
final int[] subIds = ArrayUtils.defeatNullable(sm.getActiveSubscriptionIdList());
|
||||
final String[] mergedSubscriberIds = ArrayUtils.defeatNullable(tm.getMergedSubscriberIds());
|
||||
final List<String[]> mergedSubscriberIdsList = new ArrayList();
|
||||
|
||||
final SparseArray<String> subIdToSubscriberId = new SparseArray<>(subIds.length);
|
||||
for (int subId : subIds) {
|
||||
@@ -1811,6 +1810,10 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
} else {
|
||||
Slog.wtf(TAG, "Missing subscriberId for subId " + subId);
|
||||
}
|
||||
|
||||
String[] mergedSubscriberId = ArrayUtils.defeatNullable(
|
||||
tm.createForSubscriptionId(subId).getMergedSubscriberIdsFromGroup());
|
||||
mergedSubscriberIdsList.add(mergedSubscriberId);
|
||||
}
|
||||
|
||||
synchronized (mNetworkPoliciesSecondLock) {
|
||||
@@ -1820,7 +1823,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
subIdToSubscriberId.valueAt(i));
|
||||
}
|
||||
|
||||
mMergedSubscriberIds = mergedSubscriberIds;
|
||||
mMergedSubscriberIds = mergedSubscriberIdsList;
|
||||
}
|
||||
|
||||
Trace.traceEnd(TRACE_TAG_NETWORK);
|
||||
@@ -3373,8 +3376,10 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
fout.decreaseIndent();
|
||||
|
||||
fout.println();
|
||||
fout.println("Merged subscriptions: "
|
||||
+ Arrays.toString(NetworkIdentity.scrubSubscriberId(mMergedSubscriberIds)));
|
||||
for (String[] mergedSubscribers : mMergedSubscriberIds) {
|
||||
fout.println("Merged subscriptions: " + Arrays.toString(
|
||||
NetworkIdentity.scrubSubscriberId(mergedSubscribers)));
|
||||
}
|
||||
|
||||
fout.println();
|
||||
fout.println("Policy for UIDs:");
|
||||
|
||||
Reference in New Issue
Block a user