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