Commit graph

9330 commits

Author SHA1 Message Date
Mårten Kongstad
5413a1e55d Merge "check-flagged-apis: record super class when parsing classes" into main 2024-05-07 13:52:21 +00:00
Treehugger Robot
4925954a79 Merge changes Ia6dfcfa8,I8d93c230,I4db7ff47,I003535c7,I8c0619fa into main
* changes:
  check-flagged-apis: consider interfaces when looking up symbol
  check-flagged-apis: skip self-referential interfaces
  check-flagged-apis: record interfaces when parsing classes
  check-flagged-apis: add more details to Symbol class
  check-flagged-apis: api-versions.xml: correctly parse nested class ctor
2024-05-07 13:42:25 +00:00
Mårten Kongstad
e812039036 check-flagged-apis: consider superclasses when looking up symbol
If a symbol can't be found in a class, (recursively) check the class'
superclass before reporting the symbol as missing.

Bug: 334870672
Test: atest --host check-flagged-apis-test
Change-Id: I8ef1fbfcc51e0c5ba00959536c087213d688fe39
2024-05-07 13:28:54 +02:00
Mårten Kongstad
c3f05a6d92 check-flagged-apis: record super class when parsing classes
Extend ClassSymbol with a nullable reference to the class' superclass.

Bug: 334870672
Test: atest --host check-flagged-apis-test
Change-Id: Ia2741a4d7fb5de908a03ef640f5fcd38d0ce0e28
2024-05-07 13:28:53 +02:00
Mårten Kongstad
d2c707613e check-flagged-apis: consider interfaces when looking up symbol
When searching for potential errors, if a symbol can't be found in the
api-verions.xml data, check if it is present in any of the class'
interfaces.

A follow-up CL will add similar logic to handle super classes.

Bug: 334870672
Test: atest --host check-flagged-apis-test
Change-Id: Ia6dfcfa8495b89465db60f6a4eb77d304112046b
2024-05-07 13:28:53 +02:00
Mårten Kongstad
04d8b46c37 check-flagged-apis: skip self-referential interfaces
The return value of ClassItem.allInterfaces will sometimes include the
interface itself (e.g.
android.accessibilityservice.BrailleDisplayController). It is unclear
when this happens; it doesn't happen for the unit test.

Update the logic to record the interfaces for a class to filter out
interfaces named the same as the class.

Bug: 334870672
Test: atest --host check-flagged-apis-test
Test: croot && ./build/tools/check-flagged-apis/check-flagged-apis.sh
Change-Id: I8d93c230dfedde30e8d43fefd560a47944085d3a
2024-05-07 13:16:13 +02:00
Mårten Kongstad
7c3571fe8b check-flagged-apis: record interfaces when parsing classes
Extend ClassSymbol with a list of the interfaces that class implements.
This will be used in a follow-up CL to improve the logic that checks if
a class member exists in the api-versions.xml data.

Bug: 334870672
Test: atest --host check-flagged-apis-test
Change-Id: I4db7ff47c3ce40ca892cb872810dd559426dfcb8
2024-05-07 13:16:13 +02:00
Mårten Kongstad
a1fe37137e check-flagged-apis: add more details to Symbol class
Change Symbol from a wrapper around a String to a more fleshed out data
class; symbols now encode if they represent a class, or a class member
(including a reference to the containing class).

Bug: 334870672
Test: atest --host check-flagged-apis-test
Test: croot && ./build/tools/check-flagged-apis/check-flagged-apis.sh # with and without this CL; the output should be the same
Change-Id: I003535c721c45d559d00fb3e008325e1db0e18c0
2024-05-07 13:16:13 +02:00
Mårten Kongstad
02525a88de check-flagged-apis: api-versions.xml: correctly parse nested class ctor
The constructor of a nested class is represented as follows in
api-versions.xml:

  <class name="android/Clazz$Foo$Bar" since="1">
    <method name="&lt;init>()V"/>
  </class>

The nested dollar signs are not replaced by forward slashes before the
parsing logic uses `split("/")` to find the name of the inner-most
class, incorrectly resulting in `Class$Foo$Bar` instead of `Bar`. Fix
this by immediately replacing dollar signs with forward slashes after
extracting the package and class.

Also clean up the following call of `Symbol.create`.

Bug: 334870672
Test: atest --host check-flagged-apis-test
Change-Id: I8c0619faae90ded7eb14dcc20ecb94a086a1c764
2024-05-07 13:16:13 +02:00
Jiyong Park
0a5b852656 Merge "Move fs_config_[files|dirs]_<partition> to soong" into main 2024-05-07 02:17:23 +00:00
Jooyung Han
5548c31901 Merge "Remove unused testdata" into main 2024-05-07 01:37:05 +00:00
Jiyong Park
8d6481b92c Move fs_config_[files|dirs]_<partition> to soong
Note that not all partitions are moved to Soong. Soong doesn't yet
support *_dlkm partitions and the oem partition.

This change also removes dead code for support VNDK snapshot.

Finally, as a minor clean up, the leading '_' is dropped from the module
names _fs_config_*. There's no need to hide the module names.

Bug: 337993745
Test: m
Change-Id: I5beec5c6734291b9361f870fc1a8dba19def062e
2024-05-07 08:50:10 +09:00
Dennis Shen
a49f1ba5c5 aconfig: update storage file mapping api
Return a pointer of MappedStorageFile/MutableMappedStorageFile instead
of an object of MappedStorageFile/MutableMappedStorageFile. Now added
destructor for MappedStorageFile/MutableMappedStorageFile to unmap the
in memory file to free up memory.

Bug: b/321077378
Test: atest -c
Change-Id: Iaa02696feb07ff383f0c7e46b645d82e57c38254
2024-05-06 17:25:59 +00:00
Paul Duffin
771a201f3d Use complete api-versions.xml for module-lib and system-server
Previously, the check-flagged-apis.sh script used `api-versions.xml`
for `module-lib` and `system-server` which did not include the
latest up-to-date information about updatable modules or historical
information about sdk extensions which lead to false positives for
APIs from those updatable modules. This changes switches to use the
`api-versions.xml` produced by the new `api_versions_*_complete`
modules which does include that information.

Bug: 337836752
Test: Run script before and after applying this change to make sure
      that flagged APIs from updatable modules are no longer
      reported as missing.
Change-Id: If09e89a4595a19d9f00390fb5fbd24330ec11be5
2024-05-03 12:13:32 +01:00
Mårten Kongstad
22063d0670 check-flagged-apis.sh: speed up build step
Instead of building the entire SDK, explicitly build the
api-versions.xml files.

Bug: 334870672
Test: croot && build/tools/check-flagged-apis/check-flagged-apis.sh
Change-Id: Ib165c0acd4766ad3000aaf17220050d5e66ddf2c
2024-05-03 10:05:03 +02:00
Mårten Kongstad
a57d0ef0a1 Merge "check-flagged-apis.sh: use correct path to generated API signature files" into main 2024-05-03 06:53:52 +00:00
Inseob Kim
ab47e15dd1 Merge changes from topic "merge_cc_logtags" into main
* changes:
  Add LOCAL_SOONG_LOGTAGS_FILES
  Add python Soong modules for logtags
2024-05-03 05:10:23 +00:00
Jooyung Han
d6a9631d8b Remove unused testdata
com.android.apex.compressed.v1_original is removed.

