Relace BuildCompat.isAtLeastS to check Build.VERSION.SDK_INT

Fixes: 191227729
Test: robotest & manual
Change-Id: I4b865b7de33a6801783dd645213fef0cda8d4dd2
diff --git a/packages/SettingsLib/Utils/AndroidManifest.xml b/packages/SettingsLib/Utils/AndroidManifest.xml
index 96d9e51..fd89676 100644
--- a/packages/SettingsLib/Utils/AndroidManifest.xml
+++ b/packages/SettingsLib/Utils/AndroidManifest.xml
@@ -16,7 +16,7 @@
   -->
 
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
-          package="com.android.settingslib.widget">
+          package="com.android.settingslib.utils">
 
     <uses-sdk android:minSdkVersion="21" />
 
diff --git a/packages/SettingsLib/Utils/src/com/android/settingslib/utils/BuildCompatUtils.java b/packages/SettingsLib/Utils/src/com/android/settingslib/utils/BuildCompatUtils.java
new file mode 100644
index 0000000..44f6f54
--- /dev/null
+++ b/packages/SettingsLib/Utils/src/com/android/settingslib/utils/BuildCompatUtils.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settingslib.utils;
+
+import android.os.Build.VERSION;
+
+/**
+ * An util class to check whether the current OS version is higher or equal to sdk version of
+ * device.
+ */
+public final class BuildCompatUtils {
+
+    /**
+     * Implementation of BuildCompat.isAtLeast*() suitable for use in Settings
+     *
+     * <p>This still should try using BuildCompat.isAtLeastR() as source of truth, but also checking
+     * for VERSION_SDK_INT and VERSION.CODENAME in case when BuildCompat implementation returned
+     * false. Note that both checks should be >= and not = to make sure that when Android version
+     * increases (i.e., from R to S), this does not stop working.
+     *
+     * <p>Supported configurations:
+     *
+     * <ul>
+     *   <li>For current Android release: when new API is not finalized yet (CODENAME = "S", SDK_INT
+     *       = 30|31)
+     *   <li>For current Android release: when new API is finalized (CODENAME = "REL", SDK_INT = 31)
+     *   <li>For next Android release (CODENAME = "T", SDK_INT = 30+)
+     * </ul>
+     *
+     * <p>Note that Build.VERSION_CODES.S cannot be used here until final SDK is available, because
+     * it is equal to Build.VERSION_CODES.CUR_DEVELOPMENT before API finalization.
+     *
+     * @return Whether the current OS version is higher or equal to S.
+     */
+    public static boolean isAtLeastS() {
+        if (VERSION.SDK_INT < 30) {
+            return false;
+        }
+
+        return (VERSION.CODENAME.equals("REL") && VERSION.SDK_INT >= 31)
+                || (VERSION.CODENAME.length() == 1
+                && VERSION.CODENAME.compareTo("S") >= 0
+                && VERSION.CODENAME.compareTo("Z") <= 0);
+    }
+
+    private BuildCompatUtils() {}
+}
diff --git a/packages/SettingsLib/Utils/src/com/android/settingslib/utils/applications/AppUtils.java b/packages/SettingsLib/Utils/src/com/android/settingslib/utils/applications/AppUtils.java
index 4505dad..5dc0b72 100644
--- a/packages/SettingsLib/Utils/src/com/android/settingslib/utils/applications/AppUtils.java
+++ b/packages/SettingsLib/Utils/src/com/android/settingslib/utils/applications/AppUtils.java
@@ -22,7 +22,7 @@
 import android.os.UserManager;
 import android.util.Log;
 
-import com.android.settingslib.widget.R;
+import com.android.settingslib.utils.R;
 
 public class AppUtils {