Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Incorrect screen time #545

Open
OndrejKulhavy opened this issue Nov 20, 2024 · 8 comments
Open

[BUG]: Incorrect screen time #545

OndrejKulhavy opened this issue Nov 20, 2024 · 8 comments

Comments

@OndrejKulhavy
Copy link

I've noticed that my screen time is unusually high. On 00:01 midnight, I have over an hour of screen time, which doesn't seem logical.

Here's an example from just now: Digital Wellbeing is displaying 55 minutes, which seems realistic, while OLauncher is indicating 3 hours and 12 minutes.

Image 1 Image 2
@HeCodes2Much
Copy link

Screenshot_20241121-000449.png

Ya mine says 7 hours when it's just past midnight.

I think its calculating the past 24 hours not resetting at midnight.

@OndrejKulhavy
Copy link
Author

That's stupid, I guess you are right!

@daaanny90
Copy link

I have the same problem. Samsung galaxy S23 with Android 14

@OndrejKulhavy
Copy link
Author

To be honest, since it probably only counts the last 24 hours, it's a somewhat useless indicator. I'm spending time on my phone, yet the time displayed is either stagnant or decreasing. 💀

@eddex
Copy link

eddex commented Nov 27, 2024

fun getTodaysScreenTime() {
viewModelScope.launch {
val usageStatsManager = appContext.getSystemService(USAGE_STATS_SERVICE) as UsageStatsManager
val calendar = Calendar.getInstance()
calendar.set(Calendar.HOUR_OF_DAY, 0)
calendar.set(Calendar.MINUTE, 0)
calendar.set(Calendar.SECOND, 0)
val usageStats = usageStatsManager.queryUsageStats(
UsageStatsManager.INTERVAL_DAILY,
calendar.timeInMillis,
calendar.timeInMillis + ONE_DAY_IN_MILLIS
)
val totalTimeInMillis = usageStats.sumOf { it.totalTimeInForeground }
val viewTimeSpent = appContext.formattedTimeSpent(totalTimeInMillis)
screenTimeValue.postValue(viewTimeSpent)
}
}

It seems like the intention was to show the screen time from the start of the current day until 24h after. Which seems correct. But there must be a bug somewhere. Might also be time zone related, but that's just a wild guess.

@HeCodes2Much
Copy link

fun getTodaysScreenTime() {
viewModelScope.launch {
val usageStatsManager = appContext.getSystemService(USAGE_STATS_SERVICE) as UsageStatsManager
val calendar = Calendar.getInstance()
calendar.set(Calendar.HOUR_OF_DAY, 0)
calendar.set(Calendar.MINUTE, 0)
calendar.set(Calendar.SECOND, 0)
val usageStats = usageStatsManager.queryUsageStats(
UsageStatsManager.INTERVAL_DAILY,
calendar.timeInMillis,
calendar.timeInMillis + ONE_DAY_IN_MILLIS
)
val totalTimeInMillis = usageStats.sumOf { it.totalTimeInForeground }
val viewTimeSpent = appContext.formattedTimeSpent(totalTimeInMillis)
screenTimeValue.postValue(viewTimeSpent)
}
}

It seems like the intention was to show the screen time from the start of the current day until 24h after. Which seems correct. But there must be a bug somewhere. Might also be time zone related, but that's just a wild guess.

Ya that is how it is meant to work but some reason it doesn't take the current time even changing the 0 for hour to 9 for 9am it still displays the same data so the hour is not affecting anything. I have been playing with that part of the code for 3 days now and can't figure out why the hour isn't effected

@tanujnotes
Copy link
Owner

It has something to do with the UTC timezone but I haven't been able to figure out a solution. The response Android provides for the screen time is all over the place. I tried different screen time apps and they all show different values, although not as wrong as Olauncher. Working on it.

@HeCodes2Much
Copy link

It has something to do with the UTC timezone but I haven't been able to figure out a solution. The response Android provides for the screen time is all over the place. I tried different screen time apps and they all show different values, although not as wrong as Olauncher. Working on it.

Take a look at usageDirect they seem to do a pretty good job with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants