ForceDoze icon indicating copy to clipboard operation
ForceDoze copied to clipboard

Why ForceDoze request super user access

Open gayanper opened this issue 7 years ago • 1 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 ?

gayanper avatar Mar 08 '18 15:03 gayanper

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: https://github.com/theblixguy/ForceDoze/blob/cda4db52ac133bd2a87102425db9175cb1dd2e7b/app/src/main/java/com/suyashsrijan/forcedoze/ForceDozeService.java#L326

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): https://github.com/theblixguy/ForceDoze/blob/5b21edd687f7e117e3cd79fdee9004c9c5ac8f08/app/src/main/java/com/suyashsrijan/forcedoze/MainActivity.java#L129

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): https://github.com/theblixguy/ForceDoze/blob/5b21edd687f7e117e3cd79fdee9004c9c5ac8f08/app/src/main/java/com/suyashsrijan/forcedoze/MainActivity.java#L151
  • file permissions of shared preferences are set: https://github.com/theblixguy/ForceDoze/blob/5b21edd687f7e117e3cd79fdee9004c9c5ac8f08/app/src/main/java/com/suyashsrijan/forcedoze/MainActivity.java#L272
  • doze-related device state is changed when the user toggles options (if I understood correctly): https://github.com/theblixguy/ForceDoze/blob/5b21edd687f7e117e3cd79fdee9004c9c5ac8f08/app/src/main/java/com/suyashsrijan/forcedoze/MainActivity.java#L412

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. https://github.com/theblixguy/ForceDoze/blob/380a68c0028de3549cae5bd569429984169be0fa/app/src/main/java/com/suyashsrijan/forcedoze/SettingsActivity.java#L382

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.

raphj avatar Jun 29 '18 08:06 raphj