Anton Hansson | a6caee8 | 2020-07-15 12:34:13 +0100 | [diff] [blame] | 1 | # SdkExtensions module |
| 2 | |
Artur Satayev | f734809 | 2021-04-09 12:18:10 +0100 | [diff] [blame] | 3 | SdkExtensions 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 Hansson | a6caee8 | 2020-07-15 12:34:13 +0100 | [diff] [blame] | 8 | |
Anton Hansson | b1a217c | 2020-11-30 11:43:05 +0000 | [diff] [blame] | 9 | ## General information |
| 10 | |
| 11 | ### Structure |
Anton Hansson | a6caee8 | 2020-07-15 12:34:13 +0100 | [diff] [blame] | 12 | |
Artur Satayev | f734809 | 2021-04-09 12:18:10 +0100 | [diff] [blame] | 13 | The module is packaged in an apex, `com.android.sdkext`, and has several |
| 14 | components: |
| 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 Hansson | a6caee8 | 2020-07-15 12:34:13 +0100 | [diff] [blame] | 20 | reads metadata of other modules, to set system properties relating to the |
| 21 | extension SDK (for instance `build.version.extensions.r`). |
Artur Satayev | f734809 | 2021-04-09 12:18:10 +0100 | [diff] [blame] | 22 | - `javalib/framework-sdkextension.jar`: this is a jar on the bootclasspath that |
Anton Hansson | a6caee8 | 2020-07-15 12:34:13 +0100 | [diff] [blame] | 23 | exposes APIs to applications to query the extension SDK level. |
| 24 | |
Anton Hansson | b1a217c | 2020-11-30 11:43:05 +0000 | [diff] [blame] | 25 | ### Deriving extension SDK level |
Anton Hansson | a6caee8 | 2020-07-15 12:34:13 +0100 | [diff] [blame] | 26 | `derive_sdk` is a program that reads metadata stored in other apex modules, in |
Anton Hansson | 69e6ba8 | 2021-05-26 16:52:13 +0100 | [diff] [blame] | 27 | the form of binary protobuf files in subpath `etc/sdkinfo.pb` inside each |
Anton Hansson | a6caee8 | 2020-07-15 12:34:13 +0100 | [diff] [blame] | 28 | apex. The structure of this protobuf can be seen [here][sdkinfo-proto]. The |
| 29 | exact steps for converting a set of metadata files to actual extension versions |
| 30 | is likely to change over time, and should not be depended upon. |
| 31 | |
Anton Hansson | b1a217c | 2020-11-30 11:43:05 +0000 | [diff] [blame] | 32 | ### Reading extension SDK level |
Anton Hansson | a6caee8 | 2020-07-15 12:34:13 +0100 | [diff] [blame] | 33 | The module exposes a java class [`SdkExtensions`][sdkextensions-java] in the |
| 34 | package `android.os.ext`. The method `getExtensionVersion(int)` can be used to |
| 35 | read the version of a particular sdk extension, e.g. |
| 36 | `getExtensionVersion(Build.VERSION_CODES.R)`. |
| 37 | |
Artur Satayev | f734809 | 2021-04-09 12:18:10 +0100 | [diff] [blame] | 38 | ### 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 |
| 41 | protobuf message from [`classpaths.proto`] in a proto binary format. Exact |
| 42 | merging algorithm that determines the order of the classpath entries is |
| 43 | described in [`derive_classpath.cpp`] and may change over time. |
| 44 | |
| 45 | [`classpaths.proto`]: packages/modules/SdkExtensions/proto/classpaths.proto |
| 46 | [`derive_classpath.cpp`]: packages/modules/SdkExtensions/derive_classpath/derive_classpath.cpp |
| 47 | [sdkinfo-proto]: packages/modules/SdkExtensions/proto/sdk.proto |
Anton Hansson | a6caee8 | 2020-07-15 12:34:13 +0100 | [diff] [blame] | 48 | [sdkextensions-java]: framework/java/android/os/ext/SdkExtensions.java |
Anton Hansson | b1a217c | 2020-11-30 11:43:05 +0000 | [diff] [blame] | 49 | |
| 50 | ## Developer information |
| 51 | |
Anton Hansson | 1223654 | 2022-04-12 20:34:06 +0100 | [diff] [blame] | 52 | ### Adding a new extension |
| 53 | An extension is a way to group a set of modules so that they are versioned |
| 54 | together. We currently define a new extension for every Android SDK level |
| 55 | that introduces new modules. Every module shipped in previous versions are |
| 56 | also part of the new extension. For example, all the R modules are part of |
| 57 | both the R extensions and the S extensions. |
| 58 | |
| 59 | The steps to define a new extension are: |
| 60 | - Add any new modules to the SdkModule enum in sdk.proto. |
| 61 | - Add the binary "current sdk version" proto to the apexes of the new modules. |
Anton Hansson | cda99fa | 2021-01-15 08:15:57 +0000 | [diff] [blame] | 62 | - Update `derive_sdk.cpp` by: |
| 63 | * mapping the modules' package names to the new enum values |
Anton Hansson | 1223654 | 2022-04-12 20:34:06 +0100 | [diff] [blame] | 64 | * creating a new set with the new enum values of the modules relevant for |
| 65 | this extension. |
Anton Hansson | cda99fa | 2021-01-15 08:15:57 +0000 | [diff] [blame] | 66 | * set a new sysprop to the value of `GetSdkLevel` with the new enum set |
Anton Hansson | 1223654 | 2022-04-12 20:34:06 +0100 | [diff] [blame] | 67 | * add a unit test to `derive_sdk_test.cpp` verifying the new extensions work |
Anton Hansson | b1a217c | 2020-11-30 11:43:05 +0000 | [diff] [blame] | 68 | - Make the `SdkExtensions.getExtensionVersion` API support the new extensions. |
| 69 | - Extend the CTS test to verify the above two behaviors. |