asksven / BetterBatteryStats

An attempt to provide advanced battery stats for Android
623 stars 156 forks source link

BBS grants all apps access to hidden APIs, not just itself #891

Open djpohly opened 2 years ago

djpohly commented 2 years ago

BBS runs the following command to enable hidden APIs on rooted devices:

settings put global hidden_api_policy 1

which grants every app on the system access to hidden APIs.

A tighter approach, which could be done with a Magisk helper module, is to place a copy or stub of BBS in /system/app and add a file to /system/etc/sysconfig:

<?xml version="1.0" encoding="utf-8"?>
<config>
  <hidden-api-whitelisted-app package="com.asksven.betterbatterystats" />
  <hidden-api-whitelisted-app package="com.asksven.betterbatterystats_xdaedition" />
</config>

(The stub is needed because the sysconfig whitelist only applies to system apps.)

I've tested this on an AOSP12-based phone and am able to get full stats without setting the systemwide policy.

djpohly commented 2 years ago

See module here: https://github.com/djpohly/magisk-bbs-hidden-apis.

asksven commented 2 years ago

This is pretty neat! BBS used to have a feature to install itself as a system app (for rooted devices) so I guess I will try to re-instate this.

djpohly commented 2 years ago

I remember those days!

You're welcome to adapt whatever you want of the module into the BBS repo if you'd like to make it an official feature. I don't know what is the most convenient way for an app to package a Magisk module, but I do see a magisk --install-module FILE.zip shell command that might be useful.

furopi commented 2 years ago

See module here: https://github.com/djpohly/magisk-bbs-hidden-apis.

Great work, ty! 😀

xxtecraxx commented 2 years ago

See module here: https://github.com/djpohly/magisk-bbs-hidden-apis.

forgive my ignorance but do we install this from magisk as a module?

just installed BBS on rooted cheetah p7p

djpohly commented 2 years ago

@xxtecraxx Yes, it's a Magisk module that specifically adds BBS to the list of apps allowed to use hidden APIs, as opposed to disabling the restriction globally (which grants access for all system apps). You can download the ZIP on the releases page and install it via Magisk Manager.

xxtecraxx commented 2 years ago

@djpohly thank you for rapid response!