Change version checks to use SdkLevel.isAtLeast*
Bug: 229190745 Test: m -j out/soong/.intermediates/frameworks/base/packages/SettingsLib/SettingsLib/android_common/lint/lint-baseline.xml Change-Id: Id0ce4d3089af4e9a8a9002e79c810caac5e711e2
This commit is contained in:
@@ -15,6 +15,7 @@ android_library {
|
||||
|
||||
static_libs: [
|
||||
"androidx.annotation_annotation",
|
||||
"modules-utils-build",
|
||||
],
|
||||
|
||||
sdk_version: "system_current",
|
||||
|
||||
@@ -17,10 +17,11 @@
|
||||
package com.android.settingslib.utils;
|
||||
|
||||
import android.os.Build;
|
||||
import android.os.Build.VERSION;
|
||||
|
||||
import androidx.annotation.ChecksSdkIntAtLeast;
|
||||
|
||||
import com.android.modules.utils.build.SdkLevel;
|
||||
|
||||
/**
|
||||
* An util class to check whether the current OS version is higher or equal to sdk version of
|
||||
* device.
|
||||
@@ -34,7 +35,7 @@ public final class BuildCompatUtils {
|
||||
*/
|
||||
@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.S)
|
||||
public static boolean isAtLeastS() {
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.S;
|
||||
return SdkLevel.isAtLeastS();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -44,41 +45,17 @@ public final class BuildCompatUtils {
|
||||
*/
|
||||
@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.S_V2)
|
||||
public static boolean isAtLeastSV2() {
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.S_V2;
|
||||
return SdkLevel.isAtLeastSv2();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 = "Tiramisu",
|
||||
* SDK_INT = 32)
|
||||
* <li>For current Android release: when new API is finalized (CODENAME = "REL", SDK_INT = 33)
|
||||
* <li>For next Android release (CODENAME = "U", SDK_INT = 34+)
|
||||
* </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.
|
||||
* Implementation of BuildCompat.isAtLeastT() suitable for use in Settings
|
||||
*
|
||||
* @return Whether the current OS version is higher or equal to T.
|
||||
*/
|
||||
@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.TIRAMISU)
|
||||
public static boolean isAtLeastT() {
|
||||
if (!isAtLeastS()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (VERSION.CODENAME.equals("REL") && VERSION.SDK_INT >= 33)
|
||||
|| (VERSION.CODENAME.length() >= 1
|
||||
&& VERSION.CODENAME.toUpperCase().charAt(0) >= 'T'
|
||||
&& VERSION.CODENAME.toUpperCase().charAt(0) <= 'Z')
|
||||
|| (Build.VERSION.CODENAME.equals("Tiramisu") && Build.VERSION.SDK_INT >= 32);
|
||||
return SdkLevel.isAtLeastT();
|
||||
}
|
||||
|
||||
private BuildCompatUtils() {}
|
||||
|
||||
@@ -36,7 +36,8 @@ import android.util.Log;
|
||||
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.core.os.BuildCompat;
|
||||
|
||||
import com.android.modules.utils.build.SdkLevel;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
@@ -220,7 +221,7 @@ public class DeviceInfoUtils {
|
||||
}
|
||||
|
||||
private static String getRawPhoneNumber(Context context, int subscriptionId) {
|
||||
if (BuildCompat.isAtLeastT()) {
|
||||
if (SdkLevel.isAtLeastT()) {
|
||||
return getRawPhoneNumberFromT(context, subscriptionId);
|
||||
} else {
|
||||
final TelephonyManager telephonyManager = context.getSystemService(
|
||||
|
||||
@@ -31,10 +31,11 @@ import android.util.TypedValue;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.core.os.BuildCompat;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
import com.android.modules.utils.build.SdkLevel;
|
||||
|
||||
/**
|
||||
* Helper class for managing settings preferences that can be disabled
|
||||
* by device admins via user restrictions.
|
||||
@@ -105,7 +106,7 @@ public class RestrictedPreferenceHelper {
|
||||
if (mDisabledSummary) {
|
||||
final TextView summaryView = (TextView) holder.findViewById(android.R.id.summary);
|
||||
if (summaryView != null) {
|
||||
final CharSequence disabledText = BuildCompat.isAtLeastT()
|
||||
final CharSequence disabledText = SdkLevel.isAtLeastT()
|
||||
? getDisabledByAdminUpdatableString()
|
||||
: mContext.getString(R.string.disabled_by_admin_summary_text);
|
||||
if (mDisabledByAdmin) {
|
||||
|
||||
@@ -45,12 +45,12 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.core.graphics.drawable.RoundedBitmapDrawable;
|
||||
import androidx.core.graphics.drawable.RoundedBitmapDrawableFactory;
|
||||
import androidx.core.os.BuildCompat;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.util.UserIcons;
|
||||
import com.android.launcher3.icons.BaseIconFactory.IconOptions;
|
||||
import com.android.launcher3.icons.IconFactory;
|
||||
import com.android.modules.utils.build.SdkLevel;
|
||||
import com.android.settingslib.drawable.UserIconDrawable;
|
||||
import com.android.settingslib.fuelgauge.BatteryStatus;
|
||||
|
||||
@@ -130,7 +130,7 @@ public class Utils {
|
||||
String name = info != null ? info.name : null;
|
||||
if (info.isManagedProfile()) {
|
||||
// We use predefined values for managed profiles
|
||||
return BuildCompat.isAtLeastT()
|
||||
return SdkLevel.isAtLeastT()
|
||||
? getUpdatableManagedUserTitle(context)
|
||||
: context.getString(R.string.managed_user_title);
|
||||
} else if (info.isGuest()) {
|
||||
|
||||
@@ -47,7 +47,8 @@ import android.os.UserHandle;
|
||||
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.core.os.BuildCompat;
|
||||
|
||||
import com.android.modules.utils.build.SdkLevel;
|
||||
|
||||
/**
|
||||
* Converts the user avatar icon to a circularly clipped one with an optional badge and frame
|
||||
@@ -87,7 +88,7 @@ public class UserIconDrawable extends Drawable implements Drawable.Callback {
|
||||
* @return drawable containing just the badge
|
||||
*/
|
||||
public static Drawable getManagedUserDrawable(Context context) {
|
||||
if (BuildCompat.isAtLeastT()) {
|
||||
if (SdkLevel.isAtLeastT()) {
|
||||
return getUpdatableManagedUserDrawable(context);
|
||||
} else {
|
||||
return getDrawableForDisplayDensity(
|
||||
@@ -226,7 +227,7 @@ public class UserIconDrawable extends Drawable implements Drawable.Callback {
|
||||
}
|
||||
|
||||
private static Drawable getManagementBadge(Context context) {
|
||||
if (BuildCompat.isAtLeastT()) {
|
||||
if (SdkLevel.isAtLeastT()) {
|
||||
return getUpdatableManagementBadge(context);
|
||||
} else {
|
||||
return getDrawableForDisplayDensity(
|
||||
|
||||
Reference in New Issue
Block a user