Merge "Update setSubscriptionOverride API to allow network types"

This commit is contained in:
Sarah Chin
2021-02-05 05:14:50 +00:00
committed by Gerrit Code Review
6 changed files with 122 additions and 27 deletions

View File

@@ -41213,7 +41213,9 @@ package android.telephony {
method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void removeSubscriptionsFromGroup(@NonNull java.util.List<java.lang.Integer>, @NonNull android.os.ParcelUuid); method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void removeSubscriptionsFromGroup(@NonNull java.util.List<java.lang.Integer>, @NonNull android.os.ParcelUuid);
method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean setOpportunistic(boolean, int); method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean setOpportunistic(boolean, int);
method public void setSubscriptionOverrideCongested(int, boolean, long); method public void setSubscriptionOverrideCongested(int, boolean, 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 setSubscriptionPlans(int, @NonNull java.util.List<android.telephony.SubscriptionPlan>); method public void setSubscriptionPlans(int, @NonNull java.util.List<android.telephony.SubscriptionPlan>);
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";

View File

@@ -23,6 +23,6 @@ oneway interface INetworkPolicyListener {
void onMeteredIfacesChanged(in String[] meteredIfaces); void onMeteredIfacesChanged(in String[] meteredIfaces);
void onRestrictBackgroundChanged(boolean restrictBackground); void onRestrictBackgroundChanged(boolean restrictBackground);
void onUidPoliciesChanged(int uid, int uidPolicies); void onUidPoliciesChanged(int uid, int uidPolicies);
void onSubscriptionOverride(int subId, int overrideMask, int overrideValue); void onSubscriptionOverride(int subId, int overrideMask, int overrideValue, in int[] networkTypes);
void onSubscriptionPlansChanged(int subId, in SubscriptionPlan[] plans); void onSubscriptionPlansChanged(int subId, in SubscriptionPlan[] plans);
} }

View File

@@ -76,7 +76,7 @@ interface INetworkPolicyManager {
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, String callingPackage);
String getSubscriptionPlansOwner(int subId); String getSubscriptionPlansOwner(int subId);
void setSubscriptionOverride(int subId, int overrideMask, int overrideValue, long timeoutMillis, String callingPackage); void setSubscriptionOverride(int subId, int overrideMask, int overrideValue, in int[] networkTypes, long timeoutMillis, String callingPackage);
void factoryReset(String subscriber); void factoryReset(String subscriber);

View File

@@ -34,6 +34,7 @@ import android.net.wifi.WifiInfo;
import android.os.Build; import android.os.Build;
import android.os.Process; import android.os.Process;
import android.os.RemoteException; import android.os.RemoteException;
import android.telephony.Annotation;
import android.telephony.SubscriptionPlan; import android.telephony.SubscriptionPlan;
import android.util.DebugUtils; import android.util.DebugUtils;
import android.util.Pair; import android.util.Pair;
@@ -377,6 +378,8 @@ public class NetworkPolicyManager {
* @param overrideMask the bitmask that specifies which of the overrides is being * @param overrideMask the bitmask that specifies which of the overrides is being
* set or cleared. * set or cleared.
* @param overrideValue the override values to set or clear. * @param overrideValue the override values to set or clear.
* @param networkTypes the network types this override applies to.
* {@see TelephonyManager#getAllNetworkTypes()}
* @param timeoutMillis the timeout after which the requested override will * @param timeoutMillis the timeout after which the requested override will
* be automatically cleared, or {@code 0} to leave in the * 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,
@@ -385,11 +388,12 @@ public class NetworkPolicyManager {
* @hide * @hide
*/ */
public void setSubscriptionOverride(int subId, @SubscriptionOverrideMask int overrideMask, public void setSubscriptionOverride(int subId, @SubscriptionOverrideMask int overrideMask,
@SubscriptionOverrideMask int overrideValue, long timeoutMillis, @SubscriptionOverrideMask int overrideValue,
@NonNull String callingPackage) { @NonNull @Annotation.NetworkType int[] networkTypes, long timeoutMillis,
@NonNull String callingPackage) {
try { try {
mService.setSubscriptionOverride(subId, overrideMask, overrideValue, timeoutMillis, mService.setSubscriptionOverride(subId, overrideMask, overrideValue, networkTypes,
callingPackage); timeoutMillis, callingPackage);
} catch (RemoteException e) { } catch (RemoteException e) {
throw e.rethrowFromSystemServer(); throw e.rethrowFromSystemServer();
} }
@@ -613,9 +617,10 @@ public class NetworkPolicyManager {
* @param subId the subscriber this override applies to. * @param subId the subscriber this override applies to.
* @param overrideMask a bitmask that specifies which of the overrides is set. * @param overrideMask a bitmask that specifies which of the overrides is set.
* @param overrideValue a bitmask that specifies the override values. * @param overrideValue a bitmask that specifies the override values.
* @param networkTypes the network types this override applies to.
*/ */
public void onSubscriptionOverride(int subId, @SubscriptionOverrideMask int overrideMask, public void onSubscriptionOverride(int subId, @SubscriptionOverrideMask int overrideMask,
@SubscriptionOverrideMask int overrideValue) {} @SubscriptionOverrideMask int overrideValue, int[] networkTypes) {}
/** /**
* Notify of subscription plans change about a given subscription. * Notify of subscription plans change about a given subscription.
@@ -639,8 +644,8 @@ public class NetworkPolicyManager {
@Override @Override
public void onSubscriptionOverride(int subId, @SubscriptionOverrideMask int overrideMask, public void onSubscriptionOverride(int subId, @SubscriptionOverrideMask int overrideMask,
@SubscriptionOverrideMask int overrideValue) { @SubscriptionOverrideMask int overrideValue, int[] networkTypes) {
mCallback.onSubscriptionOverride(subId, overrideMask, overrideValue); mCallback.onSubscriptionOverride(subId, overrideMask, overrideValue, networkTypes);
} }
@Override @Override
@@ -656,7 +661,7 @@ public class NetworkPolicyManager {
@Override public void onRestrictBackgroundChanged(boolean restrictBackground) { } @Override public void onRestrictBackgroundChanged(boolean restrictBackground) { }
@Override public void onUidPoliciesChanged(int uid, int uidPolicies) { } @Override public void onUidPoliciesChanged(int uid, int uidPolicies) { }
@Override public void onSubscriptionOverride(int subId, int overrideMask, @Override public void onSubscriptionOverride(int subId, int overrideMask,
int overrideValue) { } int overrideValue, int[] networkTypes) { }
@Override public void onSubscriptionPlansChanged(int subId, SubscriptionPlan[] plans) { } @Override public void onSubscriptionPlansChanged(int subId, SubscriptionPlan[] plans) { }
} }
} }

View File

@@ -70,6 +70,7 @@ import static android.net.NetworkPolicyManager.RULE_REJECT_ALL;
import static android.net.NetworkPolicyManager.RULE_REJECT_METERED; import static android.net.NetworkPolicyManager.RULE_REJECT_METERED;
import static android.net.NetworkPolicyManager.RULE_REJECT_RESTRICTED_MODE; import static android.net.NetworkPolicyManager.RULE_REJECT_RESTRICTED_MODE;
import static android.net.NetworkPolicyManager.RULE_TEMPORARY_ALLOW_METERED; import static android.net.NetworkPolicyManager.RULE_TEMPORARY_ALLOW_METERED;
import static android.net.NetworkPolicyManager.SUBSCRIPTION_OVERRIDE_UNMETERED;
import static android.net.NetworkPolicyManager.isProcStateAllowedWhileIdleOrPowerSaveMode; import static android.net.NetworkPolicyManager.isProcStateAllowedWhileIdleOrPowerSaveMode;
import static android.net.NetworkPolicyManager.isProcStateAllowedWhileOnRestrictBackground; import static android.net.NetworkPolicyManager.isProcStateAllowedWhileOnRestrictBackground;
import static android.net.NetworkPolicyManager.resolveNetworkId; import static android.net.NetworkPolicyManager.resolveNetworkId;
@@ -231,6 +232,7 @@ import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting; import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.messages.nano.SystemMessageProto.SystemMessage; import com.android.internal.messages.nano.SystemMessageProto.SystemMessage;
import com.android.internal.notification.SystemNotificationChannels; import com.android.internal.notification.SystemNotificationChannels;
import com.android.internal.os.SomeArgs;
import com.android.internal.util.ArrayUtils; import com.android.internal.util.ArrayUtils;
import com.android.internal.util.CollectionUtils; import com.android.internal.util.CollectionUtils;
import com.android.internal.util.ConcurrentUtils; import com.android.internal.util.ConcurrentUtils;
@@ -3488,13 +3490,27 @@ 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,
long timeoutMillis, String callingPackage) { int[] networkTypes, long timeoutMillis, String callingPackage) {
enforceSubscriptionPlanAccess(subId, Binder.getCallingUid(), callingPackage); enforceSubscriptionPlanAccess(subId, Binder.getCallingUid(), callingPackage);
// We can only override when carrier told us about plans final ArraySet<Integer> allNetworksSet = new ArraySet<>();
addAll(allNetworksSet, TelephonyManager.getAllNetworkTypes());
final IntArray applicableNetworks = new IntArray();
// ensure all network types are valid
for (int networkType : networkTypes) {
if (allNetworksSet.contains(networkType)) {
applicableNetworks.add(networkType);
} else {
Log.d(TAG, "setSubscriptionOverride removing invalid network type: " + networkType);
}
}
// We can only override when carrier told us about plans. For the unmetered case,
// allow override without having plans defined.
synchronized (mNetworkPoliciesSecondLock) { synchronized (mNetworkPoliciesSecondLock) {
final SubscriptionPlan plan = getPrimarySubscriptionPlanLocked(subId); final SubscriptionPlan plan = getPrimarySubscriptionPlanLocked(subId);
if (plan == null if (overrideMask != SUBSCRIPTION_OVERRIDE_UNMETERED && plan == null
|| plan.getDataLimitBehavior() == SubscriptionPlan.LIMIT_BEHAVIOR_UNKNOWN) { || plan.getDataLimitBehavior() == SubscriptionPlan.LIMIT_BEHAVIOR_UNKNOWN) {
throw new IllegalStateException( throw new IllegalStateException(
"Must provide valid SubscriptionPlan to enable overriding"); "Must provide valid SubscriptionPlan to enable overriding");
@@ -3506,11 +3522,16 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
final boolean overrideEnabled = Settings.Global.getInt(mContext.getContentResolver(), final boolean overrideEnabled = Settings.Global.getInt(mContext.getContentResolver(),
NETPOLICY_OVERRIDE_ENABLED, 1) != 0; NETPOLICY_OVERRIDE_ENABLED, 1) != 0;
if (overrideEnabled || overrideValue == 0) { if (overrideEnabled || overrideValue == 0) {
mHandler.sendMessage(mHandler.obtainMessage(MSG_SUBSCRIPTION_OVERRIDE, SomeArgs args = SomeArgs.obtain();
overrideMask, overrideValue, subId)); args.arg1 = subId;
args.arg2 = overrideMask;
args.arg3 = overrideValue;
args.arg4 = applicableNetworks.toArray();
mHandler.sendMessage(mHandler.obtainMessage(MSG_SUBSCRIPTION_OVERRIDE, args));
if (timeoutMillis > 0) { if (timeoutMillis > 0) {
mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_SUBSCRIPTION_OVERRIDE, args.arg3 = 0;
overrideMask, 0, subId), timeoutMillis); mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_SUBSCRIPTION_OVERRIDE, args),
timeoutMillis);
} }
} }
} }
@@ -4778,10 +4799,10 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
} }
private void dispatchSubscriptionOverride(INetworkPolicyListener listener, int subId, private void dispatchSubscriptionOverride(INetworkPolicyListener listener, int subId,
int overrideMask, int overrideValue) { int overrideMask, int overrideValue, int[] networkTypes) {
if (listener != null) { if (listener != null) {
try { try {
listener.onSubscriptionOverride(subId, overrideMask, overrideValue); listener.onSubscriptionOverride(subId, overrideMask, overrideValue, networkTypes);
} catch (RemoteException ignored) { } catch (RemoteException ignored) {
} }
} }
@@ -4913,13 +4934,16 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
return true; return true;
} }
case MSG_SUBSCRIPTION_OVERRIDE: { case MSG_SUBSCRIPTION_OVERRIDE: {
final int overrideMask = msg.arg1; final SomeArgs args = (SomeArgs) msg.obj;
final int overrideValue = msg.arg2; final int subId = (int) args.arg1;
final int subId = (int) msg.obj; final int overrideMask = (int) args.arg2;
final int overrideValue = (int) args.arg3;
final int[] networkTypes = (int[]) args.arg4;
final int length = mListeners.beginBroadcast(); final int length = mListeners.beginBroadcast();
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
final INetworkPolicyListener listener = mListeners.getBroadcastItem(i); final INetworkPolicyListener listener = mListeners.getBroadcastItem(i);
dispatchSubscriptionOverride(listener, subId, overrideMask, overrideValue); dispatchSubscriptionOverride(listener, subId, overrideMask, overrideValue,
networkTypes);
} }
mListeners.finishBroadcast(); mListeners.finishBroadcast();
return true; return true;

View File

@@ -2589,14 +2589,45 @@ public class SubscriptionManager {
* 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 timeoutMillis) {
setSubscriptionOverrideUnmetered(subId, overrideUnmetered,
TelephonyManager.getAllNetworkTypes(), timeoutMillis);
}
/**
* Temporarily override the billing relationship plan between a carrier and
* a specific subscriber to be considered unmetered. This will be reflected
* to apps via {@link NetworkCapabilities#NET_CAPABILITY_NOT_METERED}.
* <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 override applies to.
* @param overrideUnmetered set if the billing relationship should be
* considered unmetered.
* @param networkTypes the network types this override applies to.
* {@see TelephonyManager#getAllNetworkTypes()}
* @param timeoutMillis the timeout after which the requested override will
* be automatically cleared, or {@code 0} to leave in the
* requested state until explicitly cleared, or the next reboot,
* whichever happens first.
* @throws SecurityException if the caller doesn't meet the requirements
* outlined above.
*/
public void setSubscriptionOverrideUnmetered(int subId, boolean overrideUnmetered,
@NonNull @Annotation.NetworkType int[] networkTypes,
@DurationMillisLong long timeoutMillis) {
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, timeoutMillis, mContext.getOpPackageName()); overrideValue, networkTypes, timeoutMillis, mContext.getOpPackageName());
} }
/** /**
@@ -2621,13 +2652,46 @@ public class SubscriptionManager {
* 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 timeoutMillis) {
setSubscriptionOverrideCongested(subId, overrideCongested,
TelephonyManager.getAllNetworkTypes(), timeoutMillis);
}
/**
* Temporarily override the billing relationship plan between a carrier and
* a specific subscriber to be considered congested. This will cause the
* device to delay certain network requests when possible, such as developer
* jobs that are willing to run in a flexible time window.
* <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 override applies to.
* @param overrideCongested set if the subscription should be considered
* congested.
* @param networkTypes the network types this override applies to.
* {@see TelephonyManager#getAllNetworkTypes()}
* @param timeoutMillis the timeout after which the requested override will
* be automatically cleared, or {@code 0} to leave in the
* requested state until explicitly cleared, or the next reboot,
* whichever happens first.
* @throws SecurityException if the caller doesn't meet the requirements
* outlined above.
*/
public void setSubscriptionOverrideCongested(int subId, boolean overrideCongested,
@NonNull @Annotation.NetworkType int[] networkTypes,
@DurationMillisLong long timeoutMillis) {
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, timeoutMillis, mContext.getOpPackageName()); overrideValue, networkTypes, timeoutMillis, mContext.getOpPackageName());
} }
/** /**