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 | |
Anton Hansson | e3712b6 | 2022-09-06 15:58:42 +0000 | [diff] [blame] | 45 | [`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 Hansson | b1a217c | 2020-11-30 11:43:05 +0000 | [diff] [blame] | 49 | |
| 50 | ## Developer information |
| 51 | |
Anton Hansson | 76f9501 | 2022-09-06 15:31:07 +0000 | [diff] [blame] | 52 | ### Defining a new extension version |
| 53 | |
| 54 | In order to bump the extension version, the following steps must be taken. |
| 55 | |
| 56 | #### Gather information |
| 57 | |
| 58 | 1) Identify the set of modules that are part of this extension version release. |
| 59 | These are the set of modules that are releasing new APIs in this train. |
| 60 | |
| 61 | 2) Decide the integer value of this extension version. Usually this is the |
| 62 | `previous_version + 1`. |
| 63 | |
| 64 | #### Code changes |
| 65 | |
| 66 | 3) **build/make:** Update the extension version of the module development |
| 67 | branch. This is defined by the `PLATFORM_SDK_EXTENSION_VERSION` variable in |
| 68 | `core/version_defaults.mk`. Subsequent module builds in the branch will embed |
| 69 | the new version code into the proto in the modules. |
| 70 | |
| 71 | [Example CL][bump] |
| 72 | |
| 73 | 4) **packages/modules/SdkExtensions:** Define the new SDK extension version. |
| 74 | We 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 | |
| 85 | 5) 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 | |
| 94 | 6) The continuous test configuration has a list of module builds to include when |
| 95 | running the SdkExtensions tests. They need to be updated to use module builds |
| 96 | that contain the CLs generated above. See http://shortn/_aKhLxsQLZd |
| 97 | |
Anton Hansson | 76f9501 | 2022-09-06 15:31:07 +0000 | [diff] [blame] | 98 | #### Finalize SDK artifacts |
| 99 | |
Mårten Kongstad | ff40fda | 2022-09-19 11:03:29 +0200 | [diff] [blame] | 100 | 7) **prebuilts/sdk & module sdk repos:** Once the train is finalized, the API |
Anton Hansson | 76f9501 | 2022-09-06 15:31:07 +0000 | [diff] [blame] | 101 | artifacts need to be recorded for doc generation to work correctly. Do this by |
| 102 | running 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 Hansson | 76f9501 | 2022-09-06 15:31:07 +0000 | [diff] [blame] | 120 | |
Anton Hansson | 1223654 | 2022-04-12 20:34:06 +0100 | [diff] [blame] | 121 | ### Adding a new extension |
Anton Hansson | 76f9501 | 2022-09-06 15:31:07 +0000 | [diff] [blame] | 122 | |
Anton Hansson | 1223654 | 2022-04-12 20:34:06 +0100 | [diff] [blame] | 123 | An extension is a way to group a set of modules so that they are versioned |
Anton Hansson | 76f9501 | 2022-09-06 15:31:07 +0000 | [diff] [blame] | 124 | together. We currently define a new extension for every Android SDK level that |
| 125 | introduces new modules. Every module shipped in previous versions are also part |
| 126 | of the new extension. For example, all the R modules are part of both the R |
| 127 | extensions and the S extensions. |
Anton Hansson | 1223654 | 2022-04-12 20:34:06 +0100 | [diff] [blame] | 128 | |
| 129 | The steps to define a new extension are: |
Anton Hansson | 76f9501 | 2022-09-06 15:31:07 +0000 | [diff] [blame] | 130 | |
Paul Duffin | 0743de7 | 2023-02-20 15:53:31 +0000 | [diff] [blame] | 131 | - 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 Hansson | 76f9501 | 2022-09-06 15:31:07 +0000 | [diff] [blame] | 133 | |
| 134 | - Add the binary "current sdk version" proto to the apexes of the new modules. |
Paul Duffin | 0743de7 | 2023-02-20 15:53:31 +0000 | [diff] [blame] | 135 | e.g. [for health fitness](http://ag/21158651) and |
| 136 | [config infrastructure](http://ag/21158650). |
Anton Hansson | 76f9501 | 2022-09-06 15:31:07 +0000 | [diff] [blame] | 137 | |
| 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 Kongstad | ddc0d52 | 2023-01-24 10:52:40 +0100 | [diff] [blame] | 150 | * update the hard-coded list of extensions in `ReadSystemProperties` |
| 151 | |
Paul Duffin | 0743de7 | 2023-02-20 15:53:31 +0000 | [diff] [blame] | 152 | * e.g. [for U extension](http://ag/21481214) |
| 153 | |
Anton Hansson | 76f9501 | 2022-09-06 15:31:07 +0000 | [diff] [blame] | 154 | - Make the `SdkExtensions.getExtensionVersion` API support the new extensions. |
| 155 | |
Paul Duffin | 0743de7 | 2023-02-20 15:53:31 +0000 | [diff] [blame] | 156 | * Extend `CtsSdkExtentensionsTestCase` to verify the above two behaviors. |
| 157 | |
| 158 | * e.g. [for U extensions](http://ag/21507939) |
Mårten Kongstad | 4eb8775 | 2023-04-19 18:30:06 +0200 | [diff] [blame^] | 159 | |
| 160 | - Add a new sdk tag in sdk-extensions-info.xml |