SubscriptionPlan: remove getNetworkTypesBitMask
To avoid using hidden API TelephonyManager#getBitMaskForNetworkType Bug: 140908357 Test: make Change-Id: Ibb04fd43117d4b7cf9f768e6ccf9a8f605a2f5e8 Merged-In: Ibb04fd43117d4b7cf9f768e6ccf9a8f605a2f5e8
This commit is contained in:
@@ -227,24 +227,6 @@ public final class SubscriptionPlan implements Parcelable {
|
|||||||
return networkTypes;
|
return networkTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the networkTypes array converted to a {@link TelephonyManager.NetworkTypeBitMask}
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
public long getNetworkTypesBitMask() {
|
|
||||||
// calculate bitmask the first time and save for future calls
|
|
||||||
if (networkTypesBitMask == 0) {
|
|
||||||
if (networkTypes == null) {
|
|
||||||
networkTypesBitMask = ~0;
|
|
||||||
} else {
|
|
||||||
for (int networkType : networkTypes) {
|
|
||||||
networkTypesBitMask |= TelephonyManager.getBitMaskForNetworkType(networkType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return networkTypesBitMask;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return an iterator that will return all valid data usage cycles based on
|
* Return an iterator that will return all valid data usage cycles based on
|
||||||
* any recurrence rules. The iterator starts from the currently active cycle
|
* any recurrence rules. The iterator starts from the currently active cycle
|
||||||
|
|||||||
@@ -3094,17 +3094,16 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
long applicableNetworkTypes = 0;
|
final ArraySet<Integer> applicableNetworkTypes = new ArraySet<Integer>();
|
||||||
boolean allNetworks = false;
|
boolean allNetworks = false;
|
||||||
for (SubscriptionPlan plan : plans) {
|
for (SubscriptionPlan plan : plans) {
|
||||||
if (plan.getNetworkTypes() == null) {
|
if (plan.getNetworkTypes() == null) {
|
||||||
allNetworks = true;
|
allNetworks = true;
|
||||||
} else {
|
} else {
|
||||||
if ((applicableNetworkTypes & plan.getNetworkTypesBitMask()) != 0) {
|
final int[] networkTypes = plan.getNetworkTypes();
|
||||||
|
if (!addAll(applicableNetworkTypes, networkTypes)) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Multiple subscription plans defined for a single network type.");
|
"Multiple subscription plans defined for a single network type.");
|
||||||
} else {
|
|
||||||
applicableNetworkTypes |= plan.getNetworkTypesBitMask();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3116,6 +3115,19 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds all of the {@code elements} to the {@code set}.
|
||||||
|
*
|
||||||
|
* @return {@code false} if any element is not added because the set already have the value.
|
||||||
|
*/
|
||||||
|
private static boolean addAll(@NonNull Set<Integer> set, @NonNull int... elements) {
|
||||||
|
boolean result = true;
|
||||||
|
for (int element : elements) {
|
||||||
|
result &= set.add(element);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SubscriptionPlan[] getSubscriptionPlans(int subId, String callingPackage) {
|
public SubscriptionPlan[] getSubscriptionPlans(int subId, String callingPackage) {
|
||||||
enforceSubscriptionPlanAccess(subId, Binder.getCallingUid(), callingPackage);
|
enforceSubscriptionPlanAccess(subId, Binder.getCallingUid(), callingPackage);
|
||||||
|
|||||||
Reference in New Issue
Block a user