diff options
| -rw-r--r-- | AndroidManifest.xml | 2 | ||||
| -rw-r--r-- | res/values/strings.xml | 5 | ||||
| -rw-r--r-- | res/xml/host_prefs.xml | 6 | ||||
| -rw-r--r-- | src/de/mud/terminal/vt320.java | 2 | ||||
| -rw-r--r-- | src/org/connectbot/ConsoleActivity.java | 6 | ||||
| -rw-r--r-- | src/org/connectbot/bean/HostBean.java | 10 | ||||
| -rw-r--r-- | src/org/connectbot/service/PromptHelper.java | 33 | ||||
| -rw-r--r-- | src/org/connectbot/service/TerminalBridge.java | 34 | ||||
| -rw-r--r-- | src/org/connectbot/transport/Local.java | 1 | ||||
| -rw-r--r-- | src/org/connectbot/transport/SSH.java | 14 | ||||
| -rw-r--r-- | src/org/connectbot/util/HostDatabase.java | 14 | 
11 files changed, 79 insertions, 48 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index acbae88..8d209f6 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -2,7 +2,7 @@  <manifest xmlns:android="http://schemas.android.com/apk/res/android"  	package="org.connectbot"  	android:versionName="1.6-dev" -	android:versionCode="162"> +	android:versionCode="163">  	<application  		android:icon="@drawable/icon" diff --git a/res/values/strings.xml b/res/values/strings.xml index 4ec1c3a..999150e 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -239,6 +239,11 @@  	<!-- Summary for field asking whether a shell session should be started up upon connection or not -->  	<string name="hostpref_wantsession_summary">Disable this preference to only use port forwards</string> +	<!-- Setting for whether the host should be reconnected to automatically upon disconnect --> +	<string name="hostpref_stayconnected_title">Stay connected</string> +	<!-- Summary for preference asking whether the host should be reconnected to when it disconnects --> +	<string name="hostpref_stayconnected_summary">Try to reconnect to host if disconnected</string> +  	<!-- Setting for what key code is sent to the server when DEL key is pressed. -->  	<string name="hostpref_delkey_title">DEL Key</string>  	<!-- Summary for field asking what key code is sent to the server when DEL key is pressed. --> diff --git a/res/xml/host_prefs.xml b/res/xml/host_prefs.xml index 0d56606..67f4e9d 100644 --- a/res/xml/host_prefs.xml +++ b/res/xml/host_prefs.xml @@ -69,6 +69,12 @@  		android:summary="@string/hostpref_wantsession_summary"  		/> +	<CheckBoxPreference +		android:key="stayconnected" +		android:title="@string/hostpref_stayconnected_title" +		android:summary="@string/hostpref_stayconnected_summary" +		/> +  	<ListPreference  		android:key="delkey"  		android:title="@string/hostpref_delkey_title" diff --git a/src/de/mud/terminal/vt320.java b/src/de/mud/terminal/vt320.java index 05169ad..4df3717 100644 --- a/src/de/mud/terminal/vt320.java +++ b/src/de/mud/terminal/vt320.java @@ -2956,7 +2956,7 @@ public void setScreenSize(int c, int r, boolean broadcast) {      _SetCursor(0, 0);      if (display != null) -    	display.resetColors(); +      display.resetColors();      showCursor(true);      /*FIXME:*/ diff --git a/src/org/connectbot/ConsoleActivity.java b/src/org/connectbot/ConsoleActivity.java index 6f59a57..2f217c2 100644 --- a/src/org/connectbot/ConsoleActivity.java +++ b/src/org/connectbot/ConsoleActivity.java @@ -354,7 +354,7 @@ public class ConsoleActivity extends Activity {  				// finally clear password for next user  				stringPrompt.setText(""); -				hideAllPrompts(); +				updatePromptVisible();  				return true;  			} @@ -369,7 +369,7 @@ public class ConsoleActivity extends Activity {  				PromptHelper helper = getCurrentPromptHelper();  				if(helper == null) return;  				helper.setResponse(Boolean.TRUE); -				hideAllPrompts(); +				updatePromptVisible();  			}  		}); @@ -379,7 +379,7 @@ public class ConsoleActivity extends Activity {  				PromptHelper helper = getCurrentPromptHelper();  				if(helper == null) return;  				helper.setResponse(Boolean.FALSE); -				hideAllPrompts(); +				updatePromptVisible();  			}  		}); diff --git a/src/org/connectbot/bean/HostBean.java b/src/org/connectbot/bean/HostBean.java index 7f08fdd..3f3c1bb 100644 --- a/src/org/connectbot/bean/HostBean.java +++ b/src/org/connectbot/bean/HostBean.java @@ -48,6 +48,7 @@ public class HostBean extends AbstractBean {  	private String delKey = HostDatabase.DELKEY_DEL;  	private boolean compression = false;  	private String encoding = HostDatabase.ENCODING_DEFAULT; +	private boolean stayConnected = false;  	public HostBean() { @@ -186,6 +187,14 @@ public class HostBean extends AbstractBean {  		return this.encoding;  	} +	public void setStayConnected(boolean stayConnected) { +		this.stayConnected = stayConnected; +	} + +	public boolean getStayConnected() { +		return stayConnected; +	} +  	public String getDescription() {  		String description = String.format("%s@%s", username, hostname); @@ -216,6 +225,7 @@ public class HostBean extends AbstractBean {  		values.put(HostDatabase.FIELD_HOST_DELKEY, delKey);  		values.put(HostDatabase.FIELD_HOST_COMPRESSION, Boolean.toString(compression));  		values.put(HostDatabase.FIELD_HOST_ENCODING, encoding); +		values.put(HostDatabase.FIELD_HOST_STAYCONNECTED, stayConnected);  		return values;  	} diff --git a/src/org/connectbot/service/PromptHelper.java b/src/org/connectbot/service/PromptHelper.java index 682fa52..333c74f 100644 --- a/src/org/connectbot/service/PromptHelper.java +++ b/src/org/connectbot/service/PromptHelper.java @@ -68,12 +68,9 @@ public class PromptHelper {  	 * Only one thread can call this at a time. cancelPrompt() will force this to  	 * immediately return.  	 */ -	private Object requestPrompt(String instructions, String hint, Object type, boolean immediate) throws InterruptedException { +	private Object requestPrompt(String instructions, String hint, Object type) throws InterruptedException {  		Object response = null; -		if (immediate) -			cancelPrompt(); -  		promptToken.acquire();  		try { @@ -103,53 +100,33 @@ public class PromptHelper {  	 * Request a string response from parent. This is a blocking call until user  	 * interface returns a value.  	 * @param hint prompt hint for user to answer -	 * @param immediate whether to cancel other in-progress prompts  	 * @return string user has entered  	 */ -	public String requestStringPrompt(String instructions, String hint, boolean immediate) { +	public String requestStringPrompt(String instructions, String hint) {  		String value = null;  		try { -			value = (String)this.requestPrompt(instructions, hint, String.class, immediate); +			value = (String)this.requestPrompt(instructions, hint, String.class);  		} catch(Exception e) {  		}  		return value;  	}  	/** -	 * Convenience method for requestStringPrompt(String, boolean) -	 * @param hint prompt hint for user to answer -	 * @return string user has entered -	 */ -	public String requestStringPrompt(String instructions, String hint) { -		return requestStringPrompt(instructions, hint, false); -	} - -	/**  	 * Request a boolean response from parent. This is a blocking call until user  	 * interface returns a value.  	 * @param hint prompt hint for user to answer -	 * @param immediate whether to cancel other in-progress prompts  	 * @return choice user has made (yes/no)  	 */ -	public Boolean requestBooleanPrompt(String instructions, String hint, boolean immediate) { +	public Boolean requestBooleanPrompt(String instructions, String hint) {  		Boolean value = null;  		try { -			value = (Boolean)this.requestPrompt(instructions, hint, Boolean.class, immediate); +			value = (Boolean)this.requestPrompt(instructions, hint, Boolean.class);  		} catch(Exception e) {  		}  		return value;  	}  	/** -	 * Convenience method for requestBooleanPrompt(String, boolean) -	 * @param hint String to present to user in prompt -	 * @return choice user has made (yes/no) -	 */ -	public Boolean requestBooleanPrompt(String instructions, String hint) { -		return requestBooleanPrompt(instructions, hint, false); -	} - -	/**  	 * Cancel an in-progress prompt.  	 */  	public void cancelPrompt() { diff --git a/src/org/connectbot/service/TerminalBridge.java b/src/org/connectbot/service/TerminalBridge.java index db07bee..de507ad 100644 --- a/src/org/connectbot/service/TerminalBridge.java +++ b/src/org/connectbot/service/TerminalBridge.java @@ -255,7 +255,12 @@ public class TerminalBridge implements VDUDisplay, OnKeyListener {  			}  		}; -		buffer.setBufferSize(scrollback); +		// Don't keep any scrollback if a session is not being opened. +		if (host.getWantSession()) +			buffer.setBufferSize(scrollback); +		else +			buffer.setBufferSize(0); +  		resetColors();  		buffer.setDisplay(this); @@ -296,6 +301,7 @@ public class TerminalBridge implements VDUDisplay, OnKeyListener {  			}  		});  		connectionThread.setName("Connection"); +		connectionThread.setDaemon(true);  		connectionThread.start();  	} @@ -369,6 +375,8 @@ public class TerminalBridge implements VDUDisplay, OnKeyListener {  	 * authentication. If called before authenticated, it will just fail.  	 */  	public void onConnected() { +		disconnected = false; +  		((vt320) buffer).reset();  		// We no longer need our local output. @@ -386,6 +394,7 @@ public class TerminalBridge implements VDUDisplay, OnKeyListener {  		// create thread to relay incoming connection data to buffer  		relay = new Relay(this, transport, (vt320) buffer, host.getEncoding());  		Thread relayThread = new Thread(relay); +		relayThread.setDaemon(true);  		relayThread.setName("Relay");  		relayThread.start(); @@ -414,8 +423,15 @@ public class TerminalBridge implements VDUDisplay, OnKeyListener {  	 */  	public void dispatchDisconnect(boolean immediate) {  		// We don't need to do this multiple times. -		if (disconnected && !immediate) -			return; +		synchronized (this) { +			if (disconnected && !immediate) +				return; + +			disconnected = true; +		} + +		// Cancel any pending prompts. +		promptHelper.cancelPrompt();  		// disconnection request hangs if we havent really connected to a host yet  		// temporary fix is to just spawn disconnection into a thread @@ -428,17 +444,19 @@ public class TerminalBridge implements VDUDisplay, OnKeyListener {  		disconnectThread.setName("Disconnect");  		disconnectThread.start(); -		disconnected = true; -  		if (immediate) {  			awaitingClose = true;  			if (disconnectListener != null)  				disconnectListener.onDisconnected(TerminalBridge.this);  		} else { +			if (host.getStayConnected()) { +				startConnection(); +				return; +			}  			Thread disconnectPromptThread = new Thread(new Runnable() {  				public void run() {  					Boolean result = promptHelper.requestBooleanPrompt(null, -							manager.res.getString(R.string.prompt_host_disconnected), true); +							manager.res.getString(R.string.prompt_host_disconnected));  					if (result == null || result.booleanValue()) {  						awaitingClose = true; @@ -449,6 +467,7 @@ public class TerminalBridge implements VDUDisplay, OnKeyListener {  				}  			});  			disconnectPromptThread.setName("DisconnectPrompt"); +			disconnectPromptThread.setDaemon(true);  			disconnectPromptThread.start();  		}  	} @@ -459,8 +478,7 @@ public class TerminalBridge implements VDUDisplay, OnKeyListener {  	/**  	 * Handle onKey() events coming down from a {@link TerminalView} above us. -	 * We might collect these for our internal buffer when working with hostkeys -	 * or passwords, but otherwise we pass them directly over to the SSH host. +	 * Modify the keys to make more sense to a host then pass it to the transport.  	 */  	public boolean onKey(View v, int keyCode, KeyEvent event) {  		try { diff --git a/src/org/connectbot/transport/Local.java b/src/org/connectbot/transport/Local.java index 0c44e82..bbc8be0 100644 --- a/src/org/connectbot/transport/Local.java +++ b/src/org/connectbot/transport/Local.java @@ -135,6 +135,7 @@ public class Local extends AbsTransport {  		Thread exitWatcherThread = new Thread(exitWatcher);  		exitWatcherThread.setName("LocalExitWatcher"); +		exitWatcherThread.setDaemon(true);  		exitWatcherThread.start();  		is = new FileInputStream(shellFd); diff --git a/src/org/connectbot/transport/SSH.java b/src/org/connectbot/transport/SSH.java index f34f791..6ea6416 100644 --- a/src/org/connectbot/transport/SSH.java +++ b/src/org/connectbot/transport/SSH.java @@ -473,14 +473,20 @@ public class SSH extends AbsTransport implements ConnectionMonitor, InteractiveC  	public void close() {  		connected = false; -		if (session != null) +		if (session != null) {  			session.close(); -		if (connection != null) +			session = null; +		} + +		if (connection != null) {  			connection.close(); +			connection = null; +		}  	}  	private void onDisconnect() { -		connected = false; +		close(); +  		bridge.dispatchDisconnect(false);  	} @@ -560,7 +566,7 @@ public class SSH extends AbsTransport implements ConnectionMonitor, InteractiveC  	}  	public void connectionLost(Throwable reason) { -		bridge.dispatchDisconnect(true); +		onDisconnect();  	}  	@Override diff --git a/src/org/connectbot/util/HostDatabase.java b/src/org/connectbot/util/HostDatabase.java index b1b628d..89d5455 100644 --- a/src/org/connectbot/util/HostDatabase.java +++ b/src/org/connectbot/util/HostDatabase.java @@ -48,7 +48,7 @@ public class HostDatabase extends RobustSQLiteOpenHelper {  	public final static String TAG = "ConnectBot.HostDatabase";  	public final static String DB_NAME = "hosts"; -	public final static int DB_VERSION = 19; +	public final static int DB_VERSION = 20;  	public final static String TABLE_HOSTS = "hosts";  	public final static String FIELD_HOST_NICKNAME = "nickname"; @@ -68,6 +68,7 @@ public class HostDatabase extends RobustSQLiteOpenHelper {  	public final static String FIELD_HOST_DELKEY = "delkey";  	public final static String FIELD_HOST_COMPRESSION = "compression";  	public final static String FIELD_HOST_ENCODING = "encoding"; +	public final static String FIELD_HOST_STAYCONNECTED = "stayconnected";  	public final static String TABLE_PORTFORWARDS = "portforwards";  	public final static String FIELD_PORTFORWARD_HOSTID = "hostid"; @@ -144,7 +145,8 @@ public class HostDatabase extends RobustSQLiteOpenHelper {  				+ FIELD_HOST_DELKEY + " TEXT DEFAULT '" + DELKEY_DEL + "', "  				+ FIELD_HOST_WANTSESSION + " TEXT DEFAULT '" + Boolean.toString(true) + "', "  				+ FIELD_HOST_COMPRESSION + " TEXT DEFAULT '" + Boolean.toString(false) + "', " -				+ FIELD_HOST_ENCODING + " TEXT DEFAULT '" + ENCODING_DEFAULT + "')"); +				+ FIELD_HOST_ENCODING + " TEXT DEFAULT '" + ENCODING_DEFAULT + "', " +				+ FIELD_HOST_STAYCONNECTED + " TEXT)");  		db.execSQL("CREATE TABLE " + TABLE_PORTFORWARDS  				+ " (_id INTEGER PRIMARY KEY, " @@ -238,6 +240,9 @@ public class HostDatabase extends RobustSQLiteOpenHelper {  		case 18:  			db.execSQL("ALTER TABLE " + TABLE_HOSTS  					+ " ADD COLUMN " + FIELD_HOST_USEAUTHAGENT + " TEXT DEFAULT '" + AUTHAGENT_NO + "'"); +		case 19: +			db.execSQL("ALTER TABLE " + TABLE_HOSTS +					+ " ADD COLUMN " + FIELD_HOST_STAYCONNECTED + " TEXT");  		}  	} @@ -323,7 +328,9 @@ public class HostDatabase extends RobustSQLiteOpenHelper {  			COL_WANTSESSION = c.getColumnIndexOrThrow(FIELD_HOST_WANTSESSION),  			COL_DELKEY = c.getColumnIndexOrThrow(FIELD_HOST_DELKEY),  			COL_COMPRESSION = c.getColumnIndexOrThrow(FIELD_HOST_COMPRESSION), -			COL_ENCODING = c.getColumnIndexOrThrow(FIELD_HOST_ENCODING); +			COL_ENCODING = c.getColumnIndexOrThrow(FIELD_HOST_ENCODING), +			COL_STAYCONNECTED = c.getColumnIndexOrThrow(FIELD_HOST_STAYCONNECTED); +  		while (c.moveToNext()) {  			HostBean host = new HostBean(); @@ -344,6 +351,7 @@ public class HostDatabase extends RobustSQLiteOpenHelper {  			host.setDelKey(c.getString(COL_DELKEY));  			host.setCompression(Boolean.valueOf(c.getString(COL_COMPRESSION)));  			host.setEncoding(c.getString(COL_ENCODING)); +			host.setStayConnected(Boolean.valueOf(c.getString(COL_STAYCONNECTED)));  			hosts.add(host);  		}  | 
