Commit Graph

449 Commits

Author SHA1 Message Date
Dennis Shen
19370a0a31 aconfig: create memory map file module
This module is repsonsible for finding the storage file location based on a
pb file and then map these storage files into memory using memmap2
crate. The mapped files are cached in a static hashmap in this module.

Note that memmap2 crate has not been introduced to AOSP yet as a 3p
crate. It is in the process of importing to AOSP ATM. So in src/lib.rs,
we only include this module if we are building the target using cargo.

Also, the test storage files: package.map, flag.map and flag.val are
generated based on the storage test aconfig files in
aconfig/aconfig/tests dir. With aconfig create-cache command first to
produce cache files, and then aconfig create-storage command to create
each storage file.

aconfig create-cache --package com.android.aconfig.storage.test_1 --container system --declarations ./storage_test_1.aconfig --cache com.android.aconfig.storage.test_1.cache

aconfig create-cache --package com.android.aconfig.storage.test_2 --container system --declarations ./storage_test_2.aconfig --cache com.android.aconfig.storage.test_2.cache

aconfig create-cache --package com.android.aconfig.storage.test_4 --container system --declarations ./storage_test_4.aconfig --cache com.android.aconfig.storage.test_4.cache

aconfig create-storage --container system  --cache ./com.android.aconfig.storage.test_1.cache --cache ./com.android.aconfig.storage.test_2.cache --cache ./com.android.aconfig.storage.test_4.cache --file flag_val --out ./flag.value

aconfig create-storage --container system  --cache ./com.android.aconfig.storage.test_1.cache --cache ./com.android.aconfig.storage.test_2.cache --cache ./com.android.aconfig.storage.test_4.cache --file package_map --out ./package.map

aconfig create-storage --container system  --cache ./com.android.aconfig.storage.test_1.cache --cache ./com.android.aconfig.storage.test_2.cache --cache ./com.android.aconfig.storage.test_4.cache --file flag_map --out ./flag.map

Bug: 321077378
Test: atest aconfig_storage_file.test
Change-Id: Id4bd26ce1a2513cdda201b479cec2b8c04faabfe
2024-01-31 13:54:16 +00:00
Mårten Kongstad
6fdaa11d7c aconfig: fix formatting warnings
Update the rust toolchain to 1.75.0 and run `cargo fmt`.

Bug: N/A
Test: cargo fmt --check
Test: atest :all
Change-Id: I718c350f4c346b85ff3608f3101278c2ee776b36
2024-01-31 09:40:21 +01:00
Dennis Shen
eef9192987 aconfig: remove bucket_index from PackageTableNode/FlagTableNode struct
bucket index currently is a field in PackageTableNode/FlagTableNode, but this is
purely aux info that is never searilized or deserialized. Therefore we
should remove it from the struct definition. Instead aconfig should
define a wrapper struct that wraps around an instance PackageTableNode/FlagTableNode
as well as aux info like bucket_index.

Bug: 321077378
Test: atest aconfig.test && atest aconfig_storage_file.test
Change-Id: I20f2565d20b7feb5d39754e91cd6a9affb1f0e70
2024-01-30 15:16:29 +00:00
Dennis Shen
f39e4a2273 Merge "aconfig: add flag value query pub function" into main 2024-01-29 20:48:48 +00:00
Dennis Shen
9a76f645a2 Merge "aconfig: add flag table offset query function" into main 2024-01-29 19:47:23 +00:00
Dennis Shen
043a1eec4d Merge "aconfig: create package table query public function" into main 2024-01-29 19:47:15 +00:00
Dennis Shen
78bea3d66c aconfig: add flag value query pub function
Bug: b/321077378
Test: atest aconfig_storage_file.test
Change-Id: I83dd93c5f8d640ddbe85493a470af68df1e3e69d
2024-01-29 18:54:13 +00:00
Dennis Shen
9fd970198d aconfig: add flag table offset query function
Bug: b/321077378
Test: atest aconfig.test; atest aconfig_storage_file.test
Change-Id: Ib0ec1ec809c65d8f9f1284e4214cfbb683812f1d
2024-01-29 15:11:55 +00:00
Dennis Shen
8aa9bbeb99 aconfig: create package table query public function
Bug: b/321077378
Test: atest aconfig.test
Change-Id: I097e8ebecff6d5d9e73738a7f80a63cb482bcfbe
2024-01-29 14:43:19 +00:00
Mårten Kongstad
edd678063c aconfig: fix workspace resolver warning
Fix the following warning:

  warning: virtual workspace defaulting to `resolver = "1"` despite one or more workspace members being on edition 2021 which implies `resolver = "2"`
  note: to keep the current resolver, specify `workspace.resolver = "1"` in the workspace root's manifest
  note: to use the edition 2021 resolver, specify `workspace.resolver = "2"` in the workspace root's manifest
  note: for more details see https://doc.rust-lang.org/cargo/reference/resolver.html#resolver-versions

