Loading core/java/android/net/NetworkPolicy.java +13 −0 Original line number Diff line number Diff line Loading @@ -40,6 +40,8 @@ public class NetworkPolicy implements Parcelable, Comparable<NetworkPolicy> { public long limitBytes; public long lastSnooze; private static final long DEFAULT_MTU = 1500; public NetworkPolicy(NetworkTemplate template, int cycleDay, long warningBytes, long limitBytes, long lastSnooze) { this.template = checkNotNull(template, "missing NetworkTemplate"); Loading Loading @@ -71,6 +73,17 @@ public class NetworkPolicy implements Parcelable, Comparable<NetworkPolicy> { return 0; } /** * Test if given measurement is near enough to {@link #limitBytes} to be * considered over-limit. */ public boolean isOverLimit(long totalBytes) { // over-estimate, since kernel will trigger limit once first packet // trips over limit. totalBytes += 2 * DEFAULT_MTU; return limitBytes != LIMIT_DISABLED && totalBytes >= limitBytes; } /** {@inheritDoc} */ public int compareTo(NetworkPolicy another) { if (another == null || another.limitBytes == LIMIT_DISABLED) { Loading core/res/res/drawable-hdpi/stat_notify_disabled.png 0 → 100644 +1.03 KiB Loading image diff... core/res/res/drawable-mdpi/stat_notify_disabled.png 0 → 100644 +738 B Loading image diff... core/res/res/drawable-xhdpi/stat_notify_disabled.png 0 → 100644 +1.38 KiB Loading image diff... services/java/com/android/server/net/NetworkPolicyManagerService.java +7 −12 Original line number Diff line number Diff line Loading @@ -85,7 +85,6 @@ import android.net.NetworkIdentity; import android.net.NetworkPolicy; import android.net.NetworkQuotaInfo; import android.net.NetworkState; import android.net.NetworkStats; import android.net.NetworkTemplate; import android.os.Binder; import android.os.Environment; Loading Loading @@ -489,7 +488,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { final long end = currentTime; final long totalBytes = getTotalBytes(policy.template, start, end); if (policy.limitBytes != LIMIT_DISABLED && totalBytes >= policy.limitBytes) { if (policy.isOverLimit(totalBytes)) { if (policy.lastSnooze >= start) { enqueueNotification(policy, TYPE_LIMIT_SNOOZED, totalBytes); } else { Loading Loading @@ -574,7 +573,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { final CharSequence title = res.getText(R.string.data_usage_warning_title); final CharSequence body = res.getString(R.string.data_usage_warning_body); builder.setSmallIcon(R.drawable.ic_menu_info_details); builder.setSmallIcon(R.drawable.stat_notify_error); builder.setTicker(title); builder.setContentTitle(title); builder.setContentText(body); Loading Loading @@ -606,7 +605,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { break; } builder.setSmallIcon(com.android.internal.R.drawable.ic_menu_block); builder.setSmallIcon(R.drawable.stat_notify_disabled); builder.setTicker(title); builder.setContentTitle(title); builder.setContentText(body); Loading Loading @@ -640,7 +639,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { break; } builder.setSmallIcon(R.drawable.ic_menu_info_details); builder.setSmallIcon(R.drawable.stat_notify_error); builder.setTicker(title); builder.setContentTitle(title); builder.setContentText(body); Loading Loading @@ -677,7 +676,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { builder.setOnlyAlertOnce(true); builder.setOngoing(true); builder.setSmallIcon(R.drawable.ic_menu_info_details); builder.setSmallIcon(R.drawable.stat_notify_error); builder.setTicker(title); builder.setContentTitle(title); builder.setContentText(body); Loading Loading @@ -750,8 +749,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { final long totalBytes = getTotalBytes(policy.template, start, end); // disable data connection when over limit and not snoozed final boolean overLimit = policy.limitBytes != LIMIT_DISABLED && totalBytes > policy.limitBytes && policy.lastSnooze < start; final boolean overLimit = policy.isOverLimit(totalBytes) && policy.lastSnooze < start; final boolean enabled = !overLimit; setNetworkTemplateEnabled(policy.template, enabled); Loading Loading @@ -1535,10 +1533,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { private long getTotalBytes(NetworkTemplate template, long start, long end) { try { final NetworkStats stats = mNetworkStats.getSummaryForNetwork( template, start, end); final NetworkStats.Entry entry = stats.getValues(0, null); return entry.rxBytes + entry.txBytes; return mNetworkStats.getSummaryForNetwork(template, start, end).getTotalBytes(); } catch (RemoteException e) { // ignored; service lives in system_server return 0; Loading Loading
core/java/android/net/NetworkPolicy.java +13 −0 Original line number Diff line number Diff line Loading @@ -40,6 +40,8 @@ public class NetworkPolicy implements Parcelable, Comparable<NetworkPolicy> { public long limitBytes; public long lastSnooze; private static final long DEFAULT_MTU = 1500; public NetworkPolicy(NetworkTemplate template, int cycleDay, long warningBytes, long limitBytes, long lastSnooze) { this.template = checkNotNull(template, "missing NetworkTemplate"); Loading Loading @@ -71,6 +73,17 @@ public class NetworkPolicy implements Parcelable, Comparable<NetworkPolicy> { return 0; } /** * Test if given measurement is near enough to {@link #limitBytes} to be * considered over-limit. */ public boolean isOverLimit(long totalBytes) { // over-estimate, since kernel will trigger limit once first packet // trips over limit. totalBytes += 2 * DEFAULT_MTU; return limitBytes != LIMIT_DISABLED && totalBytes >= limitBytes; } /** {@inheritDoc} */ public int compareTo(NetworkPolicy another) { if (another == null || another.limitBytes == LIMIT_DISABLED) { Loading
services/java/com/android/server/net/NetworkPolicyManagerService.java +7 −12 Original line number Diff line number Diff line Loading @@ -85,7 +85,6 @@ import android.net.NetworkIdentity; import android.net.NetworkPolicy; import android.net.NetworkQuotaInfo; import android.net.NetworkState; import android.net.NetworkStats; import android.net.NetworkTemplate; import android.os.Binder; import android.os.Environment; Loading Loading @@ -489,7 +488,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { final long end = currentTime; final long totalBytes = getTotalBytes(policy.template, start, end); if (policy.limitBytes != LIMIT_DISABLED && totalBytes >= policy.limitBytes) { if (policy.isOverLimit(totalBytes)) { if (policy.lastSnooze >= start) { enqueueNotification(policy, TYPE_LIMIT_SNOOZED, totalBytes); } else { Loading Loading @@ -574,7 +573,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { final CharSequence title = res.getText(R.string.data_usage_warning_title); final CharSequence body = res.getString(R.string.data_usage_warning_body); builder.setSmallIcon(R.drawable.ic_menu_info_details); builder.setSmallIcon(R.drawable.stat_notify_error); builder.setTicker(title); builder.setContentTitle(title); builder.setContentText(body); Loading Loading @@ -606,7 +605,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { break; } builder.setSmallIcon(com.android.internal.R.drawable.ic_menu_block); builder.setSmallIcon(R.drawable.stat_notify_disabled); builder.setTicker(title); builder.setContentTitle(title); builder.setContentText(body); Loading Loading @@ -640,7 +639,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { break; } builder.setSmallIcon(R.drawable.ic_menu_info_details); builder.setSmallIcon(R.drawable.stat_notify_error); builder.setTicker(title); builder.setContentTitle(title); builder.setContentText(body); Loading Loading @@ -677,7 +676,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { builder.setOnlyAlertOnce(true); builder.setOngoing(true); builder.setSmallIcon(R.drawable.ic_menu_info_details); builder.setSmallIcon(R.drawable.stat_notify_error); builder.setTicker(title); builder.setContentTitle(title); builder.setContentText(body); Loading Loading @@ -750,8 +749,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { final long totalBytes = getTotalBytes(policy.template, start, end); // disable data connection when over limit and not snoozed final boolean overLimit = policy.limitBytes != LIMIT_DISABLED && totalBytes > policy.limitBytes && policy.lastSnooze < start; final boolean overLimit = policy.isOverLimit(totalBytes) && policy.lastSnooze < start; final boolean enabled = !overLimit; setNetworkTemplateEnabled(policy.template, enabled); Loading Loading @@ -1535,10 +1533,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { private long getTotalBytes(NetworkTemplate template, long start, long end) { try { final NetworkStats stats = mNetworkStats.getSummaryForNetwork( template, start, end); final NetworkStats.Entry entry = stats.getValues(0, null); return entry.rxBytes + entry.txBytes; return mNetworkStats.getSummaryForNetwork(template, start, end).getTotalBytes(); } catch (RemoteException e) { // ignored; service lives in system_server return 0; Loading