Anton Hansson | 4ec07fa | 2019-11-08 15:18:04 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.os.ext; |
| 18 | |
| 19 | import android.annotation.IntDef; |
Anton Hansson | b52bd1c | 2019-12-06 17:07:28 +0000 | [diff] [blame] | 20 | import android.annotation.SystemApi; |
Anton Hansson | 4ec07fa | 2019-11-08 15:18:04 +0000 | [diff] [blame] | 21 | import android.os.Build.VERSION_CODES; |
| 22 | import android.os.SystemProperties; |
| 23 | |
| 24 | import java.lang.annotation.Retention; |
| 25 | import java.lang.annotation.RetentionPolicy; |
| 26 | |
Anton Hansson | b52bd1c | 2019-12-06 17:07:28 +0000 | [diff] [blame] | 27 | /** |
| 28 | * Methods for interacting with the extension SDK. |
| 29 | * |
| 30 | * This class provides information about the extension SDK version present |
| 31 | * on this device. Use the {@link #getExtensionVersion(int) getExtension} to |
| 32 | * query for the extension version for the given SDK version. |
| 33 | |
| 34 | * @hide |
| 35 | */ |
| 36 | @SystemApi |
Anton Hansson | 4ec07fa | 2019-11-08 15:18:04 +0000 | [diff] [blame] | 37 | public class SdkExtensions { |
| 38 | |
| 39 | private static final int R_EXTENSION_INT; |
| 40 | static { |
Anton Hansson | d8ac5fa | 2019-12-09 17:16:13 +0000 | [diff] [blame] | 41 | R_EXTENSION_INT = SystemProperties.getInt("ro.build.version.extensions.r", 0); |
Anton Hansson | 4ec07fa | 2019-11-08 15:18:04 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Anton Hansson | b52bd1c | 2019-12-06 17:07:28 +0000 | [diff] [blame] | 44 | /** |
| 45 | * Values suitable as parameters for {@link #getExtensionVersion(int)}. |
| 46 | * @hide |
| 47 | */ |
Anton Hansson | 4ec07fa | 2019-11-08 15:18:04 +0000 | [diff] [blame] | 48 | @IntDef(value = { VERSION_CODES.R }) |
| 49 | @Retention(RetentionPolicy.SOURCE) |
| 50 | public @interface SdkVersion {} |
| 51 | |
Anton Hansson | b52bd1c | 2019-12-06 17:07:28 +0000 | [diff] [blame] | 52 | private SdkExtensions() { } |
| 53 | |
Anton Hansson | 4ec07fa | 2019-11-08 15:18:04 +0000 | [diff] [blame] | 54 | /** |
| 55 | * Return the version of the extension to the given SDK. |
| 56 | * |
| 57 | * @param sdk the SDK version to get the extension version of. |
| 58 | * @see SdkVersion |
| 59 | * @throws IllegalArgumentException if sdk is not an sdk version with extensions |
| 60 | */ |
| 61 | public static int getExtensionVersion(@SdkVersion int sdk) { |
| 62 | if (sdk < VERSION_CODES.R) { |
| 63 | throw new IllegalArgumentException(); |
| 64 | } |
| 65 | return R_EXTENSION_INT; |
| 66 | } |
| 67 | |
| 68 | } |