tree: 6590893c8b099670d3485658c0de9e2d6b3c6cbd [path history] [tgz]
  1. dbus_bindings/
  2. rust-client/
  3. scripts/
  4. share/
  5. tmpfiles.d/
  6. BUILD.gn
  7. c_fake_feature_check_example.c
  8. c_fake_feature_library.cc
  9. c_fake_feature_library.h
  10. c_feature_check_example.c
  11. c_feature_library.cc
  12. c_feature_library.h
  13. cpp_feature_check_example.cc
  14. DIR_METADATA
  15. fake_platform_features.cc
  16. fake_platform_features.h
  17. feature_export.h
  18. feature_library.cc
  19. feature_library.h
  20. feature_library_test.cc
  21. json_feature_parser_fuzzer.cc
  22. libfeatures.pc.in
  23. libfeatures_c.pc.in
  24. main.cc
  25. mock_feature_library.h
  26. mock_tmp_storage_impl.h
  27. OWNERS
  28. platform2_preinstall.sh
  29. README.md
  30. service.cc
  31. service.h
  32. service_test.cc
  33. store_impl.cc
  34. store_impl.h
  35. store_impl_mock.h
  36. store_impl_test.cc
  37. store_interface.h
  38. tmp_storage_impl.cc
  39. tmp_storage_impl.h
  40. tmp_storage_interface.h
featured/README.md

ChromeOS Feature Daemon

featured is a service used for enabling and managing platform specific features. Its main user is Chrome field trials.

Components

In this directory are two main components: feature_library and featured.

feature_library

The feature_library is the main way most users will interact with variations in platform2. (If you're familiar with base::Feature and base::FeatureList in chrome, it will look very similar.) Most documentation for this is in feature_library.h, but there is also a C wrapper API as well as a Rust API.

As of March 2023, all features queried via feature_library must start with CrOSLateBoot. For CrOSLateBoot features, feature_library is a thin wrapper around a dbus call to ash-chrome, so state can only be queried after chrome is up.

Work is underway to support “early boot” features as well; feel free to contact OWNERS for more details.

Using feature_library

Clients can use feature_library by creating an instance of PlatformFeatures. The instance is used to query feature state and associated parameters, if there are any.

PlatformFeatures is implemented as a singleton class and is thread-safe. Here is an example of how to initialize and obtain an instance:

dbus::Bus::Options options;
options.bus_type = dbus::Bus::SYSTEM;
scoped_refptr<dbus::Bus> bus(new dbus::Bus(options));

// |Initialize| must be called before calling |Get| and the return value must
// be used since it has the [[nodiscard]] attribute.
CHECK(feature::PlatformFeatures::Initialize(bus));

// |Get| will return a valid handle if |Initialize| succeeds.
// Note that |Get| and subsequent calls can happen much later than |Initialize|
// since the object pointer remains valid until program exit.
feature::PlatformFeatures* feature_lib = feature::PlatformFeatures::Get();

// Use the handle to query feature state.
feature_lib->GetParamsAndEnabled(...);

Note that no shutdown call is necessary. The initialized instance will get automatically cleaned up on program exit.

platform2/featured/cpp_feature_check_example.cc provides another example on how to use PlatformFeatures and associated functions like IsEnabled{,Blocking}, and GetParamsAndEnabled{,Blocking}.

featured

The feature daemon (featured) is primarily responsible for managing share/platform-features.json. This file configures platform and kernel features that can be enabled dynamically at runtime, late in boot (that is, after user login).

Each entry in this file consists of a feature name, to be checked using feature_library, an optional set of support_check_commands (to check whether the device supports the feature), and a set of commands to be run when the feature is supported and chrome determines that it should be enabled.

Support check commands include FileExists and FileNotExists. Commands to execute include WriteFile and Mkdir, which respectively write specified contents to a file and create a given directory.

Featured is heavily sandboxed: writing to a new location requires an update to selinux policy in platform2/sepolicy/policy/chromeos/cros_featured.te as well as the allow-list in service.cc (see CheckPathPrefix).

We are actively working (in 2023) on support for “early boot” features in featured. The primary user interface for these will be via feature_library, but featured will perform some work to support this, largely behind the scenes.

Upstart Configurations

Featured starts relatively late in boot, during system-services, since Chrome needs to be available for platform-features.json support to work.

Additionally, featured waits for user login to enable platform-features.json features for two reasons:

  1. Safety: It is easier to roll back after user login since it is more likely for the platform to have connected to the network and downloaded a new seed.
  2. Compatibility: Historically, we have checked after login. There is no strong reason to change that, and changing it could break existing users.

Upon crashes or abnormal exits (non-zero status code), featured restarts with the intention that if we fail initially, we want to re-try and make sure platform-features.json (and eventually “early boot” features) will work.

We are actively working (in 2023) on support for “early boot” features in featured. To support “early boot” features, featured startup will be moved earlier to start during basic services.