Commit graph

333 commits

Author SHA1 Message Date
Dennis Shen
455dc608f3 aconfig: move create flag info file api to aconfig_storage_write_api
rust_ffi_static right now will export excessive symbols, this lead to a
duplication of symbols when aconfig links against both
libaconfig_storage_file_cc and libaconfig_storage_read_api_cc. This is
because aconfig_storage_read_api crate depends on aconfig_storage_file
crate. To solve this problem, move create flag info file api to
aconfig_storage_write_api crate which is parallel to
aconfig_storage_read_api crate.

Bug: b/321077378
Test: atest aconfig_storage_file.test; atest
aconfig_storage_read_api.test; atest aconfig_storage_write_api.test

Change-Id: Ibbb50193a2da82d52ccbb4087c8e3fb9f320805f
2024-04-04 21:39:04 +00:00
Dennis Shen
2922ca9019 aconfig: add create_flag_info cc api
Bug: b/321077378
Test: atest aconfig_storage_file.test
Change-Id: I1d48311cade178f0b047a5b4d4f81c6dac4362c8
2024-04-03 18:09:39 +00:00
Dennis Shen
bb9912e551 aconfig: add api to create flag info file based on package map and flag
map file

Bug: b/321077378
Test: atest aconfig_storage_file.test
Change-Id: I957e231bc11db856a8c6753771eaafea2f168352
2024-04-02 21:39:51 +00:00
Dennis Shen
7d12daf9b4 aconfig: add flag type information to list flag api
Bug: b/321077378
Test: atest aconfig_storage_file.test
Change-Id: I1880e9aa441c423c3225a0ef86c6edde096d7ba3
2024-04-02 17:51:21 +00:00
Dennis Shen
467d22f2a8 aconfig: enable tests in presubmits
Bug: b/321077378
Test: atest each test
Change-Id: Id8a47605c5642a9459d16c8414adc8590fd4c46d
2024-04-02 13:47:42 +00:00
Dennis Shen
3e4c33c1bc aconfig: test updates
Previously, three seperate crates create their own test baseline which
are nearly identical. This is inconvinent when updating the baselines.
All three locations needs to be touched. This cl merges functions to
create test storage file base struct into aconfig_storage_file crate

Bug: b/321077378
Test: atest aconfig.test
Change-Id: Ic97437f856763347a11de8b449592292014bcce3
2024-04-02 13:01:26 +00:00
Dennis Shen
93d11b7bc4 aconfig: use an enum to represetn flag type
Flag type is encoded as a u16 in flag table file. Previously we are
assinging value of 1 for flag type to indicate that they are all boolean
flags. In this change, we formalize the flag type designation with an
enum.

ReadWriteBoolean -> 0
ReadOnlyBoolean -> 1
FixedReadOnlyBoolean -> 2

Bug: b/321077378
Test: atest aconfg.test; atest aconfig_storage_file.test
Change-Id: I114818435b44f1e82a611f0509787993a5a8e70e
2024-04-01 18:30:06 +00:00
Dennis Shen
88899887c0 Merge "aconfig: syntax update, as_bytes to into_bytes to be more appropriate" into main 2024-04-01 17:33:46 +00:00
Lucas Henneman
83162dfcec Merge "TEST_MAPPING: fix TODO syntax" into main 2024-04-01 17:07:17 +00:00
Dennis Shen
87fc7cecd2 aconfig: syntax update, as_bytes to into_bytes to be more appropriate
Bug: b/321077378
Test: atest aconfig_storage_file.test; atest aconfig.test
Change-Id: I124387db54cd322bcce557a27c27e1b6a8c0f465
2024-04-01 15:19:13 +00:00
Dennis Shen
abf5ea2f46 Merge "aconfig_storage_file: add flag_info definition" into main 2024-04-01 14:20:34 +00:00
Lucas Henneman
6e7137c556 TEST_MAPPING: fix TODO syntax
These two TODO tags were improperly formatted, which means automation
will not alert anyone if the ticket is closed.

Bug: 327420679
Test: git diff
Change-Id: I99c8215fe3e24cdf3fa7be517291964cc5eb1ecf
Signed-off-by: Lucas Henneman <henneman@google.com>
2024-04-01 13:21:30 +00:00
Ted Bauer
6d4db66026 aflags: add new storage mode
Add a mode that lets the user use the new aconfig storage.

