1 /* 2 * Copyright (C) 2022 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 com.android.modules.utils.build; 18 19 import static android.os.Build.VERSION_CODES.TIRAMISU; 20 import static android.os.Build.VERSION_CODES.UPSIDE_DOWN_CAKE; 21 import static android.os.Build.VERSION_CODES.VANILLA_ICE_CREAM; 22 23 /** Stub class to compile the linter for host execution. */ 24 public final class SdkLevel { SdkLevel()25 private SdkLevel() {} 26 27 private static volatile int sSdkInt = TIRAMISU; 28 29 /** 30 * Linter only method to set the mocked SDK level for the Safety Center config code. 31 * 32 * <p>You must hold the class lock before calling this method. You should hold the class lock 33 * for the whole duration of the lint check. 34 */ setSdkInt(int sdkInt)35 public static void setSdkInt(int sdkInt) { 36 if (!Thread.holdsLock(SdkLevel.class)) { 37 throw new IllegalStateException("Lock not held."); 38 } 39 sSdkInt = sdkInt; 40 } 41 42 /** Method used in the Safety Center config code. */ isAtLeastU()43 public static boolean isAtLeastU() { 44 return sSdkInt >= UPSIDE_DOWN_CAKE; 45 } 46 47 /** Method used in the Safety Center config code. */ isAtLeastV()48 public static boolean isAtLeastV() { 49 return sSdkInt >= VANILLA_ICE_CREAM; 50 } 51 } 52