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).

Comments

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

    ReplyDelete
  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?

    ReplyDelete
    Replies
    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

      Delete
  3. I get permission denial... Why?

    ReplyDelete
    Replies
    1. In other words, if the latest version of Android is Q, you must have a target SDK version of P or later.
      home remodeling pros home contractor Bonton

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

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

      Delete
    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.

      Delete
    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

      Delete
    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.

      Delete
    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)]

      Delete
  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".

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

    ReplyDelete
  7. 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.

    ReplyDelete
  8. 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.

    ReplyDelete
  9. 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.

    ReplyDelete
  10. Hi, there seem to be other methods to deal with hidden_api_policy
    https://stackoverflow.com/questions/55970137/bypass-androids-hidden-api-restrictions

    ReplyDelete
  11. 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.

    ReplyDelete
  12. 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.

    ReplyDelete
  13. 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.

    ReplyDelete
  14. 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

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

    ReplyDelete
  16. 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 바카라

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

    ReplyDelete
  18. I read the whole post and this is related to an amazing niche home remodeling near me dallas tx

    ReplyDelete
  19. Great delivery. Outstanding arguments. Keep up the amazing effort Radon Mitigation services in San Antonio Texas

    ReplyDelete
  20. 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. Crack Repair

    ReplyDelete
  21. I currently in need of a handicap ramp in our house. However in Lollipop and beyond, they partially restored the ability by allowing the user to explicitly grant an app access via ADB.

    ReplyDelete
  22. Glad to visit this site, I like the information you shard here. Appliance Pros of Kitchener

    ReplyDelete
  23. Thank you for keeping us here posted with new blogs. https://usimmivisa.com/

    ReplyDelete
  24. Very much appreciated. Thank you for this excellent article. Keep posting!

    ReplyDelete
  25. Good job! I am truly proud for the best article sharing for the best information that are experts Custom Drywall

    ReplyDelete
  26. In order to avoid breaking anything, Android permitted existing apps to continue using the APIs, but any upgraded apps had to follow the new guidelines. Checkout retaining walls dallas

    ReplyDelete
  27. These enhanced statistics features can help developers to build better apps that are optimized for performance, battery life, and user engagement.

    ReplyDelete
  28. It is important to note that restoring fully enhanced stats on P and Q by allowing GSam to access hidden APIs may pose a security concern, as it allows not only GSam but any app to access these hidden APIs. However, older apps can still access these APIs, and Google is trying to encourage developers to use formal interfaces such as the HealthStats API instead of relying on non-public interfaces. It is worth considering the potential security implications before using this workaround. cincinnatiseo.org/

    ReplyDelete
  29. Thank you for sharing this article! fridge repair

    ReplyDelete
  30. It seems that GSam Battery Monitor, an app for Android devices, has faced some challenges in gathering battery statistics due to changes made by Android. However, the changes made are considered beneficial for security purposes. Despite this, Google has provided a way for users to access the necessary data, although it may require some adjustments.

    ReplyDelete
  31. Thanks for sharing such a useful information. It is very helpful article. Very informative blog.

    Tree Service In Savannah

    ReplyDelete
  32. "Thank you very much for this wonderful topic!
    "
    Tree Service Broken Arrow

    ReplyDelete
  33. For security reasons, GSam can't gather information on applications of fixing walls running outside of the profile in which it's running for security reasons.

    ReplyDelete
  34. "Such an awesome post. Thanks for sharing!
    "
    Edmonton Accountants

    ReplyDelete
  35. As technology and operating systems continue to evolve, app developers like GSam Battery Monitor may need to adapt their approaches to comply with changing rules and restrictions while still providing valuable functionality to their users. home

    ReplyDelete
  36. Their meticulous research and inclusion of relevant data and examples added credibility and depth to the piece, while their friendly tone created an inviting atmosphere that encouraged me to delve deeper into the topic and explore its intricacies further.

    https://beardcareshop.com/

    ReplyDelete
  37. Your content is a breath of fresh air. It's thought-provoking and offers a new perspective.
    driveway sealing indianapolis

    ReplyDelete
  38. The topic is highly informative. Well done on sharing it.
    https://plasticsurgerysacramento.net

    ReplyDelete
  39. While I am not sure I agree with the author's conclusion, I appreciate their willingness to challenge my thinking.

    benchmarkgensuite.com

    ReplyDelete
  40. Thanks for sharing this interesting blog here
    Plastic Surgery Fresno CA

    ReplyDelete
  41. Thank you for sharing this post! Professionals should install resin pavement to guarantee correct preparation and application. Best Resin Driveways in Edinburgh

    ReplyDelete
  42. Great insights into the enhanced statistics for Android Pie and later! It's impressive to see how technology continues to evolve. I appreciate the detailed explanation of the new features. On a related note, I wonder how these enhancements might impact battery life. Looking forward to more updates in the Android ecosystem!

    By the way, for those facing challenges in managing their business appliances, I found a helpful resource for appliance repair services https://installationandrepairs.com/. It's crucial to ensure all aspects of your business are running smoothly, and this article has motivated me to optimize not only my advertising strategy but also the operational efficiency of my business. Kudos to the author for sharing such valuable and actionable insights!

    ReplyDelete
  43. Great insights into the enhanced statistics for Android Pie and later! It's impressive to see how technology continues to evolve. I appreciate the detailed explanation of the new features. On a related note, I wonder how these enhancements might impact battery life. Looking forward to more updates in the Android ecosystem!

    ReplyDelete
  44. It requires running another ADB command, and more importantly, is not specific to GSam.
    - bathroom installation quotes DFW Bath & Kitchen

    ReplyDelete

  45. Thank you for providing us with this blog; it's truly valuable, informative, and amazing.
    Visit the Criminal Lawyer in Edmonton website

    ReplyDelete
  46. Cool! This is a very detailed content. Thanks for sharing. https://www.dialanapplianceman.com/

    ReplyDelete
  47. Hello. Fantastic app, I have purchased your professional version, as when I had a rooted phone it worked perfectly! However I moved to a no rooted phone for security reasons, and now whenever I grant BATTERY_STATS permissions through ADB, both your app's statistics mess up, all showing "Drain Type Name" for all categories, and "Used%1$%% in %2$s" at the top, and if I click on a category it shows " NaN% of battery consumed by" with no data.

    It also sometimes right after granting this permission makes it so all data disappears from the Battery Usage screen in Settings. Reading posts on Reddit, I am not the only user with this error. Thought you would like to know about it, and I certainty would love a fix, this is one of my favorite apps! Thanks you SL much!

    ReplyDelete
  48. Empowering GSam with full access revives detailed stats on all apps, transcending security boundaries. Balancing access while evolving is crucial for app efficiency and user insights. #AndroidSecurity" Feel free to visit Our Website
    Criminal Lawyer in Edmonton

    ReplyDelete
  49. It's a great site to visit, nice content indeed. Dalton Digital ad agency

    ReplyDelete
  50. The provided text explains the challenges and changes faced by GSam Battery Monitor in gathering statistics on Android devices, particularly with the introduction of Android P and later versions. cincinnatiseo.org/

    ReplyDelete
  51. Awesome post! It's nice seeing this info here.

    ReplyDelete
  52. It's always exciting to see how developers overcome technical challenges and adapt to changing landscapes. I'm sure many GSam users would be interested in your insights and the future of their favorite battery monitoring tool.

    ReplyDelete
  53. Your blog's insights are invaluable! Discover our residential mailbox builders in Logan services for quality craftsmanship

    ReplyDelete
  54. The evolving Android ecosystem presents challenges for app developers like GSam Battery Monitor, requiring adaptation to new restrictions while ensuring access to essential data for users. Balancing security concerns with functionality remains a key consideration in navigating these changes. meet the team




    ReplyDelete
  55. Thank you for sharing the post, Great One!
    https://criminallawyerinedmonton.com/driving-traffic-offences-lawyers-edmonton

    ReplyDelete
  56. A very helpful and concise article. It made a complex topic easy to understand.
    NEBOSH Courses

    ReplyDelete
  57. I got permission denial on both commands. Can you help?

    Regards,
    Best fence contractor in Atlanta

    ReplyDelete
  58. Unlocking hidden APIs for enhanced stats raises security concerns but restores full functionality for apps like GSam. Proceed with caution. Real Estate Lawyer edmonton

    ReplyDelete

Post a Comment

Popular posts from this blog

GSam Battery Monitor - Users Guide

Support for Kernel Wakelocks