Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e2c0ce03 authored by Robert Greenwalt's avatar Robert Greenwalt
Browse files

Add warning magic to be a bit more reasonable.

Currently warns if you exceed more than 25% and 2*100%*timeUsed/(timeUsed+totalTime)

The formula means that imagining you've got half of the remaining time that you really have,
we will warn you if you would exceed the quota given your rate so far.  It's generous during the
early to mid-life and converges back to the limit as your timeUsed approaches totalTime.

bug:2576057
Change-Id: Id189de5b026f927ef478fd212d61d9e4ab5239e6
parent a18c824c
Loading
Loading
Loading
Loading
+33 −11
Original line number Diff line number Diff line
@@ -421,7 +421,24 @@ public class ThrottleService extends IThrottleManager.Stub {
            } else {
                if ((mPolicyNotificationsAllowedMask & NOTIFICATION_WARNING) != 0) {
                    // check if we should warn about throttle
                    if (currentTotal > (mPolicyThreshold/2) && !mWarningNotificationSent) {
                    // 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);
@@ -431,12 +448,17 @@ public class ThrottleService extends IThrottleManager.Stub {
                                    throttle_warning_notification_message,
                                    com.android.internal.R.drawable.stat_sys_throttle_warning,
                                    0);
                        }
                    } else {
                        if (mWarningNotificationSent == true) {
                            mNotificationManager.cancel(com.android.internal.R.drawable.
                                    stat_sys_throttle_warning);
                            mWarningNotificationSent =false;
                        }
                    }
                }
            }
        }

        private void postNotification(int titleInt, int messageInt, int icon, int flags) {
            Intent intent = new Intent();