Why ForceDoze request super user access
gayanper opened this issue · comments
On rooted phone with Magisk when ever the phone is booted i see the toast notification which says Root permission granted for ForceDoze. Why ForceDoze request root access every time the phone is rebooted ?
Hello,
I quickly looked at the code.
ForceDoze touches essential Android functionalities and root is used for that when available (because it is more straightforward than the non-root workaround -- and maybe more efficient too?). This is hinted in the Readme.
The app asks for root permission each time it starts so it can set the device in idle state each time and as soon as its screen is turned off. See method enterDoze
in class ForceDozeService
: command dumpsys deviceidle force-idle deep
(on Android 7+) or dumpsys deviceidle force-idle
(on Android 6) is ran:
Root is used for other things as well. Let's dig into the code in more details. You may want to look for occurrences of Shell.SU
and useSU
in the repository to see how exactly root is used in throughout the app.
In class MainActivity
, in method onCreate
, a root session is created (which certainly corresponds to your root permission granted notification when your phone boots):
You can see how this root session is used by looking for occurrences of executeCommand
and executeCommandWithRoot
(and actually, this applies quite everywhere throughout the whole code base).
- Android permissions are granted (
DUMP
,READ_PHONE_STATE
,WRITE_SECURE_SETTINGS
): - file permissions of shared preferences are set:
- doze-related device state is changed when the user toggles options (if I understood correctly):
In ForceDozeService
, DozeTunablesActivity
, a root session is used for quite the same purposes. In DozeTunablesActivity
, settings are set. In SettingsActivity
too, and in method resetForceDoze
, Android permission are also revoked.
Now, there is one way to be relatively sure about what the app does without trusting the developers, Google (or F-Droid when it is hosted in F-Droid) and me: review and compile ForceDoze yourself, the code is small and readable :-) (though you will probably have to trust Google anyway for the Android SDK).
Disclaimer: don’t trust me, I did not thoroughly look at the entire code base.
To the developers: thanks!! Battery saving seems quite dramatic on my phone with my usage pattern.