Bug: 338157001
Test: releasetools_test
Change-Id: Icd4fe958f260640a541e9843efa64e85036542ed
2024-05-03 11:49:55 +09:00
Treehugger Robot
c039204466 Merge "check-flagged-apis: suppress unused variable warning" into main 2024-05-02 19:01:48 +00:00
Treehugger Robot
83705ef7d1 Merge "check-flagged-apis: add support for method with parameters" into main 2024-05-02 18:59:48 +00:00
Daniel Zheng
76f13d280c Merge "create_brick_ota: logic fix" into main 2024-05-02 18:10:51 +00:00
Treehugger Robot
7bff3a85f9 Merge "Add * support products and modules" into main 2024-05-02 18:07:48 +00:00
Daniel Zheng
7e4cc58f2d create_brick_ota: logic fix
ota_metadata should be initialized outside of the if block.

Bug: 3072303
Test: th
Change-Id: Iabe52be3557c71921586d960d8a8a91c33d5558b
2024-05-02 09:55:45 -07:00
Mårten Kongstad
b9ce4c92e0 check-flagged-apis.sh: use correct path to generated API signature files
The path to the generated API signature files used with --api-signature
in the check-flagged-apis.sh script are different based on the lunch
target used: sometimes it's under $ANDROID_PRODUCT_OUT, other times
under out/target/product/mainline_x86.

Teach check-flagged-apis.sh to dynamically find the correct path by
querying ninja.

Bug: 334870672
Test: croot && build/tools/check-flagged-apis/check-flagged-apis.sh
Change-Id: I1b0b41ef3ad1bc7113a3b31323d81251e7e65933
2024-05-02 14:30:56 +02:00
Mårten Kongstad
cd93aeb947 check-flagged-apis: suppress unused variable warning
Bug: 334870672
Test: m check-flagged-apis # verify no Lint warnings
Change-Id: If4fb93703f0f0bf3f27e6ec052cf488796bd717e
2024-05-02 14:01:12 +02:00
Mårten Kongstad
b4a14bfaa9 check-flagged-apis: add support for method with parameters
Teach check-flagged-apis to parse methods containing parameters.

