Merge "Update setSubscriptionOverride API to allow network types" into rvc-qpr-dev-plus-aosp
This commit is contained in:
@@ -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 boolean setOpportunistic(boolean, int);
|
||||
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, @NonNull int[], long);
|
||||
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);
|
||||
field public static final String ACTION_DEFAULT_SMS_SUBSCRIPTION_CHANGED = "android.telephony.action.DEFAULT_SMS_SUBSCRIPTION_CHANGED";
|
||||
|
||||
@@ -23,6 +23,6 @@ oneway interface INetworkPolicyListener {
|
||||
void onMeteredIfacesChanged(in String[] meteredIfaces);
|
||||
void onRestrictBackgroundChanged(boolean restrictBackground);
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ interface INetworkPolicyManager {
|
||||
SubscriptionPlan[] getSubscriptionPlans(int subId, String callingPackage);
|
||||
void setSubscriptionPlans(int subId, in SubscriptionPlan[] plans, String callingPackage);
|
||||
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);
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ import android.net.wifi.WifiInfo;
|
||||
import android.os.Build;
|
||||
import android.os.Process;
|
||||
import android.os.RemoteException;
|
||||
import android.telephony.Annotation;
|
||||
import android.telephony.SubscriptionPlan;
|
||||
import android.util.DebugUtils;
|
||||
import android.util.Pair;
|
||||
@@ -377,6 +378,8 @@ public class NetworkPolicyManager {
|
||||
* @param overrideMask the bitmask that specifies which of the overrides is being
|
||||
* set or cleared.
|
||||
* @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
|
||||
* be automatically cleared, or {@code 0} to leave in the
|
||||
* requested state until explicitly cleared, or the next reboot,
|
||||
@@ -385,11 +388,12 @@ public class NetworkPolicyManager {
|
||||
* @hide
|
||||
*/
|
||||
public void setSubscriptionOverride(int subId, @SubscriptionOverrideMask int overrideMask,
|
||||
@SubscriptionOverrideMask int overrideValue, long timeoutMillis,
|
||||
@NonNull String callingPackage) {
|
||||
@SubscriptionOverrideMask int overrideValue,
|
||||
@NonNull @Annotation.NetworkType int[] networkTypes, long timeoutMillis,
|
||||
@NonNull String callingPackage) {
|
||||
try {
|
||||
mService.setSubscriptionOverride(subId, overrideMask, overrideValue, timeoutMillis,
|
||||
callingPackage);
|
||||
mService.setSubscriptionOverride(subId, overrideMask, overrideValue, networkTypes,
|
||||
timeoutMillis, callingPackage);
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
@@ -613,9 +617,10 @@ public class NetworkPolicyManager {
|
||||
* @param subId the subscriber this override applies to.
|
||||
* @param overrideMask a bitmask that specifies which of the overrides is set.
|
||||
* @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,
|
||||
@SubscriptionOverrideMask int overrideValue) {}
|
||||
@SubscriptionOverrideMask int overrideValue, int[] networkTypes) {}
|
||||
|
||||
/**
|
||||
* Notify of subscription plans change about a given subscription.
|
||||
@@ -639,8 +644,8 @@ public class NetworkPolicyManager {
|
||||
|
||||
@Override
|
||||
public void onSubscriptionOverride(int subId, @SubscriptionOverrideMask int overrideMask,
|
||||
@SubscriptionOverrideMask int overrideValue) {
|
||||
mCallback.onSubscriptionOverride(subId, overrideMask, overrideValue);
|
||||
@SubscriptionOverrideMask int overrideValue, int[] networkTypes) {
|
||||
mCallback.onSubscriptionOverride(subId, overrideMask, overrideValue, networkTypes);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -656,7 +661,7 @@ public class NetworkPolicyManager {
|
||||
@Override public void onRestrictBackgroundChanged(boolean restrictBackground) { }
|
||||
@Override public void onUidPoliciesChanged(int uid, int uidPolicies) { }
|
||||
@Override public void onSubscriptionOverride(int subId, int overrideMask,
|
||||
int overrideValue) { }
|
||||
int overrideValue, int[] networkTypes) { }
|
||||
@Override public void onSubscriptionPlansChanged(int subId, SubscriptionPlan[] plans) { }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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_RESTRICTED_MODE;
|
||||
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.isProcStateAllowedWhileOnRestrictBackground;
|
||||
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.messages.nano.SystemMessageProto.SystemMessage;
|
||||
import com.android.internal.notification.SystemNotificationChannels;
|
||||
import com.android.internal.os.SomeArgs;
|
||||
import com.android.internal.util.ArrayUtils;
|
||||
import com.android.internal.util.CollectionUtils;
|
||||
import com.android.internal.util.ConcurrentUtils;
|
||||
@@ -3488,13 +3490,27 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
|
||||
@Override
|
||||
public void setSubscriptionOverride(int subId, int overrideMask, int overrideValue,
|
||||
long timeoutMillis, String callingPackage) {
|
||||
int[] networkTypes, long timeoutMillis, String 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) {
|
||||
final SubscriptionPlan plan = getPrimarySubscriptionPlanLocked(subId);
|
||||
if (plan == null
|
||||
if (overrideMask != SUBSCRIPTION_OVERRIDE_UNMETERED && plan == null
|
||||
|| plan.getDataLimitBehavior() == SubscriptionPlan.LIMIT_BEHAVIOR_UNKNOWN) {
|
||||
throw new IllegalStateException(
|
||||
"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(),
|
||||
NETPOLICY_OVERRIDE_ENABLED, 1) != 0;
|
||||
if (overrideEnabled || overrideValue == 0) {
|
||||
mHandler.sendMessage(mHandler.obtainMessage(MSG_SUBSCRIPTION_OVERRIDE,
|
||||
overrideMask, overrideValue, subId));
|
||||
SomeArgs args = SomeArgs.obtain();
|
||||
args.arg1 = subId;
|
||||
args.arg2 = overrideMask;
|
||||
args.arg3 = overrideValue;
|
||||
args.arg4 = applicableNetworks.toArray();
|
||||
mHandler.sendMessage(mHandler.obtainMessage(MSG_SUBSCRIPTION_OVERRIDE, args));
|
||||
if (timeoutMillis > 0) {
|
||||
mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_SUBSCRIPTION_OVERRIDE,
|
||||
overrideMask, 0, subId), timeoutMillis);
|
||||
args.arg3 = 0;
|
||||
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,
|
||||
int overrideMask, int overrideValue) {
|
||||
int overrideMask, int overrideValue, int[] networkTypes) {
|
||||
if (listener != null) {
|
||||
try {
|
||||
listener.onSubscriptionOverride(subId, overrideMask, overrideValue);
|
||||
listener.onSubscriptionOverride(subId, overrideMask, overrideValue, networkTypes);
|
||||
} catch (RemoteException ignored) {
|
||||
}
|
||||
}
|
||||
@@ -4913,13 +4934,16 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
return true;
|
||||
}
|
||||
case MSG_SUBSCRIPTION_OVERRIDE: {
|
||||
final int overrideMask = msg.arg1;
|
||||
final int overrideValue = msg.arg2;
|
||||
final int subId = (int) msg.obj;
|
||||
final SomeArgs args = (SomeArgs) msg.obj;
|
||||
final int subId = (int) args.arg1;
|
||||
final int overrideMask = (int) args.arg2;
|
||||
final int overrideValue = (int) args.arg3;
|
||||
final int[] networkTypes = (int[]) args.arg4;
|
||||
final int length = mListeners.beginBroadcast();
|
||||
for (int i = 0; i < length; i++) {
|
||||
final INetworkPolicyListener listener = mListeners.getBroadcastItem(i);
|
||||
dispatchSubscriptionOverride(listener, subId, overrideMask, overrideValue);
|
||||
dispatchSubscriptionOverride(listener, subId, overrideMask, overrideValue,
|
||||
networkTypes);
|
||||
}
|
||||
mListeners.finishBroadcast();
|
||||
return true;
|
||||
|
||||
@@ -2589,14 +2589,45 @@ public class SubscriptionManager {
|
||||
* requested state until explicitly cleared, or the next reboot,
|
||||
* whichever happens first.
|
||||
* @throws SecurityException if the caller doesn't meet the requirements
|
||||
* outlined above.
|
||||
* outlined above.
|
||||
*/
|
||||
public void setSubscriptionOverrideUnmetered(int subId, boolean overrideUnmetered,
|
||||
@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;
|
||||
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,
|
||||
* whichever happens first.
|
||||
* @throws SecurityException if the caller doesn't meet the requirements
|
||||
* outlined above.
|
||||
* outlined above.
|
||||
*/
|
||||
public void setSubscriptionOverrideCongested(int subId, boolean overrideCongested,
|
||||
@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;
|
||||
getNetworkPolicyManager().setSubscriptionOverride(subId, SUBSCRIPTION_OVERRIDE_CONGESTED,
|
||||
overrideValue, timeoutMillis, mContext.getOpPackageName());
|
||||
overrideValue, networkTypes, timeoutMillis, mContext.getOpPackageName());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user