Home | History | Annotate | Download | only in net
      1 /* GENERATED SOURCE. DO NOT MODIFY. */
      2 /*
      3  * Copyright (C) 2014 The Android Open Source Project
      4  *
      5  * Licensed under the Apache License, Version 2.0 (the "License");
      6  * you may not use this file except in compliance with the License.
      7  * You may obtain a copy of the License at
      8  *
      9  *      http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  * Unless required by applicable law or agreed to in writing, software
     12  * distributed under the License is distributed on an "AS IS" BASIS,
     13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  * See the License for the specific language governing permissions and
     15  * limitations under the License.
     16  */
     17 package tests.net;
     18 import java.io.IOException;
     19 import java.net.InetAddress;
     20 import java.net.Socket;
     21 import java.net.UnknownHostException;
     22 import javax.net.ssl.SSLSocket;
     23 import javax.net.ssl.SSLSocketFactory;
     24 /**
     25  * {@link SSLSocketFactory} which delegates all invocations to the provided delegate
     26  * {@code SSLSocketFactory}.
     27  * @hide This class is not part of the Android public SDK API
     28  */
     29 public class DelegatingSSLSocketFactory extends SSLSocketFactory {
     30     private final SSLSocketFactory mDelegate;
     31     public DelegatingSSLSocketFactory(SSLSocketFactory delegate) {
     32         this.mDelegate = delegate;
     33     }
     34     /**
     35      * Invoked after obtaining a socket from the delegate and before returning it to the caller.
     36      *
     37      * <p>The default implementation does nothing.
     38      */
     39     protected SSLSocket configureSocket(SSLSocket socket) throws IOException {
     40         return socket;
     41     }
     42     @Override
     43     public String[] getDefaultCipherSuites() {
     44         return mDelegate.getDefaultCipherSuites();
     45     }
     46     @Override
     47     public String[] getSupportedCipherSuites() {
     48         return mDelegate.getSupportedCipherSuites();
     49     }
     50     @Override
     51     public Socket createSocket() throws IOException {
     52         SSLSocket socket = (SSLSocket) mDelegate.createSocket();
     53         return configureSocket(socket);
     54     }
     55     @Override
     56     public Socket createSocket(Socket s, String host, int port, boolean autoClose)
     57             throws IOException {
     58         SSLSocket socket = (SSLSocket) mDelegate.createSocket(s, host, port, autoClose);
     59         return configureSocket(socket);
     60     }
     61     @Override
     62     public Socket createSocket(String host, int port) throws IOException, UnknownHostException {
     63         SSLSocket socket = (SSLSocket) mDelegate.createSocket(host, port);
     64         return configureSocket(socket);
     65     }
     66     @Override
     67     public Socket createSocket(String host, int port, InetAddress localHost, int localPort)
     68             throws IOException, UnknownHostException {
     69         SSLSocket socket = (SSLSocket) mDelegate.createSocket(host, port, localHost, localPort);
     70         return configureSocket(socket);
     71     }
     72     @Override
     73     public Socket createSocket(InetAddress host, int port) throws IOException {
     74         SSLSocket socket = (SSLSocket) mDelegate.createSocket(host, port);
     75         return configureSocket(socket);
     76     }
     77     @Override
     78     public Socket createSocket(InetAddress address, int port, InetAddress localAddress,
     79             int localPort) throws IOException {
     80         SSLSocket socket = (SSLSocket) mDelegate.createSocket(address, port, localAddress, localPort);
     81         return configureSocket(socket);
     82     }
     83 }
     84