1*ec779b8eSAndroid Build Coastguard Worker# Android Audio Flagging Guide 2*ec779b8eSAndroid Build Coastguard Worker 3*ec779b8eSAndroid Build Coastguard WorkerThis directory contains the aconfig flag definitions and the associated build files for Android 4*ec779b8eSAndroid Build Coastguard WorkerAudio features. 5*ec779b8eSAndroid Build Coastguard Worker 6*ec779b8eSAndroid Build Coastguard Worker## Build Configuration 7*ec779b8eSAndroid Build Coastguard Worker 8*ec779b8eSAndroid Build Coastguard Worker### Namespaces 9*ec779b8eSAndroid Build Coastguard Worker 10*ec779b8eSAndroid Build Coastguard WorkerThere are several global namespaces involved with flagging which must be maintained: 11*ec779b8eSAndroid Build Coastguard Worker - **Mendel project**: `media_audio`. Associated with mdb group and used by gantry. 12*ec779b8eSAndroid Build Coastguard WorkerAll aconfig flags in this namespace should be defined in this directory, and all flags defined in 13*ec779b8eSAndroid Build Coastguard Workerthis directory should belong to this namespace. 14*ec779b8eSAndroid Build Coastguard Worker - **Blueprint namespaces**: the name field of any module is unique over a particular build 15*ec779b8eSAndroid Build Coastguard Workernamespace (for platform development purposes there is one). 16*ec779b8eSAndroid Build Coastguard Worker - **Aconfig package**: All flags generated by aconfig are converted by Halyard into Mendel flags 17*ec779b8eSAndroid Build Coastguard Workerof the form {PACKAGE}{FLAG}, where both fields are stripped of spaces, underscores and dashes. This 18*ec779b8eSAndroid Build Coastguard Workercombo **must** be globally unique (across Android). 19*ec779b8eSAndroid Build Coastguard Worker - **Generated code**: Both java and cpp aconfig library rules generate code which pollutes the 20*ec779b8eSAndroid Build Coastguard Workernamespace of the backend. This means that if two aconfig java libraries exist which consume **any** 21*ec779b8eSAndroid Build Coastguard Worker`aconfig_declarations` with packages which intersect, these libraries are incompatible to be linked 22*ec779b8eSAndroid Build Coastguard Workertogether (and equivalent in cc). If the library is included in the framework, it is on the 23*ec779b8eSAndroid Build Coastguard Workerbootclasspath, so no other library for that package can exist. Additionally, the cpp backend 24*ec779b8eSAndroid Build Coastguard Workergenerates header files with the same name as the unqualified name of the package which means 25*ec779b8eSAndroid Build Coastguard Workerinclude path conflicts are possible. 26*ec779b8eSAndroid Build Coastguard Worker 27*ec779b8eSAndroid Build Coastguard Worker 28*ec779b8eSAndroid Build Coastguard Worker### Naming convention 29*ec779b8eSAndroid Build Coastguard Worker 30*ec779b8eSAndroid Build Coastguard WorkerGiven above, follow the following naming convention (given a `{PACKAGE}`). 31*ec779b8eSAndroid Build Coastguard Worker 32*ec779b8eSAndroid Build Coastguard WorkerGenerally, `aconfig_declarations` and `{backend}_aconfig_library` should be 1-1, except in cases 33*ec779b8eSAndroid Build Coastguard Workerwhere different package configurations are needed with pre-processing with different classpaths. 34*ec779b8eSAndroid Build Coastguard WorkerThis is because multiple libraries with the same aconfig package cannot compile together. 35*ec779b8eSAndroid Build Coastguard Worker 36*ec779b8eSAndroid Build Coastguard Worker``` 37*ec779b8eSAndroid Build Coastguard Workeraconfig_declarations { 38*ec779b8eSAndroid Build Coastguard Worker name: "{PACKAGE}-aconfig", 39*ec779b8eSAndroid Build Coastguard Worker package: "{PACKAGE}", 40*ec779b8eSAndroid Build Coastguard Worker srcs: ["{PACKAGE}.aconfig"] 41*ec779b8eSAndroid Build Coastguard Worker} 42*ec779b8eSAndroid Build Coastguard Worker 43*ec779b8eSAndroid Build Coastguard Worker{backend}_aconfig_library { 44*ec779b8eSAndroid Build Coastguard Worker name: "{PACKAGE}-aconfig-{backend}", 45*ec779b8eSAndroid Build Coastguard Worker aconfig_declarations: "{PACKAGE}-aconfig", 46*ec779b8eSAndroid Build Coastguard Worker defaults: ["audio-aconfig-{backend}-defaults"], 47*ec779b8eSAndroid Build Coastguard Worker} 48*ec779b8eSAndroid Build Coastguard Worker 49*ec779b8eSAndroid Build Coastguard Worker``` 50*ec779b8eSAndroid Build Coastguard WorkerIf the flags are required as part of the framework, the java backend is ingested into the framework 51*ec779b8eSAndroid Build Coastguard Workervia srcjar for cyclic dependency/simplicity reasons. Add the following 52*ec779b8eSAndroid Build Coastguard Worker 53*ec779b8eSAndroid Build Coastguard Worker``` 54*ec779b8eSAndroid Build Coastguard Worker ":{PACKAGE}-aconfig-java{.generated_srcjars}" 55*ec779b8eSAndroid Build Coastguard Worker``` 56*ec779b8eSAndroid Build Coastguard Worker 57*ec779b8eSAndroid Build Coastguard Workeras a source in `audio-framework-aconfig`. This target is included in the file-list which compiles 58*ec779b8eSAndroid Build Coastguard Workerthe framework. If a lib is included in this list, it is unecessary to add it in any other blueprint 59*ec779b8eSAndroid Build Coastguard Workerfile for platform code (for non-host). For tests, the library should be **statically** linked 60*ec779b8eSAndroid Build Coastguard Worker(which shadows the bootclasspath), to get around @hide restrictions (this approach may change). 61*ec779b8eSAndroid Build Coastguard Worker 62*ec779b8eSAndroid Build Coastguard Worker 63*ec779b8eSAndroid Build Coastguard Worker### Visibility 64*ec779b8eSAndroid Build Coastguard Worker 65*ec779b8eSAndroid Build Coastguard WorkerVisibility should be controlled (private) so that flag cleanup remains maintainable by the team. 66*ec779b8eSAndroid Build Coastguard WorkerThis constraints the locations where extant flags need to be chased for removal. 67*ec779b8eSAndroid Build Coastguard Worker 68*ec779b8eSAndroid Build Coastguard Worker 69*ec779b8eSAndroid Build Coastguard Worker### Packaging preference 70*ec779b8eSAndroid Build Coastguard WorkerAs a rule, prefer the most constrained package appropriate for a particular flag. This limits viral 71*ec779b8eSAndroid Build Coastguard Workerdependencies on a flag library which restricts where/how testing can occur. It also speeds up 72*ec779b8eSAndroid Build Coastguard Workerincremental rebuilds. Packages which end up in the framework should be avoided as much as possible, 73*ec779b8eSAndroid Build Coastguard Workersince they require rebuilding the framework, pollute the bootclasspath, and require special build 74*ec779b8eSAndroid Build Coastguard Workerhandling to operate (srcjar generation, jarjar to access in CTS). 75*ec779b8eSAndroid Build Coastguard Worker 76*ec779b8eSAndroid Build Coastguard WorkerUtilize "java-like" package naming for all packages, to ensure packages are globally unique, and 77*ec779b8eSAndroid Build Coastguard Workerto avoid class conflicts if these flags are later included in java code. 78*ec779b8eSAndroid Build Coastguard Worker 79*ec779b8eSAndroid Build Coastguard Worker## Workflow 80*ec779b8eSAndroid Build Coastguard Worker 81*ec779b8eSAndroid Build Coastguard Worker### Usage Style 82*ec779b8eSAndroid Build Coastguard WorkerIn general, prefer flags at the integration level, rather than at the implementation level. 83*ec779b8eSAndroid Build Coastguard WorkerThis allows flags to be queried in as few locations as possible such as by (parametrizing functions, 84*ec779b8eSAndroid Build Coastguard Workerclasses, types, etc.) It also allows callers to make different decisions on when behavior can/should 85*ec779b8eSAndroid Build Coastguard Workerbe changed (e.g. different flags could be used for different libraries). This follows dependency 86*ec779b8eSAndroid Build Coastguard Workerinjection principles and ensures that global state has a smaller blast radius, and also makes it 87*ec779b8eSAndroid Build Coastguard Workereasier to test code by relying less on infrastructure. The more places a flag is queried, the more 88*ec779b8eSAndroid Build Coastguard Workerits implementation should be deferred upwards, either by the injection interfaces, or by explicit 89*ec779b8eSAndroid Build Coastguard Workerparametrization. 90*ec779b8eSAndroid Build Coastguard Worker 91*ec779b8eSAndroid Build Coastguard Worker### Flag scope 92*ec779b8eSAndroid Build Coastguard WorkerIn general, flags should be scoped as precisely as possible while retaining orthogonality. If 93*ec779b8eSAndroid Build Coastguard Workerflags are too specific (multiple flags interact together to encompass a single change), then 94*ec779b8eSAndroid Build Coastguard Workerreasoning about independently switching flags becomes difficult. Other than all-on and all-of 95*ec779b8eSAndroid Build Coastguard Workerconfigurations, there is limited soak for flag combinations, so it is critical that flags 96*ec779b8eSAndroid Build Coastguard Workerinteract with each other minimally (although emergent properties are inevitable). 97*ec779b8eSAndroid Build Coastguard WorkerHowever, if flags are too general, graduating/reverting flags can carry too much behavior change, 98*ec779b8eSAndroid Build Coastguard Workerthe build graph degenerates, and 99*ec779b8eSAndroid Build Coastguard Worker 100*ec779b8eSAndroid Build Coastguard Worker### Instant Staging 101*ec779b8eSAndroid Build Coastguard WorkerIn general, it is recommended that the moment a flag is added to the tree, it should be moved to 102*ec779b8eSAndroid Build Coastguard Workerstaging on gantry. There is no benefit to adding a flag but not moving into staging. 103*ec779b8eSAndroid Build Coastguard WorkerThis allows: 104*ec779b8eSAndroid Build Coastguard Worker1. Verification by treehugger in both pre/post-submit 105*ec779b8eSAndroid Build Coastguard Worker1. Automatic configuration for feature development for local engineering workflows 106*ec779b8eSAndroid Build Coastguard Worker1. Integration with other engineering features in development 107*ec779b8eSAndroid Build Coastguard Worker 108*ec779b8eSAndroid Build Coastguard Worker 109*ec779b8eSAndroid Build Coastguard Worker### FlaggedApi 110*ec779b8eSAndroid Build Coastguard WorkerFlaggedApi operates differently than other types of flags since these flags only graduate at the 111*ec779b8eSAndroid Build Coastguard Workernext API bump. These flags also must be exposed through the framework. FlaggedApis should only 112*ec779b8eSAndroid Build Coastguard Workeroperate over the same set of flags as an implementation if the implementation is entirely related 113*ec779b8eSAndroid Build Coastguard Workerto the feature. Given the constraints on the flag lifetime, it is preferable to use a "regular" 114*ec779b8eSAndroid Build Coastguard Workerflag for implementation, which can integrate/soak/ship/clean-up faster. 115*ec779b8eSAndroid Build Coastguard Worker 116*ec779b8eSAndroid Build Coastguard WorkerAdditionally, unlike "regular" flags, @FlaggedApis are not effectively soaked, so like non-trunk 117*ec779b8eSAndroid Build Coastguard WorkerAPI development, they are heavily reliant on CTS to integrate. 118*ec779b8eSAndroid Build Coastguard Worker 119*ec779b8eSAndroid Build Coastguard WorkerOn non-next configs, @FlaggedApi has no runtime control, but it is undefined for callers to 120*ec779b8eSAndroid Build Coastguard Workercall a FlaggedApi without querying the status of the flag. The build itself is not changed on 121*ec779b8eSAndroid Build Coastguard Workerstaging. Anything which builds against the platform can see all @FlaggedApis. 122*ec779b8eSAndroid Build Coastguard Worker 123*ec779b8eSAndroid Build Coastguard WorkerMethods annotated FlaggedApis are changed for release finalization -- if an API is not in next, 124*ec779b8eSAndroid Build Coastguard Workerit is stripped from the Sdk (and left @hide). If an API graduated to next, it is included fully 125*ec779b8eSAndroid Build Coastguard Workerincluded in the Sdk, and the @FlaggedApi annotation is stripped. 126*ec779b8eSAndroid Build Coastguard Worker 127*ec779b8eSAndroid Build Coastguard Worker 128*ec779b8eSAndroid Build Coastguard Worker### TestApis 129*ec779b8eSAndroid Build Coastguard WorkerTestApis do not require flagging, unless they are API additions associated with new features. 130*ec779b8eSAndroid Build Coastguard WorkerFor testing existing features, we have full control over the set of callers. 131*ec779b8eSAndroid Build Coastguard Worker 132*ec779b8eSAndroid Build Coastguard Worker### Api Changes 133*ec779b8eSAndroid Build Coastguard WorkerThere is partial (work ongoing) support for modifying API surfaces. 134*ec779b8eSAndroid Build Coastguard Worker - SystemApi -> public is supported 135*ec779b8eSAndroid Build Coastguard Worker - UAU -> SystemApi is supported, but the @UAU must remain until the flag is in next 136*ec779b8eSAndroid Build Coastguard WorkerOther modifications involving moving between surfaces, or annotation changes may not be supported: 137*ec779b8eSAndroid Build Coastguard Workercheck the [FAQ](https://g3doc.corp.google.com/company/teams/android-api-council/guidelines/faq.md?cl=head#i-cannot-use-flaggedapi-with-data-classes-generated-by-codegen) 138*ec779b8eSAndroid Build Coastguard Workerfor the up to date list of support. 139