Enhanced Statistics for Android Pie and Later

Android continues to throw wrenches into how GSam Battery Monitor gathers statistics.  That said, the changes are for the most part good from a security perspective, and Google has made it possible to continue to access much of the data - it just requires some re-work.

Standard vs Enhanced Stats

Standard:  For standard statistics (what you get if you don't run any ADB commands), GSam tracks things like bluetooth, phone, network, and screen usage using standard Android interfaces.  These all require GSam to be running at all times as a service in the background.  GSam is pretty efficient, so should have negligible impact on the battery.

Enhanced:  In enhanced mode, the user needs to provide GSam with access to the BATTERY_STATS permission.  This allows GSam to access a wealth of data that Android collects.  In KitKat, Android removed the ability for apps to request access to this permission.  However in Lollipop and beyond, they partially restored the ability by allowing the user to explicitly grant an app access via ADB.  This requires the user to connect their phone to a computer, install ADB, and run a command.  Doing so is worth the effort in terms of the stats you get, however I don't expect most users to do this!

Enhanced Changes in Android P

As of GSam version 3.39, GSam will use a combination of Standard and Enhanced mode to gather statistics.  That is, for system wide stats, it uses the Standard mode, and for App specific stats (visible in the App Sucker screens), GSam will use the Enhanced mode.

The reason for this is complex.  
  1. Google requires all apps to have a Target SDK version of n or n-1 in order to publish an update to the Play Store.  In other words, if the latest version of Android is Q, you must have a target SDK version of P or later.  This means that Version 3.39 of GSam requires updating the Target SDK to P.  Doing so has consequences.
  2. Android has started restricting access to non-public interfaces.  Unfortunately, GSam relies heavily on non-public interfaces and a technique called reflection.  Android allowed older apps to continue to access the APIs so as not to break things, but any updated app must conform to the new rules.  This all makes good sense - it just breaks GSam :).
Fortunately, Android is providing a similar level of access to battery statistics for applications via the HealthStats API.  So GSam 3.39 is written to take advantage of these formal interfaces for access to all app specific statistics.  These still require access to the BATTERY_STATS permission, but otherwise provide (almost) the same level of detail (see below for limitations and workaround).

Limitations For Enhanced Stats in P and Later (see below for workaround)

System Wide Stats:
  1. Screen Brightness Levels:  We don't track this due to the performance impact tracking it would have (the brightness changes too often).
  2. Phone Radio Signal Levels:  We don't track this for the same reason we don't track screen brightness.
