Skip to content

Commit

Permalink
Remove deprecated BuildInfo.isAtLeastS() calls.
Browse files Browse the repository at this point in the history
Replace most calls to BuildInfo.isAtLeastS() with direct checks of the
SDK version now that we build with the S SDK.

Change-Id: I1a8eec0204326ae323336155b5877ade5a412410
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3067500
Reviewed-by: Theresa  <[email protected]>
Reviewed-by: Will Cassella <[email protected]>
Reviewed-by: Ryan Hamilton <[email protected]>
Reviewed-by: Peter Boström <[email protected]>
Reviewed-by: Shimi Zhang <[email protected]>
Reviewed-by: Dominick Ng <[email protected]>
Commit-Queue: Richard Coles <[email protected]>
Cr-Commit-Position: refs/heads/master@{#908591}
  • Loading branch information
tornewuff authored and Chromium LUCI CQ committed Aug 4, 2021
1 parent caeffe4 commit 4326db5
Show file tree
Hide file tree
Showing 18 changed files with 25 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ private void initialize(WebViewDelegate webViewDelegate) {
SystemClock.uptimeMillis() - startTime);

/* TODO(torne): re-enable this once the API change is sorted out
if (BuildInfo.isAtLeastS()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
// TODO: Use the framework constants as indices in timestamps array.
startTime = mWebViewDelegate.getTimestamps()[0];
RecordHistogram.recordTimesHistogram(
Expand Down
6 changes: 0 additions & 6 deletions base/android/build_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,5 @@ BuildInfo* BuildInfo::GetInstance() {
return Singleton<BuildInfo, BuildInfoSingletonTraits >::get();
}

// static
bool BuildInfo::IsAtLeastS() {
JNIEnv* env = AttachCurrentThread();
return Java_BuildInfo_isAtLeastS(env);
}

} // namespace android
} // namespace base
5 changes: 1 addition & 4 deletions base/android/build_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ enum SdkVersion {
SDK_VERSION_P = 28,
SDK_VERSION_Q = 29,
SDK_VERSION_R = 30,
SDK_VERSION_S = 31,
};

// BuildInfo is a singleton class that stores android build and device
Expand All @@ -51,10 +52,6 @@ class BASE_EXPORT BuildInfo {
// should only be one instance of BuildInfo ever created.
static BuildInfo* GetInstance();

// Checks if the device is running on a pre-release version of Android S or a
// release version of Android S or newer.
bool IsAtLeastS();

// Const char* is used instead of std::strings because these values must be
// available even if the process is in a crash state. Sadly
// std::string.c_str() doesn't guarantee that memory won't be allocated when
Expand Down
1 change: 0 additions & 1 deletion base/android/java/src/org/chromium/base/BuildInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ private static boolean isAtLeastPreReleaseCodename(
*
* @return {@code true} if S APIs are available for use, {@code false} otherwise
*/
@CalledByNative
@ChecksSdkIntAtLeast(api = 31, codename = "S")
public static boolean isAtLeastS() {
return VERSION.SDK_INT >= 31 || isAtLeastPreReleaseCodename("S", VERSION.CODENAME);
Expand Down
2 changes: 1 addition & 1 deletion base/android/java/src/org/chromium/base/IntentUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ public static boolean isMainIntentFromLauncher(Intent intent) {
public static int getPendingIntentMutabilityFlag(boolean mutable) {
if (!mutable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
return ApiHelperForM.getPendingIntentImmutableFlag();
} else if (mutable && BuildInfo.isAtLeastS()) {
} else if (mutable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
return FLAG_MUTABLE;
}
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;

import androidx.annotation.CallSuper;
import androidx.annotation.Nullable;
import androidx.annotation.StyleRes;
import androidx.appcompat.app.AppCompatActivity;

import org.chromium.base.BuildInfo;
import org.chromium.base.ContextUtils;
import org.chromium.base.supplier.ObservableSupplier;
import org.chromium.base.supplier.ObservableSupplierImpl;
Expand Down Expand Up @@ -187,7 +187,7 @@ protected void applyThemeOverlays() {
// are not synchronized. Typically the first time overscroll is enabled, the following will
// use the old value and then content will pick up the enabled value, causing one execution
// of inconsistency.
if (BuildInfo.isAtLeastS()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
&& !CachedFeatureFlags.isEnabled(ChromeFeatureList.ELASTIC_OVERSCROLL)) {
setTheme(R.style.ThemeOverlay_DisableOverscroll);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import org.chromium.base.ActivityState;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.ApplicationStatus;
import org.chromium.base.BuildInfo;
import org.chromium.base.BundleUtils;
import org.chromium.base.Callback;
import org.chromium.base.CommandLine;
Expand Down Expand Up @@ -1148,7 +1147,7 @@ public void onResumeWithNative() {
ChromeSessionState.setIsInMultiWindowMode(
MultiWindowUtils.getInstance().isInMultiWindowMode(this));

if (BuildInfo.isAtLeastS()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
ensurePictureInPictureController();
}
if (mPictureInPictureController != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import androidx.annotation.IntDef;
import androidx.annotation.Nullable;

import org.chromium.base.BuildInfo;
import org.chromium.base.Callback;
import org.chromium.base.Log;
import org.chromium.base.MathUtils;
Expand Down Expand Up @@ -124,7 +123,7 @@ public PictureInPictureController(Activity activity, ActivityTabProvider activit
mActivityTabProvider = activityTabProvider;
mFullscreenManager = fullscreenManager;

mListenForAutoEnterability = BuildInfo.isAtLeastS();
mListenForAutoEnterability = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S;
if (mListenForAutoEnterability) addObserversIfNeeded();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Build;

import androidx.annotation.DrawableRes;
import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat;

import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.BuildInfo;
import org.chromium.base.ContextUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.notifications.NotificationUmaTracker;
Expand Down Expand Up @@ -72,7 +72,7 @@ public static void showNotification(@SystemNotificationType int type, String gro
.setDefaults(Notification.DEFAULT_ALL);

if (contentIntent != null) {
if (startsActivity && BuildInfo.isAtLeastS()) {
if (startsActivity && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
// We can't use the NotificationIntentInterceptor to start Activities starting in
// Android S. Use the unmodified PendingIntent directly instead.
builder.setContentIntent(contentIntent.getPendingIntent());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import androidx.annotation.VisibleForTesting;

import org.chromium.base.BuildInfo;
import org.chromium.base.ContextUtils;
import org.chromium.base.IntentUtils;
import org.chromium.base.annotations.CalledByNative;
Expand Down Expand Up @@ -126,7 +125,7 @@ private static Intent getDialIntent(String phoneNumber) {
private static PendingIntentProvider getContentIntentProvider(String phoneNumber) {
Context context = ContextUtils.getApplicationContext();

if (BuildInfo.isAtLeastS()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
// We can't use the TapReceiver broadcast to start the dialer Activity starting in
// Android S. Use the dial intent directly instead.
return PendingIntentProvider.getActivity(context, /*requestCode=*/0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

package org.chromium.components.permissions;

import androidx.core.os.BuildCompat;
import android.os.Build;

import org.chromium.base.annotations.CalledByNative;
import org.chromium.components.content_settings.ContentSettingsType;
Expand Down Expand Up @@ -44,7 +44,7 @@ private static boolean isApproximateLocationSupportEnabled() {
// targeting SDK version 31. Therefore enable support based on the current device's
// software's SDK version as opposed to Chrome's targetSdkVersion. See:
// https://developer.android.com/about/versions/12/approximate-location
return BuildCompat.isAtLeastS()
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
&& PermissionsAndroidFeatureList.isEnabled(
PermissionsAndroidFeatureList
.ANDROID_APPROXIMATE_LOCATION_PERMISSION_SUPPORT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;

import org.chromium.base.BuildInfo;
import org.chromium.base.Log;
import org.chromium.base.PackageManagerUtils;
import org.chromium.base.UserData;
Expand Down Expand Up @@ -1404,7 +1403,8 @@ void onSelectionEvent(
@CalledByNative
/* package */ void onDragUpdate(@TouchSelectionDraggableType int type, float x, float y) {
// If this is for longpress drag selector, we can only have mangifier on S and above.
if (type == TouchSelectionDraggableType.LONGPRESS && !BuildInfo.isAtLeastS()) {
if (type == TouchSelectionDraggableType.LONGPRESS
&& Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import android.os.Process;
import android.provider.Settings;

import org.chromium.base.BuildInfo;
import org.chromium.base.ContextUtils;
import org.chromium.base.Log;
import org.chromium.base.annotations.CalledByNative;
Expand Down Expand Up @@ -557,7 +556,7 @@ private void registerBluetoothIntentsIfNeeded() {
mHasBluetoothPermission = hasPermission(
android.Manifest.permission.BLUETOOTH);

if (BuildInfo.isAtLeastS()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
mHasBluetoothPermission &= ApiHelperForS.hasBluetoothConnectPermission();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import androidx.annotation.VisibleForTesting;

import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.BuildInfo;
import org.chromium.base.ContextUtils;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.CalledByNativeUnchecked;
Expand Down Expand Up @@ -215,7 +214,7 @@ private static boolean getIsCaptivePortal() {
*/
private static WifiInfo getWifiInfo() {
if (haveAccessWifiState()) {
if (BuildInfo.isAtLeastS()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
// On Android S+, need to use NetworkCapabilities to get the WifiInfo.
ConnectivityManager connectivityManager =
(ConnectivityManager) ContextUtils.getApplicationContext().getSystemService(
Expand Down
7 changes: 3 additions & 4 deletions ui/android/java/src/org/chromium/ui/base/Clipboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import androidx.annotation.VisibleForTesting;

import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.BuildInfo;
import org.chromium.base.Callback;
import org.chromium.base.ContextUtils;
import org.chromium.base.StreamUtil;
Expand Down Expand Up @@ -260,7 +259,7 @@ public boolean hasHTMLOrStyledText() {
boolean hasUrl() {
// ClipDescription#getConfidenceScore is only available on Android S+, so before Android S,
// we will access the clipboard content and valid by URLUtil#isValidUrl.
if (BuildInfo.isAtLeastS()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
ClipDescription description = mClipboardManager.getPrimaryClipDescription();
// If getClassificationStatus() is not CLASSIFICATION_COMPLETE,
// ClipDescription#getConfidenceScore will trows exception.
Expand Down Expand Up @@ -288,7 +287,7 @@ boolean hasUrl() {
String getUrl() {
if (!hasUrl()) return null;

if (!BuildInfo.isAtLeastS()) return getCoercedText();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) return getCoercedText();

try {
ClipData.Item item = mClipboardManager.getPrimaryClip().getItemAt(0);
Expand Down Expand Up @@ -765,7 +764,7 @@ public boolean canPaste() {
* @return True if the system clipboard contain a styled text, otherwise, false.
*/
private boolean hasStyledText(ClipDescription description) {
if (BuildInfo.isAtLeastS()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
return ApiHelperForS.isStyleText(description);
} else {
return hasStyledTextOnPreS();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
package org.chromium.ui.gfx;

import android.annotation.SuppressLint;
import android.os.Build;

import androidx.annotation.Nullable;

import org.chromium.base.BuildInfo;
import org.chromium.base.ContextUtils;
import org.chromium.base.Log;
import org.chromium.base.annotations.CalledByNative;
Expand All @@ -30,7 +30,7 @@ class AdpfRenderingStageScheduler {

static {
boolean enabled = false;
if (BuildInfo.isAtLeastS()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
try {
Class hintManagerClazz = Class.forName("android.os.PerformanceHintManager");
sHintManagerCreateHintSession =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

package org.chromium.ui.test.util;

import android.os.Build;
import android.os.IBinder;
import android.provider.Settings;

import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;

import org.chromium.base.BuildInfo;
import org.chromium.base.ContextUtils;
import org.chromium.base.Log;

Expand Down Expand Up @@ -71,7 +71,7 @@ public DisableAnimationsTestRule(boolean enableAnimation) {
// TODO(https://crbug.com/1225707): Always throw once this works on Android S. The above
// API is no longer accessible and will crash regardless of filter rules so just warn
// instead.
if (BuildInfo.isAtLeastS()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
Log.w(TAG, "Failed to access animation methods", e);
} else {
throw new RuntimeException("Failed to access animation methods", e);
Expand Down
3 changes: 2 additions & 1 deletion ui/base/ui_base_switches_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ bool IsElasticOverscrollEnabled() {
#elif defined(OS_WIN)
return base::FeatureList::IsEnabled(features::kElasticOverscroll);
#elif defined(OS_ANDROID)
return base::android::BuildInfo::GetInstance()->IsAtLeastS() &&
return base::android::BuildInfo::GetInstance()->sdk_int() >=
base::android::SDK_VERSION_S &&
!base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableOverscrollEdgeEffect) &&
base::FeatureList::IsEnabled(features::kElasticOverscroll);
Expand Down

0 comments on commit 4326db5

Please sign in to comment.