Commit 7259fe14 authored by Shimi Zhang's avatar Shimi Zhang Committed by Commit Bot

[Android] Inline isAtLeastP and targetAtLeastP

P SDK is rolled to public, we can inline these two methods now.

Bug: 850652
Change-Id: Ib2828752bdda8be5ba4f1e1d5fc84c7fd315db79
Reviewed-on: https://chromium-review.googlesource.com/c/1289434Reviewed-by: default avatarRichard Coles <torne@chromium.org>
Reviewed-by: default avatarPaul Jensen <pauljensen@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarBecca Hughes <beccahughes@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Commit-Queue: Shimi Zhang <ctzsm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#602055}
parent e593b841
......@@ -9,7 +9,6 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import org.chromium.base.BuildInfo;
import org.chromium.base.ContextUtils;
import org.chromium.base.Log;
......@@ -42,7 +41,8 @@ public class FontPreloadingWorkaround {
*/
public static void maybeInstallWorkaround(Context appContext) {
// Only isolated renderer processes running on O devices need this workaround.
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O || BuildInfo.isAtLeastP()
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O
|| Build.VERSION.SDK_INT >= Build.VERSION_CODES.P
|| !ContextUtils.isIsolatedProcess()) {
return;
}
......
......@@ -61,7 +61,6 @@ import org.chromium.android_webview.AwSettings;
import org.chromium.android_webview.ResourcesContextWrapperFactory;
import org.chromium.android_webview.ScopedSysTraceEvent;
import org.chromium.android_webview.renderer_priority.RendererPriority;
import org.chromium.base.BuildInfo;
import org.chromium.base.ThreadUtils;
import org.chromium.base.metrics.CachedMetrics.TimesHistogramSample;
import org.chromium.components.autofill.AutofillProvider;
......@@ -212,7 +211,7 @@ class WebViewChromium implements WebViewProvider, WebViewProvider.ScrollDelegate
mWebSettings.getAwSettings().setZeroLayoutHeightDisablesViewportQuirk(true);
}
if (BuildInfo.targetsAtLeastP()) {
if (mAppTargetSdkVersion >= Build.VERSION_CODES.P) {
mWebSettings.getAwSettings().setCSSHexAlphaColorEnabled(true);
mWebSettings.getAwSettings().setScrollTopLeftInteropEnabled(true);
}
......
......@@ -17,7 +17,6 @@ import android.view.ViewGroup;
import android.view.ViewStructure;
import android.view.autofill.AutofillValue;
import org.chromium.base.BuildInfo;
import org.chromium.base.ThreadUtils;
import org.chromium.components.autofill.AutofillProvider;
import org.chromium.components.autofill.FormData;
......@@ -297,7 +296,7 @@ public class AwAutofillProvider extends AutofillProvider {
// Check focusField inside short value?
// Autofill Manager might have session that wasn't started by WebView,
// we just always cancel existing session here.
if (!BuildInfo.isAtLeastP()) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
mAutofillManager.cancel();
}
mAutofillManager.notifyNewSessionStarted();
......@@ -338,7 +337,7 @@ public class AwAutofillProvider extends AutofillProvider {
public void onTextFieldDidScroll(int index, float x, float y, float width, float height) {
// crbug.com/730764 - from P and above, Android framework listens to the onScrollChanged()
// and repositions the autofill UI automatically.
if (BuildInfo.isAtLeastP()) return;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) return;
if (mRequest == null) return;
short sIndex = (short) index;
......
......@@ -18,7 +18,6 @@ import org.chromium.android_webview.command_line.CommandLineUtil;
import org.chromium.android_webview.policy.AwPolicyProvider;
import org.chromium.android_webview.services.CrashReceiverService;
import org.chromium.android_webview.services.ICrashReceiverService;
import org.chromium.base.BuildInfo;
import org.chromium.base.CommandLine;
import org.chromium.base.ContextUtils;
import org.chromium.base.Log;
......@@ -105,7 +104,7 @@ public final class AwBrowserProcess {
public static void start() {
try (ScopedSysTraceEvent e1 = ScopedSysTraceEvent.scoped("AwBrowserProcess.start")) {
final Context appContext = ContextUtils.getApplicationContext();
tryObtainingDataDirLock();
tryObtainingDataDirLock(appContext);
// We must post to the UI thread to cover the case that the user
// has invoked Chromium startup by using the (thread-safe)
// CookieManager rather than creating a WebView.
......@@ -152,12 +151,13 @@ public final class AwBrowserProcess {
}
}
private static void tryObtainingDataDirLock() {
private static void tryObtainingDataDirLock(final Context appContext) {
try (ScopedSysTraceEvent e1 =
ScopedSysTraceEvent.scoped("AwBrowserProcess.tryObtainingDataDirLock")) {
// Many existing apps rely on this even though it's known to be unsafe.
// Make it fatal when on P for apps that target P or higher
boolean dieOnFailure = BuildInfo.isAtLeastP() && BuildInfo.targetsAtLeastP();
boolean dieOnFailure = Build.VERSION.SDK_INT >= Build.VERSION_CODES.P
&& appContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.P;
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
try {
......
......@@ -15,7 +15,7 @@ import android.support.annotation.IntDef;
import android.util.Log;
import android.webkit.WebSettings;
import org.chromium.base.BuildInfo;
import org.chromium.base.ContextUtils;
import org.chromium.base.ThreadUtils;
import org.chromium.base.VisibleForTesting;
import org.chromium.base.annotations.CalledByNative;
......@@ -599,7 +599,8 @@ public class AwSettings {
@CalledByNative
private static boolean getAllowSniffingFileUrls() {
// Don't allow sniffing file:// URLs for MIME type if the application targets P or later.
return !BuildInfo.targetsAtLeastP();
return ContextUtils.getApplicationContext().getApplicationInfo().targetSdkVersion
< Build.VERSION_CODES.P;
}
/**
......
......@@ -42,7 +42,6 @@ import org.chromium.android_webview.AwContents;
import org.chromium.android_webview.AwContentsClient.AwWebResourceRequest;
import org.chromium.android_webview.AwWebResourceResponse;
import org.chromium.android_webview.test.AwActivityTestRule.TestDependencyFactory;
import org.chromium.base.BuildInfo;
import org.chromium.base.Log;
import org.chromium.base.ThreadUtils;
import org.chromium.base.metrics.RecordHistogram;
......@@ -1025,7 +1024,7 @@ public class AwAutofillTest {
assertEquals(1, values.size());
assertEquals("a", values.get(0).second.getTextValue());
executeJavaScriptAndWaitForResult("document.getElementById('text1').value='c';");
if (BuildInfo.isAtLeastP()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
// There is no AUTOFILL_CANCEL from Android P.
assertEquals(4, getCallbackCount());
} else {
......@@ -1934,7 +1933,7 @@ public class AwAutofillTest {
throws InterruptedException, TimeoutException {
Integer[] adjustedEventArray;
// Didn't call cancel after Android P.
if (BuildInfo.isAtLeastP()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
ArrayList<Integer> adjusted = new ArrayList<Integer>();
for (Integer event : expectedEventArray) {
if (event != AUTOFILL_CANCEL) adjusted.add(event);
......
......@@ -75,8 +75,7 @@ BuildInfo::BuildInfo(const std::vector<std::string>& params)
firebase_app_id_(StrDupParam(params, 18)),
custom_themes_(StrDupParam(params, 19)),
resources_version_(StrDupParam(params, 20)),
extracted_file_suffix_(params[21]),
is_at_least_p_(GetIntParam(params, 22)) {}
extracted_file_suffix_(params[21]) {}
// static
BuildInfo* BuildInfo::GetInstance() {
......
......@@ -31,6 +31,8 @@ enum SdkVersion {
SDK_VERSION_NOUGAT = 24,
SDK_VERSION_NOUGAT_MR1 = 25,
SDK_VERSION_OREO = 26,
SDK_VERSION_O_MR1 = 27,
SDK_VERSION_P = 28,
};
// BuildInfo is a singleton class that stores android build and device
......@@ -120,8 +122,6 @@ class BASE_EXPORT BuildInfo {
return sdk_int_;
}
bool is_at_least_p() const { return is_at_least_p_; }
private:
friend struct BuildInfoSingletonTraits;
......@@ -154,7 +154,6 @@ class BASE_EXPORT BuildInfo {
const char* const resources_version_;
// Not needed by breakpad.
const std::string extracted_file_suffix_;
const int is_at_least_p_;
DISALLOW_COPY_AND_ASSIGN(BuildInfo);
};
......
......@@ -64,7 +64,6 @@ public class BuildInfo {
buildInfo.androidBuildFingerprint, buildInfo.gmsVersionCode,
buildInfo.installerPackageName, buildInfo.abiString, BuildConfig.FIREBASE_APP_ID,
buildInfo.customThemes, buildInfo.resourcesVersion, buildInfo.extractedFileSuffix,
isAtLeastP() ? "1" : "0",
};
}
......@@ -171,22 +170,29 @@ public class BuildInfo {
// The markers Begin:BuildCompat and End:BuildCompat delimit code
// that is autogenerated from Android sources.
// Begin:BuildCompat P
// Begin:BuildCompat Q
/**
* Checks if the device is running on a pre-release version of Android P or newer.
* Checks if the device is running on a pre-release version of Android Q or newer.
* <p>
* @return {@code true} if P APIs are available for use, {@code false} otherwise
* <strong>Note:</strong> This method will return {@code false} on devices running release
* versions of Android. When Android Q is finalized for release, this method will be deprecated
* and all calls should be replaced with {@code Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q}.
*
* @return {@code true} if Q APIs are available for use, {@code false} otherwise
*/
public static boolean isAtLeastP() {
return VERSION.SDK_INT >= 28;
public static boolean isAtLeastQ() {
return VERSION.CODENAME.length() == 1 && VERSION.CODENAME.charAt(0) >= 'Q'
&& VERSION.CODENAME.charAt(0) <= 'Z';
}
/**
* Checks if the application targets at least released SDK P
* Checks if the application targets pre-release SDK Q
*/
public static boolean targetsAtLeastP() {
return ContextUtils.getApplicationContext().getApplicationInfo().targetSdkVersion >= 28;
public static boolean targetsAtLeastQ() {
return isAtLeastQ()
&& ContextUtils.getApplicationContext().getApplicationInfo().targetSdkVersion
== Build.VERSION_CODES.CUR_DEVELOPMENT;
}
// End:BuildCompat
......
......@@ -12,7 +12,6 @@ import android.support.annotation.VisibleForTesting;
import android.view.View;
import android.view.WindowInsets;
import org.chromium.base.BuildInfo;
import org.chromium.base.ObserverList;
import java.lang.reflect.Method;
......@@ -50,7 +49,7 @@ public class InsetObserverView extends View {
* @return an instance of a InsetObserverView.
*/
public static InsetObserverView create(Context context) {
if (BuildInfo.isAtLeastP()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
return new InsetObserverViewApi28(context);
} else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
return new InsetObserverView(context);
......
......@@ -4,13 +4,13 @@
package org.chromium.chrome.browser.display_cutout;
import android.os.Build;
import android.support.test.filters.LargeTest;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.BuildInfo;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.blink.mojom.ViewportFit;
import org.chromium.chrome.browser.ChromeActivity;
......@@ -36,8 +36,7 @@ public class DisplayCutoutTest {
@LargeTest
public void testViewportFitAuto() throws InterruptedException, TimeoutException {
// Display Cutout API requires Android P+.
if (!BuildInfo.isAtLeastP())
return;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) return;
mTestRule.enterFullscreen();
mTestRule.setViewportFit(DisplayCutoutTestRule.VIEWPORT_FIT_AUTO);
......@@ -54,8 +53,7 @@ public class DisplayCutoutTest {
@LargeTest
public void testViewportFitContain() throws InterruptedException, TimeoutException {
// Display Cutout API requires Android P+.
if (!BuildInfo.isAtLeastP())
return;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) return;
mTestRule.enterFullscreen();
mTestRule.setViewportFit(DisplayCutoutTestRule.VIEWPORT_FIT_CONTAIN);
......@@ -72,8 +70,7 @@ public class DisplayCutoutTest {
@LargeTest
public void testViewportFitCover() throws InterruptedException, TimeoutException {
// Display Cutout API requires Android P+.
if (!BuildInfo.isAtLeastP())
return;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) return;
mTestRule.enterFullscreen();
mTestRule.setViewportFit(DisplayCutoutTestRule.VIEWPORT_FIT_COVER);
......@@ -96,8 +93,7 @@ public class DisplayCutoutTest {
@LargeTest
public void testViewportFitCoverForced() throws InterruptedException, TimeoutException {
// Display Cutout API requires Android P+.
if (!BuildInfo.isAtLeastP())
return;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) return;
mTestRule.enterFullscreen();
......@@ -122,8 +118,7 @@ public class DisplayCutoutTest {
@LargeTest
public void testViewportFitDefault() throws InterruptedException, TimeoutException {
// Display Cutout API requires Android P+.
if (!BuildInfo.isAtLeastP())
return;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) return;
mTestRule.enterFullscreen();
mTestRule.setViewportFit(DisplayCutoutTestRule.VIEWPORT_FIT_COVER);
......@@ -145,8 +140,7 @@ public class DisplayCutoutTest {
@LargeTest
public void testViewportFitDipScale() throws InterruptedException, TimeoutException {
// Display Cutout API requires Android P+.
if (!BuildInfo.isAtLeastP())
return;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) return;
mTestRule.enterFullscreen();
mTestRule.setDipScale(DisplayCutoutTestRule.TEST_HIGH_DIP_SCALE);
......@@ -164,8 +158,7 @@ public class DisplayCutoutTest {
@LargeTest
public void testViewportFitSubframe() throws InterruptedException, TimeoutException {
// Display Cutout API requires Android P+.
if (!BuildInfo.isAtLeastP())
return;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) return;
mTestRule.enterFullscreen();
mTestRule.setViewportFit(DisplayCutoutTestRule.VIEWPORT_FIT_CONTAIN);
......@@ -184,8 +177,7 @@ public class DisplayCutoutTest {
@LargeTest
public void testViewportFitCoverNoCutout() throws InterruptedException, TimeoutException {
// Display Cutout API requires Android P+.
if (!BuildInfo.isAtLeastP())
return;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) return;
mTestRule.setDeviceHasCutout(false);
mTestRule.enterFullscreen();
......
......@@ -119,7 +119,8 @@ std::unique_ptr<ui::TouchSelectionController> CreateSelectionController(
config.hide_active_handle =
base::FeatureList::IsEnabled(
content::android::kEnhancedSelectionInsertionHandle) &&
base::android::BuildInfo::GetInstance()->is_at_least_p();
base::android::BuildInfo::GetInstance()->sdk_int() >=
base::android::SDK_VERSION_P;
return std::make_unique<ui::TouchSelectionController>(client, config);
}
......
......@@ -446,7 +446,8 @@ void SetRuntimeFeaturesDefaultsAndUpdateFromArgs(
#if defined(OS_ANDROID)
if (base::FeatureList::IsEnabled(features::kDisplayCutoutAPI) &&
base::android::BuildInfo::GetInstance()->is_at_least_p()) {
base::android::BuildInfo::GetInstance()->sdk_int() >=
base::android::SDK_VERSION_P) {
// Display Cutout is limited to Android P+.
WebRuntimeFeatures::EnableDisplayCutoutAPI(true);
}
......
......@@ -23,7 +23,6 @@ import android.security.NetworkSecurityPolicy;
import android.telephony.TelephonyManager;
import android.util.Log;
import org.chromium.base.BuildInfo;
import org.chromium.base.ContextUtils;
import org.chromium.base.VisibleForTesting;
import org.chromium.base.annotations.CalledByNative;
......@@ -290,7 +289,7 @@ class AndroidNetworkLibrary {
* @returns result of linkProperties.isPrivateDnsActive().
*/
static boolean isPrivateDnsActive(LinkProperties linkProperties) {
if (BuildInfo.isAtLeastP() && linkProperties != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && linkProperties != null) {
// TODO(pauljensen): When Android P SDK is available, remove reflection.
try {
// This could be racy if called on multiple threads, but races will
......
......@@ -34,7 +34,6 @@ import android.telephony.TelephonyManager;
import org.chromium.base.ApplicationState;
import org.chromium.base.ApplicationStatus;
import org.chromium.base.BuildConfig;
import org.chromium.base.BuildInfo;
import org.chromium.base.ContextUtils;
import org.chromium.base.VisibleForTesting;
import org.chromium.base.compat.ApiHelperForM;
......@@ -237,7 +236,7 @@ public class NetworkChangeNotifierAutoDetect extends BroadcastReceiver {
if (network != null) {
return new NetworkState(true, networkInfo.getType(), networkInfo.getSubtype(),
String.valueOf(networkToNetId(network)),
BuildInfo.isAtLeastP()
Build.VERSION.SDK_INT >= Build.VERSION_CODES.P
&& AndroidNetworkLibrary.isPrivateDnsActive(
mConnectivityManager.getLinkProperties(network)));
}
......@@ -830,7 +829,9 @@ public class NetworkChangeNotifierAutoDetect extends BroadcastReceiver {
mNetworkCallback = null;
mNetworkRequest = null;
}
mDefaultNetworkCallback = BuildInfo.isAtLeastP() ? new DefaultNetworkCallback() : null;
mDefaultNetworkCallback = Build.VERSION.SDK_INT >= Build.VERSION_CODES.P
? new DefaultNetworkCallback()
: null;
mNetworkState = getCurrentNetworkState();
mIntentFilter = new NetworkConnectivityIntentFilter();
mIgnoreNextBroadcast = false;
......
......@@ -37,7 +37,6 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.ApplicationState;
import org.chromium.base.BuildInfo;
import org.chromium.base.ContextUtils;
import org.chromium.base.ThreadUtils;
import org.chromium.base.library_loader.LibraryLoader;
......@@ -435,7 +434,7 @@ public class NetworkChangeNotifierTest {
@Override
public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter) {
// Should not be used starting with Pie.
Assert.assertFalse(BuildInfo.isAtLeastP());
Assert.assertFalse(Build.VERSION.SDK_INT >= Build.VERSION_CODES.P);
return null;
}
......@@ -609,7 +608,7 @@ public class NetworkChangeNotifierTest {
* Uses same signals that system would use.
*/
private void notifyConnectivityChange() {
if (BuildInfo.isAtLeastP()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
mConnectivityDelegate.getDefaultNetworkCallback().onAvailable(null);
} else {
Intent connectivityIntent = new Intent(ConnectivityManager.CONNECTIVITY_ACTION);
......@@ -656,7 +655,7 @@ public class NetworkChangeNotifierTest {
Assert.assertFalse(observer.hasReceivedNotification());
// We should be notified if use of DNS-over-TLS changes.
if (BuildInfo.isAtLeastP()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
// Verify notification for enabling.
mConnectivityDelegate.setIsPrivateDnsActive(true);
mConnectivityDelegate.getDefaultNetworkCallback().onLinkPropertiesChanged(null, null);
......@@ -674,7 +673,7 @@ public class NetworkChangeNotifierTest {
// Mimic that connectivity has been lost and ensure that Chrome notifies our observer.
mConnectivityDelegate.setActiveNetworkExists(false);
if (BuildInfo.isAtLeastP()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
mConnectivityDelegate.getDefaultNetworkCallback().onLost(null);
} else {
mReceiver.onReceive(InstrumentationRegistry.getTargetContext(), connectivityIntent);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment