Loading...
Home
  • Tech Blogs
  • Videos
  • Conferences
    • Droidcon News
    • Upcoming Conferences
    • Become a Partner
    • Past Events
    • Keep Me Informed
    • Diversity Scholarships
  • Community
    • droidcon Team
    • How to Hold a Droidcon
  • Android Careers
Sign In

Global CSS

 

Thermal in Android

 

 
Husayn Hakeem
Android Engineer @ Google
Published: September 03, 2020
Tweet
Share
 

 

Android Q introduced new thermal APIs to allow better handling of thermal issues. This article goes over why these APIs were needed, the information and controls they provide, and how you can test your app under different thermal stress levels.

 

The need for thermal APIs

An Android device undergoes thermal stress when the amount of heat it’s generating is greater than what it’s able to dissipate (get rid of). This causes the device’s surface to overheat. It may also throttle the CPU/GPU and can cause display jank, audio jitter and other side effects which heavily depend on the device and its hardware. As a result, new thermal APIs were introduced in Android Q to allow app developers to better react to and handle thermal issues.

 

Understanding thermal severity levels

Instead of providing actual device temperature values which wouldn’t be very indicative of whether the device is undergoing thermal issues, the Android thermal APIs introduced the concept of thermal severity levels, which are based on status codes, and are defined in the PowerManager class. Below are examples of how one might react to each of them to maintain a good user experience.

 

Thermal status codes

 

As the thermal severity level increases, an app should disable -optional- power-consuming features, such as reducing the resolution/bit rate on a video streaming app, disabling intensive image enhancement features on a camera app, and disabling GPS on a maps app. This will help lower power usage and potentially restore the device back to its normal temperature.

 

Receiving thermal notifications

To receive thermal status updates, the Android thermal APIs provide the following callback and polling methods through the PowerManager class.

  • getCurrentThermalStatus() returns the current thermal status of the device.
  • addThermalStatusListener() adds a listener that’s notified of thermal status changes.
  • removeThermalStatusListener() removes a previously added listener.

An app can choose to register a thermal status listener once it’s resumed, and unregister it when it’s paused. This would allow it to receive updates as long as it’s foregrounded.

Note that these thermal APIs were introduced with a redesigned thermal HAL, Thermal HAL 2.0. It provides thermal signals to the Android framework’s thermal Service, IThermalService, which then passes them to its clients, which include Android apps.

 

Image for post

The flow of thermal signals

 

The fact that the thermal APIs depend on Thermal HAL 2.0 means that not all devices running Android 10 or later will support them. At the time of their release, the thermal APIs were supported on Pixel devices.

 

Testing thermal levels

To see how your app reacts to thermal status changes, you can test its behavior using the command line with the following.

 

Set the device’s thermal status

 

STATUS represents the thermal severity status, it’s an integer between 0 (THERMAL_STATUS_NONE) and 6 (THERMAL_STATUS_SHUTDOWN).

When you’re done testing, you can reset the thermal status back to its normal value using the following command.

 

Reset the device’s thermal status

 

Sample code

The following sample app showcases how to register for updates of the device’s thermal severity level, and keep the user aware of them using a foreground service.

 

husaynhakeem/android-playground

Android sample app to learn about the thermal API in Android. The app allows to register a thermal status listener on…

github.com

 

Conclusion

In summary:

  • The thermal APIs introduced in Android Q expose the severity of the device’s thermal stress.
  • Use getCurrentThermalStatus() to poll for the device’s thermal status.
  • Register a thermal status listener to continually receive updates on the device’s thermal status using addThermalStatusListener().
  • Simulate different thermal severity levels using the command line to test how your app reacts to them.

Want to learn more about Android thermal APIs? Check out these resources:

  • Thermal mitigation
  • Keeping cool in Android Q with the Thermal API

For more on Android, follow me to get notified when I write new posts or let’s connect on Github and Twitter!

 

 

 

Tags: Android, Android App Development, AndroidDev, Programming, Android Optimisation

 

View original article at: 


 

Originally published: August 27, 2020

Android News
Our Engineering Roadmap
Our Engineering Roadmap

By Mark Ng

We just completed our engineering road map for our Android apps at Australia Post. Each year we get together and try to decide on what we are going to do from an engineering perspective for the next 12 months. Each team gets to decide on what should be done now, what they want to complete by the end of the year and whats on the horizon for next year.

By ProAndroidDev -
Android News
Android Activity Lifecycle considered harmful
Android Activity Lifecycle considered harmful

By Eric Silverberg

The Android activity lifecycle is one of the first architectural concepts learned by a new Android developer. Ask any Android dev and they’ll likely all have seen this handy diagram from Google: 

By ProAndroidDev -
Android News
Our Safe Approach to Android Jetpack Navigation in a Multi-Modular App
Our Safe Approach to Android Jetpack Navigation in a Multi-Modular App

By Alejandro Weichandt

It has been a year since we started working on the Android version of the mobile app at Sync. During that year, we faced more than once that moment when we had to choose which path to follow on an Architectural decision. This story is about Navigation.

By ProAndroidDev -
Android News
Custom KotlinX Serializers
Custom KotlinX Serializers

By Jobin Lawrance

Let’s say we have a third-party class that we are using as a type in one of our data class that we want to be serialized, then we have to write a custom serializable for @Serializable to work.

 

By ProAndroidDev -
droidcon News

Tech Showcases,

Developer Resources &

Partners

/portal/rest/jcr/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/home-details/EmployerBrandingHeader
EmployerBrandingHeader
https://jobs.droidcon.com/
/portal/rest/jcr/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/employerbranding/jobs-droidcon/jobs.droidcon.com
jobs.droidcon.com

Latest Android Jobs

http://www.kotlinweekly.net/
/portal/rest/jcr/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/employerbranding/kotlin-weekly/Kotlin Weekly
Kotlin Weekly

Your weekly dose of Kotlin

https://proandroiddev.com/
/portal/rest/jcr/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/employerbranding/pad/ProAndroidDev
ProAndroidDev

Android Tech Blogs, Case Studies and Step-by-Step Coding

/detail?content-id=/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/employerbranding/Zalando/Zalando
/portal/rest/jcr/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/employerbranding/Zalando/Zalando
Zalando

Meet one of Berlin's top employers

/detail?content-id=/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/employerbranding/Academy for App Success/Academy for App Success
/portal/rest/jcr/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/employerbranding/Academy for App Success/Academy for App Success
Academy for App Success

Google Play resources tailored for the global droidcon community

Follow us

Team droidcon

Get in touch with us

Write us an Email

 

 

Quicklinks

> Code of Conduct

> Terms and Conditions

> How to hold a conference

> FAQs

> Imprint

Droidcon is a registered trademark of Mobile Seasons GmbH Copyright © 2020. All rights reserved.

powered by Breakpoint One