Loading core/java/android/app/usage/NetworkStatsManager.java +10 −0 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import android.os.Messenger; import android.os.RemoteException; import android.os.ServiceManager; import android.os.ServiceManager.ServiceNotFoundException; import android.util.DataUnit; import android.util.Log; import com.android.internal.annotations.VisibleForTesting; Loading Loading @@ -95,6 +96,15 @@ public class NetworkStatsManager { /** @hide */ public static final int CALLBACK_RELEASED = 1; /** * Minimum data usage threshold for registering usage callbacks. * * Requests registered with a threshold lower than this will only be triggered once this minimum * is reached. * @hide */ public static final long MIN_THRESHOLD_BYTES = DataUnit.MEBIBYTES.toBytes(2); private final Context mContext; private final INetworkStatsService mService; Loading services/core/java/com/android/server/connectivity/MultipathPolicyTracker.java +15 −4 Original line number Diff line number Diff line Loading @@ -56,6 +56,7 @@ import android.net.Uri; import android.os.UserHandle; import android.provider.Settings; import android.telephony.TelephonyManager; import android.util.DataUnit; import android.util.DebugUtils; import android.util.Pair; import android.util.Range; Loading Loading @@ -333,11 +334,11 @@ public class MultipathPolicyTracker { if (DBG) Slog.d(TAG, "Setting quota: " + quota + " bytes"); } // TODO: re-register if day changed: budget may have run out but should be refreshed. if (haveMultipathBudget() && quota == mQuota) { // If we already have a usage callback pending , there's no need to re-register it // If there is already a usage callback pending , there's no need to re-register it // if the quota hasn't changed. The callback will simply fire as expected when the // budget is spent. Also: if we re-register the callback when we're below the // UsageCallback's minimum value of 2MB, we'll overshoot the budget. // budget is spent. if (DBG) Slog.d(TAG, "Quota still " + quota + ", not updating."); return; } Loading @@ -347,7 +348,17 @@ public class MultipathPolicyTracker { // ourselves any budget to work with. final long usage = getDailyNonDefaultDataUsage(); final long budget = (usage == -1) ? 0 : Math.max(0, quota - usage); if (budget > 0) { // Only consider budgets greater than MIN_THRESHOLD_BYTES, otherwise the callback will // fire late, after data usage went over budget. Also budget should be 0 if remaining // data is close to 0. // This is necessary because the usage callback does not accept smaller thresholds. // Because it snaps everything to MIN_THRESHOLD_BYTES, the lesser of the two evils is // to snap to 0 here. // This will only be called if the total quota for the day changed, not if usage changed // since last time, so even if this is called very often the budget will not snap to 0 // as soon as there are less than 2MB left for today. if (budget > NetworkStatsManager.MIN_THRESHOLD_BYTES) { if (DBG) Slog.d(TAG, "Setting callback for " + budget + " bytes on network " + network); registerUsageCallback(budget); Loading services/core/java/com/android/server/net/NetworkStatsObservers.java +1 −3 Original line number Diff line number Diff line Loading @@ -16,7 +16,7 @@ package com.android.server.net; import static android.net.TrafficStats.MB_IN_BYTES; import static android.app.usage.NetworkStatsManager.MIN_THRESHOLD_BYTES; import static com.android.internal.util.Preconditions.checkArgument; Loading Loading @@ -52,8 +52,6 @@ class NetworkStatsObservers { private static final String TAG = "NetworkStatsObservers"; private static final boolean LOGV = false; private static final long MIN_THRESHOLD_BYTES = 2 * MB_IN_BYTES; private static final int MSG_REGISTER = 1; private static final int MSG_UNREGISTER = 2; private static final int MSG_UPDATE_STATS = 3; Loading Loading
core/java/android/app/usage/NetworkStatsManager.java +10 −0 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import android.os.Messenger; import android.os.RemoteException; import android.os.ServiceManager; import android.os.ServiceManager.ServiceNotFoundException; import android.util.DataUnit; import android.util.Log; import com.android.internal.annotations.VisibleForTesting; Loading Loading @@ -95,6 +96,15 @@ public class NetworkStatsManager { /** @hide */ public static final int CALLBACK_RELEASED = 1; /** * Minimum data usage threshold for registering usage callbacks. * * Requests registered with a threshold lower than this will only be triggered once this minimum * is reached. * @hide */ public static final long MIN_THRESHOLD_BYTES = DataUnit.MEBIBYTES.toBytes(2); private final Context mContext; private final INetworkStatsService mService; Loading
services/core/java/com/android/server/connectivity/MultipathPolicyTracker.java +15 −4 Original line number Diff line number Diff line Loading @@ -56,6 +56,7 @@ import android.net.Uri; import android.os.UserHandle; import android.provider.Settings; import android.telephony.TelephonyManager; import android.util.DataUnit; import android.util.DebugUtils; import android.util.Pair; import android.util.Range; Loading Loading @@ -333,11 +334,11 @@ public class MultipathPolicyTracker { if (DBG) Slog.d(TAG, "Setting quota: " + quota + " bytes"); } // TODO: re-register if day changed: budget may have run out but should be refreshed. if (haveMultipathBudget() && quota == mQuota) { // If we already have a usage callback pending , there's no need to re-register it // If there is already a usage callback pending , there's no need to re-register it // if the quota hasn't changed. The callback will simply fire as expected when the // budget is spent. Also: if we re-register the callback when we're below the // UsageCallback's minimum value of 2MB, we'll overshoot the budget. // budget is spent. if (DBG) Slog.d(TAG, "Quota still " + quota + ", not updating."); return; } Loading @@ -347,7 +348,17 @@ public class MultipathPolicyTracker { // ourselves any budget to work with. final long usage = getDailyNonDefaultDataUsage(); final long budget = (usage == -1) ? 0 : Math.max(0, quota - usage); if (budget > 0) { // Only consider budgets greater than MIN_THRESHOLD_BYTES, otherwise the callback will // fire late, after data usage went over budget. Also budget should be 0 if remaining // data is close to 0. // This is necessary because the usage callback does not accept smaller thresholds. // Because it snaps everything to MIN_THRESHOLD_BYTES, the lesser of the two evils is // to snap to 0 here. // This will only be called if the total quota for the day changed, not if usage changed // since last time, so even if this is called very often the budget will not snap to 0 // as soon as there are less than 2MB left for today. if (budget > NetworkStatsManager.MIN_THRESHOLD_BYTES) { if (DBG) Slog.d(TAG, "Setting callback for " + budget + " bytes on network " + network); registerUsageCallback(budget); Loading
services/core/java/com/android/server/net/NetworkStatsObservers.java +1 −3 Original line number Diff line number Diff line Loading @@ -16,7 +16,7 @@ package com.android.server.net; import static android.net.TrafficStats.MB_IN_BYTES; import static android.app.usage.NetworkStatsManager.MIN_THRESHOLD_BYTES; import static com.android.internal.util.Preconditions.checkArgument; Loading Loading @@ -52,8 +52,6 @@ class NetworkStatsObservers { private static final String TAG = "NetworkStatsObservers"; private static final boolean LOGV = false; private static final long MIN_THRESHOLD_BYTES = 2 * MB_IN_BYTES; private static final int MSG_REGISTER = 1; private static final int MSG_UNREGISTER = 2; private static final int MSG_UPDATE_STATS = 3; Loading