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 email@example.com::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.
These messages can be used to signal
init to bring up and down
specific hardware interfaces. When a service is requested and it is not
hwservicemanager will request the service to be
Determining HAL exit
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
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).