Anton Hansson | a6caee8 | 2020-07-15 12:34:13 +0100 | [diff] [blame] | 1 | # SdkExtensions module |
| 2 | |
| 3 | SdkExtensions is a module that decides the extension SDK level of the device, |
| 4 | and provides APIs for applications to query the extension SDK level. |
| 5 | |
Anton Hansson | b1a217c | 2020-11-30 11:43:05 +0000 | [diff] [blame] | 6 | ## General information |
| 7 | |
| 8 | ### Structure |
Anton Hansson | a6caee8 | 2020-07-15 12:34:13 +0100 | [diff] [blame] | 9 | |
| 10 | The module is packaged in an apex, `com.android.sdkext`, and has two components: |
| 11 | - `bin/derive_sdk`: Native binary that runs early in the device boot process and |
| 12 | reads metadata of other modules, to set system properties relating to the |
| 13 | extension SDK (for instance `build.version.extensions.r`). |
| 14 | - `javalib/framework-sdkextension.jar`: This is a jar on the bootclasspath that |
| 15 | exposes APIs to applications to query the extension SDK level. |
| 16 | |
Anton Hansson | b1a217c | 2020-11-30 11:43:05 +0000 | [diff] [blame] | 17 | ### Deriving extension SDK level |
Anton Hansson | a6caee8 | 2020-07-15 12:34:13 +0100 | [diff] [blame] | 18 | `derive_sdk` is a program that reads metadata stored in other apex modules, in |
| 19 | the form of binary protobuf files in subpath `etc/sdkinfo.binarypb` inside each |
| 20 | apex. The structure of this protobuf can be seen [here][sdkinfo-proto]. The |
| 21 | exact steps for converting a set of metadata files to actual extension versions |
| 22 | is likely to change over time, and should not be depended upon. |
| 23 | |
Anton Hansson | b1a217c | 2020-11-30 11:43:05 +0000 | [diff] [blame] | 24 | ### Reading extension SDK level |
Anton Hansson | a6caee8 | 2020-07-15 12:34:13 +0100 | [diff] [blame] | 25 | The module exposes a java class [`SdkExtensions`][sdkextensions-java] in the |
| 26 | package `android.os.ext`. The method `getExtensionVersion(int)` can be used to |
| 27 | read the version of a particular sdk extension, e.g. |
| 28 | `getExtensionVersion(Build.VERSION_CODES.R)`. |
| 29 | |
| 30 | [sdkinfo-proto]: sdk.proto |
| 31 | [sdkextensions-java]: framework/java/android/os/ext/SdkExtensions.java |
Anton Hansson | b1a217c | 2020-11-30 11:43:05 +0000 | [diff] [blame] | 32 | |
| 33 | ## Developer information |
| 34 | |
| 35 | ### Adding a new extension version |
| 36 | For every new Android SDK level a new extension version should be defined. These |
| 37 | are the steps necessary to do that: |
Anton Hansson | cda99fa | 2021-01-15 08:15:57 +0000 | [diff] [blame] | 38 | - Add the new modules in this extension version to the SdkModule enum in |
| 39 | sdk.proto. |
| 40 | - Update `derive_sdk.cpp` by: |
| 41 | * mapping the modules' package names to the new enum values |
| 42 | * creating a new set with the new enum values |
| 43 | * set a new sysprop to the value of `GetSdkLevel` with the new enum set |
| 44 | * add a unit test to `derive_sdk_test.cpp` verifying the new extensions works |
Anton Hansson | b1a217c | 2020-11-30 11:43:05 +0000 | [diff] [blame] | 45 | - Make the `SdkExtensions.getExtensionVersion` API support the new extensions. |
| 46 | - Extend the CTS test to verify the above two behaviors. |
| 47 | - Update `RollbackManagerServiceImpl#getExtensionVersions` to account for the |
| 48 | new extension version. |