Application Stats (under App Usage / App Sucker):
  1. Multiple Profiles - such as personal vs work profile:  Android has the ability to have multiple profiles.  Often your work apps are running in a work profile separately from those apps in your personal profile.  You'll likely notice you may have to install the same app in both profiles.  For security reasons, GSam can't gather information on applications running outside of the profile in which it's running for security reasons.  So - if you need details on the app usage in your work profile, you'll need to install another instance of GSam in your work profile.  Yes, this is a pretty big limitation if you have work profiles (fortunately most users don't) - see below for a workaround.
  2. CPU Stepping:  The power that the CPU uses can't be determined quite as accurately.  Previously, GSam would look at how much time the app spent running at different CPU frequencies (which all draw different levels of power).  Now, we have to collapse all the frequencies into one bucket and average them out.
  3. Kernel Wakelocks:  There is no longer a way to gather kernel wakelocks.  

Workaround - Restore Full Enhanced Stats

Fortunately, it IS possible to restore fully enhanced stats, even on P and Q by allowing GSam to access what Android has deemed hidden apis.  It requires running another ADB command, and more importantly, is not specific to GSam.  In short, it not only allows GSam to access hidden APIs, but allows ANY app to access the hidden APIs.

Is this a security concern?  Yes - sort of.  That said, older apps can still access these APIs, but it is something Google is trying to ween people from.   From a security perspective, it allows GSam to access statistics on apps that are outside of its profile.

On Android Q and later, run the following ADB command:

adb shell settings put global hidden_api_policy 1

On Android P, run the following ADB command:
adb shell settings put global hidden_api_policy_p_apps 1

Finally, restart GSam (force close it).


  1. Is that setting persistent? Do the hidden APIs remain enabled after a reboot?

  2. I used the adb command to allow global access ( adb shell settings put global hidden_api_policy 1 ) and changed my mind. How do I revoke that permission?

    1. Just put this adb command:

      adb shell settings put global hidden_api_policy 0

      You can test it by this:

      adb shell settings get global hidden_api_policy

  3. I get permission denial... Why?

  4. I got permission denial on both commands. Android 10 on Realme X2 Pro.

    1. The same thing with Realme 5 pro on Android 10

    2. C:\Program Files (x86)\Minimal ADB and Fastboot>adb shell pm grant com.gsamlabs.bbm android.permission.BATTERY_STATS
      Security exception: grantRuntimePermission: Neither user 2000 nor current process has android.permission.GRANT_RUNTIME_PERMISSIONS.

      java.lang.SecurityException: grantRuntimePermission: Neither user 2000 nor current process has android.permission.GRANT_RUNTIME_PERMISSIONS.

    3. C:\Program Files (x86)\Minimal ADB and Fastboot>adb shell settings put global hidden_api_policy 1
      Security exception: Permission denial: writing to settings requires:android.permission.WRITE_SECURE_SETTINGS

      java.lang.SecurityException: Permission denial: writing to settings requires:android.permission.WRITE_SECURE_SETTINGS

    4. I'm using realme XT, you need to enable one more option in dev. Options. Disable permission monitoring. Just scroll down to bottom, you should find it down there. Then re-run the command in adb, it should work now.

    5. I have a Poco X3 and I needed enable one more option in dev options (it wasn't disable permission monitoring on my phone) called [USB debugging (Security settings)]

  5. Great app but I have a question. What is the advantage of running the command "adb shell settings put global hidden_api_policy 1"? More detailed statistics? Of course I have run the command "adb shell pm grant com.gsamlabs.bbm.pro android.permission.BATTERY_STATS".

  6. I read the whole post and this is related to an amazing niche. Now you can book flight from Delta Airlines Official Site easily.

  7. The content is well optimized and now you can book online tickets for the SAS Airlines Reservations at Fares Match.

  8. I like the whole post and this is very well written. According to me Virgin Australia Reservations is ideal to make sure travel goals.

  9. I am dam sure this content is really good because of the knowledge of author. Now you can also move your saving towards big saving by choosing the Allegiant Airlines Reservations.

  10. Anyone know how to fix the Video On wakelock? I have to restart my phone everyday to get rid of it and it's happening to many different apps.

  11. Has anyone gotten this to work on a Pixel 5? I just got my phone, and I'm trying to see if I can live without root.

  12. Hi, there seem to be other methods to deal with hidden_api_policy


    With so much in my heart I am here to express myself on how Dr. JUMBA saved my marriage from divorce. Myself and my husband were having some misunderstanding and it was tearing our marriage apart to the extent my husband was seeking a divorce. So I have no option than to go to the internet to seek for solution to my problem. It was there I came across Dr. JUMBA details and about how he has helped a lot of people by restoring their relationship. I contacted Dr. JUMBA and in less than 48 hours my husband cancelled the divorce papers. Now myself and my husband live together in peace and harmony all thanks to Dr .JUMBA for saving my marriage from breaking up. Dr. JUMBA contact information is via email: Wiccalovespelltools@gmail.com or call his phone number or WhatsApp: +19085174108 .or check out his website : https://drjumbaspellhome.wordpress.com    

  14. Wow this blog is very nice …
    What is a Monitor? A monitor is called a device through which users can communicate with the computer by receiving data. It went through various stages from its birth, continuously evolving and offering new improvements, until it reached the modern led technology of today

  15. Many men and women struggle with drug and alcohol use boca rehabilitation clinic along with mental illness. In 2018, an estimated 9.2 million people in the U.S. struggled with co-occurring disorders like this, according to the Substance Abuse and mental Health Services Administration.

  16. is alcoholism hereditary reddit is a hallucinogenic drug. This means that when consumed, it causes the user to have unusual experiences such as hearing sounds, seeing illusions, and feeling things that are not actually there. A drug with an extensive history of both medicinal and recreational use, LSD use does not come without risks. An acid trip can last 12 hours or more, and when it goes wrong it can go terribly wrong. This substance is common at raves, parties, and music festivals, so knowing what acid looks like and understanding the risks is imperative, especially for young adults and teenagers.

  17. The We Level Up FL restoril withdrawal timeline emotional wellness community is an exceptionally particular, present day, forward-thinking office giving imaginative conduct recuperation treatment programs. Treatments happen in a serene manicured setting with open air unwinding regions offering restoration spaces. Giving science-based psychological wellness medicines intended for every customer and conveyed through profoundly customized individual consideration.

  18. The california detox treatment center stage is the initial phase in treating liquor addiction. Withdrawal indications normally die down inside around one to about fourteen days subsequent to beginning detox; be that as it may, this could take longer relying upon the seriousness of your Alcohol Use Disorder (AUD). From that point, you will actually want to zero in on different parts of the recuperation cycle, like various exercises, treatments, advising meetings, and backing choices.

  19. The CBD Gummies for Tinnitus is an independent audiological practice specializing in tinnitus treatment and management, and providing hearing aid consultations and fitting. The Tinnitus Clinic leads the way in bespoke treatment and packages, including our own evidence-based Tinnitus Desensitisation Therapy (TDT).
    Cheack Out For More Details: https://www.ecosia.org/search?q=cbd%20gummies%20tinnitus%20

  20. Hello friends, its great post about tutoring and completely defined, keep it up all the time. 토토사이트

  21. Great delivery. Outstanding arguments. Keep up the amazing effort. 온라인경마

  22. I think this is among the most vital info for me.
    And i am glad reading your article. But wanna remark on few general things,
    The website style is great, the articles is really excellent 바카라

  23. Interesting post. I Have Been wondering about this issue, so thanks for posting. Pretty cool post. It’s really very nice and Useful post 토토사이트


Post a Comment

Popular posts from this blog

GSam Battery Monitor - Users Guide

Support for Kernel Wakelocks