Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Uptime is always 0 on Android 11 #158

Closed
Un1q32 opened this issue Sep 25, 2021 · 12 comments
Closed

Uptime is always 0 on Android 11 #158

Un1q32 opened this issue Sep 25, 2021 · 12 comments
Labels
bug Something isn't working

Comments

@Un1q32
Copy link

Un1q32 commented Sep 25, 2021

Tested on a Samsung Galaxy s10e through termux (not rooted)

@dylanaraps dylanaraps added the bug Something isn't working label Sep 25, 2021
@dylanaraps
Copy link
Owner

Does /proc/uptime exist?

@Un1q32
Copy link
Author

Un1q32 commented Sep 25, 2021

Does /proc/uptime exist?

Yes but it can't be accessed. I've since tested this on a rooted device and the uptime displays properly, so I guess root is required to read that file.

@ghost
Copy link

ghost commented Sep 27, 2021

Seems to be an issue with android's tighter permission control with the newer versions.
However, uptime in Termux still seems to work so you could use that to fix the issue.

Why does htop or netstat not work on my device

In order to stop leaking sensitive information via side channels, Android has blocked access to certain interfaces in /proc. This is done for your privacy.

Specifically:

/proc/net/*
/proc/loadavg
/proc/stat
/proc/uptime
/proc/version
/proc/vmstat
And few others.

Restrictions vary between Android OS versions. Thus Android 7 is less restrictive than 8/9/10+. You can use root to bypass them.

Do not open issues in our repositories on this or complain how Google is evil. We do not support such opinion or other Android-specific conspiracy.

from Termux FAQ

@ghost
Copy link

ghost commented Sep 27, 2021

I made a quick fix by treating Android as a different OS and using uptime to get the information.
This made me use a lot of awks and greps which I don't know how to avoid while being practical.
For now you can use this patch file and patch pfetch using patch -Np1 -i path/to/patch_file.txt
in the directory where pfetch resides.
fix_android_uptime.txt

EDIT: I have not tested this that much.

@dylanaraps
Copy link
Owner

Send me example output from the uptime command.

@ghost
Copy link

ghost commented Sep 27, 2021

u0_a0@localhost
os     Android 4.14.190-214423334
host   aarch64
kernel 4.14.190-21442333-abSCV414
uptime 24d 13h 23m
memory 4398M / 7459M

I guess changing the os variable could cause some issues with
other information. I only made this patch with the default settings
in mind.

@dylanaraps
Copy link
Owner

I meant output from uptime verbatim. Apologies.

@ghost
Copy link

ghost commented Sep 28, 2021

I meant output from uptime verbatim. Apologies.

I'm dumb...
Anyway, it should be the exact same as how Linux would output it.

 14:44:55 up 25 days, 8:29, load average: 0.00, 0.00, 0.00

@sweatymachete
Copy link

neofetch works, so i just ripped its code. comment out line 372 (in the get_uptime function under case Linux) and then put

# IFS=. read -r s _ < /proc/uptime
boot=$(date -d"$(uptime -s)" +%s)
now=$(date +%s)
s=$((now - boot))

@Un1q32
Copy link
Author

Un1q32 commented Aug 7, 2022

@sweatymachete lmao thats exactly what i did in my pfetch fork. I just check if /proc/uptime has read permission and if not i do that instead of the normal method.

@Un1q32
Copy link
Author

Un1q32 commented Aug 7, 2022

closing this now cuz the repo seems unmaintained

@Un1q32 Un1q32 closed this as completed Aug 7, 2022
@Un1q32
Copy link
Author

Un1q32 commented Aug 7, 2022

@sweatymachete heres the full code if you're interested

if ! [ -r /proc/uptime ] || [ "$PF_FORCEALTUPTIME" -eq 1 ]; then
    boot=$(date -d"$(uptime -s)" +%s)
    now=$(date +%s)
    s=$((now - boot))
else
    IFS=. read -r s _ < /proc/uptime
fi

polluks added a commit to polluks2/pfetch that referenced this issue Aug 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants