Android 11(R) Power HAL AIDL简析 -- 基本接口

1 前言

Android 11 引入了在 Android 中使用 AIDL 实现 HAL 的功能。这样就可以在不使用 HIDL 的情况下实现 Android 的部分代码。Power HAL模块即可以采用AIDL方式来实现。在Android 11中已经引入这个Power AIDL Interface,源码位于:

/hardware/interfaces/power/aidl/

在学习这部分之前,推荐阅读AIDL的相关知识,特别是Android 10之后引入的对稳定的 Android 接口定义语言 (AIDL) 的支持(stable AIDL),这里放上几篇官网链接:


2 Power HAL AIDL接口介绍


2.1 接口定义源码的目录结构

1. 在Androi源码目录/hardware/interfaces/power/aidl/android/hardware/power/下定义了三个aidl文件,分别为:

IPower.aidl定义 power hal接口
Mode.aidl定义各种 power mode
Boost.aidl定义Boost type

2. aidl_api目录:对于Stable AIDL,从 Android 11 开始,versions 冻结在 aidl_api/name 下,和AIDL接口版本相关。

3. default目录:功能实现的一个示例代码,实现了一个android.hardware.power-service.example 这个aidl service

4. vts目录:vts测试用例


2.2 IPower接口介绍

先看看IPower源码是如何定义的,interface IPower的源码定义如下:

点击查看IPower代码

/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.hardware.power;

import android.hardware.power.Boost;
import android.hardware.power.Mode;

@VintfStability
interface IPower {
    /**
     * setMode() is called to enable/disable specific hint mode, which
     * may result in adjustment of power/performance parameters of the
     * cpufreq governor and other controls on device side.
     *
     * A particular platform may choose to ignore any mode hint.
     *
     * @param type Mode which is to be enable/disable.
     * @param enabled true to enable, false to disable the mode.
     */
    oneway void setMode(in Mode type, in boolean enabled);

    /**
     * isModeSupported() is called to query if the given mode hint is
     * supported by vendor.
     *
     * @return true if the hint passed is supported on this platform.
     *         If false, setting the mode will have no effect.
     * @param type Mode to be queried
     */
    boolean isModeSupported(in Mode type);

    /**
     * setBoost() indicates the device may need to boost some resources, as the
     * the load is likely to increase before the kernel governors can react.
     * Depending on the boost, it may be appropriate to raise the frequencies of
     * CPU, GPU, memory subsystem, or stop CPU from going into deep sleep state.
     * A particular platform may choose to ignore this hint.
     *
     * @param type Boost type which is to be set with a timeout.
     * @param durationMs The expected duration of the user's interaction, if
     *        known, or 0 if the expected duration is unknown.
     *        a negative value indicates canceling previous boost.
     *        A given platform can choose to boost some time based on durationMs,
     *        and may also pick an appropriate timeout for 0 case.
     */
    oneway void setBoost(in Boost type, in int durationMs);

    /**
     * isBoostSupported() is called to query if the given boost hint is
     * supported by vendor. When returns false, set the boost will have
     * no effect on the platform.
     *
     * @return true if the hint passed is supported on this platform.
     *         If false, setting the boost will have no effect.
     * @param type Boost to be queried
     */
    boolean isBoostSupported(in Boost type);
}

从源码中可以看到,IPower的定义还是比较简单的,只提供了4个接口,从源码注释也很容易理解其作用,下面我们简单总结一下:

接口名称参数返回值作用
setMode

Mode type:开启或关闭的Power Mode

boolean enabled:true表示开启,false表示关闭

调用这个接口可以启用/禁用特定Power Mode,这可能导致cpufreq调控器或设备端其他控件的power/performance参数调整。
isModeSupported

Mode type:要查询的Power Mode

true:支持

fasle:不支持

查询给定的Power Mode是否支持
setBoost

Boost type:需要设置的type

int durationMs:已知情况下的用户交互的预期时间。值为0表示未知预期时间,负值表示取消上一次的boost

