blob: c039a820fc040cce8a010d293f641a66f8c66a0c [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;
20import android.os.Build.VERSION_CODES;
21import android.os.SystemProperties;
22
23import java.lang.annotation.Retention;
24import java.lang.annotation.RetentionPolicy;
25
26/** @hide */
27public class SdkExtensions {
28
29 private static final int R_EXTENSION_INT;
30 static {
31 R_EXTENSION_INT = SystemProperties.getInt("persist.com.android.sdkext.sdk_info", 0);
32 }
33
34 /** Values suitable as parameters for {@link #getExtensionVersion(int)}. */
35 @IntDef(value = { VERSION_CODES.R })
36 @Retention(RetentionPolicy.SOURCE)
37 public @interface SdkVersion {}
38
39 /**
40 * Return the version of the extension to the given SDK.
41 *
42 * @param sdk the SDK version to get the extension version of.
43 * @see SdkVersion
44 * @throws IllegalArgumentException if sdk is not an sdk version with extensions
45 */
46 public static int getExtensionVersion(@SdkVersion int sdk) {
47 if (sdk < VERSION_CODES.R) {
48 throw new IllegalArgumentException();
49 }
50 return R_EXTENSION_INT;
51 }
52
53}