Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit caa0302e authored by kholoud mohamed's avatar kholoud mohamed
Browse files

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
parent 96770f25
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ android_library {

    static_libs: [
        "androidx.annotation_annotation",
        "modules-utils-build",
    ],

    sdk_version: "system_current",
+7 −30
Original line number Diff line number Diff line
@@ -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() {}
+3 −2
Original line number Diff line number Diff line
@@ -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(
+3 −2
Original line number Diff line number Diff line
@@ -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) {
+2 −2
Original line number Diff line number Diff line
@@ -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()) {
Loading