Bug: 324436145
Test: adb shell aflags list --use-new-storage
Change-Id: I97d7a229a64c6ef1aea844281298ce5449b02570
2024-03-29 16:57:42 +00:00
Ted Bauer
9b7185ca9c Merge "aconfig: make APIs apex available" into main 2024-03-28 23:33:32 +00:00
Dennis Shen
76163aaa38 aconfig_storage_file: add flag_info definition
Flag info file is another memory mapped file to store the file
information such as if current flag has been staged or not, is it sticky
and etc. This file will be created by aconfig storage daemon during
container initialization.

Bug: b/321077378
Test: atest aconfig_storage_file.test
Change-Id: I8f70e04c74b5770f89dbe981d9f03c787ea5eeed
2024-03-28 17:22:01 +00:00
Ted Bauer
e30efac744 aconfig: make APIs apex available
We need the aconfig APIs to be available on every mainline module, so
set the min_sdk_version as low as possible.

Bug: 328444881
Test: m
Change-Id: I02e569d510a30f4809d4a82f7630326b0b30f263
2024-03-28 13:46:18 +00:00
Charisee
58708f5d7b Update needed for Rust v1.77.0
error: this `let...else` may be rewritten with the `?` operator
   --> build/make/tools/aconfig/aconfig/src/commands.rs:320:5
    |
320 | /     let Some(package) = parsed_flags.first().map(|pf| pf.package()) else {
321 | |         return None;
322 | |     };
    | |______^ help: replace it with: `let package = parsed_flags.first().map(|pf| pf.package())?;`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ques
