Hooks are scripts that automatically trigger actions based on an event performed in the life cycle of an instance. A hook can be any executable file that is placed in the
hooks directory of an addon or an application folder.
The hook name must be one of the following:
|Executed before Android is started. If the hook fails to execute, the instance fails to start and has an error status.
|Executed after Android is started. If the hook fails to execute, the instance stops with an error.
|Executed after Android is stopped. If the instance fails to start, this hook will not be invoked. If the hook fails to execute, the instance stops with an error.
pre-start instead. Executed during the application bootstrap when the addon is installed.
post-start instead. Executed during the application bootstrap when Android is running.
pre-start instead. Executed before Android starts.
post-stop instead. Executed after Android shuts down.
A failed hook will cause the instance to stop immediately and end up in an error state. In such cases, view the instance logs to further investigate the causes of failure.
The following figure shows when the different hooks are executed in the life cycle of a base or a regular instance.
When hooks are invoked, several environment variables are set to provide context to the addon.
The following variables are available:
|Directory of the addon whose hook is currently running.
|Path to the Anbox application directory.
|Path to the Anbox directory.
|Path to the Android RootFS.
|Boot package of the APK.
|Type of container being run. This variable is now deprecated. Use
regular (container running an application or a raw image)
base (container bootstrapping, thus creating or updating, an application)
|Type of instance being run
regular (instance running an application or a raw image)
base (instance bootstrapping, thus creating or updating, an application)
post-stop hook only: Exit code of the Anbox process.
0 if no error occurred, otherwise set to the actual return code.
By default, all hooks are subject to a 5 minute timeout to avoid blocking an instance for too long. The timeout can be configured through the
hooks.timeout key in the addon or application manifest. For example:
A hook that runs into a timeout exits with an error. Timeout values longer than 15 minutes are considered invalid.