blob: d3b9397d45f205a03ad9e81fdd5455c53972ebe9 [file] [log] [blame]
Anton Hansson4ec07fa2019-11-08 15:18:04 +00001/*
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
17package android.os.ext;
18
19import android.annotation.IntDef;
Anton Hanssonb52bd1c2019-12-06 17:07:28 +000020import android.annotation.SystemApi;
Anton Hansson4ec07fa2019-11-08 15:18:04 +000021import android.os.Build.VERSION_CODES;
22import android.os.SystemProperties;
23
24import java.lang.annotation.Retention;
25import java.lang.annotation.RetentionPolicy;
26
Anton Hanssonb52bd1c2019-12-06 17:07:28 +000027/**
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 Hansson4ec07fa2019-11-08 15:18:04 +000037public class SdkExtensions {
38
39 private static final int R_EXTENSION_INT;
40 static {
Anton Hanssond8ac5fa2019-12-09 17:16:13 +000041 R_EXTENSION_INT = SystemProperties.getInt("ro.build.version.extensions.r", 0);
Anton Hansson4ec07fa2019-11-08 15:18:04 +000042 }
43
Anton Hanssonb52bd1c2019-12-06 17:07:28 +000044 /**
45 * Values suitable as parameters for {@link #getExtensionVersion(int)}.
46 * @hide
47 */
Anton Hansson4ec07fa2019-11-08 15:18:04 +000048 @IntDef(value = { VERSION_CODES.R })
49 @Retention(RetentionPolicy.SOURCE)
50 public @interface SdkVersion {}
51
Anton Hanssonb52bd1c2019-12-06 17:07:28 +000052 private SdkExtensions() { }
53
Anton Hansson4ec07fa2019-11-08 15:18:04 +000054 /**
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}