表示设备可能需要增加一些资源,因为在内核调控器做出反应之前,负载可能会增加。根据增压情况,可能适合提高CPU、GPU、内存子系统的频率或停止CPU进入深度睡眠状态.
isBoostSupportedBoost type:要查询的Boost type

true:支持

fasle:不支持

查询给定的Boost type是否支持

2.3 Power Mode介绍

先看一下AIDL文件中的定义

点击查看PowerMode源码

 

简单介绍各个Mode:

  • DOUBLE_TAP_TO_WAKE : 此模式表示设备允许在屏幕被点击两次时被唤醒
  • LOW_POWER:此模式表示低电量模式是否被激活。这种模式以牺牲性能为代价来节省电量消耗
  • SUSTAINED_PERFORMANCE:持续性能模式旨在在较长时间内提供一致的性能水平。
  • FIXED_PERFORMANCE:将设备设置为一个固定的性能水平,该水平可在正常室内条件下持续至少10分钟。此模式于SUSTAINED_PERFORMANCE模式,不同之处在于:SUSTAINED_PERFORMANCE为了长期稳定性对性能设置了上限;FIXED_PERFORMANCE模式对性能同时设置了上限和下限,以便在FIXED_PERFORMANCE模式下运行的任何工作负载都应在可重复的时间内完成。
  • VR:VR 模式旨在在设备可以维持的时间内为性能提供最低限度的保证。
  • LAUNCH:此模式表示已启动应用程序
  • EXPENSIVE_RENDERING:此模式表示设备即将进入昂贵的渲染周期。 
  • INTERACTIVE:此模式表示设备即将进入/离开 交互状态或非交互状态。 非交互状态可以在不活动时间段之后进入,以便在这样的不活动时间段期间节省电池电量。典型的操作是打开或关闭设备并调整 cpufreq 参数。该函数还可以调用适当的接口,允许内核在进入非交互状态时将系统挂起到低功耗休眠状态,并在系统处于交互状态时禁止低功耗挂起。 当允许低功耗挂起状态时,内核可以在没有唤醒锁保持时挂起系统。
  • DEVICE_IDLE:此模式表示设备处于设备空闲状态,详细信息可参考: 针对低电耗模式和应用待机模式进行优化
  • DISPLAY_INACTIVE:此模式表示显示器关闭或仍然打开,但已针对低功耗进行了优化。 

以下提示选项目前未在加入 Android 框架,但 OEM 可能会选择实施电源/性能优化。 

  • AUDIO_STREAMING_LOW_LATENCY:此模式表示低延迟音频处于激活状态
  • CAMERA_STREAMING_SECURE:此模式表示正在启动相机 安全流
  • CAMERA_STREAMING_LOW:此模式表示正在启动相机 低 分辨率流。 
  • CAMERA_STREAMING_MID:此模式表示正在启动相机 中 分辨率流。 
  • CAMERA_STREAMING_HIGH:此模式表示正在启动相机 高 分辨率流

2.4 Boost type介绍

首先看一下AIDL的源码:

点击查看Boost代码

 

几个枚举常量的大概解释如下:

  • INTERACTION:这种boost是在用户与设备交互时设置的,例如,触摸屏事件传入。 CPU 和 GPU 负载可能很快就会出现,可能适当提高 CPU、内存总线等的速度。 注意,这与 INTERACTIVE 模式不同,交互模式仅表示这种交互*可能*发生,而不是主动发生 . 
  • DISPLAY_UPDATE_IMMINENT:这种boost表明框架可能很快会提供一个新的显示帧。这意味着设备应确保显示处理路径已通电并准备好接收该更新。 
  • ML_ACC:此boost表明设备正在与 ML 加速器交互
  • AUDIO_LAUNCH:此boost表示设备正在设置音频流。
  • CAMERA_LAUNCH:此boost表示Camera正在被启动
  • CAMERA_SHOT:此boost表示Camera正在拍摄

3 结语

通过上面的介绍,应该对power hal aidl有了一个直观的认识,清楚了有哪些接口/哪些模式,下一篇中我们会在此基础上通过一个示例讲解如何实现这个aidl serivice功能。

  • 0
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值