diff options
| author | Kenny Root <kenny@the-b.org> | 2011-10-12 20:03:12 -0700 | 
|---|---|---|
| committer | Kenny Root <kenny@the-b.org> | 2011-10-12 20:03:12 -0700 | 
| commit | 61ba1c09afb9b59a9940a0a30c6fd0093c9b71a0 (patch) | |
| tree | 20f5aa2860e77faa93c124927a5bb959054e8794 /src | |
| parent | 8a00dfc08cf3d47670156e789d9434389ad69f74 (diff) | |
| download | connectbot-61ba1c09afb9b59a9940a0a30c6fd0093c9b71a0.tar.gz connectbot-61ba1c09afb9b59a9940a0a30c6fd0093c9b71a0.tar.bz2 connectbot-61ba1c09afb9b59a9940a0a30c6fd0093c9b71a0.zip | |
Remove nullwire service
Android Market will report traces for things installed via Market.
Nullwire's stuff isn't really worth it.
Also, the TerminalManager isn't really a "background" service since the
calls into it still runs on the UI looper.
Diffstat (limited to 'src')
| -rw-r--r-- | src/com/nullwire/trace/DefaultExceptionHandler.java | 58 | ||||
| -rw-r--r-- | src/com/nullwire/trace/ExceptionClickListener.java | 49 | ||||
| -rw-r--r-- | src/com/nullwire/trace/ExceptionHandler.java | 216 | ||||
| -rw-r--r-- | src/com/nullwire/trace/G.java | 14 | ||||
| -rw-r--r-- | src/org/connectbot/ConsoleActivity.java | 4 | ||||
| -rw-r--r-- | src/org/connectbot/HostListActivity.java | 6 | ||||
| -rw-r--r-- | src/org/connectbot/service/TerminalManager.java | 16 | 
7 files changed, 6 insertions, 357 deletions
| diff --git a/src/com/nullwire/trace/DefaultExceptionHandler.java b/src/com/nullwire/trace/DefaultExceptionHandler.java deleted file mode 100644 index f9abe70..0000000 --- a/src/com/nullwire/trace/DefaultExceptionHandler.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.nullwire.trace; - -import java.io.BufferedWriter; -import java.io.FileWriter; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.io.Writer; -import java.lang.Thread.UncaughtExceptionHandler; -import java.util.Random; - -import android.util.Log; - -public class DefaultExceptionHandler implements UncaughtExceptionHandler { - -	private UncaughtExceptionHandler defaultExceptionHandler; - -	private static final String TAG = "UNHANDLED_EXCEPTION"; - -	// constructor -	public DefaultExceptionHandler(UncaughtExceptionHandler pDefaultExceptionHandler) -	{ -		defaultExceptionHandler = pDefaultExceptionHandler; -	} - -	// Default exception handler -	public void uncaughtException(Thread t, Throwable e) { -		// Here you should have a more robust, permanent record of problems -		final Writer result = new StringWriter(); -		final PrintWriter printWriter = new PrintWriter(result); -		e.printStackTrace(printWriter); -		try { -			// Random number to avoid duplicate files -			Random generator = new Random(); -			int random = generator.nextInt(99999); -			// Embed version in stacktrace filename -			String filename = G.APP_VERSION + "-" + Integer.toString(random); -			Log.d(TAG, "Writing unhandled exception to: " + G.FILES_PATH + "/" -					+ filename + ".stacktrace"); -			// Write the stacktrace to disk -			BufferedWriter bos = new BufferedWriter(new FileWriter(G.FILES_PATH -					+ "/" + filename + ".stacktrace")); -			bos.write(G.APP_VERSION + "\n"); -			bos.write(G.APP_DESCRIPTION + "\n"); -			bos.write(G.ANDROID_VERSION + "\n"); -			bos.write(G.PHONE_MODEL + "\n"); -			bos.write(result.toString()); -			bos.flush(); -			// Close up everything -			bos.close(); -		} catch (Exception ebos) { -			// Nothing much we can do about this - the game is over -			ebos.printStackTrace(); -		} -		Log.d(TAG, result.toString()); -		//call original handler -		defaultExceptionHandler.uncaughtException(t, e); -	} -} diff --git a/src/com/nullwire/trace/ExceptionClickListener.java b/src/com/nullwire/trace/ExceptionClickListener.java deleted file mode 100644 index 525b755..0000000 --- a/src/com/nullwire/trace/ExceptionClickListener.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * - */ -package com.nullwire.trace; - -import java.lang.ref.WeakReference; - -import android.content.Context; -import android.content.DialogInterface; -import android.content.DialogInterface.OnClickListener; -import android.util.Log; - -/** - * @author Kenny Root - * - */ -public class ExceptionClickListener implements OnClickListener { -	public static String TAG = "com.nullwire.trace.ExceptionClickListener"; - -	WeakReference<Context> context; - -	public ExceptionClickListener() { } - -	public void onClick(DialogInterface dialog, int whichButton) { -		switch (whichButton) { -		case DialogInterface.BUTTON_POSITIVE: -			dialog.dismiss(); -			Log.d(TAG, "Trying to submit stack traces"); -			new Thread(new Runnable() { -				public void run() { -					ExceptionHandler.submitStackTraces(); -				} -			}).start(); -			break; -		case DialogInterface.BUTTON_NEGATIVE: -			dialog.dismiss(); -			Log.d(TAG, "Deleting old stack traces."); -			new Thread(new Runnable() { -				public void run() { -					ExceptionHandler.removeStackTraces(); -				} -			}).start(); -			break; -		default: -			Log.d("ExceptionClickListener", "Got unknown button click: " + whichButton); -			dialog.cancel(); -		} -	} -} diff --git a/src/com/nullwire/trace/ExceptionHandler.java b/src/com/nullwire/trace/ExceptionHandler.java deleted file mode 100644 index 0fabe68..0000000 --- a/src/com/nullwire/trace/ExceptionHandler.java +++ /dev/null @@ -1,216 +0,0 @@ -package com.nullwire.trace; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.FilenameFilter; -import java.util.ArrayList; -import java.util.List; - -import org.apache.http.NameValuePair; -import org.apache.http.client.entity.UrlEncodedFormEntity; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.impl.client.DefaultHttpClient; -import org.apache.http.message.BasicNameValuePair; -import org.apache.http.protocol.HTTP; -import org.connectbot.R; - -import android.app.AlertDialog; -import android.content.Context; -import android.content.pm.PackageInfo; -import android.content.pm.PackageManager; -import android.content.pm.PackageManager.NameNotFoundException; -import android.os.Handler; -import android.os.Message; -import android.util.Log; - -public class ExceptionHandler { -	public static String TAG = "com.nullwire.trace.ExceptionsHandler"; - -	private static String[] stackTraceFileList = null; - -	/** -	 * @param context -	 */ -	public static void checkForTraces(final Context context) { -		new Thread(new Runnable() { -			public void run() { -				String[] stackTraces = searchForStackTraces(); -				if (stackTraces != null && stackTraces.length > 0) { -					Log.d(TAG, "number of stack traces: " + stackTraces.length); -					submissionHandler.sendMessage(submissionHandler -							.obtainMessage(-1, context)); -				} -			} -		}).start(); -	} - - -	/** -	* Register handler for unhandled exceptions. -	* -	* @param context -	*/ -	public static boolean register(Context context) { -		Log.i(TAG, "Registering default exceptions handler"); -		// Get information about the Package -		PackageManager pm = context.getPackageManager(); -		try { -			PackageInfo pi; -			// Version -			pi = pm.getPackageInfo(context.getPackageName(), 0); -			// Package name -			G.APP_PACKAGE = pi.packageName; -			// Version information -			G.APP_VERSION = pi.versionName; -			G.APP_DESCRIPTION = context.getString(R.string.msg_version); -			// Files dir for storing the stack traces -			G.FILES_PATH = context.getFilesDir().getAbsolutePath(); -			// Device model -			G.PHONE_MODEL = android.os.Build.MODEL; -			// Android version -			G.ANDROID_VERSION = android.os.Build.VERSION.RELEASE; -		} catch (NameNotFoundException e) { -			e.printStackTrace(); -		} - -		Log.d(TAG, "APP_VERSION: " + G.APP_VERSION); -		Log.d(TAG, "APP_PACKAGE: " + G.APP_PACKAGE); -		Log.d(TAG, "FILES_PATH: " + G.FILES_PATH); -		Log.d(TAG, "URL: " + G.URL); - -		boolean stackTracesFound = false; - -		// We'll return true if any stack traces were found -		String[] list = searchForStackTraces(); -		if (list != null && list.length > 0) { -			stackTracesFound = true; -		} - -		new Thread() { -			@Override -			public void run() { -				UncaughtExceptionHandler currentHandler = Thread.getDefaultUncaughtExceptionHandler(); - -				if (currentHandler != null) { -					Log.d(TAG, "current handler class="+currentHandler.getClass().getName()); -				} -				// don't register again if already registered -				if (!(currentHandler instanceof DefaultExceptionHandler)) { -					// Register default exceptions handler -					Thread.setDefaultUncaughtExceptionHandler( -							new DefaultExceptionHandler(currentHandler)); -				} -			} -		}.start(); - -		return stackTracesFound; -	} - -	/** -	 * Search for stack trace files. -	 * @return -	 */ -	private static String[] searchForStackTraces() { -		if (stackTraceFileList != null) { -			return stackTraceFileList; -		} -		File dir = new File(G.FILES_PATH + "/"); -		// Try to create the files folder if it doesn't exist -		dir.mkdir(); -		// Filter for ".stacktrace" files -		FilenameFilter filter = new FilenameFilter() { -			public boolean accept(File dir, String name) { -				return name.endsWith(".stacktrace"); -			} -		}; -		return (stackTraceFileList = dir.list(filter)); -	} - -	private static Handler submissionHandler = new Handler() { -		@Override -		public void handleMessage(Message msg) { -			Context context = (Context) msg.obj; -			ExceptionClickListener clickListener = new ExceptionClickListener(); -			new AlertDialog.Builder(context) -					.setMessage(R.string.exceptions_submit_message) -					.setPositiveButton(android.R.string.yes, clickListener) -					.setNegativeButton(android.R.string.no, clickListener) -					.create().show(); -		} -	}; - -	/** -	 * Look into the files folder to see if there are any "*.stacktrace" files. -	 * If any are present, submit them to the trace server. -	 */ -	public static void submitStackTraces() { -		try { -			Log.d(TAG, "Looking for exceptions in: " + G.FILES_PATH); -			String[] list = searchForStackTraces(); -			if (list != null && list.length > 0) { -				Log.d(TAG, "Found " + list.length + " stacktrace(s)"); -				StringBuilder contents = new StringBuilder(); -				for (int i = 0; i < list.length; i++) { -					String filePath = G.FILES_PATH + "/" + list[i]; -					// Extract the version from the filename: -					// "packagename-version-...." -					String version = list[i].split("-")[0]; -					Log.d(TAG, "Stacktrace in file '" + filePath -							+ "' belongs to version " + version); -					// Read contents of stacktrace -					contents.setLength(0); -					BufferedReader input; -					try { -						input = new BufferedReader(new FileReader(filePath)); -					} catch (FileNotFoundException fnf) { -						continue; -					} -					String line = null; -					while ((line = input.readLine()) != null) { -						contents.append(line); -						contents.append(System.getProperty("line.separator")); -					} -					input.close(); -					String stacktrace; -					stacktrace = contents.toString(); -					Log.d(TAG, "Transmitting stack trace: " + stacktrace); -					// Transmit stack trace with POST request -					DefaultHttpClient httpClient = new DefaultHttpClient(); -					HttpPost httpPost = new HttpPost(G.URL); -					List<NameValuePair> nvps = new ArrayList<NameValuePair>(); -					nvps.add(new BasicNameValuePair("package_name", G.APP_PACKAGE)); -					nvps.add(new BasicNameValuePair("package_version", version)); -					nvps.add(new BasicNameValuePair("stacktrace", stacktrace)); -					httpPost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); -					// We don't care about the response, so we just hope it went -					// well and on with it -					httpClient.execute(httpPost); -				} -			} -		} catch (Exception e) { -			e.printStackTrace(); -		} finally { -			removeStackTraces(); -		} -	} - -	public synchronized static void removeStackTraces() { -		try { -			String[] list = searchForStackTraces(); - -			if (list == null) -				return; - -			for (int i = 0; i < list.length; i++) { -				File file = new File(G.FILES_PATH + "/" + list[i]); -				file.delete(); -			} - -			stackTraceFileList = null; -		} catch (Exception e) { -			e.printStackTrace(); -		} -	} -} diff --git a/src/com/nullwire/trace/G.java b/src/com/nullwire/trace/G.java deleted file mode 100644 index 2e63aa1..0000000 --- a/src/com/nullwire/trace/G.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.nullwire.trace; - -public class G { -	// This must be set by the application - it used to automatically -	// transmit exceptions to the trace server -	public static String FILES_PATH = null; -	public static String APP_PACKAGE = "unknown"; -	public static String APP_VERSION = "unknown"; -	public static String APP_DESCRIPTION = "unknown"; -	public static String PHONE_MODEL = "unknown"; -	public static String ANDROID_VERSION = "unknown"; -	// Where are the stack traces posted? -	public static String URL = "http://connectbot.the-b.org/trace/"; -} diff --git a/src/org/connectbot/ConsoleActivity.java b/src/org/connectbot/ConsoleActivity.java index 31ba444..5882a84 100644 --- a/src/org/connectbot/ConsoleActivity.java +++ b/src/org/connectbot/ConsoleActivity.java @@ -75,8 +75,6 @@ import android.widget.Toast;  import android.widget.ViewFlipper;  import android.widget.AdapterView.OnItemClickListener; -import com.nullwire.trace.ExceptionHandler; -  import de.mud.terminal.vt320;  public class ConsoleActivity extends Activity { @@ -276,8 +274,6 @@ public class ConsoleActivity extends Activity {  		this.setContentView(R.layout.act_console); -		ExceptionHandler.register(this); -  		clipboard = (ClipboardManager)getSystemService(CLIPBOARD_SERVICE);  		prefs = PreferenceManager.getDefaultSharedPreferences(this); diff --git a/src/org/connectbot/HostListActivity.java b/src/org/connectbot/HostListActivity.java index 3b02530..a0e40e8 100644 --- a/src/org/connectbot/HostListActivity.java +++ b/src/org/connectbot/HostListActivity.java @@ -63,8 +63,6 @@ import android.widget.Spinner;  import android.widget.TextView;  import android.widget.AdapterView.OnItemClickListener; -import com.nullwire.trace.ExceptionHandler; -  public class HostListActivity extends ListActivity {  	public final static int REQUEST_EDIT = 1; @@ -135,8 +133,6 @@ public class HostListActivity extends ListActivity {  	@Override  	public void onResume() {  		super.onResume(); - -		ExceptionHandler.checkForTraces(this);  	}  	@Override @@ -165,8 +161,6 @@ public class HostListActivity extends ListActivity {  				getResources().getText(R.string.app_name),  				getResources().getText(R.string.title_hosts_list))); -		ExceptionHandler.register(this); -  		// check for eula agreement  		this.prefs = PreferenceManager.getDefaultSharedPreferences(this); diff --git a/src/org/connectbot/service/TerminalManager.java b/src/org/connectbot/service/TerminalManager.java index 86a30f5..3bfcdde 100644 --- a/src/org/connectbot/service/TerminalManager.java +++ b/src/org/connectbot/service/TerminalManager.java @@ -59,12 +59,10 @@ import android.os.Vibrator;  import android.preference.PreferenceManager;  import android.util.Log; -import com.nullwire.trace.ExceptionHandler; -  /** - * Manager for SSH connections that runs as a background service. This service - * holds a list of currently connected SSH bridges that are ready for connection - * up to a GUI if needed. + * Manager for SSH connections that runs as a service. This service holds a list + * of currently connected SSH bridges that are ready for connection up to a GUI + * if needed.   *   * @author jsharkey   */ @@ -120,9 +118,7 @@ public class TerminalManager extends Service implements BridgeDisconnectedListen  	@Override  	public void onCreate() { -		Log.i(TAG, "Starting background service"); - -		ExceptionHandler.register(this); +		Log.i(TAG, "Starting service");  		prefs = PreferenceManager.getDefaultSharedPreferences(this);  		prefs.registerOnSharedPreferenceChangeListener(this); @@ -171,7 +167,7 @@ public class TerminalManager extends Service implements BridgeDisconnectedListen  	@Override  	public void onDestroy() { -		Log.i(TAG, "Destroying background service"); +		Log.i(TAG, "Destroying service");  		disconnectAll(true); @@ -453,7 +449,7 @@ public class TerminalManager extends Service implements BridgeDisconnectedListen  				idleTimer.schedule(new IdleTask(), IDLE_TIMEOUT);  			}  		} else { -			Log.d(TAG, "Stopping background service immediately"); +			Log.d(TAG, "Stopping service immediately");  			stopSelf();  		}  	} | 
