public static synchronized ServerSocketFactory getDefault ( ) { // Android-changed: Use security version instead of propertyChecked. // // We use the same lookup logic in SSLSocketFactory.getDefault(). Any changes // made here must be mirrored in that class. if ( defaultServerSocketFactory != null && lastVersion == Security . getVersion ( ) ) { return defaultServerSocketFactory ; } lastVersion = Security . getVersion ( ) ; SSLServerSocketFactory previousDefaultServerSocketFactory = defaultServerSocketFactory ; defaultServerSocketFactory = null ; String clsName = SSLSocketFactory . getSecurityProperty ( "ssl.ServerSocketFactory.provider" ) ; if ( clsName != null ) { // The instance for the default socket factory is checked for updates quite // often (for instance, every time a security provider is added). Which leads // to unnecessary overload and excessive error messages in case of class-loading // errors. Avoid creating a new object if the class name is the same as before. if ( previousDefaultServerSocketFactory != null && clsName . equals ( previousDefaultServerSocketFactory . getClass ( ) . getName ( ) ) ) { defaultServerSocketFactory = previousDefaultServerSocketFactory ; return defaultServerSocketFactory ; } Class cls = null ; log ( "setting up default SSLServerSocketFactory" ) ; try { log ( "setting up default SSLServerSocketFactory" ) ; try { cls = Class . forName ( clsName ) ; } catch ( ClassNotFoundException e ) { // Android-changed; Try the contextClassLoader first. ClassLoader cl = Thread . currentThread ( ) . getContextClassLoader ( ) ; if ( cl == null ) { cl = ClassLoader . getSystemClassLoader ( ) ; } if ( cl != null ) { cls = Class . forName ( clsName , true , cl ) ; } } log ( "class " + clsName + " is loaded" ) ; SSLServerSocketFactory fac = ( SSLServerSocketFactory ) cls . newInstance ( ) ; log ( "instantiated an instance of class " + clsName ) ; defaultServerSocketFactory = fac ; if ( defaultServerSocketFactory != null ) { return defaultServerSocketFactory ; } } catch ( Exception e ) { log ( "SSLServerSocketFactory instantiation failed: " + e ) ; // Android-changed: Fallback to the default SSLContext if an exception // is thrown during the initialization of ssl.ServerSocketFactory.provider. } } try { SSLContext context = SSLContext . getDefault ( ) ; if ( context != null ) { defaultServerSocketFactory = context . getServerSocketFactory ( ) ; } } catch ( NoSuchAlgorithmException e ) { } if ( defaultServerSocketFactory == null ) { defaultServerSocketFactory = new DefaultSSLServerSocketFactory ( new IllegalStateException ( "No ServerSocketFactory implementation found" ) ) ; } return defaultServerSocketFactory ; }
Returns the default SSL server socket factory .