tion_mark
    = note: `-D clippy::question-mark` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(clippy::question_mark)]`

error: this `let...else` may be rewritten with the `?` operator
   --> build/make/tools/aconfig/aconfig/src/commands.rs:330:5
    |
330 | /     let Some(container) = parsed_flags.parsed_flag.first().map(|pf| pf.container()) else {
331 | |         return None;
332 | |     };
    | |______^ help: replace it with: `let container = parsed_flags.parsed_flag.first().map(|pf| pf.cont
ainer())?;`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ques
tion_mark

error: aborting due to 2 previous errors


Bug: 330185853
Test: ./test_compiler.py --prebuilt-path dist/rust-dev.tar.xz  --target aosp_cf_x86_64_phone --image
Change-Id: I00e22fc75137e8bd6fe28a8c20f8a1c3bbe711fd
2024-03-27 19:53:24 +00:00
Dennis Shen
bb13bbb086 aconfig: update aconfig_storage_read_api
Previously we are ensuring that the public rust api to get mapped file
is safe as we are ensuring that the file being mapped has a permission
of 444. However, a file permission of 444 is not possible due to build
system needs to make file 644 while creating img files. Thus need to make the rust api to get mapped file unsafe.

In reality, this should have no impact. Because, even though the storage
files have a file permission of 644, they are on a RO partition like
system. So the files are not writable anyway. This is true for all the
containers (platform partitions and mainline modules) we know so far.

Bug: b/321077378
Test: atest aconfig_storage_read_api.test; atest
aconfig_storage_read_api.test.rust; atest
aconfig_storage_read_api.test.cpp

Change-Id: I643fe191e697a524e2303a32750f04c268f408fd
2024-03-21 01:44:02 +00:00
Dennis Shen
5e909adbc8 aconfig: update pb file location
We have moved the storage records metadata pb file to the boot dir.

Bug: b/321077378
Test: atest aconfig_storage_read_api.test
Change-Id: Ic5bd89052e311ec5b1993ba1779d49be8451caa2
2024-03-20 16:38:09 +00:00
Dennis Shen
435fe14146 aconfig: c++ read api to return an android::base::Result and cargo fmt
Bug: b/312444587
Test: atest aconfig_storage_read_api.test.rust; atest
aconfig_storage_write_api.test.cpp

Change-Id: I6beb6e8d43b6f5418476101a929374e97832e27f
2024-03-14 19:25:07 +00:00
Dennis Shen
1fdb6cc456 aconfig_storage: create aconfig storage c++ flag value write api
Bug: b/312444587
Test: atest aconfig_storage_write_api.test.cpp
Change-Id: Ib08575b7e6ca23141ebbf739bf604a66da472dc2
2024-03-14 16:06:03 +00:00
Dennis Shen
808bf915a8 aconfig: update aconfig_storage_read_api c++ lib
Now the read api lib no longer owns the memory mapped file. The rust lib
aconfig_storage_read_api api to get memory mapped file just returns an
Mmap rust struct. However cxx does not support Mmap data type, so we
cannot export the api to get memory mapped file from rust to c++. This
means we have to implement c++ apis to get memory mapped files.

This change is basically implementing c++ api to get memory mapped files,
mirroring the rust implementation. In addition, the integration test is
also updated to lock down the new c++ api implementation.

Bug: b/321077378
Test: atest aconfig_storage_read_api.test.cpp
Change-Id: I5e93a220cdd05cc0e5b0eb441284ac3e9dc34da7
2024-03-13 20:29:13 +00:00
Dennis Shen
71f9303dc0 aconfig: update aconfig_storage_read_api
Right now, aconfig_storage_read_api rust lib would own mapped files. So
individual flag lib does not need to. The original intent is that all
these flag lib can dynamically link against this lib. So say we have
different variants of flag lib for one flag package, there is just one
unique memory mapped file. In addition, the exposed rust apis hides the
memory mapped files. So when exporting these apis to c++/java, we don't
have to implement memory mapping in c++/java flag read api lib.

However, this design has its own downside. The biggest being that these
memory mapped files are stored in a mutable static hash map. For rust,
it must be protected by a mutex lock. The real effect on the lock is
mostly minimal as it immediately unlocks when the clone of memory
mapping is returned. But still we could get more performance out of it
in exchange of having more c++/java side implementation of mapping
files. (Note, apis that interpret mapped files are still exported by
Rust, so no c++/java implementation needed).

In this change, aconfig_storage_read_api give away its ownership of
memory mapped file in its api to get memory mapped file. The memory
mapped file is supposed to be owned by generated flag lib. By doing so,
no more mutex lock is needed. Also, since each flag lib has one flag
package, which maps to a single owning container. The flag lib can have
the memory mapped files as non mutable static variables. So no mutex
lock penalty on flag lib side.

Bug: b/321077378
Test: atest aconfig_storage_read_api.test; atest
aconfig_storage_read_api.test.rust

Change-Id: I29060bae90db6f7d296252ed73f7e312143f4b7e
2024-03-13 18:10:19 +00:00
Treehugger Robot
c7704f1650 Merge "aflags: show staged values for each flag." into main 2024-03-13 17:01:14 +00:00
Ted Bauer
46d758bd49 aflags: show staged values for each flag.
Lines now have a new column, and look like this:

com.android.example.flag1 enabled -            server read-write system
com.android.example.flag2 enabled (->disabled) server read-write system

The dash represents no change on boot, the (->value) represents a change
to value on the next boot.

Test: adb shell device_config put staged multitasking*com.android.wm.shell.enable_taskbar_navbar_unification true && adb shell aflags list | grep navbar_unification
Bug: 324436145
Change-Id: I022460bc69fcb2ccd9c6db8f060fcbd0337d1ea6
2024-03-13 14:46:31 +00:00
Dennis Shen
7176a4fdfa aconfig: update aconfig_storage_file crate unit test to lockdown file
size

Bug: b/321077378
m: atest aconfig_storage_file.test
Change-Id: Ic5e7e7a9fd7ac53bb1207a13acc0c992fe0afd2d
2024-03-12 22:40:53 +00:00
Dennis Shen
1d9f0dd291 aconfig: add rust integration test for aconfig_storage_write_api
Bug: b/312444587
Test: atest aconfig_storage_write_api.test.rust
Change-Id: I05f992ea93a19507ad865e97315c128473841a33
2024-03-12 19:09:04 +00:00
Dennis Shen
ee18b35565 Merge "aconfig: add storage file type into storage file serialization" into main 2024-03-12 14:38:50 +00:00
Treehugger Robot
1986c86bb2 Merge "aflags: make flag storage error message more user-friendly" into main 2024-03-12 13:20:21 +00:00
Dennis Shen
e9b9573def aconfig: add storage file type into storage file serialization
1, add storage file type into storage files serialization
2, update aconfig_storage_read_api integration tests to not rely on
soong to produce read only storage files. Instead, have the test process
create temp read only storage file copies.

Bug: b/312444587
Test: atest aconfig.test; atest.aconfig_storage_file.test
Change-Id: I1607fb000b48e8acffc966b16a5136578911ab3e
2024-03-12 12:43:31 +00:00
Treehugger Robot
672af9523b Merge "aconfig: create aconfig_storage_write_api crate" into main 2024-03-12 04:12:20 +00:00
Dennis Shen
7e5fca5898 aconfig: create aconfig_storage_write_api crate
aconfig_storage_write_api crate is the lib to be used by aconfig storage
daemon to update flag value at a given offset.

Note that mmap api is unsafe from memmap2 crate. This is due to the
possibility of other code write to the file after mmaping the file into
memory. Therefore the api to write to storage value file is also marked
as unsafe. In reality, the persistent storage value file is protected by
SELinux policy to allow write access only to aconfig storage daemon. In
addition, aconfig storage daemon is single threaded. So at any time,
only one thread is writing to a storage file, and only thru the mmapped
file in memory (not thru direct file write). So it would safe for
storage daemon to call this api.

Bug: b/312444587
Test: m libaconfig_storage_write_api; atest
aconfig_storage_write_api.test

Change-Id: I93cffea0d94e4c40e711d809418c0b18b6d9bfe1
2024-03-11 14:26:38 +00:00
Ted Bauer
e52434aa18 aflags: make flag storage error message more user-friendly
Bug: 328577149
Test: adb shell stop && sleep 10 && adb shell aflags list
Change-Id: Idb28c93f883b72031cf3e1ff4e8d396c4df708e2
2024-03-11 14:12:58 +00:00
Zhi Dou
8837769f46 aconfig: remove UnsupportedAppUsage from java exported mode
UnsupportedAppUsage was added to support cts test access issue. For new
exported mode, if the cts tests code with exported flag, there won't be access issue. So this annotation is not needed. Removing this annotation also removes the dependency on this annotation in google3 code.

Test: atest aconfig.test
Bug: 311152507
Bug: 303773055
Change-Id: I8c190e69cdb514af7992ccca7fea152c917047dc
2024-03-11 13:04:51 +00:00
Ted Bauer
71287f5e6b Merge "aflags: only permit enable/disable with root access." into main 2024-03-08 15:51:57 +00:00
Dennis Shen
760d21d991 Merge "aconfig: update aconfig_storage_file crate" into main 2024-03-08 13:33:37 +00:00
Mårten Kongstad
f0c594d66d aflags: list flags as "enabled|disabled" instead of raw bool value
To keep things consistent and to reduce the risk of confusion, aconfig
flags are "enabled" or "disabled", not "true" or "false".

Do not represent flag states via a String. Instead, introduce a new
FlagValue enum and use this enum instead. FlagValue implements ToString
which returns "enabled" or "disabled".

Bug: N/A
Test: adb shell aflags list # verify that flags are "enabled" or "disabled"
Test: atest aflags.test
Change-Id: I9be998d7891656d118b7cc971449da58e17d5031
2024-03-08 10:27:14 +01:00
Zhi Dou
5f1a854b11 Merge "aconfig_proto: add document for container filed" into main 2024-03-07 19:42:56 +00:00
Ted Bauer
a98448f4e7 aflags: only permit enable/disable with root access.
Bug: 324436145
Test: adb unroot && adb shell aflags enable com.android.window.flags.sync_window_config_update_flag # Fails
Test: adb root && adb shell aflags enable com.android.window.flags.sync_window_config_update_flag # Succeeds
Change-Id: I88db174b51462199a234eeb3b6fb70c4da538700
2024-03-07 17:55:27 +00:00
Dennis Shen
12705d46be aconfig: update aconfig_storage_file crate
Add android.bp target for the binary. Change the binary name to
aconfig-storage. And a number of small updates.

Bug: b/321077378
Test: m aconfig-stoarge; atest aconfig_storage_file.test
Change-Id: I9f560a031433407800ded1c2f4f2bdab459f5df7
2024-03-07 15:03:27 +00:00
Mårten Kongstad
b47f7bae6d aflags: remove unnecessary String conversions
Reduce the number of allocations by removing superfluous calls to
to_string: use a &str where possible, and avoid converting a String to a
String.

Bug: N/A
Test: adb shell aflags list
Change-Id: I373018e9ecb393137d11e039ca2c73c0ca5308d7
2024-03-07 15:29:00 +01:00
Mårten Kongstad
d408e96505 aflags: list: merge package and name into fully qualified name
Print the fully qualified name instead of splitting flag package and
flag name into separate columns. This aligns the output with the
expected input to `aflags enable <fully-qualified-name>` and makes it
easier to copy-and-paste the flag names.

Before this change:

  $ adb shell aflags list | head -n4
  android.app.admin.flags                   cross_user_suspension_enabled                                              false default read-write system
  android.app.admin.flags                   dedicated_device_control_enabled                                           false default read-write system
  android.app.admin.flags                   device_policy_size_tracking_enabled                                        false default read-write system
  android.app.admin.flags                   dumpsys_policy_engine_migration_enabled                                    false default read-write system

After this change:

  $ adb shell aflags list | head -n4
  android.app.admin.flags.cross_user_suspension_enabled                                                           false default read-write system
  android.app.admin.flags.dedicated_device_control_enabled                                                        false default read-write system
  android.app.admin.flags.device_policy_size_tracking_enabled                                                     false default read-write system
  android.app.admin.flags.dumpsys_policy_engine_migration_enabled                                                 false default read-write system

Bug: N/A
Test: adb shell aflags list
Change-Id: I3227c9c9c7355b5b0c1b75ada73b1a8f87d1be55
2024-03-07 14:58:14 +01:00
Mårten Kongstad
2243581535 aconfig: remove reference to non-existent workspace member "aconfig_storage_write_api"
Commit bca2f3c28c incorrectly added "aconfig_storage_write_api" as a
workspace member even though that project has not yet been created. This
broke cargo.

Unbreak cargo by removing "aconfig_storage_write_api".

Bug: N/A
Test: croot build/make/tools/aconfig && cargo c
Change-Id: Ic0f71a53d49736228a376f64808aea24c2ec8ce5
2024-03-07 09:18:33 +01:00
Dennis Shen
bca2f3c28c aconfig: move aconfig_storage_metadata proto and its apis to
aconfig_storage_file crate

Bug: b/321077378
Test: m aconfig_storage_file.test; m aconfig_storage_read_api.test
Change-Id: Ifeeeff62dc09e172b7e88c45860d2febccc29570
2024-03-06 22:05:02 +00:00
Dennis Shen
190304985c aconfig: create aconfig_storage_file binary to print the storage files
To help debug storage files. We need a binary to parse the storage
binary files and print out the flag values like device_config list
command. In addition, aconfig_storage_file needs to provide a public api
to allow flag cli to call to get the flag values. Therefore creating
this change.

This change includes the following changes:

1, Implement debug print trait for package table, flag table, and flag
value struct. So the debug dump is more readable.

2, Add a list flag api to create a vector of flag name and value tuples
given the storage file names. This api will be used by
aconfig_storage_file binary as well as aconfig flag cli.

3, Add a main.rs to create aconfig_storage_file binary to debug print
storage files or list all the flags in storage files. It has two
subcommands.

3.1 print command:
aconfig_storage_file print --file <storage file> --type
<package_map|flag_map|flag_val>

This command produce a debug print of a single the storage file content

3.2 list command:
aconfig_storage_file list --package_map <package map file> --flag_map
<flag map file> --flag_val <flag value file>

This command parses all storage files to print out list of flag values
in the following form:

<package>/<flag>, <value>
...
<package>/<flag>, <value>

Bug: b/321077378
Test: manual test of the binary command
Change-Id: I000e216d13854f853cbd9b63cabb6db3a47dbece
2024-03-06 17:46:18 +00:00
Zhi Dou
2d2610c787 aconfig_proto: add document for container filed
Test: n/a
Bug: 328027300
Change-Id: Ieec2c24cb9024f429fcd7888ef6c7c89d212ff63
2024-03-06 15:36:34 +00:00
Dennis Shen
cdde8f39f8 Merge "aconfig: add a storage file read api to get file version number" into main 2024-03-06 13:39:23 +00:00
Treehugger Robot
07c3faa081 Merge "set exportable to true for aconfig.test.exported.flags" into main 2024-03-06 01:10:49 +00:00
Zhi Dou
8320380d55 set exportable to true for aconfig.test.exported.flags
Test: m aconfig_test_java_library_exported
Bug: 310504781
Change-Id: Ib405febc739c49dff7340d43c65a7ec2b314d7de
2024-03-05 22:27:09 +00:00
Ted Bauer
ee09882e54 Merge "aflags: add initial enable and disable commands" into main 2024-03-05 22:23:57 +00:00