Differentiate depleted and unset multipath quota

NetworkPolicyManagerInternalImpl#getSubscriptionOpportunisticQuota
would return 0 both for unset and depleted quota, which cannot be
interpreted properly by MultipathPolicyTracker (the only caller),
to use a fallback policy.

Return OPPORTUNISTIC_QUOTA_UNKNOWN (-1) instead for unknown quota.

Test: verified with CTS tests in ag/3811166
Bug: b/72631572
Bug: b/72877610
Change-Id: Ic087f7bfa9f10cc376b5ccd68a4685bd5242c586
This commit is contained in:
Remi NGUYEN VAN
2018-03-30 21:17:42 +09:00
parent 601861fd1c
commit 5a89f94096
2 changed files with 13 additions and 9 deletions

View File

@@ -44,6 +44,7 @@ import android.util.Slog;
import com.android.internal.util.IndentingPrintWriter;
import com.android.server.LocalServices;
import com.android.server.net.NetworkPolicyManagerInternal;
import com.android.server.net.NetworkPolicyManagerService;
import com.android.server.net.NetworkStatsManagerInternal;
import java.util.Calendar;
@@ -191,7 +192,7 @@ public class MultipathPolicyTracker {
.getSubscriptionOpportunisticQuota(this.network, QUOTA_TYPE_MULTIPATH);
if (DBG) Slog.d(TAG, "Opportunistic quota from data plan: " + quota + " bytes");
if (quota == 0) {
if (quota == NetworkPolicyManagerService.OPPORTUNISTIC_QUOTA_UNKNOWN) {
// STOPSHIP: replace this with a configurable mechanism.
quota = DEFAULT_DAILY_MULTIPATH_QUOTA;
if (DBG) Slog.d(TAG, "Setting quota: " + quota + " bytes");

View File

@@ -274,6 +274,11 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
private static final boolean LOGD = NetworkPolicyLogger.LOGD;
private static final boolean LOGV = NetworkPolicyLogger.LOGV;
/**
* No opportunistic quota could be calculated from user data plan or data settings.
*/
public static final int OPPORTUNISTIC_QUOTA_UNKNOWN = -1;
private static final int VERSION_INIT = 1;
private static final int VERSION_ADDED_SNOOZE = 2;
private static final int VERSION_ADDED_RESTRICT_BACKGROUND = 3;
@@ -1732,12 +1737,10 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
final SubscriptionPlan plan = getPrimarySubscriptionPlanLocked(subId);
if (plan == null) continue;
// By default assume we have no quota
long quotaBytes = 0;
final long quotaBytes;
final long limitBytes = plan.getDataLimitBytes();
if (limitBytes == SubscriptionPlan.BYTES_UNKNOWN) {
// Ignore missing limits
quotaBytes = OPPORTUNISTIC_QUOTA_UNKNOWN;
} else if (limitBytes == SubscriptionPlan.BYTES_UNLIMITED) {
// Unlimited data; let's use 20MiB/day (600MiB/month)
quotaBytes = DataUnit.MEBIBYTES.toBytes(20);
@@ -1751,9 +1754,8 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
final long remainingBytes = limitBytes - totalBytes;
final long remainingDays = Math.max(1, (end - mClock.millis())
/ TimeUnit.DAYS.toMillis(1));
if (remainingBytes > 0) {
quotaBytes = (remainingBytes / remainingDays) / 10;
}
quotaBytes = Math.max(0, (remainingBytes / remainingDays) / 10);
}
mSubscriptionOpportunisticQuota.put(subId, quotaBytes);
@@ -4658,7 +4660,8 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
public long getSubscriptionOpportunisticQuota(Network network, int quotaType) {
synchronized (mNetworkPoliciesSecondLock) {
// TODO: handle splitting quota between use-cases
return mSubscriptionOpportunisticQuota.get(getSubIdLocked(network));
return mSubscriptionOpportunisticQuota.get(getSubIdLocked(network),
OPPORTUNISTIC_QUOTA_UNKNOWN);
}
}