android中的热量

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.

Android Q引入了新的散热API,以更好地处理散热问题。 本文介绍了为什么需要这些API,它们提供的信息和控件以及如何在不同的热应力水平下测试应用程序。

对热API的需求 (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.

当Android设备产生的热量大于其散热能力(消除热量)时,它将承受热应力。 这会导致设备表面过热。 它还可能会限制CPU / GPU,并可能导致显示抖动,音频抖动和其他严重依赖于设备及其硬件的副作用。 因此,Android Q中引入了新的散热API,以使应用程序开发人员可以更好地应对和处理散热问题。

了解热严重性等级 (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.

Android散热API并未提供实际的设备温度值,该值不能很好地指示设备是否正在发生散热问题,而是引入了散热严重性级别的概念,该概念基于状态码并在PowerManager类中定义。 下面是一个示例,说明如何应对每个示例以保持良好的用户体验。

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.

随着温度严重性级别的提高,应用程序应禁用(可选)耗电功能,例如降低视频流应用程序的分辨率/比特率,禁用相机应用程序上的强化图像增强功能以​​及禁用地图应用程序上的GPS 。 这将有助于降低功耗,并有可能使设备恢复到正常温度。

接收热量通知 (Receiving thermal notifications)

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

为了接收热量状态更新,Android热量API通过PowerManager类提供了以下回调和轮询方法。

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.

请注意,这些热能API是通过重新设计的热能HAL,热能HAL 2.0引入的。 它向Android框架的热服务IThermalService提供热信号,然后将其传递给其客户端(包括Android应用)。

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.

Thermal API依赖于Thermal HAL 2.0的事实意味着并非所有运行Android 10或更高版本的设备都支持它们。 在其发行之时,Pixel设备支持热API。

测试热量水平 (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.

若要查看您的应用对热状态变化的React,可以使用带有以下内容的命令行来测试其行为。

$ adb shell cmd thermalservice override-status STATUS

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

STATUS表示热严重性状态,它是0( THERMAL_STATUS_NONE )和6( THERMAL_STATUS_SHUTDOWN )之间的整数。

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

完成测试后,可以使用以下命令将热状态重置为正常值。

$ adb shell cmd thermalservice reset

样例代码(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.

以下示例应用程序展示了如何注册设备热严重性级别的更新,以及如何使用前台服务使用户了解它们。

结论 (Conclusion)

In summary:

综上所述:

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

想更多地了解Android Thermal API? 查看以下资源:

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

如需更多有关Android的信息,请在我撰写新帖子或关注GithubTwitter关注我,以得到通知!

翻译自: https://proandroiddev.com/thermal-in-android-26cc202e9d3b

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值