Bug: 334870672
Test: atest --host check-flagged-apis-test
Change-Id: I171660b914b73fd85e03ed9300c2c81f33d80d61
2024-05-02 09:53:54 +02:00
Mårten Kongstad
ece054c856 check-flagged-apis: change internal format
Switch the internal format to represent Symbols to (something close to)
the format described in section 4.3.2 of the JVM spec, i.e.

  com/android/SomeClass/someMethod(II[Ljava/lang/String;)Z

This will make parsing method parameters from api-versions.xml easier,
as that file already uses this format, and converting API signature
files to the same format is less painful than going in the other
direction.

Bug: 334870672
Test: atest --host check-flagged-apis-test
Change-Id: I1e1fb8fe208cd51cce2cc129f5aa1cb495672c16
2024-05-02 09:50:33 +02:00
Inseob Kim
f441f7d8fd Add python Soong modules for logtags
Bug: 336189540
Test: m out/soong/.intermediates/all-event-log-tags.txt
Test: m out/target/common/obj/all-event-log-tags
Change-Id: Iae336a05bb2f27564b0bf8d4ea3753a30be89e90
2024-05-02 13:51:34 +09:00
Ted Bauer
daa3c71739 Merge "Update dependencies for new aconfig flag storage" into main 2024-05-01 15:37:20 +00:00
Ted Bauer
4560e3ae8f Update dependencies for new aconfig flag storage
Bug: 328444881
Test: m
Change-Id: I3685a74e9e93a6ecb89a054e243b48b67f470d55
2024-04-30 23:57:51 +00:00
Dennis Shen
c0102331c8 Merge "aconfig: add a new aconfig storage file flag listing api" into main 2024-04-30 23:06:18 +00:00
Dennis Shen
45c94c6421 aconfig: add a new aconfig storage file flag listing api
added a new function called list_flag_with_info to list all the flags
given all four storage files (package.map, flag.map, flag.val, flag.info).
also exported this api thru cxx interface so aconfigd can use it.

Bug: b/312444587
Test: atest -c
Change-Id: Ibbfe657b980d40e25e5e28962b930338192e2d98
2024-04-30 17:52:44 +00:00
Ted Bauer
ced25ac630 Merge "Add cc_defaults containing libs needed for static linking" into main 2024-04-30 01:20:21 +00:00
Treehugger Robot
15967616ca Merge "Add tool to determine if products can be lunched" into main 2024-04-29 23:57:36 +00:00
Ted Bauer
d724dd04e2 Add cc_defaults containing libs needed for static linking
Bug: 328444881
Test: m
Change-Id: I35cbce94301415381b3ad38d7e5c697f9c010856
2024-04-29 23:41:52 +00:00
Fabián Cañas
29252f8001 Add tool to determine if products can be lunched
This could aid in cleaning unmaintained products from manifests.

Change-Id: Ic1ae4d62711cf27f17c1e4c770f64db074768fd5
Test: lunchable
2024-04-29 22:58:11 +00:00
Treehugger Robot
faeac4d7f7 Merge "Drive instrumentation with build flag" into main 2024-04-29 21:26:55 +00:00
Michael Wright
c791547786 Merge "check-flagged-apis: remove debug print" into main 2024-04-29 20:29:51 +00:00
Michael Wright
cfbcdc1ec5 Merge changes Ia860d7b0,Ie98db767 into main
* changes:
  check-flagged-apis: allow / chars in Symbol names
  check-flagged-apis: add support for methods (no parameters)
2024-04-29 20:29:35 +00:00
Ted Bauer
d19d351148 Drive instrumentation with build flag
Bug: 328444881
Test: m
Change-Id: Iebb250e8a836c77b14fcc6b9536eba90f9da7a4b
2024-04-29 20:12:27 +00:00
Treehugger Robot
80c40c4d91 Merge "FakeFeatureFlagsImpl optionally takes defaults via a FeatureFlags." into main 2024-04-29 16:53:28 +00:00
Ted Bauer
d475818504 Merge "Read from new storage in C++ aconfig codegen" into main 2024-04-29 16:47:45 +00:00
Mårten Kongstad
9aef0d9bda check-flagged-apis: remove debug print
Bug: 334870672
Test: atest --host check-flagged-apis-test
Change-Id: Ida3ba78bc240b5aed2382bf5a0ea12e8d1e1d763
2024-04-29 10:35:28 +02:00
Mårten Kongstad
8d74fd0a31 check-flagged-apis: allow / chars in Symbol names
Allow forward slash characters (/) in Symbol names: when adding support
for method arguments, this will be needed.

The current implementation does not change; forward slash conversions to
dots still happen, but now explicitly at the call site of Symbol.create.

Bug: 334870672
Test: atest --host check-flagged-apis-test
Change-Id: Ia860d7b0c8703fcc56fec6ea722cf995ccf20cd0
2024-04-28 00:50:11 +02:00
Jeff DeCew
23fbd1e2f6 FakeFeatureFlagsImpl optionally takes defaults via a FeatureFlags.
Bug: 337449122
Flag: test_only
Test: presubmit
Change-Id: I45e2a523b36a6b14627c89ee7deffda711a32f5e
2024-04-27 18:08:45 +00:00
Zhuoyao Zhang
836b9e1ba9 Merge "Add a Clearcut tool event logger" into main 2024-04-27 02:39:21 +00:00
Zhuoyao Zhang
7b11b7106a Add a Clearcut tool event logger
Implement a binary that logs tool events to Clearcut. The binary is designed to be eventually called by the `run_tool_with_logging` script in the `envsetup.sh` script that sets up the build environment.

Only start and stop events are currently logged for each invocation.

Test: atest tool_event_logger_test
bug: 331638854
Change-Id: I9268e4cb986975ceda171204e6ce8ef1732eaeea
2024-04-27 01:01:50 +00:00
Mårten Kongstad
40da97047c check-flagged-apis: add support for methods (no parameters)
Teach check-flagged-apis to parse methods. The implementation is only
half done: method signatures that accept parameters are ignored. A
follow-up CL will add support for these.

check-flagged-apis treats constructors and regular methods the same.

Bug: 334870672
Test: atest --host check-flagged-apis-test
Change-Id: Ie98db767289ac2a35aa85371f60ecb3970170d86
2024-04-27 01:51:08 +02:00
Jared Duke
a97d385b69 Restrict aconfig version script to linux
Avoid breakage on other platforms.
Bug: 336657207
Test: m

Change-Id: I167dbbe934a133e8f08f630846707870404f62fd
2024-04-26 20:22:12 +00:00
Treehugger Robot
d2469987ce Merge "Use a version script for libaconfig_storage_read_api_cc" into main 2024-04-26 19:35:54 +00:00
Ted Bauer
8e7cfad672 Read from new storage in C++ aconfig codegen
Read from the new aconfig storage backing in C++ aconfig codegen, for
READ_ONLY flags. Log if there is a match with the legacy storage, or a
mismatch, or a failure.

Only enabled if instrumentation is enabled, which will be enabled by a
build flag in a follow-up CL.

Test: m && cargo t
Bug: 328444881
Change-Id: I691dfad8860d8f917e93c5d56dac19f8791de943
2024-04-26 18:45:31 +00:00
Jeff DeCew
cfd7b0df36 Merge "Generate CustomFeatureFlags" into main 2024-04-26 18:39:43 +00:00
Jared Duke
8782e1e858 Use a version script for libaconfig_storage_read_api_cc
Restrict the set of exported symbols to those in the aconfig_storage
namespace by way of a version script. This shrinks the shared lib size
by ~75%, from ~800KB to <200KB.

Bug: 336657207
Test: m
Change-Id: I56044fe667a713cf1d94f96c992f379a5725850f
2024-04-26 17:43:14 +00:00
Mårten Kongstad
18ff19a563 check-flagged-apis: parse classes
Teach check-flagged-apis to parse classes, including inner classes.

Bug: 334870672
Test: atest --host check-flagged-apis-test
Change-Id: I17f65d3af55a20a1920b47f4c47fd0e92f9fa852
2024-04-26 05:58:41 +02:00
Mårten Kongstad
04e4564f49 check-flagged-apis: add missing requireNotNull
Bug: 334870672
Test: atest --host check-flagged-apis-test
Change-Id: Ibffafb504240c82d525105d4678983b30b70592d
2024-04-26 05:39:03 +02:00
Ben Fennema
cd6de1bc7f Allow boot_variable_file to be read from input_target_files
If boot_variable_file is not found locally, look for it inside
input_target_files.

Bug: 335732867
Test: generate OTA with file in target-files.zip and verify metadata
Change-Id: I2e61f50850e82a3795f2e0e1aefcaf2329a8cfb1
2024-04-25 17:11:13 +00:00
Ted Bauer
966e558e9f Merge "Prune unnecessary symbols from read API" into main 2024-04-25 16:59:05 +00:00
Ted Bauer
ad07bd54f6 Prune unnecessary symbols from read API
Bug: 328444881
Test: m
Change-Id: I3b730a6c3390a5d116d467f15f17e74a9096961d
2024-04-25 15:51:15 +00:00
Dennis Shen
fe5065705c aconfig: update aconfig storage write api and test update
Simplify storage write api so that we don't need the storage records pb
file.

Bug: b/312444587
Test: atest -c
Change-Id: I7e336b1d7766983364715dae15786b91b0c0743f
2024-04-25 13:40:07 +00:00
Fabián Cañas
c1f344e980 Add * support products and modules
Passing "*" to --products is equivalent to passing the all_named_producs
build variable

Passing "*" to --modules passes the contents of
PRODUCT_OUT/all_modules.txt

The total length of the text of all_modules can easily exceed the
maximum argument size for the OS. The proper solution is likely to call
getconf ARG_MAX, then concatenate the command to be executed to check
against the limit. Instead, the modules are processed in batches of 40k
modules. As long as module names don't get extremely long, this should
keep us under the ARG_MAX limit. In testing, using --modules "*" gets
split into two batches.

Test: build/make/tools/whichgit --modules "*"
Test: build/make/tools/whichgit --modules "*" --unused
Test: build/make/tools/whichgit --modules "*" --products "*"

Existing use-cases should remain unchanged:

TEST: build/make/tools/whichgit --modules framework
Change-Id: Ifa947daea2d439df0145e6def92637b67a8b5d22
2024-04-24 21:23:58 +00:00
Jeff DeCew
c3bc24f33b Generate CustomFeatureFlags
* Creates a new general-purpose CustomFeatureFlags class
* Simplifies FakeFeatureFlagsImpl to be based on that
* This allows teams to fake FeatureFlags without having to make changes per flag.
* This allows SetFlagsRule to inject an instance of FeatureFlags that would detect if a flag has been read.

Bug: 336768870
Flag: none
Test: presubmit
Change-Id: Id3c2530d484fa5584c46d11381fcfc0ab294f33f

NOTE FOR REVIEWERS - original patch and result patch are not identical.
PLEASE REVIEW CAREFULLY.
Diffs between the patches:
     "CustomFeatureFlags.java",
> +        include_str!("../../templates/CustomFeatureFlags.java.template"),
> +    )?;
> +    template.add_template(
> -    ["Flags.java", "FeatureFlags.java", "FeatureFlagsImpl.java", "FakeFeatureFlagsImpl.java"]
> -        .iter()
> -        .map(|file| {
> -            Ok(OutputFile {
> -                contents: template.render(file, &context)?.into(),
> -                path: path.join(file),
> -            })
> -        })
> -        .collect::<Result<Vec<OutputFile>>>()
> +    [
> +        "Flags.java",
> +        "FeatureFlags.java",
> +        "FeatureFlagsImpl.java",
> +        "CustomFeatureFlags.java",
> +        "FakeFeatureFlagsImpl.java",
> +    ]
> +    .iter()
> +    .map(|file| {
> +        Ok(OutputFile { contents: template.render(file, &context)?.into(), path: path.join(file) })
> +    })
> +    .collect::<Result<Vec<OutputFile>>>()
> -    const EXPECTED_FAKEFEATUREFLAGSIMPL_CONTENT: &str = r#"
> +    const EXPECTED_CUSTOMFEATUREFLAGS_CONTENT: &str = r#"
> +
> -    import java.util.HashMap;
> -    import java.util.Map;
> +    import java.util.List;
> +    import java.util.function.BiPredicate;
> +    import java.util.function.Predicate;
> +
> -    public class FakeFeatureFlagsImpl implements FeatureFlags {
> -        public FakeFeatureFlagsImpl() {
> -            resetAll();
> +    public class CustomFeatureFlags implements FeatureFlags {
> +
> +        private BiPredicate<String, Predicate<FeatureFlags>> mGetValueImpl;
> +
> +        public CustomFeatureFlags(BiPredicate<String, Predicate<FeatureFlags>> getValueImpl) {
> +            mGetValueImpl = getValueImpl;
> +
> -            return getValue(Flags.FLAG_DISABLED_RO);
> +            return getValue(Flags.FLAG_DISABLED_RO,
> +                    FeatureFlags::disabledRo);
> -            return getValue(Flags.FLAG_DISABLED_RW);
> +            return getValue(Flags.FLAG_DISABLED_RW,
> +                FeatureFlags::disabledRw);
> -            return getValue(Flags.FLAG_DISABLED_RW_EXPORTED);
> +            return getValue(Flags.FLAG_DISABLED_RW_EXPORTED,
> +                FeatureFlags::disabledRwExported);
> -            return getValue(Flags.FLAG_DISABLED_RW_IN_OTHER_NAMESPACE);
> +            return getValue(Flags.FLAG_DISABLED_RW_IN_OTHER_NAMESPACE,
> +                FeatureFlags::disabledRwInOtherNamespace);
> -            return getValue(Flags.FLAG_ENABLED_FIXED_RO);
> +            return getValue(Flags.FLAG_ENABLED_FIXED_RO,
> +                FeatureFlags::enabledFixedRo);
> -            return getValue(Flags.FLAG_ENABLED_FIXED_RO_EXPORTED);
> +            return getValue(Flags.FLAG_ENABLED_FIXED_RO_EXPORTED,
> +                FeatureFlags::enabledFixedRoExported);
> -            return getValue(Flags.FLAG_ENABLED_RO);
> +            return getValue(Flags.FLAG_ENABLED_RO,
> +                FeatureFlags::enabledRo);
> -            return getValue(Flags.FLAG_ENABLED_RO_EXPORTED);
> +            return getValue(Flags.FLAG_ENABLED_RO_EXPORTED,
> +                FeatureFlags::enabledRoExported);
> -            return getValue(Flags.FLAG_ENABLED_RW);
> +            return getValue(Flags.FLAG_ENABLED_RW,
> +                FeatureFlags::enabledRw);
> -        public void setFlag(String flagName, boolean value) {
> -            if (!this.mFlagMap.containsKey(flagName)) {
> -                throw new IllegalArgumentException("no such flag " + flagName);
> -            }
> -            this.mFlagMap.put(flagName, value);
> -        }
> -        public void resetAll() {
> -            for (Map.Entry entry : mFlagMap.entrySet()) {
> -                entry.setValue(null);
> -            }
> -        }
> +
> +
> -        private boolean getValue(String flagName) {
> -            Boolean value = this.mFlagMap.get(flagName);
> -            if (value == null) {
> -                throw new IllegalArgumentException(flagName + " is not set");
> -            }
> -            return value;
> +
> +        protected boolean getValue(String flagName, Predicate<FeatureFlags> getter) {
> +            return mGetValueImpl.test(flagName, getter);
> -        private Map<String, Boolean> mFlagMap = new HashMap<>(
> -            Map.ofEntries(
> -                Map.entry(Flags.FLAG_DISABLED_RO, false),
> -                Map.entry(Flags.FLAG_DISABLED_RW, false),
> -                Map.entry(Flags.FLAG_DISABLED_RW_EXPORTED, false),
> -                Map.entry(Flags.FLAG_DISABLED_RW_IN_OTHER_NAMESPACE, false),
> -                Map.entry(Flags.FLAG_ENABLED_FIXED_RO, false),
> -                Map.entry(Flags.FLAG_ENABLED_FIXED_RO_EXPORTED, false),
> -                Map.entry(Flags.FLAG_ENABLED_RO, false),
> -                Map.entry(Flags.FLAG_ENABLED_RO_EXPORTED, false),
> -                Map.entry(Flags.FLAG_ENABLED_RW, false)
> -            )
> -        );
> +
> +        public List<String> getFlagNames() {
> +            return Arrays.asList(
> +                Flags.FLAG_DISABLED_RO,
> +                Flags.FLAG_DISABLED_RW,
> +                Flags.FLAG_DISABLED_RW_EXPORTED,
> +                Flags.FLAG_DISABLED_RW_IN_OTHER_NAMESPACE,
> +                Flags.FLAG_ENABLED_FIXED_RO,
> +                Flags.FLAG_ENABLED_FIXED_RO_EXPORTED,
> +                Flags.FLAG_ENABLED_RO,
> +                Flags.FLAG_ENABLED_RO_EXPORTED,
> +                Flags.FLAG_ENABLED_RW
> +            );
> +        }
> +
> +    const EXPECTED_FAKEFEATUREFLAGSIMPL_CONTENT: &str = r#"
> +    package com.android.aconfig.test;
> +
> +    import java.util.HashMap;
> +    import java.util.Map;
> +    import java.util.function.Predicate;
> +
> +    /** @hide */
> +    public class FakeFeatureFlagsImpl extends CustomFeatureFlags {
> +        private Map<String, Boolean> mFlagMap = new HashMap<>();
> +
> +        public FakeFeatureFlagsImpl() {
> +            super(null);
> +            // Initialize the map with null values
> +            for (String flagName : getFlagNames()) {
> +                mFlagMap.put(flagName, null);
> +            }
> +        }
> +
> +        @Override
> +        protected boolean getValue(String flagName, Predicate<FeatureFlags> getter) {
> +            Boolean value = this.mFlagMap.get(flagName);
> +            if (value == null) {
> +                throw new IllegalArgumentException(flagName + " is not set");
> +            }
> +            return value;
> +        }
> +
> +        public void setFlag(String flagName, boolean value) {
> +            if (!this.mFlagMap.containsKey(flagName)) {
> +                throw new IllegalArgumentException("no such flag " + flagName);
> +            }
> +            this.mFlagMap.put(flagName, value);
> +        }
> +
> +        public void resetAll() {
> +            for (Map.Entry entry : mFlagMap.entrySet()) {
> +                entry.setValue(null);
> +            }
> +        }
> +    }
> +    "#;
> +
> +                "com/android/aconfig/test/CustomFeatureFlags.java",
> +                EXPECTED_CUSTOMFEATUREFLAGS_CONTENT,
> +            ),
> +            (
> -        let expect_fake_feature_flags_impl_content = r#"
> +        let expect_custom_feature_flags_content = r#"
> +
> -        import java.util.HashMap;
> -        import java.util.Map;
> +        import java.util.List;
> +        import java.util.function.BiPredicate;
> +        import java.util.function.Predicate;
> +
> -        public class FakeFeatureFlagsImpl implements FeatureFlags {
> -            public FakeFeatureFlagsImpl() {
> -                resetAll();
> +        public class CustomFeatureFlags implements FeatureFlags {
> +
> +            private BiPredicate<String, Predicate<FeatureFlags>> mGetValueImpl;
> +
> +            public CustomFeatureFlags(BiPredicate<String, Predicate<FeatureFlags>> getValueImpl) {
> +                mGetValueImpl = getValueImpl;
> +
> -                return getValue(Flags.FLAG_DISABLED_RW_EXPORTED);
> +                return getValue(Flags.FLAG_DISABLED_RW_EXPORTED,
> +                    FeatureFlags::disabledRwExported);
> -                return getValue(Flags.FLAG_ENABLED_FIXED_RO_EXPORTED);
> +                return getValue(Flags.FLAG_ENABLED_FIXED_RO_EXPORTED,
> +                    FeatureFlags::enabledFixedRoExported);
> -                return getValue(Flags.FLAG_ENABLED_RO_EXPORTED);
> +                return getValue(Flags.FLAG_ENABLED_RO_EXPORTED,
> +                    FeatureFlags::enabledRoExported);
> -            public void setFlag(String flagName, boolean value) {
> -                if (!this.mFlagMap.containsKey(flagName)) {
> -                    throw new IllegalArgumentException("no such flag " + flagName);
> -                }
> -                this.mFlagMap.put(flagName, value);
> +
> +            protected boolean getValue(String flagName, Predicate<FeatureFlags> getter) {
> +                return mGetValueImpl.test(flagName, getter);
> -            public void resetAll() {
> -                for (Map.Entry entry : mFlagMap.entrySet()) {
> -                    entry.setValue(null);
> -                }
> +
> +            public List<String> getFlagNames() {
> +                return Arrays.asList(
> +                    Flags.FLAG_DISABLED_RW_EXPORTED,
> +                    Flags.FLAG_ENABLED_FIXED_RO_EXPORTED,
> +                    Flags.FLAG_ENABLED_RO_EXPORTED
> +                );
> -            private boolean getValue(String flagName) {
> -                Boolean value = this.mFlagMap.get(flagName);
> -                if (value == null) {
> -                    throw new IllegalArgumentException(flagName + " is not set");
> -                }
> -                return value;
> -            }
> -            private Map<String, Boolean> mFlagMap = new HashMap<>(
> -                Map.ofEntries(
> -                    Map.entry(Flags.FLAG_DISABLED_RW_EXPORTED, false),
> -                    Map.entry(Flags.FLAG_ENABLED_FIXED_RO_EXPORTED, false),
> -                    Map.entry(Flags.FLAG_ENABLED_RO_EXPORTED, false)
> -                )
> -            );
> +
> +                "com/android/aconfig/test/CustomFeatureFlags.java",
> +                expect_custom_feature_flags_content,
> +            ),
> +            (
> -                expect_fake_feature_flags_impl_content,
> +                EXPECTED_FAKEFEATUREFLAGSIMPL_CONTENT,
> +                "com/android/aconfig/test/CustomFeatureFlags.java",
> +                EXPECTED_CUSTOMFEATUREFLAGS_CONTENT,
> +            ),
> +            (
> -        let expect_fakefeatureflags_content = r#"
> +        let expect_customfeatureflags_content = r#"
> +
> -        import java.util.HashMap;
> -        import java.util.Map;
> +        import java.util.List;
> +        import java.util.function.BiPredicate;
> +        import java.util.function.Predicate;
> +
> -        public class FakeFeatureFlagsImpl implements FeatureFlags {
> -            public FakeFeatureFlagsImpl() {
> -                resetAll();
> +        public class CustomFeatureFlags implements FeatureFlags {
> +
> +            private BiPredicate<String, Predicate<FeatureFlags>> mGetValueImpl;
> +
> +            public CustomFeatureFlags(BiPredicate<String, Predicate<FeatureFlags>> getValueImpl) {
> +                mGetValueImpl = getValueImpl;
> +
> -                return getValue(Flags.FLAG_DISABLED_RO);
> +                return getValue(Flags.FLAG_DISABLED_RO,
> +                        FeatureFlags::disabledRo);
> -                return getValue(Flags.FLAG_DISABLED_RW);
> +                return getValue(Flags.FLAG_DISABLED_RW,
> +                    FeatureFlags::disabledRw);
> -                return getValue(Flags.FLAG_DISABLED_RW_IN_OTHER_NAMESPACE);
> +                return getValue(Flags.FLAG_DISABLED_RW_IN_OTHER_NAMESPACE,
> +                    FeatureFlags::disabledRwInOtherNamespace);
> -                return getValue(Flags.FLAG_ENABLED_FIXED_RO);
> +                return getValue(Flags.FLAG_ENABLED_FIXED_RO,
> +                    FeatureFlags::enabledFixedRo);
> -                return getValue(Flags.FLAG_ENABLED_RO);
> +                return getValue(Flags.FLAG_ENABLED_RO,
> +                    FeatureFlags::enabledRo);
> -                return getValue(Flags.FLAG_ENABLED_RW);
> +                return getValue(Flags.FLAG_ENABLED_RW,
> +                    FeatureFlags::enabledRw);
> -            public void setFlag(String flagName, boolean value) {
> -                if (!this.mFlagMap.containsKey(flagName)) {
> -                    throw new IllegalArgumentException("no such flag " + flagName);
> -                }
> -                this.mFlagMap.put(flagName, value);
> -            }
> -            public void resetAll() {
> -                for (Map.Entry entry : mFlagMap.entrySet()) {
> -                    entry.setValue(null);
> -                }
> -            }
> +
> +
> -            private boolean getValue(String flagName) {
> -                Boolean value = this.mFlagMap.get(flagName);
> -                if (value == null) {
> -                    throw new IllegalArgumentException(flagName + " is not set");
> -                }
> -                return value;
> +
> +            protected boolean getValue(String flagName, Predicate<FeatureFlags> getter) {
> +                return mGetValueImpl.test(flagName, getter);
> -            private Map<String, Boolean> mFlagMap = new HashMap<>(
> -                Map.ofEntries(
> -                    Map.entry(Flags.FLAG_DISABLED_RO, false),
> -                    Map.entry(Flags.FLAG_DISABLED_RW, false),
> -                    Map.entry(Flags.FLAG_DISABLED_RW_IN_OTHER_NAMESPACE, false),
> -                    Map.entry(Flags.FLAG_ENABLED_FIXED_RO, false),
> -                    Map.entry(Flags.FLAG_ENABLED_RO, false),
> -                    Map.entry(Flags.FLAG_ENABLED_RW, false)
> -                )
> -            );
> +
> +            public List<String> getFlagNames() {
> +                return Arrays.asList(
> +                    Flags.FLAG_DISABLED_RO,
> +                    Flags.FLAG_DISABLED_RW,
> +                    Flags.FLAG_DISABLED_RW_IN_OTHER_NAMESPACE,
> +                    Flags.FLAG_ENABLED_FIXED_RO,
> +                    Flags.FLAG_ENABLED_RO,
> +                    Flags.FLAG_ENABLED_RW
> +                );
> +            }
> +
> +
> -            ("com/android/aconfig/test/FakeFeatureFlagsImpl.java", expect_fakefeatureflags_content),
> +            ("com/android/aconfig/test/CustomFeatureFlags.java", expect_customfeatureflags_content),
> +            (
> +                "com/android/aconfig/test/FakeFeatureFlagsImpl.java",
> +                EXPECTED_FAKEFEATUREFLAGSIMPL_CONTENT,
> +            ),
> --- /dev/null
> +++ tools/aconfig/aconfig/templates/CustomFeatureFlags.java.template
> +package {package_name};
> +
> +{{ if not library_exported- }}
> +// TODO(b/303773055): Remove the annotation after access issue is resolved.
> +import android.compat.annotation.UnsupportedAppUsage;
> +{{ -endif }}
> +import java.util.Arrays;
> +import java.util.HashSet;
> +import java.util.List;
> +import java.util.Set;
> +import java.util.function.BiPredicate;
> +import java.util.function.Predicate;
> +
> +/** @hide */
> +public class CustomFeatureFlags implements FeatureFlags \{
> +
> +    private BiPredicate<String, Predicate<FeatureFlags>> mGetValueImpl;
> +
> +    public CustomFeatureFlags(BiPredicate<String, Predicate<FeatureFlags>> getValueImpl) \{
> +        mGetValueImpl = getValueImpl;
> +    }
> +
> +{{ -for item in flag_elements}}
> +    @Override
> +{{ if not library_exported }}    @UnsupportedAppUsage{{ -endif }}
> +    public boolean {item.method_name}() \{
> +        return getValue(Flags.FLAG_{item.flag_name_constant_suffix},
> +            FeatureFlags::{item.method_name});
> +    }
> +{{ endfor }}
> +
> +{{ -if not library_exported }}
> +    public boolean isFlagReadOnlyOptimized(String flagName) \{
> +        if (mReadOnlyFlagsSet.contains(flagName) &&
> +            isOptimizationEnabled()) \{
> +                return true;
> +        }
> +        return false;
> +    }
> +
> +    @com.android.aconfig.annotations.AssumeTrueForR8
> +    private boolean isOptimizationEnabled() \{
> +        return false;
> +    }
> +{{ -endif }}
> +
> +    protected boolean getValue(String flagName, Predicate<FeatureFlags> getter) \{
> +        return mGetValueImpl.test(flagName, getter);
> +    }
> +
> +    public List<String> getFlagNames() \{
> +        return Arrays.asList(
> +            {{ -for item in flag_elements }}
> +            Flags.FLAG_{item.flag_name_constant_suffix}
> +            {{ -if not @last }},{{ endif }}
> +            {{ -endfor }}
> +        );
> +    }
> +
> +    private Set<String> mReadOnlyFlagsSet = new HashSet<>(
> +        Arrays.asList(
> +            {{ -for item in flag_elements }}
> +            {{ -if not item.is_read_write }}
> +            Flags.FLAG_{item.flag_name_constant_suffix},
> +            {{ -endif }}
> +            {{ -endfor }}
> +            ""{# The empty string here is to resolve the ending comma #}
> +        )
> +    );
> +}
> --- tools/aconfig/aconfig/templates/FakeFeatureFlagsImpl.java.template
> +++ tools/aconfig/aconfig/templates/FakeFeatureFlagsImpl.java.template
> -{{ if not library_exported- }}
> -// TODO(b/303773055): Remove the annotation after access issue is resolved.
> -import android.compat.annotation.UnsupportedAppUsage;
> -{{ -endif }}
> -import java.util.Arrays;
> +
> -import java.util.HashSet;
> -import java.util.Set;
> +import java.util.function.Predicate;
> -public class FakeFeatureFlagsImpl implements FeatureFlags \{
> +public class FakeFeatureFlagsImpl extends CustomFeatureFlags \{
> +    private Map<String, Boolean> mFlagMap = new HashMap<>();
> +
> -        resetAll();
> +        super(null);
> +        // Initialize the map with null values
> +        for (String flagName : getFlagNames()) \{
> +            mFlagMap.put(flagName, null);
> +        }
> -{{ for item in flag_elements}}
> -{{ if not library_exported }}    @UnsupportedAppUsage{{ -endif }}
> -    public boolean {item.method_name}() \{
> -        return getValue(Flags.FLAG_{item.flag_name_constant_suffix});
> +    protected boolean getValue(String flagName, Predicate<FeatureFlags> getter) \{
> +        Boolean value = this.mFlagMap.get(flagName);
> +        if (value == null) \{
> +            throw new IllegalArgumentException(flagName + " is not set");
> +        }
> +        return value;
> -{{ endfor}}
> +
> -{{ if not library_exported }}
> -    public boolean isFlagReadOnlyOptimized(String flagName) \{
> -        if (mReadOnlyFlagsSet.contains(flagName) &&
> -            isOptimizationEnabled()) \{
> -                return true;
> -        }
> -        return false;
> -    }
> -
> -    @com.android.aconfig.annotations.AssumeTrueForR8
> -    private boolean isOptimizationEnabled() \{
> -        return false;
> -    }
> -{{ -endif }}
> -    private boolean getValue(String flagName) \{
> -        Boolean value = this.mFlagMap.get(flagName);
> -        if (value == null) \{
> -            throw new IllegalArgumentException(flagName + " is not set");
> -        }
> -        return value;
> -    }
> -
> -
> -    private Map<String, Boolean> mFlagMap = new HashMap<>(
> -        Map.ofEntries(
> -            {{ -for item in flag_elements }}
> -            Map.entry(Flags.FLAG_{item.flag_name_constant_suffix}, false)
> -            {{ -if not @last }},{{ endif }}
> -            {{ -endfor }}
> -        )
> -    );
> -
> -    private Set<String> mReadOnlyFlagsSet = new HashSet<>(
> -        Arrays.asList(
> -            {{ -for item in flag_elements }}
> -            {{ -if not item.is_read_write }}
> -            Flags.FLAG_{item.flag_name_constant_suffix},
> -            {{ -endif }}
> -            {{ -endfor }}
> -            ""{# The empty string here is to resolve the ending comma #}
> -        )
> -    );

Original patch:
 diff --git a/tools/aconfig/aconfig/src/codegen/java.rs b/tools/aconfig/aconfig/src/codegen/java.rs
old mode 100644
new mode 100644
--- a/tools/aconfig/aconfig/src/codegen/java.rs
+++ b/tools/aconfig/aconfig/src/codegen/java.rs
@@ -63,21 +63,28 @@
         "FeatureFlags.java",
         include_str!("../../templates/FeatureFlags.java.template"),
     )?;
+    template.add_template(
+        "CustomFeatureFlags.java",
+        include_str!("../../templates/CustomFeatureFlags.java.template"),
+    )?;
     template.add_template(
         "FakeFeatureFlagsImpl.java",
         include_str!("../../templates/FakeFeatureFlagsImpl.java.template"),
     )?;
 
     let path: PathBuf = package.split('.').collect();
-    ["Flags.java", "FeatureFlags.java", "FeatureFlagsImpl.java", "FakeFeatureFlagsImpl.java"]
-        .iter()
-        .map(|file| {
-            Ok(OutputFile {
-                contents: template.render(file, &context)?.into(),
-                path: path.join(file),
-            })
-        })
-        .co
[[[Original patch trimmed due to size. Decoded string size: 26318. Decoded string SHA1: 7db34b7baf0a0bbaa1cff48b6ccab9c65408e743.]]]

Result patch:
 diff --git a/tools/aconfig/aconfig/src/codegen/java.rs b/tools/aconfig/aconfig/src/codegen/java.rs
index 18a4be5..9abc892 100644
--- a/tools/aconfig/aconfig/src/codegen/java.rs
+++ b/tools/aconfig/aconfig/src/codegen/java.rs
@@ -64,20 +64,27 @@
         include_str!("../../templates/FeatureFlags.java.template"),
     )?;
     template.add_template(
+        "CustomFeatureFlags.java",
+        include_str!("../../templates/CustomFeatureFlags.java.template"),
+    )?;
+    template.add_template(
         "FakeFeatureFlagsImpl.java",
         include_str!("../../templates/FakeFeatureFlagsImpl.java.template"),
     )?;
 
     let path: PathBuf = package.split('.').collect();
-    ["Flags.java", "FeatureFlags.java", "FeatureFlagsImpl.java", "FakeFeatureFlagsImpl.java"]
-        .iter()
-        .map(|file| {
-            Ok(OutputFile {
-                contents: template.render(file, &context)?.into(),
-                path: path.join(file),
-            })
-        })
-        .collect::<Result<Vec<OutputFile>>>
[[[Result patch trimmed due to size. Decoded string size: 26308. Decoded string SHA1: bb07ee948a630a6bc4cfbbf2a8df178f3e6d3103.]]]

Change-Id: I94184633303b9d76f7943451fb3b2c93d071ec1c
2024-04-24 14:43:27 +00:00
Fabián Cañas
e0c74fbdd6 Merge "Add --unused parameter to whichgit" into main 2024-04-24 13:11:08 +00:00
Fabián Cañas
97ea68aea6 Add --unused parameter to whichgit
The --unused parameter inverts the output of whichgit, reporting which
git projects are not used for a given build target.

Test: build/make/tools/whichgit --unused
Test: build/make/tools/whichgit --unused --modules framework

Existing use-cases should remain unchanged:

Test: build/make/tools/whichgit --modules framework
Change-Id: Ia4e55a5cb0331d522fed76821fe813ef98c25a67
2024-04-23 21:28:29 -04:00
Michael Wright
c55d79b7c7 Make check-flagged-apis executable
Occasionally sourcing the script would close my overall shell when it
hit an error. By having it just be an executable script, this prevents
it from impacting a user's normal shell environment and can depend on it
always being bash, rather than whatever shell people happen to be using.

Bug: 334870672
Test: tools/check-flagged-apis/check-flagged-apis.sh
Change-Id: Ic46cb4fefdea8d51be018d4f7a92b0d9ca7e57b3
2024-04-24 01:05:49 +02:00
Ted Bauer
171944d88a Merge "Update aconfig storage deps for CPP codegen" into main 2024-04-23 22:56:50 +00:00
Treehugger Robot
6974bbf7ee Merge "Update sdk finalizer to change soong instead of bazel" into main 2024-04-23 20:26:05 +00:00
Dennis Shen
59274f816c Merge "aconfig: remove cache filtering by container" into main 2024-04-23 20:17:35 +00:00
Michael Merg
c9d54b0877 Merge "Set enforce SOONG_GEN_COMPDB=1 when running soong for ide_query" into main 2024-04-23 19:59:04 +00:00
Jihoon Kang
ed37595aaf Update sdk finalizer to change soong instead of bazel
Update the map in soong instead of that in bazel

Bug: 315353489
Test: manual
Merged-In: I3a51be1119109d2a6cf3959bdc8a48192872580f
Change-Id: Ia61a17be4a7d85c00d2e9758ea2409019d451dfd
2024-04-23 19:53:46 +00:00
Dennis Shen
67e44dd2c3 Merge "aconfig: update flag info storage file" into main 2024-04-23 18:08:13 +00:00
Ted Bauer
8d20d51bf8 Update aconfig storage deps for CPP codegen
Bug: 328444881
Test: m AconfigDemoActivity
Change-Id: I12d746d3270dce39533e1afd213343e232044161
2024-04-23 18:07:40 +00:00
Dennis Shen
1ebcd017ae aconfig: remove cache filtering by container
No need for cache filtering based on container anymore. This is now
performed by build system automatically. The caches feed into storage
generation command are automatically filtered based on owning
container.

Bug: b/312444587
Test: atest aconfig.test
Change-Id: I44f3ac03d50b77a191a82ff7ed4d02766012492d
2024-04-19 21:44:32 +00:00
Treehugger Robot
563a2f62c5 Merge "fixup! Support generating partial OTAs from extracted target_files" into main 2024-04-19 16:19:32 +00:00
Michael Wright
2d3e50527d Merge changes I8b5e2642,I0520ab0f into main
* changes:
  check-flagged-apis: add script to run tool on actual data
  check-flagged-apis: simplify unit test dependencies
2024-04-19 15:25:22 +00:00
Dennis Shen
6f4c692948 aconfig: update flag info storage file
previously we store three bits per flag: is sticky, is read write, has
override. so when a local override arrives, is sticky bit as well has
override bit are set to true. this becomes problematic when the local
override is removed. we are not sure if we should remove has override
bit as well (server override could still be in place).

therefore restructuring the flag info for each flag into new three bits:
is read write, has server override and has local override. so now server
override and local override bits are independent from each other.

Bug: b/312444587
Test: atest -c
Change-Id: I03b2bb7312480773236c95f2b39f2589fee41924
2024-04-18 21:22:49 +00:00
Chirayu Desai
c8edf8af33 fixup! Support generating partial OTAs from extracted target_files
Test: Sign crosshatch
Change-Id: I6728da3a3a50ee24a35581af7e6ead3e13c5ff1d
2024-04-19 02:49:17 +05:30
Ted Bauer
206d44aff5 aflags: read protos from all containers
Create one library for reading protos from all containers, instead of
having numerous libraries perform the same logic. For Java, we will
create a similar library reusing the same
partition_aconfig_flags_paths.txt.

Bug: 324436145
Test: adb shell aflags list # Confirm that various containers appear
Change-Id: I924e281a50f9a609e1c07c03267eebe3dce52752
2024-04-18 14:38:41 +00:00
Mårten Kongstad
76460bd770 check-flagged-apis: add script to run tool on actual data
Add a script to make it easier to check-flagged-apis for the public APIs
and the three flavours of @FlaggedApi.

Bug: 334870672
Test: lunch sdk-next-eng && source check-flagged-apis.sh
Change-Id: I8b5e2642ade84560c5c61ae49d8c0dcdedb841ca
2024-04-18 16:13:52 +02:00
Michael Merg
75d934f261 Set enforce SOONG_GEN_COMPDB=1 when running soong for ide_query
Change-Id: I125a82fb07285bf53e9a6d591dee69d85ee82050
2024-04-18 12:06:31 +00:00
Mårten Kongstad
7cc217459a check-flagged-apis: simplify unit test dependencies
Replace the current unit test runner DeviceJUnit4ClassRunner with JUnit4
and replace the (larger) dependency tradefed with the (smaller)
dependency junit.

This has no impact other than minimizing the unit test static_libs.

Bug: 334870672
Test: atest --host check-flagged-apis-test
Change-Id: I0520ab0feeea5ea2ed15905136ba2647f86162cb
2024-04-18 10:25:33 +02:00
Dennis Shen
e6b424ad4a Merge "aconfig: add support for local override" into main 2024-04-17 19:07:56 +00:00
Mårten Kongstad
9238a3ab76 check-flagged-apis: create list of @FlaggedApi errors
Teach check-flagged-apis to cross-check the data from its three input
sources. This allows the tool to detect

  - @FlaggedApi references to non-existent flags
  - @FlaggedApi APIs present in the build artifacts even though the flag
    is disabled
  - @FlaggedApi APIs not present in the build artifacts even though the
    flag is enabled

By passing in different sources, the tool can detect these errors for
any of the API surfaces (public, @SystemApi(MODULE_LIBRARIES), etc).

Note: the tool assumes that a disabled flag means that the @FlaggedApi
should not be present in the build output. This is currently true, but
won't be once metalava starts reverting @FlaggedApis to their previous
SDK snapshot.

Bug: 334870672
Test: atest --host check-flagged-apis-test
Test: check-flagged-apis --api-signature out/target/product/mainline_x86/obj/ETC/frameworks-base-api-current.txt_intermediates/frameworks-base-api-current.txt --flag-values out/soong/.intermediates/all_aconfig_declarations.pb --api-versions out/dist/data/api-versions.xml
Change-Id: I790234865f831af7d45895def14d1d6740365622
2024-04-17 16:40:03 +02:00
Mårten Kongstad
b673d3bb7d check-flagged-apis: parse API versions XML
Teach check-flagged-apis to parse API versions XML; this represents the
APIs after metalava has processed the source and kept APIs as is, or
reverted them to the previous SDK snapshot, according to their
@FlaggedApi flags.

As with the API signature parser, limit support to fields to keep things
simple; support for classes and methods will be added in later CLs.

Note: `m sdk dist` will generate an API versions XML file.

Bug: 334870672
Test: atest --host check-flagged-apis-test
Test: check-flagged-apis --api-signature out/target/product/mainline_x86/obj/ETC/frameworks-base-api-current.txt_intermediates/frameworks-base-api-current.txt --flag-values out/soong/.intermediates/all_aconfig_declarations.pb --api-versions out/dist/data/api-versions.xml
Change-Id: I779a0d0cdb8a50536d3fc8d517fa38ba4b0dcd1c
2024-04-17 15:27:48 +02:00
Mårten Kongstad
387ff6cfe8 check-flagged-apis: parse flag names and values
Teach check-flagged-apis to parse the parsed_flags protobuf generated by
aconfig.

Note: `m all_aconfig_declarations` generates a protobuf file that
contains all info about all flags.

Bug: 334870672
Test: atest --host check-flagged-apis-test
Test: check-flagged-apis --api-signature out/target/product/mainline_x86/obj/ETC/frameworks-base-api-current.txt_intermediates/frameworks-base-api-current.txt --flag-values out/soong/.intermediates/all_aconfig_declarations.pb
Change-Id: I397b32ae2a373b429ef6ce22e0a06a0f15202b91
2024-04-17 15:27:48 +02:00
Mårten Kongstad
20de405dd5 check-flagged-apis: parse API signature files
Teach check-flagged-apis to extract flagged APIs from API signature files.

To keep things simple, only consider fields for now: support for classes
and methods will be added in a later CL.

Note: `m frameworks-base-api-current.txt` will generate an API signature
file that includes both the platform and mainline APIs.

Bug: 334870672
Test: atest --host check-flagged-apis-test
Test: check-flagged-apis --api-signature out/target/product/mainline_x86/obj/ETC/frameworks-base-api-current.txt_intermediates/frameworks-base-api-current.txt
Change-Id: Ic244b896672569f44af793796189b34c1f9d0c36
2024-04-17 15:27:48 +02:00
Mårten Kongstad
f242ec8989 check-flagged-apis: add unit test infrastructure
Add scaffolding for unit tests.

Bug: 334870672
Test: atest --host check-flagged-apis-test
Change-Id: I5ccf2a6424c19e739923379cdc41c359388484da
2024-04-17 15:27:45 +02:00
Dennis Shen
9f236037a2 aconfig: add support for local override
1, add a new field in storage metadata proto, for each container, there
is a local override file.

2, update write api to expose the api to map a writable file given the
specific path. the cannonical api will require a storage metadata proto,
and then find the right file path and map it.

3, minor update to make the proto lib cc_library instead of
cc_library_static

Bug: b/312444587
Test: atest -c
Change-Id: Iaf0aff44c1ca3ad4bffc5e06bb99bb276b9069c5
2024-04-17 12:25:11 +00:00
Mårten Kongstad
dc3fc2e0bc check-flagged-apis: add Flag value class
Add a value class to represent Flag names. We could use plain Strings
but having a dedicated class (with no overhead compared to String) makes
the intent of the code much clearer.

Bug: 334870672
Test: m check-flagged-apis && check-flagged-apis
Change-Id: Icdd4fb97d3fd49e507b7559504ea173a3dc52dea
2024-04-17 09:54:53 +02:00
Mårten Kongstad
e0179976cd check-flagged-apis: add Symbol value class
check-flagged-apis will read contents from various sources, which use
different formats to represent the same piece information (e.g.
"class#field" or "<class><field>").

Introduce a Symbol value class to represent any API (i.e. a class, field
or method) in a unified format.

Bug: 334870672
Test: m check-flagged-apis && check-flagged-apis
Change-Id: Id9404294a87b23a9d43e5e13ce39ea5a92608e33
2024-04-17 09:54:53 +02:00
Mårten Kongstad
4feb33fefc Merge "check-flagged-apis: add support for command line options" into main 2024-04-17 05:52:09 +00:00
Mårten Kongstad
e2ec38c51b Merge "check-flagged-apis: add new CLI to verify @FlaggedApi APIs" into main 2024-04-17 05:51:48 +00:00
Daniel Zheng
2fc519a568 Merge "ota_from_target_files: read correct api level" into main 2024-04-16 19:32:37 +00:00
Daniel Zheng
dc411eda4c ota_from_target_files: read correct api level
ro.product.first_api_level looks like the value we actually want to read
to since it inherits from $PRODUCT_SHIPPING_API_LEVEL. Other variables
we attempted to look at were giving other values (e.g 202504 for pixel
watch)

Bug: 331202590
Test: th
Change-Id: Ied3da247cba45611132db6c9e3cdefb447891f96
2024-04-16 12:32:05 -07:00
Mårten Kongstad
acfeb11d86 check-flagged-apis: add support for command line options
Use clikt as the command line options parser library.

Bug: 334870672
Test: m check-flagged-apis && check-flagged-apis
Change-Id: I7c406456b00e29293294dcdbef411d2543a1e8d5
2024-04-16 10:32:17 +02:00
Mårten Kongstad
9008724b50 check-flagged-apis: add new CLI to verify @FlaggedApi APIs
Add a new CLI to verify that the build artifacts contain the right set
of @FlaggedApi APIs, based on the value of the corresponding aconfig
flag.

This CLI will act as an end-to-end test of Soong and metalava.

This CL only adds the project scaffolding; later CLs will add the
implementation.

Bug: 334870672
Test: m check-flagged-apis && check-flagged-apis
Change-Id: Ib00653f2a549217da2b0058867c711f35efd5760
2024-04-16 10:32:17 +02:00
Treehugger Robot
8b1e29ae7e Merge "Make output of MakeVbmeta consistent" into main 2024-04-15 22:27:36 +00:00
Ted Bauer
8f9ca8075f Merge "aconfig: switch read api lib to cc_library" into main 2024-04-15 17:22:00 +00:00
Kelvin Zhang
1d9b3daad2 Make output of MakeVbmeta consistent
The order of items in `partitions` map is non-deterministic. To make
sure that builds are hermetic, sort the map before use.

Test: th
Bug: 332550989
Change-Id: I76c7037ef9f03904899339813819fcf985a7c893
2024-04-15 09:45:03 -07:00
Dennis Shen
36661d4cd0 aconfig: switch read api lib to cc_library
Bug: b/321077378
Test: atest -c
Change-Id: I8d64396797b01a8ce2f4bee165596701940836e4
2024-04-12 21:21:44 +00:00
Dennis Shen
7d642b10df Merge "aconfig: add write api cpp test to presubmit" into main 2024-04-12 18:26:55 +00:00