Skip to content

Commit

Permalink
Merge pull request square#6057 from yschimke/fix_is_android_check_3_14
Browse files Browse the repository at this point in the history
Fix isAndroid check [3.14.x]
  • Loading branch information
swankjesse authored May 16, 2020
2 parents 02e57be + 46f6a8e commit 60cf3a0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ private void enableSessionTickets(SSLSocket sslSocket) {
}

public static @Nullable Platform buildIfSupported() {
if (!Platform.isAndroid()) {
return null;
}

try {
if (getSdkInt() >= 29) {
Class<?> sslParametersClass =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public CertificateChainCleaner buildCertificateChainCleaner(X509TrustManager tru
}

public static @Nullable Platform buildIfSupported() {
if (getSdkInt() == 0) {
if (!Platform.isAndroid()) {
return null;
}

Expand Down
36 changes: 27 additions & 9 deletions okhttp/src/main/java/okhttp3/internal/platform/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,18 +199,20 @@ public static boolean isConscryptPreferred() {

/** Attempt to match the host runtime to a capable Platform implementation. */
private static Platform findPlatform() {
Platform android10 = Android10Platform.buildIfSupported();

if (android10 != null) {
return android10;
if (isAndroid()) {
return findAndroidPlatform();
} else {
return findJvmPlatform();
}
}

Platform android = AndroidPlatform.buildIfSupported();

if (android != null) {
return android;
}
public static boolean isAndroid() {
// This explicit check avoids activating in Android Studio with Android specific classes
// available when running plugins inside the IDE.
return "Dalvik".equals(System.getProperty("java.vm.name"));
}

private static Platform findJvmPlatform() {
if (isConscryptPreferred()) {
Platform conscrypt = ConscryptPlatform.buildIfSupported();

Expand All @@ -235,6 +237,22 @@ private static Platform findPlatform() {
return new Platform();
}

private static Platform findAndroidPlatform() {
Platform android10 = Android10Platform.buildIfSupported();

if (android10 != null) {
return android10;
}

Platform android = AndroidPlatform.buildIfSupported();

if (android == null) {
throw new NullPointerException("No platform found on Android");
}

return android;
}

/**
* Returns the concatenation of 8-bit, length prefixed protocol names.
* http://tools.ietf.org/html/draft-agl-tls-nextprotoneg-04#page-4
Expand Down

0 comments on commit 60cf3a0

Please sign in to comment.