Further info: https://doc.rust-lang.org/edition-guide/rust-2021/default-cargo-resolver.html

Bug: N/A
Test: cargo c # no warnings related to the resolver
Change-Id: I5ee546e4f2ba9e854026bf4baee380e89cf4a01b
2024-01-29 14:51:51 +01:00
Dennis Shen
997745dc13 aconfig: add aconfig_storage_metadata proto
Introduce a new proto to capture storage file location for each
container. This proto file will appeara as
/metadata/aconfig/storage_file_location.pb. Storage service daemon is
responsible for writing entires to it when a new storage file set is
available. The flag read lib will use this file to find the
corresponding storage file and mmap them.

Bug: b/321077378
Test: atest aconfig_storage_file.test
Change-Id: I226e76be895805dce52a075050dcd5b42d337be8
2024-01-26 18:02:07 +00:00
Dennis Shen
c7a1c76e28 Merge "aconfig: create unit test targets for aconfig_protos and aconfig_storage_file crate" into main 2024-01-26 18:01:54 +00:00
Dennis Shen
a4294b0c6a aconfig: create unit test targets for aconfig_protos and
aconfig_storage_file crate

also added a bunch of comments to satisfy android lint requirements

Bug: b/321077378
Test: atest aconfig.test, atest aconfig_protos.test, atest aconfig_storage_files.test
Change-Id: I9bce302ac3bc98c5347e5334d915e77337ee89c4
2024-01-25 17:33:36 +00:00
Zhi Dou
b874ca75e4 aconfig: add isOptimizationEnabled in FakeFeatureFlagsImpl
This change adds isOptimizationEnabled method in FakeFeatureFlagsImpl.
This method can help test to decide whether the code using flag is
optimized.

Bug: 309406391
Test: atest aconfig.test aconfig.test.java
Change-Id: I7e7109ac06ab44f9b8dee56c76be9479f60a9148
2024-01-25 16:07:32 +00:00
Dennis Shen
cf9a752092 aconfig: create aconfig_storage_file crate
Move aconfig storage file definition into its own crate, as flag read
lib will need it as well. The new crate is placed under
aconfig_storage_file dir.

Bug: b/321077378
Test: atest aconfig.test, Cargo test at repo root level
Change-Id: I91e8ada2c9bab479ed81cf03824042f3fa460be5
2024-01-24 21:33:42 +00:00
Dennis Shen
277e5dc36e Restructure aconfig repo to be a cargo workspace with many crates
Previously, aconfig repo is the root directory of aconfig binary crate,
but it also hosts printflags crate inside, and there is no cargo support
for printflags binary crate. In addition, with more aconfig development,
more crates are being added to this repo. Thus this repo should be
configured as a Cargo workspace with multiple crates rather than a
single crate.

Note the top level Cargo.toml file specifies the crates this workspace
carries:
(1) aconfig_protos: the proto library crate that will be used by many other
crates such as aconfig binary crate and printflags binary crate
(2) aconfig: the aconfig binary crate
(3) printflags: the printflags binary crate

(1) aconfig_protos crate setup:

Inside aconfig_protos dir we set up the aconfig_protos crate, the
previously src/proto.rs is now aconfig_protos/src/lib.rs, the build.rs
is carried over to this crate.

(2) aconfig binary crate setup:

Notice its Cargo.toml file claims package dependency on aconfig_protos
crate. It no longer carries proto related module and build.rs file.

