diff options
| author | 2010-04-09 16:47:10 -0700 | |
|---|---|---|
| committer | 2010-04-09 16:47:10 -0700 | |
| commit | 5cc072522b51f796085a73545a3dd34a02877059 (patch) | |
| tree | 4f158c8c35e3022db5209e75ac8812f48f40ae90 | |
| parent | 15b02f04c7b5e895dd8ebbb9448863a7d608b00f (diff) | |
| parent | e2c0ce03631fc81651b8bde578e993c25e3291e9 (diff) | |
Merge "Add warning magic to be a bit more reasonable." into froyo
| -rw-r--r-- | services/java/com/android/server/ThrottleService.java | 44 |
1 files changed, 33 insertions, 11 deletions
diff --git a/services/java/com/android/server/ThrottleService.java b/services/java/com/android/server/ThrottleService.java index 2fc9249e8e4a..9d4e2263b902 100644 --- a/services/java/com/android/server/ThrottleService.java +++ b/services/java/com/android/server/ThrottleService.java @@ -421,18 +421,40 @@ public class ThrottleService extends IThrottleManager.Stub { } else { if ((mPolicyNotificationsAllowedMask & NOTIFICATION_WARNING) != 0) { // check if we should warn about throttle - if (currentTotal > (mPolicyThreshold/2) && !mWarningNotificationSent) { - mWarningNotificationSent = true; - mNotificationManager.cancel(com.android.internal.R.drawable. - stat_sys_throttle_warning); - postNotification(com.android.internal.R.string. - throttle_warning_notification_title, - com.android.internal.R.string. - throttle_warning_notification_message, - com.android.internal.R.drawable.stat_sys_throttle_warning, - 0); + // pretend we only have 1/2 the time remaining that we actually do + // if our burn rate in the period so far would have us exceed the limit + // in that 1/2 window, warn the user. + // this gets more generous in the early to middle period and converges back + // to the limit as we move toward the period end. + + // adding another factor - it must be greater than the total cap/4 + // else we may get false alarms very early in the period.. in the first + // tenth of a percent of the period if we used more than a tenth of a percent + // of the cap we'd get a warning and that's not desired. + long start = mRecorder.getPeriodStart(); + long end = mRecorder.getPeriodEnd(); + long periodLength = end - start; + long now = System.currentTimeMillis(); + long timeUsed = now - start; + long warningThreshold = 2*mPolicyThreshold*timeUsed/(timeUsed+periodLength); + if ((currentTotal > warningThreshold) && (currentTotal > mPolicyThreshold/4)) { + if (mWarningNotificationSent == false) { + mWarningNotificationSent = true; + mNotificationManager.cancel(com.android.internal.R.drawable. + stat_sys_throttle_warning); + postNotification(com.android.internal.R.string. + throttle_warning_notification_title, + com.android.internal.R.string. + throttle_warning_notification_message, + com.android.internal.R.drawable.stat_sys_throttle_warning, + 0); + } } else { - mWarningNotificationSent =false; + if (mWarningNotificationSent == true) { + mNotificationManager.cancel(com.android.internal.R.drawable. + stat_sys_throttle_warning); + mWarningNotificationSent =false; + } } } } |