Skip to content

Commit

Permalink
Android: inline isAtLeastO and targetsAtLeastO
Browse files Browse the repository at this point in the history
No change in logic.

This inlines isAtLeastO and targetsAtLeastO checks, since the SDK
constant is available. This also removes the targetsAtLeastO method,
since it's no longer used (isAtLeastO is required for robolectric
tests, which compile with the N_MR1 SDK).

Downstream uses are removed in another CL.

This also fixes some import mistakes, due to presubmit warnings.

Bug: 783418
Cq-Include-Trybots: master.tryserver.chromium.android:android_cronet_tester;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I4d03589b7fabd2475ad5b4642013c11160ff793e
Reviewed-on: https://chromium-review.googlesource.com/762136
Commit-Queue: Nate Fischer <ntfschr@chromium.org>
Reviewed-by: Tommy Nyquist <nyquist@chromium.org>
Reviewed-by: Mounir Lamouri <mlamouri@chromium.org>
Reviewed-by: David Benjamin <davidben@chromium.org>
Reviewed-by: Bo <boliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#516507}
  • Loading branch information
ntfschr-chromium authored and Commit Bot committed Nov 14, 2017
1 parent 58cb655 commit edca8f9
Show file tree
Hide file tree
Showing 39 changed files with 95 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import android.webkit.WebSettings.ZoomDensity;

import org.chromium.android_webview.AwSettings;
import org.chromium.base.BuildInfo;
import org.chromium.base.annotations.SuppressFBWarnings;

/**
Expand Down Expand Up @@ -150,14 +149,14 @@ public boolean getUseWebViewBackgroundForOverscrollBackground() {

@Override
public void setSaveFormData(boolean save) {
if (BuildInfo.isAtLeastO()) return;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) return;

mAwSettings.setSaveFormData(save);
}

@Override
public boolean getSaveFormData() {
if (BuildInfo.isAtLeastO()) return false;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) return false;

return mAwSettings.getSaveFormData();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
import org.chromium.android_webview.command_line.CommandLineUtil;
import org.chromium.android_webview.variations.AwVariationsSeedHandler;
import org.chromium.base.BuildConfig;
import org.chromium.base.BuildInfo;
import org.chromium.base.CommandLine;
import org.chromium.base.ContextUtils;
import org.chromium.base.MemoryPressureListener;
Expand Down Expand Up @@ -228,7 +227,7 @@ private void initialize(WebViewDelegate webViewDelegate) {
CommandLineUtil.initCommandLine();

boolean multiProcess = false;
if (BuildInfo.isAtLeastO()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// Ask the system if multiprocess should be enabled on O+.
multiProcess = mWebViewDelegate.isMultiProcessEnabled();
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Expand Down Expand Up @@ -345,7 +344,8 @@ private void doNetworkInitializations(Context applicationContext) {
new AwNetworkChangeNotifierRegistrationPolicy());
}

AwContentsStatics.setCheckClearTextPermitted(BuildInfo.targetsAtLeastO(applicationContext));
AwContentsStatics.setCheckClearTextPermitted(
applicationContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.O);
}

private void ensureChromiumStartedLocked(boolean onMainThread) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

package com.android.webview.chromium;

import android.os.Build;
import android.webkit.WebViewDatabase;

import org.chromium.android_webview.AwFormDatabase;
import org.chromium.android_webview.HttpAuthDatabase;
import org.chromium.base.BuildInfo;
import org.chromium.base.ThreadUtils;

import java.util.concurrent.Callable;
Expand Down Expand Up @@ -98,7 +98,7 @@ public String[] call() {

@Override
public boolean hasFormData() {
if (BuildInfo.isAtLeastO()) return false;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) return false;

if (checkNeedsPost()) {
return mFactory.runOnUiThreadBlocking(new Callable<Boolean>() {
Expand All @@ -114,7 +114,7 @@ public Boolean call() {

@Override
public void clearFormData() {
if (BuildInfo.isAtLeastO()) return;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) return;

if (checkNeedsPost()) {
mFactory.addTask(new Runnable() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Handler;
import android.os.Message;
import android.os.Process;
Expand All @@ -14,7 +15,6 @@
import android.util.Log;
import android.webkit.WebSettings;

import org.chromium.base.BuildInfo;
import org.chromium.base.ThreadUtils;
import org.chromium.base.VisibleForTesting;
import org.chromium.base.annotations.CalledByNative;
Expand Down Expand Up @@ -135,7 +135,7 @@ public class AwSettings {
private int mCacheMode = WebSettings.LOAD_DEFAULT;
private boolean mShouldFocusFirstNode = true;
private boolean mGeolocationEnabled = true;
private boolean mAutoCompleteEnabled = !BuildInfo.isAtLeastO();
private boolean mAutoCompleteEnabled = Build.VERSION.SDK_INT < Build.VERSION_CODES.O;
private boolean mFullscreenSupported;
private boolean mSupportZoom = true;
private boolean mBuiltInZoomControls;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ public static void setStatusBarColor(Window window, int statusBarColor) {
// removing or shrinking the SurfaceFlinger overlay required for our views.
// This benefits battery usage on L and M. However, this no longer provides a battery
// benefit as of N and starts to cause flicker bugs on O, so don't bother on O and up.
if (!BuildInfo.isAtLeastO() && statusBarColor == Color.BLACK
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O && statusBarColor == Color.BLACK
&& window.getNavigationBarColor() == Color.BLACK) {
window.clearFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.app.Activity;
import android.app.Application;
import android.app.Application.ActivityLifecycleCallbacks;
import android.os.Build;
import android.os.Bundle;

import org.chromium.base.annotations.CalledByNative;
Expand Down Expand Up @@ -191,7 +192,7 @@ private static void onStateChange(Activity activity, @ActivityState int newState
// changed in O and the activity info may have been lazily created
// on first access to avoid a crash on startup. This should be removed
// once the new lifecycle APIs are available.
if (!BuildInfo.isAtLeastO()) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
assert !sActivityInfo.containsKey(activity);
}
sActivityInfo.put(activity, new ActivityInfo());
Expand Down Expand Up @@ -366,7 +367,8 @@ public static void registerStateListenerForActivity(ActivityStateListener listen
// TODO(tedchoc): crbug/691100. The timing of application callback lifecycles were changed
// in O and the activity info may need to be lazily created if the onCreate
// event has not yet been received.
if (BuildInfo.isAtLeastO() && info == null && !activity.isDestroyed()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && info == null
&& !activity.isDestroyed()) {
info = new ActivityInfo();
sActivityInfo.put(activity, info);
}
Expand Down
13 changes: 4 additions & 9 deletions base/android/java/src/org/chromium/base/BuildInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

package org.chromium.base;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
Expand Down Expand Up @@ -127,15 +126,11 @@ public static boolean isDebugAndroid() {

/**
* @return Whether the current device is running Android O release or newer.
*
* @deprecated Please inline this method where possible.
*/
@Deprecated
public static boolean isAtLeastO() {
return Build.VERSION.SDK_INT >= 26;
}

