annotate src/com/five_ten_sg/connectbot/transport/Local.java @ 52:0e3fc85d0586 tn5250

start tn5250 integration
author Carl Byington <carl@five-ten-sg.com>
date Wed, 11 Jun 2014 12:18:18 -0700
parents 139394237973
children 77ac18bc1b2f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
1 /*
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
2 * ConnectBot: simple, powerful, open-source SSH client for Android
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
3 * Copyright 2007 Kenny Root, Jeffrey Sharkey
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
4 *
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
5 * Licensed under the Apache License, Version 2.0 (the "License");
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
6 * you may not use this file except in compliance with the License.
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
7 * You may obtain a copy of the License at
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
8 *
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
9 * http://www.apache.org/licenses/LICENSE-2.0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
10 *
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
11 * Unless required by applicable law or agreed to in writing, software
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
12 * distributed under the License is distributed on an "AS IS" BASIS,
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
14 * See the License for the specific language governing permissions and
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
15 * limitations under the License.
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
16 */
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
17
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
18 package com.five_ten_sg.connectbot.transport;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
19
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
20 import java.io.FileDescriptor;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
21 import java.io.FileInputStream;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
22 import java.io.FileOutputStream;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
23 import java.io.IOException;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
24 import java.util.Map;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
25
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
26 import com.five_ten_sg.connectbot.R;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
27 import com.five_ten_sg.connectbot.bean.HostBean;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
28 import com.five_ten_sg.connectbot.service.TerminalBridge;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
29 import com.five_ten_sg.connectbot.service.TerminalManager;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
30 import com.five_ten_sg.connectbot.util.HostDatabase;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
31 import android.content.Context;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
32 import android.net.Uri;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
33 import android.util.Log;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
34
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
35 import com.google.ase.Exec;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
36
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
37 /**
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
38 * @author Kenny Root
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
39 *
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
40 */
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
41 public class Local extends AbsTransport {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
42 private static final String TAG = "ConnectBot.Local";
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
43 private static final String PROTOCOL = "local";
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
44 private static final String DEFAULT_URI = "local:#Local";
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
45
31
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
46 private FileDescriptor shellFd;
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
47 private FileInputStream is;
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
48 private FileOutputStream os;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
49
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
50 /**
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
51 *
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
52 */
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
53 public Local() {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
54 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
55
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
56
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
57 public static String getProtocolName() {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
58 return PROTOCOL;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
59 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
60
31
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
61
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
62 public Uri getUri(String input) {
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
63 Uri uri = Uri.parse(DEFAULT_URI);
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
64
31
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
65 if (input != null && input.length() > 0) {
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
66 uri = uri.buildUpon().fragment(input).build();
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
67 }
31
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
68
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
69 return uri;
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
70 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
71
31
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
72
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
73 @Override
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
74 public void connect() {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
75 int[] pids = new int[1];
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
76
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
77 try {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
78 shellFd = Exec.createSubprocess("/system/bin/sh", "-", null, pids);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
79 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
80 catch (Exception e) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
81 bridge.outputLine(manager.res.getString(R.string.local_shell_unavailable));
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
82 Log.e(TAG, "Cannot start local shell", e);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
83 return;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
84 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
85
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
86 final int shellPid = pids[0];
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
87 Runnable exitWatcher = new Runnable() {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
88 public void run() {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
89 Exec.waitFor(shellPid);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
90 bridge.dispatchDisconnect(false);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
91 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
92 };
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
93 Thread exitWatcherThread = new Thread(exitWatcher);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
94 exitWatcherThread.setName("LocalExitWatcher");
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
95 exitWatcherThread.setDaemon(true);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
96 exitWatcherThread.start();
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
97 is = new FileInputStream(shellFd);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
98 os = new FileOutputStream(shellFd);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
99 bridge.onConnected();
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
100 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
101
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
102
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
103 @Override
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
104 public boolean willBlock() {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
105 if (is == null) return true;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
106 try {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
107 return is.available() == 0;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
108 } catch (Exception e) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
109 return true;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
110 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
111 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
112
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
113 @Override
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
114 public int read(byte[] buffer, int start, int len) throws IOException {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
115 if (is == null) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
116 bridge.dispatchDisconnect(false);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
117 throw new IOException("session closed");
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
118 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
119
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
120 return is.read(buffer, start, len);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
121 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
122
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
123 @Override
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
124 public void write(byte[] buffer) throws IOException {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
125 if (os != null)
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
126 os.write(buffer);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
127 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
128
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
129 @Override
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
130 public void write(int c) throws IOException {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
131 if (os != null)
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
132 os.write(c);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
133 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
134
31
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
135 @Override
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
136 public void flush() throws IOException {
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
137 os.flush();
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
138 }
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
139
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
140 @Override
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
141 public void close() {
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
142 try {
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
143 if (os != null) {
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
144 os.close();
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
145 os = null;
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
146 }
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
147
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
148 if (is != null) {
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
149 is.close();
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
150 is = null;
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
151 }
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
152 }
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
153 catch (IOException e) {
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
154 Log.e(TAG, "Couldn't close shell", e);
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
155 }
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
156 }
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
157
31
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
158 @Override
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
159 public void setDimensions(int columns, int rows, int width, int height) {
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
160 try {
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
161 Exec.setPtyWindowSize(shellFd, rows, columns, width, height);
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
162 }
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
163 catch (Exception e) {
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
164 Log.e(TAG, "Couldn't resize pty", e);
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
165 }
31
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
166 }
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
167
31
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
168 @Override
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
169 public int getDefaultPort() {
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
170 return 0;
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
171 }
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
172
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
173 @Override
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
174 public boolean isConnected() {
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
175 return is != null && os != null;
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
176 }
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
177
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
178 @Override
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
179 public boolean isSessionOpen() {
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
180 return isConnected();
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
181 }
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
182
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
183 @Override
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
184 public boolean isAuthenticated() {
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
185 return isConnected();
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
186 }
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
187
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
188 @Override
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
189 public String getDefaultNickname(String username, String hostname, int port) {
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
190 return DEFAULT_URI;
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
191 }
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
192
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
193 @Override
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
194 public void getSelectionArgs(Uri uri, Map<String, String> selection) {
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
195 selection.put(HostDatabase.FIELD_HOST_PROTOCOL, PROTOCOL);
139394237973 start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents: 12
diff changeset
196 selection.put(HostDatabase.FIELD_HOST_NICKNAME, uri.getFragment());
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
197 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
198
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
199 @Override
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
200 public HostBean createHost(Uri uri) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
201 HostBean host = new HostBean();
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
202 host.setProtocol(PROTOCOL);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
203 String nickname = uri.getFragment();
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
204
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
205 if (nickname == null || nickname.length() == 0) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
206 host.setNickname(getDefaultNickname(host.getUsername(),
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
207 host.getHostname(), host.getPort()));
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
208 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
209 else {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
210 host.setNickname(uri.getFragment());
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
211 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
212
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
213 return host;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
214 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
215
12
6aaefb22d876 adding tn5250 files
Carl Byington <carl@five-ten-sg.com>
parents: 0
diff changeset
216 public String getFormatHint(Context context) {
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
217 return context.getString(R.string.hostpref_nickname_title);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
218 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
219
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
220 @Override
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
221 public boolean usesNetwork() {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
222 return false;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
223 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
224 }