(3) printflags binary crate setup:

Similary, notice that in its Cargo.toml file, it claims package
dependency on aconfig_protos crate.

With this setup, we can Cargo build/test each crate individually when
inside a specific crate dir. But we can also run Cargo build/test at
repo root level, which will build/test all the crates in this workplace.

This is the structuring cl. The next cl is to move storage modules into
its own library crate. This storage file library crate will be used by
both aconfig binary crate as well as flag read library crate (to be
created as another new crate here).

Bug: b/321984352
Test: top and individual crate dir level Cargo build/test, m each
individual targets

Change-Id: I75833f4997f7ee554ff6c1557df9ac87f62b2732
Merged-In: I75833f4997f7ee554ff6c1557df9ac87f62b2732
2024-01-24 02:18:52 +00:00
Dennis Shen
bac87875fa aconfig: create one file at each create-storage command invocation
Based on the build system feedback, it is better to create storage file
individually per each aconfig command invocation in a makefile. Thus
updating the create-storage command to create one file at a time based
on passed in file selection.

Bug: b/321243743
Test: atest aconfig.test and manually invoke create-storage command
Change-Id: I53625c08e44d3ece4476835827c6b7d28ddd5a1b
2024-01-19 19:02:07 +00:00
Dennis Shen
12eacc1e4e Merge "aconfig: create flag value file" into main 2024-01-12 18:37:53 +00:00
Treehugger Robot
45db966e90 Merge "aconfig: update cache arg to support multiple cache files" into main 2024-01-12 14:28:19 +00:00
Dennis Shen
d4ea260758 aconfig: create flag value file
Create flag_value module to create flag value file. Flag value file
contains a header section at the start of the file, followed by a
boolean array.

Bug: b/312243587
Test: atest aconfig.test
Change-Id: If76660189d63073fbd477e1e447240e0cd029604
2024-01-12 13:44:51 +00:00
Treehugger Robot
375cb9ab07 Merge "aconfig: Print flags with namespace, and sort them" into main 2024-01-12 04:31:30 +00:00
Dennis Shen
88ec7f624f Merge "aconfig: add flag type in flag table and remove info byte from value array" into main 2024-01-11 18:43:18 +00:00
Dennis Shen
cfb65827d8 aconfig: update cache arg to support multiple cache files
Bug: b/312243587
Test: atest aconfig.test
Change-Id: I6f5f9b5ca6e2a60b8aac9ea8bf3032b00b7af7da
2024-01-11 17:13:39 +00:00
Dennis Shen
d088650481 aconfig: add flag type in flag table and remove info byte from value
array

1, add flag type to the flag table. Before flag table only stores the
mapping from (package id, flag name) to (flag id u32). The original
intent is to do bitmasking on the top byte of flag id to indicate flag
type. Now split the flag id u32 to two u16, the first represent flag
type, the second represent flag id. So after the change, the flag table
now shows the following mapping:

(package id, flag name) -> (flag type as u16, flag id as u16)

2, originally we plan to store a info byte together with each flag
value. The info byte is used by storage service damemon to mark up the
flag status, such as if it is accepting server side flag push. After
internal discussion, it is better to just create the info bytes as
another file by storage service damemon. So that the value file is
purely a flag value array.

Bug: b/312243587
test: atest aconfig.test
Change-Id: I7f953076b4269cf786bc23723078290e5ebe10bc
2024-01-11 15:30:10 +00:00
Dennis Shen
25167e387f aconfig: remove debug print out
Bug: b/312243587
Test: atest aconfig.test
Change-Id: Id1bd4b5a1e60a7906908a432f58d45d2a4a56248
2024-01-10 22:55:37 +00:00
Dennis Shen
9b5d19bdff Merge "aconfig: create flag.map storage file" into main 2024-01-08 17:30:39 +00:00
Dennis Shen
01fca9877b Merge "aconfig: update storage unit test case" into main 2024-01-08 17:30:39 +00:00
Treehugger Robot
868f3e8dba Merge "aconfig: simplify is_valid_container" into main 2024-01-08 17:28:19 +00:00
Mårten Kongstad
32c6ef5e25 aconfig: simplify is_valid_container
str::split always returns at least one item (the entire string) if the
delimiter is not found. Simplify the implementation of
is_valid_container accordingly.

