itsdrnoob / DataMonitor

Data usage monitoring app for android.
GNU General Public License v3.0
528 stars 49 forks source link

Incorrect data rollover computation in Smart Data Allocation #238

Open lfos opened 3 months ago

lfos commented 3 months ago

Checklist

Affected app version

v2.4.0

Steps to reproduce the bug

Expected behavior

Data gracefully rolls over at the end of day, keeping daily quota always below remaining data left.

Actual behavior

Daily quota seems to grow much more than expected, after a few days even exceeding total available data on plan.

Screenshots/Screen recordings

Screenshot_20240401-141743~2

Logs

No response

Affected Android/Custom ROM version

Android 14

Affected device model

Pixel 7

Additional context

Let me know if there's more information that'd be useful to have for troubleshooting.

lfos commented 3 months ago

Next day after the screenshot in the original report was taken, and daily quota is now at 19.6GB. Note that this is rougly a doubling from yesterday's quota. Could there be a bug where the current quota is accidentally added to the daily rollover?

lfos commented 3 months ago

Next day after the screenshot in the original report was taken, and daily quota is now at 19.6GB. Note that this is rougly a doubling from yesterday's quota. Could there be a bug where the current quota is accidentally added to the daily rollover?

Looking at the code, this guess seems to be correct; new quota is currently computed as 2 * dailyQuota - dataUsage in DataRolloverHelper, leading to the observed exponential quota growth. One way to address this is to separate "original" daily quota and current rollover amount:

  1. Original daily quota is computed once, when Smart Data Allocation is enabled, and never modified (unless the plan or Smart Data Allocation settings are changed). Computation spreads available data evenly across remaining days; optionally with the enhancement proposed in issue #235.
  2. At the end of a day, new rollover amount is computed as current rollover amount + original daily quota - daily data usage.
  3. Actual (displayed and enforced) daily quota is original daily quota + current rollover amount.

As a bonus, with these changes issue #236 becomes quite simple to implement: After adding the option, all that's needed is to omit addition of current rollover amount in step 3 above.

itsdrnoob commented 3 months ago

@lfos Thanks for your input. Indeed, this particular behaviour seems to be caused due to the rollover of the remaining data entirely to the following day, causing a large accumulation over time. New quota is currently calculated by adding / subtracting the remaining / excess data as per the use case. Will have to implement some checks in place to fix the behaviour. Thanks again for suggestion.

lfos commented 3 months ago

@itsdrnoob - Thanks! A small nit: Rollover of the entierty of remaining data does not seem to be the issue. The problem is that DataMonitor "forgets" what the proper quota of the "next day" should be, and assumes it's the same as the current day's quota (which includes "original quota" and rollover, thus doubling the rollover amount). Thus the proposal above to keep track of both "original quota" and rollover amount separately.