[GUIDE][LP-MM-N][CM-CAF-AOSP] Workaround for "apps with access to usage data" bug!
There are A LOT of (even good) LP/MM ROMs out there that has the "apps with access to usage data" bug (it seems some Nougat too...).
There are two main types of this bug:
- the first, more spreaded on "branded" LP ROMs is that this menu has fully removed from Settings at all (should be inside Security section, as last choice available...). This happened on some old Samsung & LG ROMs if I don't go wrong...
- the second, more spreaded on MM (& N?) "cooked" ROM as CM, AOSPA, RRmx, etc... is that apps reported inside the menu are not the ones eventually needing this security settings introduced with LP, BUT totally RANDOM and, worse, quite ever, the needing ones are missing, limiting this way their complete functionality...
I'm *quite sure* this could be fixed by an Xposed Module but, as of today, I've not find one and nobody seemed able to realize one!
This bug is very discussed on the web, since it limits hardly the functionality of a lot of "technical apps" like many antivirus apps (e.g. Sophos, Malwarebytes...), anti thefts (e.g. Avast...), battery stats (e.g. Accubattery & 3C Battery Stats Pro...), battery savings (e.g. Greenify, Leandroid...), blue filters (e.g. Eyefilter...) and so on...
All these can't fully work or work at all since of the "apps with access to usage data" bug.
Many people at the end decided to switch from good ROMs only since of this bug, because for advanced users this is surely a "major one".
And nobody, as of today, was able to fix/patch it or to find a workaround.
I've so investigated on this with the intention to find at least a workaround for this (a fix/patch requires at least an Xposed module to be realize and this is out of my actual possibilities...).
At first I've found that granting that permission could be done even via adb and/or terminal: having root permissions (I'm talking to advanced users, OK? You have root for sure... ) there is a comand to grant permissions to apps, in this specific case it is:
>pm grant <package_internal_name> android.permission.PACKAGE_USAGE_STATS
This probably should work fine on ROMs where the related settings menu has been removed, BUT on "cooked" ROMs affected by the bugged menu this simply doesn't work: command is accepted with no error BUT... it simply doesn't change anything!
This is interesting for who eventually will investigate on this bug, since it is clear that it is not a "cosmetic" bug related to settings submenu functionality, but it is something more core related since of the commands not working too...
At the end I've found a really *great* app, developed probably for other needs but that I've found it working perfectly as a workaround for this issue too!
The app is App Ops or, better, one of the numerous apps with that name present on Play Store (most of not working at all... ), so you can search it as rikka.appops
Starting first time this app, it asks if you have root or not, to decide how to install it (yes, it seems able to work without root too, but functionality with our needs has to be confirmed), so, after have chosen "root mode" it will scan and show complete app list.
Then you have to go to your limited-since-of-the-bug-app ant tap on it. It will show you a list of the permission of that app and their actual status.
You have to go to get usage stats permission and you will find it indicated as "Default". Tap on it and simply change to "Allow", then exit.
Since now (even without a reboot!) your app will ignore (wrong...) system settings and will work fine as you have granted normally that permission.
I've tested it with a lot of apps and all work fine after this workaround.
I guess this could be useful to *many*!
P.S.: please note that on bugged settings menu nothing will change... but, who minds!