content: package okhttp3.internal.platform;
  
  import androidx.core.os.EnvironmentCompat;
  import java.lang.reflect.InvocationHandler;
  import java.lang.reflect.InvocationTargetException;
  import java.lang.reflect.Method;
  import java.lang.reflect.Proxy;
  import java.util.Arrays;
  import java.util.List;
  import javax.net.ssl.SSLSocket;
  import kotlin.Metadata;
  import kotlin.jvm.internal.DefaultConstructorMarker;
  import kotlin.jvm.internal.Intrinsics;
  import mt.Log1F380D;
  import okhttp3.Protocol;
  
  @Metadata(bv = {1, 0, 3}, d1 = {"\u0000:\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u000e\n\u0000\n\u0002\u0010 \n\u0002\u0018\u0002\n\u0002\b\u0004\u0018\u0000 \u00162\u00020\u0001:\u0002\u0015\u0016B5\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\u0006\u0010\u0004\u001a\u00020\u0003\u0012\u0006\u0010\u0005\u001a\u00020\u0003\u0012\n\u0010\u0006\u001a\u0006\u0012\u0002\b\u00030\u0007\u0012\n\u0010\b\u001a\u0006\u0012\u0002\b\u00030\u0007¢\u0006\u0002\u0010\tJ\u0010\u0010\n\u001a\u00020\u000b2\u0006\u0010\f\u001a\u00020\rH\u0016J(\u0010\u000e\u001a\u00020\u000b2\u0006\u0010\f\u001a\u00020\r2\b\u0010\u000f\u001a\u0004\u0018\u00010\u00102\f\u0010\u0011\u001a\b\u0012\u0004\u0012\u00020\u00130\u0012H\u0016J\u0012\u0010\u0014\u001a\u0004\u0018\u00010\u00102\u0006\u0010\f\u001a\u00020\rH\u0016R\u0012\u0010\u0006\u001a\u0006\u0012\u0002\b\u00030\u0007X\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u0004\u001a\u00020\u0003X\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u0002\u001a\u00020\u0003X\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u0005\u001a\u00020\u0003X\u0004¢\u0006\u0002\n\u0000R\u0012\u0010\b\u001a\u0006\u0012\u0002\b\u00030\u0007X\u0004¢\u0006\u0002\n\u0000¨\u0006\u0017"}, d2 = {"Lokhttp3/internal/platform/Jdk8WithJettyBootPlatform;", "Lokhttp3/internal/platform/Platform;", "putMethod", "Ljava/lang/reflect/Method;", "getMethod", "removeMethod", "clientProviderClass", "Ljava/lang/Class;", "serverProviderClass", "(Ljava/lang/reflect/Method;Ljava/lang/reflect/Method;Ljava/lang/reflect/Method;Ljava/lang/Class;Ljava/lang/Class;)V", "afterHandshake", "", "sslSocket", "Ljavax/net/ssl/SSLSocket;", "configureTlsExtensions", "hostname", "", "protocols", "", "Lokhttp3/Protocol;", "getSelectedProtocol", "AlpnProvider", "Companion", "okhttp"}, k = 1, mv = {1, 4, 0})
  /* compiled from: Jdk8WithJettyBootPlatform.kt */
  public final class Jdk8WithJettyBootPlatform extends Platform {
      public static final Companion Companion = new Companion((DefaultConstructorMarker) null);
      private final Class<?> clientProviderClass;
      private final Method getMethod;
      private final Method putMethod;
      private final Method removeMethod;
      private final Class<?> serverProviderClass;
  
      @Metadata(bv = {1, 0, 3}, d1 = {"\u00004\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010 \n\u0002\u0010\u000e\n\u0002\b\u0007\n\u0002\u0010\u000b\n\u0002\b\u0005\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u0011\n\u0002\b\u0002\b\u0002\u0018\u00002\u00020\u0001B\u0013\u0012\f\u0010\u0002\u001a\b\u0012\u0004\u0012\u00020\u00040\u0003¢\u0006\u0002\u0010\u0005J0\u0010\u0011\u001a\u0004\u0018\u00010\u00122\u0006\u0010\u0013\u001a\u00020\u00122\u0006\u0010\u0014\u001a\u00020\u00152\u000e\u0010\u0016\u001a\n\u0012\u0004\u0012\u00020\u0012\u0018\u00010\u0017H\u0002¢\u0006\u0002\u0010\u0018R\u0014\u0010\u0002\u001a\b\u0012\u0004\u0012\u00020\u00040\u0003X\u0004¢\u0006\u0002\n\u0000R\u001c\u0010\u0006\u001a\u0004\u0018\u00010\u0004X\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\u0007\u0010\b\"\u0004\b\t\u0010\nR\u001a\u0010\u000b\u001a\u00020\fX\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\r\u0010\u000e\"\u0004\b\u000f\u0010\u0010¨\u0006\u0019"}, d2 = {"Lokhttp3/internal/platform/Jdk8WithJettyBootPlatform$AlpnProvider;", "Ljava/lang/reflect/InvocationHandler;", "protocols", "", "", "(Ljava/util/List;)V", "selected", "getSelected", "()Ljava/lang/String;", "setSelected", "(Ljava/lang/String;)V", "unsupported", "", "getUnsupported", "()Z", "setUnsupported", "(Z)V", "invoke", "", "proxy", "method", "Ljava/lang/reflect/Method;", "args", "", "(Ljava/lang/Object;Ljava/lang/reflect/Method;[Ljava/lang/Object;)Ljava/lang/Object;", "okhttp"}, k = 1, mv = {1, 4, 0})
      /* compiled from: Jdk8WithJettyBootPlatform.kt */
      private static final class AlpnProvider implements InvocationHandler {
          private final List<String> protocols;
          private String selected;
          private boolean unsupported;
  
          public AlpnProvider(List<String> protocols2) {
              Intrinsics.checkNotNullParameter(protocols2, "protocols");
              this.protocols = protocols2;
          }
  
          public final String getSelected() {
              return this.selected;
          }
  
          public final boolean getUnsupported() {
              return this.unsupported;
          }
  
          public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
              Intrinsics.checkNotNullParameter(proxy, "proxy");
              Intrinsics.checkNotNullParameter(method, "method");
              Object[] objArr = args != null ? args : new Object[0];
              String name = method.getName();
              Class<?> returnType = method.getReturnType();
              if (Intrinsics.areEqual((Object) name, (Object) "supports") && Intrinsics.areEqual((Object) Boolean.TYPE, (Object) returnType)) {
                  return true;
              }
              if (!Intrinsics.areEqual((Object) name, (Object) "unsupported") || !Intrinsics.areEqual((Object) Void.TYPE, (Object) returnType)) {
                  if (Intrinsics.areEqual((Object) name, (Object) "protocols")) {
                      if (objArr.length == 0) {
                          return this.protocols;
                      }
                  }
                  if ((Intrinsics.areEqual((Object) name, (Object) "selectProtocol") || Intrinsics.areEqual((Object) name, (Object) "select")) && Intrinsics.areEqual((Object) String.class, (Object) returnType) && objArr.length == 1 && (objArr[0] instanceof List)) {
                      Object obj = objArr[0];
                      if (obj != null) {
                          List list = (List) obj;
                          int size = list.size();
                          if (size >= 0) {
                              int i = 0;
                              while (true) {
                                  Object obj2 = list.get(i);
                                  if (obj2 != null) {
                                      String str = (String) obj2;
                                      if (!this.protocols.contains(str)) {
                                          if (i == size) {
                                              break;
                                          }
                                          i++;
                                      } else {
                                          this.selected = str;
                                          return str;
                                      }
                                  } else {
                                      throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
                                  }
                              }
                          }
                          String str2 = this.protocols.get(0);
                          this.selected = str2;
                          return str2;
                      }
                      throw new NullPointerException("null cannot be cast to non-null type kotlin.collections.List<*>");
                  } else if ((!Intrinsics.areEqual((Object) name, (Object) "protocolSelected") && !Intrinsics.areEqual((Object) name, (Object) "selected")) || objArr.length != 1) {
                      return method.invoke(this, Arrays.copyOf(objArr, objArr.length));
                  } else {
                      Object obj3 = objArr[0];
                      if (obj3 != null) {
                          this.selected = (String) obj3;
                          return null;
                      }
                      throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
                  }
              } else {
                  this.unsupported = true;
                  return null;
              }
          }
  
          public final void setSelected(String str) {
              this.selected = str;
          }
  
          public final void setUnsupported(boolean z) {
              this.unsupported = z;
          }
      }
  
      @Metadata(bv = {1, 0, 3}, d1 = {"\u0000\u0012\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\b\u0003\u0018\u00002\u00020\u0001B\u0007\b\u0002¢\u0006\u0002\u0010\u0002J\b\u0010\u0003\u001a\u0004\u0018\u00010\u0004¨\u0006\u0005"}, d2 = {"Lokhttp3/internal/platform/Jdk8WithJettyBootPlatform$Companion;", "", "()V", "buildIfSupported", "Lokhttp3/internal/platform/Platform;", "okhttp"}, k = 1, mv = {1, 4, 0})
      /* compiled from: 01DA */
      public static final class Companion {
          private Companion() {
          }
  
          public /* synthetic */ Companion(DefaultConstructorMarker $constructor_marker) {
              this();
          }
  
          public final Platform buildIfSupported() {
              String property = System.getProperty("java.specification.version", EnvironmentCompat.MEDIA_UNKNOWN);
              Log1F380D.a((Object) property);
              try {
                  Intrinsics.checkNotNullExpressionValue(property, "jvmVersion");
                  if (Integer.parseInt(property) >= 9) {
                      return null;
                  }
              } catch (NumberFormatException e) {
              }
              try {
                  Class<?> cls = Class.forName("org.eclipse.jetty.alpn.ALPN", true, (ClassLoader) null);
                  Class<?> cls2 = Class.forName("org.eclipse.jetty.alpn.ALPN" + "$Provider", true, (ClassLoader) null);
                  Class<?> cls3 = Class.forName("org.eclipse.jetty.alpn.ALPN" + "$ClientProvider", true, (ClassLoader) null);
                  Class<?> cls4 = Class.forName("org.eclipse.jetty.alpn.ALPN" + "$ServerProvider", true, (ClassLoader) null);
                  Method method = cls.getMethod("put", new Class[]{SSLSocket.class, cls2});
                  Method method2 = cls.getMethod("get", new Class[]{SSLSocket.class});
                  Method method3 = cls.getMethod("remove", new Class[]{SSLSocket.class});
                  Intrinsics.checkNotNullExpressionValue(method, "putMethod");
                  Intrinsics.checkNotNullExpressionValue(method2, "getMethod");
                  Intrinsics.checkNotNullExpressionValue(method3, "removeMethod");
                  Intrinsics.checkNotNullExpressionValue(cls3, "clientProviderClass");
                  Intrinsics.checkNotNullExpressionValue(cls4, "serverProviderClass");
                  return new Jdk8WithJettyBootPlatform(method, method2, method3, cls3, cls4);
              } catch (ClassNotFoundException | NoSuchMethodException e2) {
                  return null;
              }
          }
      }
  
      public Jdk8WithJettyBootPlatform(Method putMethod2, Method getMethod2, Method removeMethod2, Class<?> clientProviderClass2, Class<?> serverProviderClass2) {
          Intrinsics.checkNotNullParameter(putMethod2, "putMethod");
          Intrinsics.checkNotNullParameter(getMethod2, "getMethod");
          Intrinsics.checkNotNullParameter(removeMethod2, "removeMethod");
          Intrinsics.checkNotNullParameter(clientProviderClass2, "clientProviderClass");
          Intrinsics.checkNotNullParameter(serverProviderClass2, "serverProviderClass");
          this.putMethod = putMethod2;
          this.getMethod = getMethod2;
          this.removeMethod = removeMethod2;
          this.clientProviderClass = clientProviderClass2;
          this.serverProviderClass = serverProviderClass2;
      }
  
      public void afterHandshake(SSLSocket sslSocket) {
          Intrinsics.checkNotNullParameter(sslSocket, "sslSocket");
          try {
              this.removeMethod.invoke((Object) null, new Object[]{sslSocket});
          } catch (IllegalAccessException e) {
              throw new AssertionError("failed to remove ALPN", e);
          } catch (InvocationTargetException e2) {
              throw new AssertionError("failed to remove ALPN", e2);
          }
      }
  
      public void configureTlsExtensions(SSLSocket sslSocket, String hostname, List<? extends Protocol> protocols) {
          Intrinsics.checkNotNullParameter(sslSocket, "sslSocket");
          Intrinsics.checkNotNullParameter(protocols, "protocols");
          List<String> alpnProtocolNames = Platform.Companion.alpnProtocolNames(protocols);
          try {
              Object newProxyInstance = Proxy.newProxyInstance(Platform.class.getClassLoader(), new Class[]{this.clientProviderClass, this.serverProviderClass}, new AlpnProvider(alpnProtocolNames));
              this.putMethod.invoke((Object) null, new Object[]{sslSocket, newProxyInstance});
          } catch (InvocationTargetException e) {
              throw new AssertionError("failed to set ALPN", e);
          } catch (IllegalAccessException e2) {
              throw new AssertionError("failed to set ALPN", e2);
          }
      }
  
      public String getSelectedProtocol(SSLSocket sslSocket) {
          Intrinsics.checkNotNullParameter(sslSocket, "sslSocket");
          try {
              InvocationHandler invocationHandler = Proxy.getInvocationHandler(this.getMethod.invoke((Object) null, new Object[]{sslSocket}));
              if (invocationHandler != null) {
                  AlpnProvider alpnProvider = (AlpnProvider) invocationHandler;
                  if (!alpnProvider.getUnsupported() && alpnProvider.getSelected() == null) {
                      Platform.log$default(this, "ALPN callback dropped: HTTP/2 is disabled. Is alpn-boot on the boot class path?", 0, (Throwable) null, 6, (Object) null);
                      return null;
                  } else if (alpnProvider.getUnsupported()) {
                      return null;
                  } else {
                      return alpnProvider.getSelected();
                  }
              } else {
                  throw new NullPointerException("null cannot be cast to non-null type okhttp3.internal.platform.Jdk8WithJettyBootPlatform.AlpnProvider");
              }
          } catch (InvocationTargetException e) {
              throw new AssertionError("failed to get ALPN selected protocol", e);
          } catch (IllegalAccessException e2) {
              throw new AssertionError("failed to get ALPN selected protocol", e2);
          }
      }
  }
  