Merge "Change version checks to use SdkLevel.isAtLeast*" into tm-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
9e446d561b
@@ -15,6 +15,7 @@ android_library {
|
|||||||
|
|
||||||
static_libs: [
|
static_libs: [
|
||||||
"androidx.annotation_annotation",
|
"androidx.annotation_annotation",
|
||||||
|
"modules-utils-build",
|
||||||
],
|
],
|
||||||
|
|
||||||
sdk_version: "system_current",
|
sdk_version: "system_current",
|
||||||
|
|||||||
@@ -17,10 +17,11 @@
|
|||||||
package com.android.settingslib.utils;
|
package com.android.settingslib.utils;
|
||||||
|
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Build.VERSION;
|
|
||||||
|
|
||||||
import androidx.annotation.ChecksSdkIntAtLeast;
|
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
|
* An util class to check whether the current OS version is higher or equal to sdk version of
|
||||||
* device.
|
* device.
|
||||||
@@ -34,7 +35,7 @@ public final class BuildCompatUtils {
|
|||||||
*/
|
*/
|
||||||
@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.S)
|
@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.S)
|
||||||
public static boolean isAtLeastS() {
|
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)
|
@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.S_V2)
|
||||||
public static boolean isAtLeastSV2() {
|
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
|
* Implementation of BuildCompat.isAtLeastT() 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.
|
|
||||||
*
|
*
|
||||||
* @return Whether the current OS version is higher or equal to T.
|
* @return Whether the current OS version is higher or equal to T.
|
||||||
*/
|
*/
|
||||||
|
@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.TIRAMISU)
|
||||||
public static boolean isAtLeastT() {
|
public static boolean isAtLeastT() {
|
||||||
if (!isAtLeastS()) {
|
return SdkLevel.isAtLeastT();
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private BuildCompatUtils() {}
|
private BuildCompatUtils() {}
|
||||||
|
|||||||
@@ -36,7 +36,8 @@ import android.util.Log;
|
|||||||
|
|
||||||
import androidx.annotation.RequiresApi;
|
import androidx.annotation.RequiresApi;
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
import androidx.core.os.BuildCompat;
|
|
||||||
|
import com.android.modules.utils.build.SdkLevel;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
@@ -220,7 +221,7 @@ public class DeviceInfoUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static String getRawPhoneNumber(Context context, int subscriptionId) {
|
private static String getRawPhoneNumber(Context context, int subscriptionId) {
|
||||||
if (BuildCompat.isAtLeastT()) {
|
if (SdkLevel.isAtLeastT()) {
|
||||||
return getRawPhoneNumberFromT(context, subscriptionId);
|
return getRawPhoneNumberFromT(context, subscriptionId);
|
||||||
} else {
|
} else {
|
||||||
final TelephonyManager telephonyManager = context.getSystemService(
|
final TelephonyManager telephonyManager = context.getSystemService(
|
||||||
|
|||||||
@@ -31,10 +31,11 @@ import android.util.TypedValue;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.annotation.RequiresApi;
|
import androidx.annotation.RequiresApi;
|
||||||
import androidx.core.os.BuildCompat;
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceViewHolder;
|
import androidx.preference.PreferenceViewHolder;
|
||||||
|
|
||||||
|
import com.android.modules.utils.build.SdkLevel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper class for managing settings preferences that can be disabled
|
* Helper class for managing settings preferences that can be disabled
|
||||||
* by device admins via user restrictions.
|
* by device admins via user restrictions.
|
||||||
@@ -105,7 +106,7 @@ public class RestrictedPreferenceHelper {
|
|||||||
if (mDisabledSummary) {
|
if (mDisabledSummary) {
|
||||||
final TextView summaryView = (TextView) holder.findViewById(android.R.id.summary);
|
final TextView summaryView = (TextView) holder.findViewById(android.R.id.summary);
|
||||||
if (summaryView != null) {
|
if (summaryView != null) {
|
||||||
final CharSequence disabledText = BuildCompat.isAtLeastT()
|
final CharSequence disabledText = SdkLevel.isAtLeastT()
|
||||||
? getDisabledByAdminUpdatableString()
|
? getDisabledByAdminUpdatableString()
|
||||||
: mContext.getString(R.string.disabled_by_admin_summary_text);
|
: mContext.getString(R.string.disabled_by_admin_summary_text);
|
||||||
if (mDisabledByAdmin) {
|
if (mDisabledByAdmin) {
|
||||||
|
|||||||
@@ -45,12 +45,12 @@ import androidx.annotation.NonNull;
|
|||||||
import androidx.annotation.RequiresApi;
|
import androidx.annotation.RequiresApi;
|
||||||
import androidx.core.graphics.drawable.RoundedBitmapDrawable;
|
import androidx.core.graphics.drawable.RoundedBitmapDrawable;
|
||||||
import androidx.core.graphics.drawable.RoundedBitmapDrawableFactory;
|
import androidx.core.graphics.drawable.RoundedBitmapDrawableFactory;
|
||||||
import androidx.core.os.BuildCompat;
|
|
||||||
|
|
||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
import com.android.internal.util.UserIcons;
|
import com.android.internal.util.UserIcons;
|
||||||
import com.android.launcher3.icons.BaseIconFactory.IconOptions;
|
import com.android.launcher3.icons.BaseIconFactory.IconOptions;
|
||||||
import com.android.launcher3.icons.IconFactory;
|
import com.android.launcher3.icons.IconFactory;
|
||||||
|
import com.android.modules.utils.build.SdkLevel;
|
||||||
import com.android.settingslib.drawable.UserIconDrawable;
|
import com.android.settingslib.drawable.UserIconDrawable;
|
||||||
import com.android.settingslib.fuelgauge.BatteryStatus;
|
import com.android.settingslib.fuelgauge.BatteryStatus;
|
||||||
|
|
||||||
@@ -130,7 +130,7 @@ public class Utils {
|
|||||||
String name = info != null ? info.name : null;
|
String name = info != null ? info.name : null;
|
||||||
if (info.isManagedProfile()) {
|
if (info.isManagedProfile()) {
|
||||||
// We use predefined values for managed profiles
|
// We use predefined values for managed profiles
|
||||||
return BuildCompat.isAtLeastT()
|
return SdkLevel.isAtLeastT()
|
||||||
? getUpdatableManagedUserTitle(context)
|
? getUpdatableManagedUserTitle(context)
|
||||||
: context.getString(R.string.managed_user_title);
|
: context.getString(R.string.managed_user_title);
|
||||||
} else if (info.isGuest()) {
|
} else if (info.isGuest()) {
|
||||||
|
|||||||
@@ -47,7 +47,8 @@ import android.os.UserHandle;
|
|||||||
|
|
||||||
import androidx.annotation.RequiresApi;
|
import androidx.annotation.RequiresApi;
|
||||||
import androidx.annotation.VisibleForTesting;
|
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
|
* 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
|
* @return drawable containing just the badge
|
||||||
*/
|
*/
|
||||||
public static Drawable getManagedUserDrawable(Context context) {
|
public static Drawable getManagedUserDrawable(Context context) {
|
||||||
if (BuildCompat.isAtLeastT()) {
|
if (SdkLevel.isAtLeastT()) {
|
||||||
return getUpdatableManagedUserDrawable(context);
|
return getUpdatableManagedUserDrawable(context);
|
||||||
} else {
|
} else {
|
||||||
return getDrawableForDisplayDensity(
|
return getDrawableForDisplayDensity(
|
||||||
@@ -226,7 +227,7 @@ public class UserIconDrawable extends Drawable implements Drawable.Callback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static Drawable getManagementBadge(Context context) {
|
private static Drawable getManagementBadge(Context context) {
|
||||||
if (BuildCompat.isAtLeastT()) {
|
if (SdkLevel.isAtLeastT()) {
|
||||||
return getUpdatableManagementBadge(context);
|
return getUpdatableManagementBadge(context);
|
||||||
} else {
|
} else {
|
||||||
return getDrawableForDisplayDensity(
|
return getDrawableForDisplayDensity(
|
||||||
|
|||||||
Reference in New Issue
Block a user