OSDN Git Service

Merge "Use duck typing in X509TrustManagerExtensions" am: 9c3982f75d am: a26cafc2b2
authorChad Brubaker <cbrubaker@google.com>
Thu, 12 Nov 2015 23:09:05 +0000 (23:09 +0000)
committerandroid-build-merger <android-build-merger@google.com>
Thu, 12 Nov 2015 23:09:05 +0000 (23:09 +0000)
am: cd03475fc4

* commit 'cd03475fc44ed52939e836b8c3a9426691beedd8':
  Use duck typing in X509TrustManagerExtensions

1  2 
core/java/android/net/http/X509TrustManagerExtensions.java

  
  package android.net.http;
  
 +import android.annotation.SystemApi;
 +
  import com.android.org.conscrypt.TrustManagerImpl;
  
+ import java.lang.reflect.Field;
+ import java.lang.reflect.InvocationTargetException;
+ import java.lang.reflect.Method;
  import java.security.cert.CertificateException;
  import java.security.cert.X509Certificate;
  import java.util.List;
@@@ -80,17 -123,20 +125,31 @@@ public class X509TrustManagerExtension
       * otherwise.
       */
      public boolean isUserAddedCertificate(X509Certificate cert) {
-         return mDelegate.isUserAddedCertificate(cert);
+         if (mDelegate != null) {
+             return mDelegate.isUserAddedCertificate(cert);
+         } else {
+             try {
+                 return (Boolean) mIsUserAddedCertificate.invoke(mTrustManager, cert);
+             } catch (IllegalAccessException e) {
+                 throw new RuntimeException("Failed to call isUserAddedCertificate", e);
+             } catch (InvocationTargetException e) {
+                 if (e.getCause() instanceof RuntimeException) {
+                     throw (RuntimeException) e.getCause();
+                 } else {
+                     throw new RuntimeException("isUserAddedCertificate failed", e.getCause());
+                 }
+             }
+         }
      }
 +
 +    /**
 +     * Returns {@code true} if the TrustManager uses the same trust configuration for the provided
 +     * hostnames.
 +     *
 +     * @hide
 +     */
 +    @SystemApi
 +    public boolean isSameTrustConfiguration(String hostname1, String hostname2) {
 +        return true;
 +    }
  }