2 * wpadebug - wpa_supplicant and Wi-Fi debugging app for Android
3 * Copyright (c) 2013, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 package w1.fi.wpadebug;
11 import android.app.Activity;
12 import android.app.AlertDialog;
13 import android.content.DialogInterface;
14 import android.content.Intent;
15 import android.content.res.Configuration;
16 import android.net.http.SslError;
17 import android.os.Bundle;
18 import android.util.Log;
19 import android.view.Window;
20 import android.webkit.SslErrorHandler;
21 import android.webkit.WebChromeClient;
22 import android.webkit.WebView;
23 import android.webkit.WebViewClient;
24 import android.widget.Toast;
26 public class WpaWebViewActivity extends Activity
28 private static final String TAG = "wpadebug";
29 private static final String EXTRA_MESSAGE = "w1.fi.wpadebug.URL";
30 private WebView mWebView;
31 final Activity activity = this;
34 public void onCreate(Bundle savedInstanceState)
36 Log.d(TAG, "WpaWebViewActivity::onCreate");
37 super.onCreate(savedInstanceState);
39 Intent intent = getIntent();
40 String url = intent.getStringExtra(EXTRA_MESSAGE);
41 Log.d(TAG, "url=" + url);
42 if (url.equals("FINISH")) {
47 mWebView = new WebView(this);
48 mWebView.getSettings().setJavaScriptEnabled(true);
49 mWebView.setWebViewClient(new WpaWebViewClient());
51 getWindow().requestFeature(Window.FEATURE_PROGRESS);
53 mWebView.setWebChromeClient(new WebChromeClient()
55 public void onProgressChanged(WebView view, int progress)
57 Log.d(TAG, "progress=" + progress);
58 activity.setProgress(progress * 1000);
62 setContentView(mWebView);
64 mWebView.loadUrl(url);
68 public void onResume()
70 Log.d(TAG, "WpaWebViewActivity::onResume");
75 protected void onNewIntent(Intent intent)
77 Log.d(TAG, "WpaWebViewActivity::onNewIntent");
78 super.onNewIntent(intent);
79 String url = intent.getStringExtra(EXTRA_MESSAGE);
80 Log.d(TAG, "url=" + url);
82 if (url.equals("FINISH")) {
86 mWebView.loadUrl(url);
89 private class WpaWebViewClient extends WebViewClient {
91 public boolean shouldOverrideUrlLoading(WebView view, String url)
93 Log.d(TAG, "shouldOverrideUrlLoading: url=" + url);
94 Intent intent = getIntent();
95 intent.putExtra(EXTRA_MESSAGE, url);
102 public void onPageFinished(WebView view, String url)
104 Log.d(TAG, "onPageFinished: url=" + url);
107 public void onReceivedError(WebView view, int errorCode,
108 String description, String failingUrl)
110 Log.d(TAG, "Failed to load page: errorCode=" +
111 errorCode + " description=" + description +
112 " URL=" + failingUrl);
113 Toast.makeText(activity, "Failed to load page: " +
114 description + " (URL=" + failingUrl + ")",
115 Toast.LENGTH_LONG).show();
119 public void onReceivedSslError(WebView view, SslErrorHandler handler,
122 Log.d(TAG, "SSL error: " + error);
124 final SslErrorHandler h = handler;
125 AlertDialog.Builder alert = new AlertDialog.Builder(activity);
126 alert.setTitle("SSL error - Continue?");
127 alert.setMessage(error.toString())
128 .setCancelable(false)
129 .setPositiveButton("Yes", new DialogInterface.OnClickListener()
131 public void onClick(DialogInterface dialog, int id)
136 .setNegativeButton("No", new DialogInterface.OnClickListener()
138 public void onClick(DialogInterface dialog, int id)