FileDocCategorySizeDatePackage
SslLoad.javaAPI DocAndroid 1.5 API3714Wed May 06 22:42:02 BST 2009com.android.sslload

SslLoad

public class SslLoad extends android.app.Activity implements Runnable, android.view.View.OnClickListener

Fields Summary
private static final String
TAG
private android.widget.Button
button
private boolean
running
Constructors Summary
Methods Summary
public voidonClick(android.view.View v)

        synchronized (this) {
            running = !running;
            button.setText(running ? "STOP" : "GO");
            if (running) {
                this.notifyAll();
            }
        }
    
public voidonCreate(android.os.Bundle icicle)


    
        
        super.onCreate(icicle);

        Thread requestThread = new Thread(this);
        requestThread.setDaemon(true);
        requestThread.start();

        button = new Button(this);
        button.setText("GO");
        button.setOnClickListener(this);

        setContentView(button);
    
protected voidonStop()

        super.onStop();

        synchronized (this) {
            running = false;
        }
    
public voidrun()

        boolean error = false;
        while (true) {
            synchronized (this) {
                while (!running) {
                    try {
                        this.wait();
                    } catch (InterruptedException e) { /* ignored */ }
                }
            }

            AndroidHttpClient client = AndroidHttpClient.newInstance(
                    "Mozilla/5.001 (windows; U; NT4.0; en-us) Gecko/25250101");
            try {
                // Cert. is for "www.google.com", not "google.com".
                String url = error ? "https://google.com/"
                        : "https://www.google.com";
                client.execute(new HttpGet(url),
                        new ResponseHandler<Void>() {
                            public Void handleResponse(HttpResponse response) {
                                /* ignore */
                                return null;
                            }
                        });
                Log.i(TAG, "Request succeeded.");
            } catch (IOException e) {
                Log.w(TAG, "Request failed.", e);
            }

            client.close();
            
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) { /* ignored */ }

            error = !error;
        }