Ensure SubscriptionPlans can be removed

Add a duration that the plans last and don't read to/write from disk
for plans. Make non-duration setSubscriptionPlans API deprecated.

Test: atest SubscriptionManagerTest, NetworkPolicyManagerServiceTest
Bug: 210696427
Change-Id: I93aece78eda324c333fbf9f1adbedcf46e4864f0
This commit is contained in:
Sarah Chin
2022-01-31 19:10:14 -08:00
parent 2810da2c61
commit e6f17feb77
6 changed files with 136 additions and 143 deletions

View File

@@ -43058,7 +43058,8 @@ package android.telephony {
method public void setSubscriptionOverrideCongested(int, boolean, @NonNull int[], long); method public void setSubscriptionOverrideCongested(int, boolean, @NonNull int[], long);
method public void setSubscriptionOverrideUnmetered(int, boolean, long); method public void setSubscriptionOverrideUnmetered(int, boolean, long);
method public void setSubscriptionOverrideUnmetered(int, boolean, @NonNull int[], long); method public void setSubscriptionOverrideUnmetered(int, boolean, @NonNull int[], long);
method public void setSubscriptionPlans(int, @NonNull java.util.List<android.telephony.SubscriptionPlan>); method @Deprecated public void setSubscriptionPlans(int, @NonNull java.util.List<android.telephony.SubscriptionPlan>);
method public void setSubscriptionPlans(int, @NonNull java.util.List<android.telephony.SubscriptionPlan>, long);
method @RequiresPermission("android.permission.WRITE_EMBEDDED_SUBSCRIPTIONS") public void switchToSubscription(int, @NonNull android.app.PendingIntent); method @RequiresPermission("android.permission.WRITE_EMBEDDED_SUBSCRIPTIONS") public void switchToSubscription(int, @NonNull android.app.PendingIntent);
field public static final String ACTION_DEFAULT_SMS_SUBSCRIPTION_CHANGED = "android.telephony.action.DEFAULT_SMS_SUBSCRIPTION_CHANGED"; field public static final String ACTION_DEFAULT_SMS_SUBSCRIPTION_CHANGED = "android.telephony.action.DEFAULT_SMS_SUBSCRIPTION_CHANGED";
field public static final String ACTION_DEFAULT_SUBSCRIPTION_CHANGED = "android.telephony.action.DEFAULT_SUBSCRIPTION_CHANGED"; field public static final String ACTION_DEFAULT_SUBSCRIPTION_CHANGED = "android.telephony.action.DEFAULT_SUBSCRIPTION_CHANGED";

View File

@@ -72,9 +72,9 @@ interface INetworkPolicyManager {
SubscriptionPlan getSubscriptionPlan(in NetworkTemplate template); SubscriptionPlan getSubscriptionPlan(in NetworkTemplate template);
void notifyStatsProviderWarningOrLimitReached(); void notifyStatsProviderWarningOrLimitReached();
SubscriptionPlan[] getSubscriptionPlans(int subId, String callingPackage); SubscriptionPlan[] getSubscriptionPlans(int subId, String callingPackage);
void setSubscriptionPlans(int subId, in SubscriptionPlan[] plans, String callingPackage); void setSubscriptionPlans(int subId, in SubscriptionPlan[] plans, long expirationDurationMillis, String callingPackage);
String getSubscriptionPlansOwner(int subId); String getSubscriptionPlansOwner(int subId);
void setSubscriptionOverride(int subId, int overrideMask, int overrideValue, in int[] networkTypes, long timeoutMillis, String callingPackage); void setSubscriptionOverride(int subId, int overrideMask, int overrideValue, in int[] networkTypes, long expirationDurationMillis, String callingPackage);
void factoryReset(String subscriber); void factoryReset(String subscriber);

View File

@@ -482,8 +482,8 @@ public class NetworkPolicyManager {
* @param networkTypes the network types this override applies to. If no * @param networkTypes the network types this override applies to. If no
* network types are specified, override values will be ignored. * network types are specified, override values will be ignored.
* {@see TelephonyManager#getAllNetworkTypes()} * {@see TelephonyManager#getAllNetworkTypes()}
* @param timeoutMillis the timeout after which the requested override will * @param expirationDurationMillis the duration after which the requested override
* be automatically cleared, or {@code 0} to leave in the * will be automatically cleared, or {@code 0} to leave in the
* requested state until explicitly cleared, or the next reboot, * requested state until explicitly cleared, or the next reboot,
* whichever happens first * whichever happens first
* @param callingPackage the name of the package making the call. * @param callingPackage the name of the package making the call.
@@ -491,11 +491,11 @@ public class NetworkPolicyManager {
*/ */
public void setSubscriptionOverride(int subId, @SubscriptionOverrideMask int overrideMask, public void setSubscriptionOverride(int subId, @SubscriptionOverrideMask int overrideMask,
@SubscriptionOverrideMask int overrideValue, @SubscriptionOverrideMask int overrideValue,
@NonNull @Annotation.NetworkType int[] networkTypes, long timeoutMillis, @NonNull @Annotation.NetworkType int[] networkTypes, long expirationDurationMillis,
@NonNull String callingPackage) { @NonNull String callingPackage) {
try { try {
mService.setSubscriptionOverride(subId, overrideMask, overrideValue, networkTypes, mService.setSubscriptionOverride(subId, overrideMask, overrideValue, networkTypes,
timeoutMillis, callingPackage); expirationDurationMillis, callingPackage);
} catch (RemoteException e) { } catch (RemoteException e) {
throw e.rethrowFromSystemServer(); throw e.rethrowFromSystemServer();
} }
@@ -506,13 +506,16 @@ public class NetworkPolicyManager {
* *
* @param subId the subscriber this relationship applies to. * @param subId the subscriber this relationship applies to.
* @param plans the list of plans. * @param plans the list of plans.
* @param expirationDurationMillis the duration after which the subscription plans
* will be automatically cleared, or {@code 0} to leave the plans until
* explicitly cleared, or the next reboot, whichever happens first
* @param callingPackage the name of the package making the call * @param callingPackage the name of the package making the call
* @hide * @hide
*/ */
public void setSubscriptionPlans(int subId, @NonNull SubscriptionPlan[] plans, public void setSubscriptionPlans(int subId, @NonNull SubscriptionPlan[] plans,
@NonNull String callingPackage) { long expirationDurationMillis, @NonNull String callingPackage) {
try { try {
mService.setSubscriptionPlans(subId, plans, callingPackage); mService.setSubscriptionPlans(subId, plans, expirationDurationMillis, callingPackage);
} catch (RemoteException e) { } catch (RemoteException e) {
throw e.rethrowFromSystemServer(); throw e.rethrowFromSystemServer();
} }

View File

@@ -119,9 +119,7 @@ import static com.android.internal.util.XmlUtils.readBooleanAttribute;
import static com.android.internal.util.XmlUtils.readIntAttribute; import static com.android.internal.util.XmlUtils.readIntAttribute;
import static com.android.internal.util.XmlUtils.readLongAttribute; import static com.android.internal.util.XmlUtils.readLongAttribute;
import static com.android.internal.util.XmlUtils.readStringAttribute; import static com.android.internal.util.XmlUtils.readStringAttribute;
import static com.android.internal.util.XmlUtils.readThisIntArrayXml;
import static com.android.internal.util.XmlUtils.writeBooleanAttribute; import static com.android.internal.util.XmlUtils.writeBooleanAttribute;
import static com.android.internal.util.XmlUtils.writeIntArrayXml;
import static com.android.internal.util.XmlUtils.writeIntAttribute; import static com.android.internal.util.XmlUtils.writeIntAttribute;
import static com.android.internal.util.XmlUtils.writeLongAttribute; import static com.android.internal.util.XmlUtils.writeLongAttribute;
import static com.android.internal.util.XmlUtils.writeStringAttribute; import static com.android.internal.util.XmlUtils.writeStringAttribute;
@@ -246,7 +244,6 @@ import com.android.internal.util.ConcurrentUtils;
import com.android.internal.util.DumpUtils; import com.android.internal.util.DumpUtils;
import com.android.internal.util.IndentingPrintWriter; import com.android.internal.util.IndentingPrintWriter;
import com.android.internal.util.StatLogger; import com.android.internal.util.StatLogger;
import com.android.internal.util.XmlUtils;
import com.android.net.module.util.NetworkIdentityUtils; import com.android.net.module.util.NetworkIdentityUtils;
import com.android.net.module.util.NetworkStatsUtils; import com.android.net.module.util.NetworkStatsUtils;
import com.android.net.module.util.PermissionUtils; import com.android.net.module.util.PermissionUtils;
@@ -260,8 +257,6 @@ import com.android.server.usage.AppStandbyInternal.AppIdleStateChangeListener;
import libcore.io.IoUtils; import libcore.io.IoUtils;
import org.xmlpull.v1.XmlPullParserException;
import java.io.File; import java.io.File;
import java.io.FileDescriptor; import java.io.FileDescriptor;
import java.io.FileInputStream; import java.io.FileInputStream;
@@ -336,7 +331,8 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
private static final int VERSION_ADDED_CYCLE = 11; private static final int VERSION_ADDED_CYCLE = 11;
private static final int VERSION_ADDED_NETWORK_TYPES = 12; private static final int VERSION_ADDED_NETWORK_TYPES = 12;
private static final int VERSION_SUPPORTED_CARRIER_USAGE = 13; private static final int VERSION_SUPPORTED_CARRIER_USAGE = 13;
private static final int VERSION_LATEST = VERSION_SUPPORTED_CARRIER_USAGE; private static final int VERSION_REMOVED_SUBSCRIPTION_PLANS = 14;
private static final int VERSION_LATEST = VERSION_REMOVED_SUBSCRIPTION_PLANS;
@VisibleForTesting @VisibleForTesting
public static final int TYPE_WARNING = SystemMessage.NOTE_NET_WARNING; public static final int TYPE_WARNING = SystemMessage.NOTE_NET_WARNING;
@@ -349,7 +345,6 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
private static final String TAG_POLICY_LIST = "policy-list"; private static final String TAG_POLICY_LIST = "policy-list";
private static final String TAG_NETWORK_POLICY = "network-policy"; private static final String TAG_NETWORK_POLICY = "network-policy";
private static final String TAG_SUBSCRIPTION_PLAN = "subscription-plan";
private static final String TAG_UID_POLICY = "uid-policy"; private static final String TAG_UID_POLICY = "uid-policy";
private static final String TAG_APP_POLICY = "app-policy"; private static final String TAG_APP_POLICY = "app-policy";
private static final String TAG_WHITELIST = "whitelist"; private static final String TAG_WHITELIST = "whitelist";
@@ -426,6 +421,13 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
* obj = oldBlockedReasons * obj = oldBlockedReasons
*/ */
private static final int MSG_BLOCKED_REASON_CHANGED = 21; private static final int MSG_BLOCKED_REASON_CHANGED = 21;
/**
* Message to indicate that subscription plans expired and should be cleared.
* arg1 = subId
* arg2 = setSubscriptionPlans call ID
* obj = callingPackage
*/
private static final int MSG_CLEAR_SUBSCRIPTION_PLANS = 22;
private static final int UID_MSG_STATE_CHANGED = 100; private static final int UID_MSG_STATE_CHANGED = 100;
private static final int UID_MSG_GONE = 101; private static final int UID_MSG_GONE = 101;
@@ -492,6 +494,12 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
/** Map from subId to package name that owns subscription plans. */ /** Map from subId to package name that owns subscription plans. */
@GuardedBy("mNetworkPoliciesSecondLock") @GuardedBy("mNetworkPoliciesSecondLock")
final SparseArray<String> mSubscriptionPlansOwner = new SparseArray<>(); final SparseArray<String> mSubscriptionPlansOwner = new SparseArray<>();
/** Map from subId to the ID of the clear plans request. */
@GuardedBy("mNetworkPoliciesSecondLock")
final SparseIntArray mSetSubscriptionPlansIds = new SparseIntArray();
/** Atomic integer to generate a new ID for each clear plans request. */
@GuardedBy("mNetworkPoliciesSecondLock")
int mSetSubscriptionPlansIdCounter = 0;
/** Map from subId to daily opportunistic quota. */ /** Map from subId to daily opportunistic quota. */
@GuardedBy("mNetworkPoliciesSecondLock") @GuardedBy("mNetworkPoliciesSecondLock")
@@ -2523,56 +2531,6 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
warningBytes, limitBytes, lastWarningSnooze, warningBytes, limitBytes, lastWarningSnooze,
lastLimitSnooze, metered, inferred)); lastLimitSnooze, metered, inferred));
} }
} else if (TAG_SUBSCRIPTION_PLAN.equals(tag)) {
final String start = readStringAttribute(in, ATTR_CYCLE_START);
final String end = readStringAttribute(in, ATTR_CYCLE_END);
final String period = readStringAttribute(in, ATTR_CYCLE_PERIOD);
final SubscriptionPlan.Builder builder = new SubscriptionPlan.Builder(
RecurrenceRule.convertZonedDateTime(start),
RecurrenceRule.convertZonedDateTime(end),
RecurrenceRule.convertPeriod(period));
builder.setTitle(readStringAttribute(in, ATTR_TITLE));
builder.setSummary(readStringAttribute(in, ATTR_SUMMARY));
final long limitBytes = readLongAttribute(in, ATTR_LIMIT_BYTES,
SubscriptionPlan.BYTES_UNKNOWN);
final int limitBehavior = readIntAttribute(in, ATTR_LIMIT_BEHAVIOR,
SubscriptionPlan.LIMIT_BEHAVIOR_UNKNOWN);
if (limitBytes != SubscriptionPlan.BYTES_UNKNOWN
&& limitBehavior != SubscriptionPlan.LIMIT_BEHAVIOR_UNKNOWN) {
builder.setDataLimit(limitBytes, limitBehavior);
}
final long usageBytes = readLongAttribute(in, ATTR_USAGE_BYTES,
SubscriptionPlan.BYTES_UNKNOWN);
final long usageTime = readLongAttribute(in, ATTR_USAGE_TIME,
SubscriptionPlan.TIME_UNKNOWN);
if (usageBytes != SubscriptionPlan.BYTES_UNKNOWN
&& usageTime != SubscriptionPlan.TIME_UNKNOWN) {
builder.setDataUsage(usageBytes, usageTime);
}
final int subId = readIntAttribute(in, ATTR_SUB_ID);
final String ownerPackage = readStringAttribute(in, ATTR_OWNER_PACKAGE);
if (version >= VERSION_ADDED_NETWORK_TYPES) {
final int depth = in.getDepth();
while (XmlUtils.nextElementWithin(in, depth)) {
if (TAG_XML_UTILS_INT_ARRAY.equals(in.getName())
&& ATTR_NETWORK_TYPES.equals(
readStringAttribute(in, ATTR_XML_UTILS_NAME))) {
final int[] networkTypes =
readThisIntArrayXml(in, TAG_XML_UTILS_INT_ARRAY, null);
builder.setNetworkTypes(networkTypes);
}
}
}
final SubscriptionPlan plan = builder.build();
mSubscriptionPlans.put(subId, ArrayUtils.appendElement(
SubscriptionPlan.class, mSubscriptionPlans.get(subId), plan));
mSubscriptionPlansOwner.put(subId, ownerPackage);
} else if (TAG_UID_POLICY.equals(tag)) { } else if (TAG_UID_POLICY.equals(tag)) {
final int uid = readIntAttribute(in, ATTR_UID); final int uid = readIntAttribute(in, ATTR_UID);
final int policy = readIntAttribute(in, ATTR_POLICY); final int policy = readIntAttribute(in, ATTR_POLICY);
@@ -2763,38 +2721,6 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
out.endTag(null, TAG_NETWORK_POLICY); out.endTag(null, TAG_NETWORK_POLICY);
} }
// write all known subscription plans
for (int i = 0; i < mSubscriptionPlans.size(); i++) {
final int subId = mSubscriptionPlans.keyAt(i);
if (subId == INVALID_SUBSCRIPTION_ID) continue;
final String ownerPackage = mSubscriptionPlansOwner.get(subId);
final SubscriptionPlan[] plans = mSubscriptionPlans.valueAt(i);
if (ArrayUtils.isEmpty(plans)) continue;
for (SubscriptionPlan plan : plans) {
out.startTag(null, TAG_SUBSCRIPTION_PLAN);
writeIntAttribute(out, ATTR_SUB_ID, subId);
writeStringAttribute(out, ATTR_OWNER_PACKAGE, ownerPackage);
final RecurrenceRule cycleRule = plan.getCycleRule();
writeStringAttribute(out, ATTR_CYCLE_START,
RecurrenceRule.convertZonedDateTime(cycleRule.start));
writeStringAttribute(out, ATTR_CYCLE_END,
RecurrenceRule.convertZonedDateTime(cycleRule.end));
writeStringAttribute(out, ATTR_CYCLE_PERIOD,
RecurrenceRule.convertPeriod(cycleRule.period));
writeStringAttribute(out, ATTR_TITLE, plan.getTitle());
writeStringAttribute(out, ATTR_SUMMARY, plan.getSummary());
writeLongAttribute(out, ATTR_LIMIT_BYTES, plan.getDataLimitBytes());
writeIntAttribute(out, ATTR_LIMIT_BEHAVIOR, plan.getDataLimitBehavior());
writeLongAttribute(out, ATTR_USAGE_BYTES, plan.getDataUsageBytes());
writeLongAttribute(out, ATTR_USAGE_TIME, plan.getDataUsageTime());
try {
writeIntArrayXml(plan.getNetworkTypes(), ATTR_NETWORK_TYPES, out);
} catch (XmlPullParserException ignored) { }
out.endTag(null, TAG_SUBSCRIPTION_PLAN);
}
}
// write all known uid policies // write all known uid policies
for (int i = 0; i < mUidPolicy.size(); i++) { for (int i = 0; i < mUidPolicy.size(); i++) {
final int uid = mUidPolicy.keyAt(i); final int uid = mUidPolicy.keyAt(i);
@@ -3668,7 +3594,8 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
} }
@Override @Override
public void setSubscriptionPlans(int subId, SubscriptionPlan[] plans, String callingPackage) { public void setSubscriptionPlans(int subId, SubscriptionPlan[] plans,
long expirationDurationMillis, String callingPackage) {
enforceSubscriptionPlanAccess(subId, Binder.getCallingUid(), callingPackage); enforceSubscriptionPlanAccess(subId, Binder.getCallingUid(), callingPackage);
enforceSubscriptionPlanValidity(plans); enforceSubscriptionPlanValidity(plans);
@@ -3678,6 +3605,14 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
final long token = Binder.clearCallingIdentity(); final long token = Binder.clearCallingIdentity();
try { try {
setSubscriptionPlansInternal(subId, plans, expirationDurationMillis, callingPackage);
} finally {
Binder.restoreCallingIdentity(token);
}
}
private void setSubscriptionPlansInternal(int subId, SubscriptionPlan[] plans,
long expirationDurationMillis, String callingPackage) {
synchronized (mUidRulesFirstLock) { synchronized (mUidRulesFirstLock) {
synchronized (mNetworkPoliciesSecondLock) { synchronized (mNetworkPoliciesSecondLock) {
mSubscriptionPlans.put(subId, plans); mSubscriptionPlans.put(subId, plans);
@@ -3692,17 +3627,22 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
} }
handleNetworkPoliciesUpdateAL(true); handleNetworkPoliciesUpdateAL(true);
}
}
final Intent intent = new Intent(SubscriptionManager.ACTION_SUBSCRIPTION_PLANS_CHANGED); final Intent intent = new Intent(
SubscriptionManager.ACTION_SUBSCRIPTION_PLANS_CHANGED);
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId); intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId);
mContext.sendBroadcast(intent, android.Manifest.permission.MANAGE_SUBSCRIPTION_PLANS); mContext.sendBroadcast(intent,
mHandler.sendMessage( android.Manifest.permission.MANAGE_SUBSCRIPTION_PLANS);
mHandler.obtainMessage(MSG_SUBSCRIPTION_PLANS_CHANGED, subId, 0, plans)); mHandler.sendMessage(mHandler.obtainMessage(
} finally { MSG_SUBSCRIPTION_PLANS_CHANGED, subId, 0, plans));
Binder.restoreCallingIdentity(token); final int setPlansId = mSetSubscriptionPlansIdCounter++;
mSetSubscriptionPlansIds.put(subId, setPlansId);
if (expirationDurationMillis > 0) {
mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_CLEAR_SUBSCRIPTION_PLANS,
subId, setPlansId, callingPackage), expirationDurationMillis);
}
}
} }
} }
@@ -3728,7 +3668,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
@Override @Override
public void setSubscriptionOverride(int subId, int overrideMask, int overrideValue, public void setSubscriptionOverride(int subId, int overrideMask, int overrideValue,
int[] networkTypes, long timeoutMillis, String callingPackage) { int[] networkTypes, long expirationDurationMillis, String callingPackage) {
enforceSubscriptionPlanAccess(subId, Binder.getCallingUid(), callingPackage); enforceSubscriptionPlanAccess(subId, Binder.getCallingUid(), callingPackage);
final ArraySet<Integer> allNetworksSet = new ArraySet<>(); final ArraySet<Integer> allNetworksSet = new ArraySet<>();
@@ -3766,10 +3706,10 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
args.arg3 = overrideValue; args.arg3 = overrideValue;
args.arg4 = applicableNetworks.toArray(); args.arg4 = applicableNetworks.toArray();
mHandler.sendMessage(mHandler.obtainMessage(MSG_SUBSCRIPTION_OVERRIDE, args)); mHandler.sendMessage(mHandler.obtainMessage(MSG_SUBSCRIPTION_OVERRIDE, args));
if (timeoutMillis > 0) { if (expirationDurationMillis > 0) {
args.arg3 = 0; args.arg3 = 0;
mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_SUBSCRIPTION_OVERRIDE, args), mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_SUBSCRIPTION_OVERRIDE, args),
timeoutMillis); expirationDurationMillis);
} }
} }
} }
@@ -5184,6 +5124,22 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
mListeners.finishBroadcast(); mListeners.finishBroadcast();
return true; return true;
} }
case MSG_CLEAR_SUBSCRIPTION_PLANS: {
synchronized (mUidRulesFirstLock) {
synchronized (mNetworkPoliciesSecondLock) {
int subId = msg.arg1;
if (msg.arg2 == mSetSubscriptionPlansIds.get(subId)) {
if (LOGD) Slog.d(TAG, "Clearing expired subscription plans.");
setSubscriptionPlansInternal(subId, new SubscriptionPlan[]{},
0 /* expirationDurationMillis */,
(String) msg.obj /* callingPackage */);
} else {
if (LOGD) Slog.d(TAG, "Ignoring stale CLEAR_SUBSCRIPTION_PLANS.");
}
}
}
return true;
}
case MSG_BLOCKED_REASON_CHANGED: { case MSG_BLOCKED_REASON_CHANGED: {
final int uid = msg.arg1; final int uid = msg.arg1;
final int newBlockedReasons = msg.arg2; final int newBlockedReasons = msg.arg2;

View File

@@ -2237,7 +2237,7 @@ public class NetworkPolicyManagerServiceTest {
private void setSubscriptionPlans(int subId, SubscriptionPlan[] plans, String callingPackage) private void setSubscriptionPlans(int subId, SubscriptionPlan[] plans, String callingPackage)
throws InterruptedException { throws InterruptedException {
mService.setSubscriptionPlans(subId, plans, callingPackage); mService.setSubscriptionPlans(subId, plans, 0, callingPackage);
// setSubscriptionPlans() triggers async events, wait for those to be completed before // setSubscriptionPlans() triggers async events, wait for those to be completed before
// moving forward as they could interfere with the tests later. // moving forward as they could interfere with the tests later.
postMsgAndWaitForCompletion(); postMsgAndWaitForCompletion();

View File

@@ -2863,10 +2863,43 @@ public class SubscriptionManager {
* outlined above. * outlined above.
* @throws IllegalArgumentException if plans don't meet the requirements * @throws IllegalArgumentException if plans don't meet the requirements
* defined in {@link SubscriptionPlan}. * defined in {@link SubscriptionPlan}.
* @deprecated use {@link #setSubscriptionPlans(int, List, long)} instead.
*/ */
@Deprecated
public void setSubscriptionPlans(int subId, @NonNull List<SubscriptionPlan> plans) { public void setSubscriptionPlans(int subId, @NonNull List<SubscriptionPlan> plans) {
setSubscriptionPlans(subId, plans, 0);
}
/**
* Set the description of the billing relationship plan between a carrier
* and a specific subscriber.
* <p>
* This method is only accessible to the following narrow set of apps:
* <ul>
* <li>The carrier app for this subscriberId, as determined by
* {@link TelephonyManager#hasCarrierPrivileges()}.
* <li>The carrier app explicitly delegated access through
* {@link CarrierConfigManager#KEY_CONFIG_PLANS_PACKAGE_OVERRIDE_STRING}.
* </ul>
*
* @param subId the subscriber this relationship applies to. An empty list
* may be sent to clear any existing plans.
* @param plans the list of plans. The first plan is always the primary and
* most important plan. Any additional plans are secondary and
* may not be displayed or used by decision making logic.
* @param expirationDurationMillis the duration after which the subscription plans
* will be automatically cleared, or {@code 0} to leave the plans until
* explicitly cleared, or the next reboot, whichever happens first.
* @throws SecurityException if the caller doesn't meet the requirements
* outlined above.
* @throws IllegalArgumentException if plans don't meet the requirements
* defined in {@link SubscriptionPlan}.
*/
public void setSubscriptionPlans(int subId, @NonNull List<SubscriptionPlan> plans,
@DurationMillisLong long expirationDurationMillis) {
getNetworkPolicyManager().setSubscriptionPlans(subId, getNetworkPolicyManager().setSubscriptionPlans(subId,
plans.toArray(new SubscriptionPlan[plans.size()]), mContext.getOpPackageName()); plans.toArray(new SubscriptionPlan[0]), expirationDurationMillis,
mContext.getOpPackageName());
} }
/** /**
@@ -2885,17 +2918,17 @@ public class SubscriptionManager {
* @param subId the subscriber this override applies to. * @param subId the subscriber this override applies to.
* @param overrideUnmetered set if the billing relationship should be * @param overrideUnmetered set if the billing relationship should be
* considered unmetered. * considered unmetered.
* @param timeoutMillis the timeout after which the requested override will * @param expirationDurationMillis the duration after which the requested override
* be automatically cleared, or {@code 0} to leave in the * will be automatically cleared, or {@code 0} to leave in the
* requested state until explicitly cleared, or the next reboot, * requested state until explicitly cleared, or the next reboot,
* whichever happens first. * whichever happens first.
* @throws SecurityException if the caller doesn't meet the requirements * @throws SecurityException if the caller doesn't meet the requirements
* outlined above. * outlined above.
*/ */
public void setSubscriptionOverrideUnmetered(int subId, boolean overrideUnmetered, public void setSubscriptionOverrideUnmetered(int subId, boolean overrideUnmetered,
@DurationMillisLong long timeoutMillis) { @DurationMillisLong long expirationDurationMillis) {
setSubscriptionOverrideUnmetered(subId, overrideUnmetered, setSubscriptionOverrideUnmetered(subId, overrideUnmetered,
TelephonyManager.getAllNetworkTypes(), timeoutMillis); TelephonyManager.getAllNetworkTypes(), expirationDurationMillis);
} }
/** /**
@@ -2917,8 +2950,8 @@ public class SubscriptionManager {
* @param networkTypes the network types this override applies to. If no * @param networkTypes the network types this override applies to. If no
* network types are specified, override values will be ignored. * network types are specified, override values will be ignored.
* {@see TelephonyManager#getAllNetworkTypes()} * {@see TelephonyManager#getAllNetworkTypes()}
* @param timeoutMillis the timeout after which the requested override will * @param expirationDurationMillis the duration after which the requested override
* be automatically cleared, or {@code 0} to leave in the * will be automatically cleared, or {@code 0} to leave in the
* requested state until explicitly cleared, or the next reboot, * requested state until explicitly cleared, or the next reboot,
* whichever happens first. * whichever happens first.
* @throws SecurityException if the caller doesn't meet the requirements * @throws SecurityException if the caller doesn't meet the requirements
@@ -2926,10 +2959,10 @@ public class SubscriptionManager {
*/ */
public void setSubscriptionOverrideUnmetered(int subId, boolean overrideUnmetered, public void setSubscriptionOverrideUnmetered(int subId, boolean overrideUnmetered,
@NonNull @Annotation.NetworkType int[] networkTypes, @NonNull @Annotation.NetworkType int[] networkTypes,
@DurationMillisLong long timeoutMillis) { @DurationMillisLong long expirationDurationMillis) {
final int overrideValue = overrideUnmetered ? SUBSCRIPTION_OVERRIDE_UNMETERED : 0; final int overrideValue = overrideUnmetered ? SUBSCRIPTION_OVERRIDE_UNMETERED : 0;
getNetworkPolicyManager().setSubscriptionOverride(subId, SUBSCRIPTION_OVERRIDE_UNMETERED, getNetworkPolicyManager().setSubscriptionOverride(subId, SUBSCRIPTION_OVERRIDE_UNMETERED,
overrideValue, networkTypes, timeoutMillis, mContext.getOpPackageName()); overrideValue, networkTypes, expirationDurationMillis, mContext.getOpPackageName());
} }
/** /**
@@ -2949,17 +2982,17 @@ public class SubscriptionManager {
* @param subId the subscriber this override applies to. * @param subId the subscriber this override applies to.
* @param overrideCongested set if the subscription should be considered * @param overrideCongested set if the subscription should be considered
* congested. * congested.
* @param timeoutMillis the timeout after which the requested override will * @param expirationDurationMillis the duration after which the requested override
* be automatically cleared, or {@code 0} to leave in the * will be automatically cleared, or {@code 0} to leave in the
* requested state until explicitly cleared, or the next reboot, * requested state until explicitly cleared, or the next reboot,
* whichever happens first. * whichever happens first.
* @throws SecurityException if the caller doesn't meet the requirements * @throws SecurityException if the caller doesn't meet the requirements
* outlined above. * outlined above.
*/ */
public void setSubscriptionOverrideCongested(int subId, boolean overrideCongested, public void setSubscriptionOverrideCongested(int subId, boolean overrideCongested,
@DurationMillisLong long timeoutMillis) { @DurationMillisLong long expirationDurationMillis) {
setSubscriptionOverrideCongested(subId, overrideCongested, setSubscriptionOverrideCongested(subId, overrideCongested,
TelephonyManager.getAllNetworkTypes(), timeoutMillis); TelephonyManager.getAllNetworkTypes(), expirationDurationMillis);
} }
/** /**
@@ -2982,8 +3015,8 @@ public class SubscriptionManager {
* @param networkTypes the network types this override applies to. If no * @param networkTypes the network types this override applies to. If no
* network types are specified, override values will be ignored. * network types are specified, override values will be ignored.
* {@see TelephonyManager#getAllNetworkTypes()} * {@see TelephonyManager#getAllNetworkTypes()}
* @param timeoutMillis the timeout after which the requested override will * @param expirationDurationMillis the duration after which the requested override
* be automatically cleared, or {@code 0} to leave in the * will be automatically cleared, or {@code 0} to leave in the
* requested state until explicitly cleared, or the next reboot, * requested state until explicitly cleared, or the next reboot,
* whichever happens first. * whichever happens first.
* @throws SecurityException if the caller doesn't meet the requirements * @throws SecurityException if the caller doesn't meet the requirements
@@ -2991,10 +3024,10 @@ public class SubscriptionManager {
*/ */
public void setSubscriptionOverrideCongested(int subId, boolean overrideCongested, public void setSubscriptionOverrideCongested(int subId, boolean overrideCongested,
@NonNull @Annotation.NetworkType int[] networkTypes, @NonNull @Annotation.NetworkType int[] networkTypes,
@DurationMillisLong long timeoutMillis) { @DurationMillisLong long expirationDurationMillis) {
final int overrideValue = overrideCongested ? SUBSCRIPTION_OVERRIDE_CONGESTED : 0; final int overrideValue = overrideCongested ? SUBSCRIPTION_OVERRIDE_CONGESTED : 0;
getNetworkPolicyManager().setSubscriptionOverride(subId, SUBSCRIPTION_OVERRIDE_CONGESTED, getNetworkPolicyManager().setSubscriptionOverride(subId, SUBSCRIPTION_OVERRIDE_CONGESTED,
overrideValue, networkTypes, timeoutMillis, mContext.getOpPackageName()); overrideValue, networkTypes, expirationDurationMillis, mContext.getOpPackageName());
} }
/** /**