Bug: N/A
Test: atest aconfig.test
Change-Id: I3e92035309a7b019912710e42e69f9bdfa538795
2024-01-08 17:26:59 +01:00
Treehugger Robot
0f2e089f97 Merge "aconfig: remove trailing whitespace in test input" into main 2024-01-08 14:53:47 +00:00
Mårten Kongstad
36d3edbf1a aconfig: remove trailing whitespace in test input
Bug: N/A
Test: atest aconfig.test
Change-Id: I248acae172fdeeb9ab9c4bb922f36b560cb44787
2024-01-08 10:07:04 +01:00
Mårten Kongstad
ca1e7c3e06 aconfig: Cargo.toml: remove obsolete dev-dependencies
The itertools crate was initially added as a dev-dependency. A later CL
also added it as a regular dependency, rendering the dev-dependency
obsolete. Remove it.

Bug: N/A
Test: cargo b
Change-Id: I12099f672f865430cf1cef97f8b4a8bc3eb055ec
2024-01-08 09:51:10 +01:00
Dennis Shen
e59313185f aconfig: create flag.map storage file
Add flag_table module for the creation of flag.map file. This is a hash
table in file similar to package.map hash table in file. This is created
per each container. It stores a mapping from a composite key (package id
and flag name) to its flag id (within package index of a flag).

This hash table allows us to look up the within package offset for a
specific flag. Along with the package offset obtained from package.map,
we will be able to find the global offset of a flag in the flag value
file.

Added unit tests to lock down the table creation and serialization.

Bug: b/312243587
Test: atest aconfig.test
Change-Id: I6e9d07bef05131cb06cfb4aa2ef29985578a6949
2024-01-04 16:17:34 +00:00
Dennis Shen
b65b350fc1 aconfig: update storage unit test case
merge storage_test_1_part_1.aconfig and storage_test_1_part_2.aconfig
into one aconfig file: storage_test_1.aconfig

remove two flags from test_1 package so the total number of flags across
three aconfig package is now 8, which is easier to test in unit test.

Bug: b/312243587
Test: atest aconfig.test
Change-Id: Idd249a8dcddfbae09b211e6310d74697763618f4
2024-01-04 16:08:17 +00:00
Zhi Dou
f7c585604a Merge "aconfig: add ForceReadOnly mode to aconfig c/c++ codegen" into main 2024-01-03 23:00:57 +00:00
Zhi Dou
758cb81194 Merge "aconfig: add ForceReadOnly mode to aconfig rust codegen" into main 2024-01-03 23:00:44 +00:00
Zhi Dou
5e64029bcd aconfig: add ForceReadOnly mode to aconfig rust codegen
This commit adds ForceReadOnly mode to rust codegen.

Bug: 316357759
Test: atest aconfig.test aconfig.prod_mode.test.rust
aconfig.test_mode.test.rust aconfig.exported_mode.test.rust
aconfig.force_read_only_mode.test.rust

Change-Id: I4cf98a6e9fc908fc372d4e68098a516808718c57
2024-01-03 15:56:24 +00:00
Zhi Dou
e567abdf3e aconfig: add ForceReadOnly mode to aconfig java codegen
This commit adds ForceReadOnly mode to java codegen.

Bug: 316357759
Test: atest aconfig.test aconfig.test.java

Change-Id: I10cd60def9ea20f7d56d87d18f680afeac61dc9d
2024-01-03 15:56:18 +00:00
Zhi Dou
8410cf4476 aconfig: add ForceReadOnly mode to aconfig c/c++ codegen
This commit adds ForceReadOnly mode to c/c++ codegen.

Bug: 316357759
Test: atest aconfig.test aconfig.test.cpp aconfig.test.cpp.test_mode
aconfig.test.cpp.exported_mode aconfig.test.cpp.force_read_only_mode

Change-Id: I4842dd69993fe4fc1f504358f59513cf064919d9
2024-01-03 15:56:10 +00:00
Zhi Dou
1a8281ccc2 aconfig: add new codegen mode force_read_only
The "force_read_only" mode is designed for libraries shared among
multiple containers for the following two scenarios where:
1. The library must be built with read_only flags or
2. Different containers requires different values for the same flags.

