Android Init Language --------------------- The Android Init Language consists of five broad classes of statements, which are Actions, Commands, Services, Options, and Imports. All of these are line-oriented, consisting of tokens separated by whitespace. The c-style backslash escapes may be used to insert whitespace into a token. Double quotes may also be used to prevent whitespace from breaking text into multiple tokens. The backslash, when it is the last character on a line, may be used for line-folding. Lines which start with a # (leading whitespace allowed) are comments. Actions and Services implicitly declare a new section. All commands or options belong to the section most recently declared. Commands or options before the first section are ignored. Actions and Services have unique names. If a second Action is defined with the same name as an existing one, its commands are appended to the commands of the existing action. If a second Service is defined with the same name as an existing one, it is ignored and an error message is logged. Init .rc Files -------------- The init language is used in plaintext files that take the .rc file extension. These are typically multiple of these in multiple locations on the system, described below. /init.rc is the primary .rc file and is loaded by the init executable at the beginning of its execution. It is responsible for the initial set up of the system. It imports /init.${ro.hardware}.rc which is the primary vendor supplied .rc file. During the mount_all command, the init executable loads all of the files contained within the /{system,vendor,odm}/etc/init/ directories. These directories are intended for all Actions and Services used after file system mounting. The intention of these directories is as follows 1) /system/etc/init/ is for core system items such as SurfaceFlinger and MediaService. 2) /vendor/etc/init/ is for SoC vendor items such as actions or daemons needed for core SoC functionality. 3) /odm/etc/init/ is for device manufacturer items such as actions or daemons needed for motion sensor or other peripheral functionality. Actions ------- Actions are named sequences of commands. Actions have a trigger which is used to determine when the action should occur. When an event occurs which matches an action's trigger, that action is added to the tail of a to-be-executed queue (unless it is already on the queue). Each action in the queue is dequeued in sequence and each command in that action is executed in sequence. Init handles other activities (device creation/destruction, property setting, process restarting) "between" the execution of the commands in activities. Actions take the form of: on [&& ]* Services -------- Services are programs which init launches and (optionally) restarts when they exit. Services take the form of: service [ ]*