/**
* @return Whether the current app targets the SDK for at least O
*/
public static boolean targetsAtLeastO(Context appContext) {
return appContext.getApplicationInfo().targetSdkVersion >= 26;
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O;
}
}
2 changes: 1 addition & 1 deletion base/android/java/src/org/chromium/base/SysUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private static boolean detectLowEndDevice() {
boolean isLowEnd = true;
if (ramSizeKB <= 0) {
isLowEnd = false;
} else if (BuildInfo.isAtLeastO()) {
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
isLowEnd = ramSizeKB / 1024 <= ANDROID_O_LOW_MEMORY_DEVICE_THRESHOLD_MB;
} else {
isLowEnd = ramSizeKB / 1024 <= ANDROID_LOW_MEMORY_DEVICE_THRESHOLD_MB;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

import android.app.Notification;
import android.content.Intent;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.Nullable;

import org.chromium.base.BuildInfo;
import org.chromium.base.Callback;
import org.chromium.base.ContextUtils;
import org.chromium.base.VisibleForTesting;
Expand Down Expand Up @@ -297,7 +297,7 @@ public void startForegroundService(Intent intent) {
*/
@CalledByNative
public boolean shouldDetectVideoFullscreen() {
return BuildInfo.isAtLeastO();
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
import android.graphics.drawable.Icon;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.util.Base64;

import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.BuildInfo;
import org.chromium.base.ContextUtils;
import org.chromium.base.Log;
import org.chromium.base.ThreadUtils;
Expand Down Expand Up @@ -701,7 +701,7 @@ private static boolean shouldShowToastWhenAddingShortcut() {

private static boolean isRequestPinShortcutSupported() {
if (!sCheckedIfRequestPinShortcutSupported) {
if (BuildInfo.isAtLeastO()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
checkIfRequestPinShortcutSupported();
}
sCheckedIfRequestPinShortcutSupported = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@

import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.ApplicationStatus;
import org.chromium.base.BuildInfo;
import org.chromium.base.ContextUtils;
import org.chromium.base.Log;
import org.chromium.base.ObserverList;
Expand Down Expand Up @@ -152,7 +151,7 @@ public interface Observer {
*/
@VisibleForTesting
static boolean useForegroundService() {
return BuildInfo.isAtLeastO();
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Build;
import android.os.StrictMode;
import android.os.SystemClock;
import android.provider.Browser;

import org.chromium.base.BuildInfo;
import org.chromium.base.ContextUtils;
import org.chromium.base.Log;
import org.chromium.base.VisibleForTesting;
Expand Down Expand Up @@ -213,7 +213,7 @@ public boolean handleIncomingIntent(Context context, Intent intent,
private boolean handleIncomingIntentInternal(
Context context, Intent intent, boolean isCustomTabsIntent, long startTime,
boolean isRedirect) {
if (!isRedirect && !isCustomTabsIntent && BuildInfo.isAtLeastO()) {
if (!isRedirect && !isCustomTabsIntent && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Log.i(TAG, "Package manager handles intents on O+, not handling in Chrome");
return false;
}
Expand All @@ -225,7 +225,8 @@ private boolean handleIncomingIntentInternal(
}

if (IntentUtils.safeGetBooleanExtra(intent, DO_NOT_LAUNCH_EXTRA, false)
|| (BuildInfo.isAtLeastO() && (intent.getFlags() & FLAG_DO_NOT_LAUNCH) != 0)) {
|| (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
&& (intent.getFlags() & FLAG_DO_NOT_LAUNCH) != 0)) {
maybeRecordFallbackStats(intent);
Log.i(TAG, "Not handling with Instant Apps (DO_NOT_LAUNCH_EXTRA)");
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Handler;
import android.os.SystemClock;

import com.google.ipc.invalidation.ticl.android2.channel.AndroidGcmController;

import org.chromium.base.ApplicationState;
import org.chromium.base.ApplicationStatus;
import org.chromium.base.BuildInfo;
import org.chromium.base.FieldTrialList;
import org.chromium.base.Log;
import org.chromium.base.VisibleForTesting;
Expand Down Expand Up @@ -244,7 +244,7 @@ public void stop() {
private void startServiceIfPossible(Intent intent) {
// The use of background services is restricted when the application is not in foreground
// for O. See crbug.com/680812.
if (BuildInfo.isAtLeastO()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
try {
mContext.startService(intent);
} catch (IllegalStateException exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.graphics.Rect;
import android.os.Build;
import android.os.SystemClock;
import android.support.annotation.Nullable;
import android.util.Rational;

import org.chromium.base.BuildInfo;
import org.chromium.base.Callback;
import org.chromium.base.Log;
import org.chromium.base.library_loader.LibraryLoader;
Expand Down Expand Up @@ -105,7 +105,7 @@ private boolean shouldAttempt(ChromeActivity activity) {
return false;
}

if (!BuildInfo.isAtLeastO()) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
recordAttemptResult(METRICS_ATTEMPT_RESULT_NO_SYSTEM_SUPPORT);
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import android.util.SparseArray;
import android.view.KeyEvent;

import org.chromium.base.BuildInfo;
import org.chromium.base.ContextUtils;
import org.chromium.base.Log;
import org.chromium.base.SysUtils;
Expand Down Expand Up @@ -285,7 +284,7 @@ public NotificationOptions(
// created service no matter what or it will crash. Show the minimal notification. The caller is
// responsible for hiding it afterwards.
private static void finishStartingForegroundService(ListenerService s) {
if (!BuildInfo.isAtLeastO()) return;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return;

ChromeNotificationBuilder builder =
NotificationBuilderFactory.createChromeNotificationBuilder(
Expand Down Expand Up @@ -918,7 +917,7 @@ void updateNotification(boolean serviceStarting) {
// On O, finish starting the foreground service nevertheless, or Android will
// crash Chrome.
boolean foregroundedService = false;
if (BuildInfo.isAtLeastO() && serviceStarting) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && serviceStarting) {
mService.startForeground(mMediaNotificationInfo.id, notification);
foregroundedService = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import android.content.Intent;
import android.graphics.Bitmap;
import android.media.AudioManager;
import android.os.Build;
import android.os.Handler;
import android.text.TextUtils;

import org.chromium.base.BuildInfo;
import org.chromium.base.Log;
import org.chromium.base.SysUtils;
import org.chromium.base.VisibleForTesting;
Expand Down Expand Up @@ -433,7 +433,8 @@ private boolean updateFavicon(Bitmap icon) {

// Disable favicons in notifications for low memory devices on O
// where the notification icon is optional.
if (SysUtils.isLowEndDevice() && BuildInfo.isAtLeastO()) return false;
if (SysUtils.isLowEndDevice() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
return false;

if (!MediaNotificationManager.isBitmapSuitableAsMediaImage(icon)) return false;
if (mFavicon != null && (icon.getWidth() < mFavicon.getWidth()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import android.annotation.SuppressLint;
import android.app.NotificationManager;
import android.content.Context;
import android.os.Build;

import org.chromium.base.BuildInfo;
import org.chromium.base.ContextUtils;
import org.chromium.chrome.browser.notifications.channels.ChannelsInitializer;

Expand All @@ -34,7 +34,7 @@ public class NotificationBuilderFactory {
public static ChromeNotificationBuilder createChromeNotificationBuilder(
boolean preferCompat, String channelId) {
Context context = ContextUtils.getApplicationContext();
if (BuildInfo.isAtLeastO()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
return createNotificationBuilderForO(channelId, context);
}
return preferCompat ? new NotificationCompatBuilder(context)
Expand Down
Loading

0 comments on commit edca8f9

Please sign in to comment.