blob: d699eb4cdcb4d1aa59098469f1a05e6591d1c248 [file] [log] [blame] [view]
Anton Hanssona6caee82020-07-15 12:34:13 +01001# SdkExtensions module
2
Artur Satayevf7348092021-04-09 12:18:10 +01003SdkExtensions module is responsible for:
4- deciding the extension SDK level of the device;
5- providing APIs for applications to query the extension SDK level;
6- determining the values for the BOOTCLASSPATH, DEX2OATBOOTCLASSPATH, and
7 SYSTEMSERVERCLASSPATH environment variables.
Anton Hanssona6caee82020-07-15 12:34:13 +01008
Anton Hanssonb1a217c2020-11-30 11:43:05 +00009## General information
10
11### Structure
Anton Hanssona6caee82020-07-15 12:34:13 +010012
Artur Satayevf7348092021-04-09 12:18:10 +010013The module is packaged in an apex, `com.android.sdkext`, and has several
14components:
15- `bin/derive_classpath`: a native binary that runs early in the device boot
16 process. It reads individual classpath configs files from the system and
17 other modules, merges them, and defines the definition of *CLASSPATH environ
18 variables.
19- `bin/derive_sdk`: native binary that runs early in the device boot process and
Anton Hanssona6caee82020-07-15 12:34:13 +010020 reads metadata of other modules, to set system properties relating to the
21 extension SDK (for instance `build.version.extensions.r`).
Artur Satayevf7348092021-04-09 12:18:10 +010022- `javalib/framework-sdkextension.jar`: this is a jar on the bootclasspath that
Anton Hanssona6caee82020-07-15 12:34:13 +010023 exposes APIs to applications to query the extension SDK level.
24
Anton Hanssonb1a217c2020-11-30 11:43:05 +000025### Deriving extension SDK level
Anton Hanssona6caee82020-07-15 12:34:13 +010026`derive_sdk` is a program that reads metadata stored in other apex modules, in
Anton Hansson69e6ba82021-05-26 16:52:13 +010027the form of binary protobuf files in subpath `etc/sdkinfo.pb` inside each
Anton Hanssona6caee82020-07-15 12:34:13 +010028apex. The structure of this protobuf can be seen [here][sdkinfo-proto]. The
29exact steps for converting a set of metadata files to actual extension versions
30is likely to change over time, and should not be depended upon.
31
Anton Hanssonb1a217c2020-11-30 11:43:05 +000032### Reading extension SDK level
Anton Hanssona6caee82020-07-15 12:34:13 +010033The module exposes a java class [`SdkExtensions`][sdkextensions-java] in the
34package `android.os.ext`. The method `getExtensionVersion(int)` can be used to
35read the version of a particular sdk extension, e.g.
36`getExtensionVersion(Build.VERSION_CODES.R)`.
37
Artur Satayevf7348092021-04-09 12:18:10 +010038### Deriving classpaths
39`derive_classpath` service reads and merges individual config files in the
40`/system/etc/classpaths/` and `/apex/*/etc/classpaths`. Each config stores
41protobuf message from [`classpaths.proto`] in a proto binary format. Exact
42merging algorithm that determines the order of the classpath entries is
43described in [`derive_classpath.cpp`] and may change over time.
44
Anton Hanssone3712b62022-09-06 15:58:42 +000045[`classpaths.proto`]: https://android.googlesource.com/platform/packages/modules/common/+/refs/heads/master/proto/classpaths.proto
46[`derive_classpath.cpp`]: derive_classpath/derive_classpath.cpp
47[sdkinfo-proto]: https://android.googlesource.com/platform/packages/modules/common/+/refs/heads/master/proto/sdk.proto
48[sdkextensions-java]: java/android/os/ext/SdkExtensions.java
Anton Hanssonb1a217c2020-11-30 11:43:05 +000049
50## Developer information
51
Anton Hansson76f95012022-09-06 15:31:07 +000052### Defining a new extension version
53
54In order to bump the extension version, the following steps must be taken.
55
56#### Gather information
57
581) Identify the set of modules that are part of this extension version release.
59These are the set of modules that are releasing new APIs in this train.
60
612) Decide the integer value of this extension version. Usually this is the
62`previous_version + 1`.
63
64#### Code changes
65
663) **build/make:** Update the extension version of the module development
67branch. This is defined by the `PLATFORM_SDK_EXTENSION_VERSION` variable in
68`core/version_defaults.mk`. Subsequent module builds in the branch will embed
69the new version code into the proto in the modules.
70
71 [Example CL][bump]
72
734) **packages/modules/SdkExtensions:** Define the new SDK extension version.
74We have a utility script that automates this. Run:
75 ```sh
76 $ packages/modules/SdkExtensions/gen_sdk/bump_sdk.sh <NEW_VERSION> <MODULES> <BUG>
77 ```
78
79 ...where `<MODULES>` is a comma-separated list of modules included in the
80 bump, with identifiers listed in the [sdkinfo proto][sdkinfo-proto]). To
81 include all modules, this argument can be omitted.
82
83 [Example CL][def]
84
855) Upload these two CLs in a topic and submit them. It is imperative that
86
87 * the cl generated in step #3 is included in the builds of all the relevant
88 modules in the train
89 * the cl generated in step #4 is included in the SdkExtensions build of the
90 train
91
92#### Update continuous test configuration
93
946) The continuous test configuration has a list of module builds to include when
95running the SdkExtensions tests. They need to be updated to use module builds
96that contain the CLs generated above. See http://shortn/_aKhLxsQLZd
97
Anton Hansson76f95012022-09-06 15:31:07 +000098#### Finalize SDK artifacts
99
Mårten Kongstadff40fda2022-09-19 11:03:29 +02001007) **prebuilts/sdk & module sdk repos:** Once the train is finalized, the API
Anton Hansson76f95012022-09-06 15:31:07 +0000101artifacts need to be recorded for doc generation to work correctly. Do this by
102running the finalize_sdk script:
103
104 ```
105 $ packages/modules/common/tools/finalize_sdk.py \
106 -f <VERSION> \
107 -b <BUG> \
108 -r <README_ENTRY> \
109 -m <MODULE1> \
110 -m <MODULE2> [..]
111 ```
112
113 [Example CL][finalize]
114
115[bump]: https://android.googlesource.com/platform//build/+/f5dfe3ff7b59b44556510ba89d15161c87312069
116[def]: https://android.googlesource.com/platform/packages/modules/SdkExtensions/+/5663ebb842412b0235a140656db17025280f9f08
117[derive_sdk_test]: derive_sdk/derive_sdk_test.cpp
118[current_version]: java/com/android/os/ext/testing/CurrentVersion.java
119[finalize]: https://android.googlesource.com/platform/prebuilts/sdk/+/d77e77b6746acba806c263344711eb0c4df2b108
Anton Hansson76f95012022-09-06 15:31:07 +0000120
Anton Hansson12236542022-04-12 20:34:06 +0100121### Adding a new extension
Anton Hansson76f95012022-09-06 15:31:07 +0000122
Anton Hansson12236542022-04-12 20:34:06 +0100123An extension is a way to group a set of modules so that they are versioned
Anton Hansson76f95012022-09-06 15:31:07 +0000124together. We currently define a new extension for every Android SDK level that
125introduces new modules. Every module shipped in previous versions are also part
126of the new extension. For example, all the R modules are part of both the R
127extensions and the S extensions.
Anton Hansson12236542022-04-12 20:34:06 +0100128
129The steps to define a new extension are:
Anton Hansson76f95012022-09-06 15:31:07 +0000130
Paul Duffin0743de72023-02-20 15:53:31 +0000131- Add any new modules to the SdkModule enum in sdk.proto. e.g.
132 [for new required, updatable modules in U](http://ag/21148706)
Anton Hansson76f95012022-09-06 15:31:07 +0000133
134- Add the binary "current sdk version" proto to the apexes of the new modules.
Paul Duffin0743de72023-02-20 15:53:31 +0000135 e.g. [for health fitness](http://ag/21158651) and
136 [config infrastructure](http://ag/21158650).
Anton Hansson76f95012022-09-06 15:31:07 +0000137
138- Update `derive_sdk.cpp` by:
139
140 * mapping the modules' package names to the new enum values
141
142 * creating a new set with the new enum values of the modules relevant for
143 this extension.
144
145 * set a new sysprop to the value of `GetSdkLevel` with the new enum set
146
147 * add a unit test to `derive_sdk_test.cpp` verifying the new extensions
148 work
149
Mårten Kongstadddc0d522023-01-24 10:52:40 +0100150 * update the hard-coded list of extensions in `ReadSystemProperties`
151
Paul Duffin0743de72023-02-20 15:53:31 +0000152 * e.g. [for U extension](http://ag/21481214)
153
Anton Hansson76f95012022-09-06 15:31:07 +0000154- Make the `SdkExtensions.getExtensionVersion` API support the new extensions.
155
Paul Duffin0743de72023-02-20 15:53:31 +0000156 * Extend `CtsSdkExtentensionsTestCase` to verify the above two behaviors.
157
158 * e.g. [for U extensions](http://ag/21507939)
Mårten Kongstad4eb87752023-04-19 18:30:06 +0200159
160- Add a new sdk tag in sdk-extensions-info.xml