In this mode, the library includes only non-exported flags, adhering to
the concept that exported flags should maintain consistent values across
containers. Additionally, regardless of their original permissions, all
flags within this mode will be set to read_only.

Bug: 316357759
Test: atest aconfig.test
Change-Id: I65df39416c96404d84044a46bbcfe1bc8ce9ba8f
2024-01-03 15:53:01 +00:00
Dennis Shen
ba72cc7ae1 aconfig: add assign_flag_ids function
Add a function to assign flag id for flags in a package. We first assert
that the flags should have been sorted by its name, then assign a u32 id
to each flag in order. Note this cl adds the function, it will be used
in later cls.

Bug: b/312243116
Test: atest aconfig.test
Change-Id: I843433305abecbe0cc78988fe23dcf35c6a03358
2024-01-02 19:00:44 +00:00
Treehugger Robot
df7014c202 Merge "aconfig: adjust integration tests to correctly set flag values" into main 2023-12-21 18:56:15 +00:00
Mårten Kongstad
c761847832 aconfig: call Vec::retain instead of Vec::retain_mut
Replace a call to Vec::retain_mut with a call to Vec::retain instead:
the predicate used doesn't require its parameter to be a *mutable*
reference.

Bug: N/A
Test: atest aconfig.test
Change-Id: Iacd5f2ebef358ebc92ae6a1a78dd3045e44196f4
2023-12-21 10:28:34 +01:00
Mårten Kongstad
0b2a2a8c19 aconfig: adjust integration tests to correctly set flag values
With the introduction of a root release config, the
com.android.aconfig.test flags now have their values correctly assigned.
Update the integration tests accordingly.

Bug: 317178122
Test: atest :all
Merged-In: I1acdf9442a465f20f71bcda9b15eb69058aa4b3a
Change-Id: I1acdf9442a465f20f71bcda9b15eb69058aa4b3a
2023-12-21 09:00:48 +01:00
Mårten Kongstad
85c9c5b81a Merge changes from topic "aconfig-remove-format-aliases" into main
* changes:
  aconfig: remove support for --format=text
  aconfig: remove support for --format=verbose
  aconfig: remove support for --format=bool
2023-12-21 07:03:38 +00:00
Dennis Shen
e6330986d0 aconfig: add whole table serialization test
1, Add whole table serialization test to also lock down how the buckets
are serialized. Before this change, we are only locking down the header
and nodes serialization.

2, Switch over to the absolute offset in the file instead of relative
offset. Before we are using relative offset. For example, if a bucket is
Some(10), it means that it is pointing to 10 bytes over the start of the
node region of the table. Now it will be the absolute byte offset with
respect to the start of the table.

Bug: b/312243587
Test: atest aconfig.test
Change-Id: If7abc8c6b6687c0bc0c40bbfc6afbe0e46ece770
2023-12-20 19:46:03 +00:00
Dennis Shen
8bab859f84 aconfig: add additional test aconfig to test chaining
Add an additional package com.android.acondfig.storage.test_4 to test
so that the chaining in package.map can also be tested.

Bug: b/312243587
Test: atest aconfig.test
Change-Id: I8d0fad8941a20c7f6ed60caf529667549abdcdd7
2023-12-20 17:45:00 +00:00
Zhi Dou
9cd08c66a4 Merge "aconfig: update error message in modify_parsed_flags_based_on_mode" into main 2023-12-20 16:46:32 +00:00
Zhi Dou
e381a17cfc Merge "aconfig: update codegen templates" into main 2023-12-20 16:29:44 +00:00
Zhi Dou
ea48335042 aconfig: update error message in modify_parsed_flags_based_on_mode
This commit updates the error message in
modify_parsed_flags_based_on_mode, when there is no certain mode flags
in the corresponding library, and this change remove "." at the end of
the error message to conform to existing standard in this project.

Bug: 311152507
Test: atest aconfig.test
Change-Id: Ib120e7f7252981bbeb6ca1cf785da24f329507b4
2023-12-20 15:42:49 +00:00