Android_Architecture_HAL--Dynamic Lifecycle

说明:转载自Android官网https://source.android.com/devices/architecture/hal/dynamic-lifecycle,方便国内查看。


Dynamically Available HALs

Android 9 supports the dynamic shutdown of Android hardware subsystems when they are not in use or not needed. For example, when a user is not using Wi-Fi, the Wi-Fi subsystems should not be taking up memory, power, or other system resources. In earlier versions of Android, HALs/drivers were kept open on Android devices for the entire duration an Android phone was booted.

Implementing dynamic shutdown involves wiring up data flows and executing dynamic processes as detailed in the following sections.

Changes to HAL definitions


Dynamic shutdown requires information on which processes serve what HAL interfaces (this information may also be useful later in other contexts) as well as not starting processes on boot and not restarting them (until requested again) when they exit.

# some init.rc script associated with the HAL
service vendor.some-service-name /vendor/bin/hw/some-binary-service
    # init language extension, provides information of what service is served
    # if multiple interfaces are served, they can be specified one on each line
    interface android.hardware.light@2.0::ILight default
    # restarted if hwservicemanager dies
    # would also cause the hal to start early during boot if oneshot wasn't set
    class hal
    # will not be restarted if it exits until it is requested to be restarted
    oneshot
    # will only be started when requested
    disabled
    # ... other properties

Changes to init and hwservicemanager


Dynamic shutdown also requires the hwservicemanager to tell init to start requested services. In Android 9, init includes three additional control messages (e.g. ctl.start): ctl.interface_start, ctl.interface_stop, and ctl.interface_restart. These messages can be used to signal init to bring up and down specific hardware interfaces. When a service is requested and isn’t registered, hwservicemanager requests that the service be started. However, dynamic HALs don’t require using any of these.

Determining HAL exit


In Android 9, HAL exit has to be manually determined. For Android 10 and higher, it can also be determined with automatic lifecycles.

Dynamic shutdown requires multiple policies for deciding when to start a HAL and when to shutdown a HAL. If a HAL decides to exit for any reason, it will automatically be restarted when it is needed again using the information provided in the HAL definition and the infrastructure provided by changes to init and hwservicemanager. This could involve a couple of different strategies, including:

  • A HAL could choose to call exit on itself if someone calls a close or similar API on it. This behavior must be specified in the corresponding HAL interface.
  • HALs can shut down when their task is completed (documented in the HAL file).

Automatic lifecycles


Android 10 adds more support to the kernel and hwservicemanager, which allows HALs to shut down automatically whenever they have no clients. To use this feature, do all of the steps in Changes to HAL definitions as well as:

  • Register the service in C++ with LazyServiceRegistrar instead of the member function, registerAsService, for example:
// only one instance of LazyServiceRegistrar per process
LazyServiceRegistrar registrar();
registrar.registerAsService(myHidlService /* , "default" */);
  • Verify that the HAL client keeps a reference to the top-level HAL (the interface registered with hwservicemanager) only when it’s in use. To avoid delays if this reference is dropped on a hwbinder thread that continues to execute, the client should also call IPCThreadState::self()->flushCommands() after dropping the reference to ensure that the binder driver is notified of the associated reference count changes.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值