|
85 | 85 | import android.net.NetworkPolicy; |
86 | 86 | import android.net.NetworkQuotaInfo; |
87 | 87 | import android.net.NetworkState; |
88 | | -import android.net.NetworkStats; |
89 | 88 | import android.net.NetworkTemplate; |
90 | 89 | import android.os.Binder; |
91 | 90 | import android.os.Environment; |
@@ -489,7 +488,7 @@ private void updateNotificationsLocked() { |
489 | 488 | final long end = currentTime; |
490 | 489 | final long totalBytes = getTotalBytes(policy.template, start, end); |
491 | 490 |
|
492 | | - if (policy.limitBytes != LIMIT_DISABLED && totalBytes >= policy.limitBytes) { |
| 491 | + if (policy.isOverLimit(totalBytes)) { |
493 | 492 | if (policy.lastSnooze >= start) { |
494 | 493 | enqueueNotification(policy, TYPE_LIMIT_SNOOZED, totalBytes); |
495 | 494 | } else { |
@@ -574,7 +573,7 @@ private void enqueueNotification(NetworkPolicy policy, int type, long totalBytes |
574 | 573 | final CharSequence title = res.getText(R.string.data_usage_warning_title); |
575 | 574 | final CharSequence body = res.getString(R.string.data_usage_warning_body); |
576 | 575 |
|
577 | | - builder.setSmallIcon(R.drawable.ic_menu_info_details); |
| 576 | + builder.setSmallIcon(R.drawable.stat_notify_error); |
578 | 577 | builder.setTicker(title); |
579 | 578 | builder.setContentTitle(title); |
580 | 579 | builder.setContentText(body); |
@@ -606,7 +605,7 @@ private void enqueueNotification(NetworkPolicy policy, int type, long totalBytes |
606 | 605 | break; |
607 | 606 | } |
608 | 607 |
|
609 | | - builder.setSmallIcon(com.android.internal.R.drawable.ic_menu_block); |
| 608 | + builder.setSmallIcon(R.drawable.stat_notify_disabled); |
610 | 609 | builder.setTicker(title); |
611 | 610 | builder.setContentTitle(title); |
612 | 611 | builder.setContentText(body); |
@@ -640,7 +639,7 @@ private void enqueueNotification(NetworkPolicy policy, int type, long totalBytes |
640 | 639 | break; |
641 | 640 | } |
642 | 641 |
|
643 | | - builder.setSmallIcon(R.drawable.ic_menu_info_details); |
| 642 | + builder.setSmallIcon(R.drawable.stat_notify_error); |
644 | 643 | builder.setTicker(title); |
645 | 644 | builder.setContentTitle(title); |
646 | 645 | builder.setContentText(body); |
@@ -677,7 +676,7 @@ private void enqueueRestrictedNotification(String tag) { |
677 | 676 |
|
678 | 677 | builder.setOnlyAlertOnce(true); |
679 | 678 | builder.setOngoing(true); |
680 | | - builder.setSmallIcon(R.drawable.ic_menu_info_details); |
| 679 | + builder.setSmallIcon(R.drawable.stat_notify_error); |
681 | 680 | builder.setTicker(title); |
682 | 681 | builder.setContentTitle(title); |
683 | 682 | builder.setContentText(body); |
@@ -750,8 +749,7 @@ private void updateNetworkEnabledLocked() { |
750 | 749 | final long totalBytes = getTotalBytes(policy.template, start, end); |
751 | 750 |
|
752 | 751 | // disable data connection when over limit and not snoozed |
753 | | - final boolean overLimit = policy.limitBytes != LIMIT_DISABLED |
754 | | - && totalBytes > policy.limitBytes && policy.lastSnooze < start; |
| 752 | + final boolean overLimit = policy.isOverLimit(totalBytes) && policy.lastSnooze < start; |
755 | 753 | final boolean enabled = !overLimit; |
756 | 754 |
|
757 | 755 | setNetworkTemplateEnabled(policy.template, enabled); |
@@ -1535,10 +1533,7 @@ private String getActiveSubscriberId() { |
1535 | 1533 |
|
1536 | 1534 | private long getTotalBytes(NetworkTemplate template, long start, long end) { |
1537 | 1535 | try { |
1538 | | - final NetworkStats stats = mNetworkStats.getSummaryForNetwork( |
1539 | | - template, start, end); |
1540 | | - final NetworkStats.Entry entry = stats.getValues(0, null); |
1541 | | - return entry.rxBytes + entry.txBytes; |
| 1536 | + return mNetworkStats.getSummaryForNetwork(template, start, end).getTotalBytes(); |
1542 | 1537 | } catch (RemoteException e) { |
1543 | 1538 | // ignored; service lives in system_server |
1544 | 1539 | return 0; |
|
0 commit comments