Determine flag usage and type

Feature launch flags are used by Google as an approach to ensuring stable code branches. These flags are also required for certain types of contributions to AOSP. Before implementing feature launch flagging, determine if a flag is necessary for your change. And, if a flag is necessary, you should determine the type of flag to use.

Determine flag usage

To determine when to use a feature launch flag, follow these guidelines:

  • If you are making a change that could cause the AOSP codebase to be unstable, such as adding a new feature or fixing a particularly complex bug, use a feature launch flag.

  • Conversely, if you are making a code change that isn't apt to cause the codebase to be unstable, such as modifying comments, you don't need to use a feature launch flag.

Determine flag type

There are two types of flags: aconfig flags and build flags.

Aconfig flags

Aconfig flags are used to separate the execution of unreleased code from released code during the testing and release process. Aconfig flags can be read-write or read-only:

  • Read-write aconfig flags are boolean variables that you can enable (set to true) or disable (set to false) at runtime. Use a read-write flag to test and release changes without affecting the stability of a main branch.

  • Read-only aconfig flags are boolean constants that you can't change at runtime. You can convert read-write aconfig flags to read-only aconfig flags for code that is stable and ready to release.

    Additionally, depending on the compiler you're using, when a read-only flag is used, the code that isn't executed might be excluded from the build. Therefore, you can use read-only flags to hide any code that isn't ready to be part of a release.

Build flags

Build flags are build-time constants (strings) and you can't change them during runtime. Use these flags in circumstances where you can't use aconfig flags, such as:

  • You have a precompiled or prebuilt piece of code that you want to include in the build.
  • You want to make changes to build system itself.
  • You want to put flags around dependencies to manage code size.