1 /* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.sslload; 18 19 import java.io.IOException; 20 import java.net.InetAddress; 21 import java.net.UnknownHostException; 22 import java.util.Calendar; 23 import java.util.Map; 24 25 import android.app.Activity; 26 import android.content.res.Resources; 27 import android.media.MediaPlayer; 28 import android.os.Handler; 29 import android.os.Vibrator; 30 import android.os.Bundle; 31 import android.view.Menu; 32 import android.view.MenuItem; 33 import android.view.View; 34 import android.view.View.OnClickListener; 35 import android.widget.Button; 36 import android.widget.TextView; 37 import android.util.Log; 38 import android.net.http.AndroidHttpClient; 39 import org.apache.http.client.HttpClient; 40 import org.apache.http.client.ResponseHandler; 41 import org.apache.http.client.methods.HttpGet; 42 import org.apache.http.HttpResponse; 43 44 public class SslLoad extends Activity implements OnClickListener, Runnable { 45 46 private static final String TAG = SslLoad.class.getSimpleName(); 47 48 private Button button; 49 private boolean running = false; 50 51 @Override 52 public void onCreate(Bundle icicle) { 53 super.onCreate(icicle); 54 55 Thread requestThread = new Thread(this); 56 requestThread.setDaemon(true); 57 requestThread.start(); 58 59 button = new Button(this); 60 button.setText("GO"); 61 button.setOnClickListener(this); 62 63 setContentView(button); 64 } 65 66 @Override 67 protected void onStop() { 68 super.onStop(); 69 70 synchronized (this) { 71 running = false; 72 } 73 } 74 75 public void onClick(View v) { 76 synchronized (this) { 77 running = !running; 78 button.setText(running ? "STOP" : "GO"); 79 if (running) { 80 this.notifyAll(); 81 } 82 } 83 } 84 85 public void run() { 86 boolean error = false; 87 while (true) { 88 synchronized (this) { 89 while (!running) { 90 try { 91 this.wait(); 92 } catch (InterruptedException e) { /* ignored */ } 93 } 94 } 95 96 AndroidHttpClient client = AndroidHttpClient.newInstance( 97 "Mozilla/5.001 (windows; U; NT4.0; en-us) Gecko/25250101"); 98 try { 99 // Cert. is for "www.google.com", not "google.com". 100 String url = error ? "https://google.com/" 101 : "https://www.google.com"; 102 client.execute(new HttpGet(url), 103 new ResponseHandler<Void>() { 104 public Void handleResponse(HttpResponse response) { 105 /* ignore */ 106 return null; 107 } 108 }); 109 Log.i(TAG, "Request succeeded."); 110 } catch (IOException e) { 111 Log.w(TAG, "Request failed.", e); 112 } 113 114 client.close(); 115 116 try { 117 Thread.sleep(1000); 118 } catch (InterruptedException e) { /* ignored */ } 119 120 error = !error; 121 } 122 } 123 } 124