Mercurial > 510Connectbot
annotate app/src/main/java/com/five_ten_sg/connectbot/HostListActivity.java @ 499:267e72057707
updates for android10+
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Tue, 07 Jun 2022 16:04:52 -0700 |
parents | 3feac274a27b |
children | 11d714165a2d |
rev | line source |
---|---|
0 | 1 /* |
2 * ConnectBot: simple, powerful, open-source SSH client for Android | |
3 * Copyright 2007 Kenny Root, Jeffrey Sharkey | |
4 * | |
5 * Licensed under the Apache License, Version 2.0 (the "License"); | |
6 * you may not use this file except in compliance with the License. | |
7 * You may obtain a copy of the License at | |
8 * | |
9 * http://www.apache.org/licenses/LICENSE-2.0 | |
10 * | |
11 * Unless required by applicable law or agreed to in writing, software | |
12 * distributed under the License is distributed on an "AS IS" BASIS, | |
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 * See the License for the specific language governing permissions and | |
15 * limitations under the License. | |
16 */ | |
17 | |
18 package com.five_ten_sg.connectbot; | |
19 | |
20 | |
21 import com.five_ten_sg.connectbot.bean.HostBean; | |
22 import com.five_ten_sg.connectbot.service.TerminalBridge; | |
23 import com.five_ten_sg.connectbot.service.TerminalManager; | |
24 import com.five_ten_sg.connectbot.transport.TransportFactory; | |
25 import com.five_ten_sg.connectbot.util.HostDatabase; | |
26 import com.five_ten_sg.connectbot.util.PreferenceConstants; | |
135
e251b3b679c3
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
134
diff
changeset
|
27 |
e251b3b679c3
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
134
diff
changeset
|
28 import java.io.BufferedReader; |
136
398503d13f35
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
135
diff
changeset
|
29 import java.io.FileReader; |
134
81cafbe7cd9b
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
132
diff
changeset
|
30 import java.io.File; |
195
e98ac723383f
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
194
diff
changeset
|
31 import java.util.HashMap; |
135
e251b3b679c3
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
134
diff
changeset
|
32 import java.util.List; |
e251b3b679c3
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
134
diff
changeset
|
33 |
0 | 34 import android.app.Activity; |
35 import android.app.AlertDialog; | |
36 import android.app.ListActivity; | |
37 import android.content.ComponentName; | |
135
e251b3b679c3
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
134
diff
changeset
|
38 import android.content.ContentValues; |
0 | 39 import android.content.Context; |
40 import android.content.DialogInterface; | |
41 import android.content.Intent; | |
42 import android.content.Intent.ShortcutIconResource; | |
43 import android.content.ServiceConnection; | |
44 import android.content.SharedPreferences; | |
45 import android.content.SharedPreferences.Editor; | |
46 import android.content.res.ColorStateList; | |
135
e251b3b679c3
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
134
diff
changeset
|
47 import android.database.sqlite.SQLiteDatabase; |
0 | 48 import android.net.Uri; |
49 import android.os.Build; | |
50 import android.os.Bundle; | |
132
265a4733edcb
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
51 import android.os.Environment; |
0 | 52 import android.os.Handler; |
53 import android.os.IBinder; | |
54 import android.os.Message; | |
55 import android.preference.PreferenceManager; | |
498
3feac274a27b
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
497
diff
changeset
|
56 import android.provider.Settings; |
0 | 57 import android.util.Log; |
58 import android.view.ContextMenu; | |
59 import android.view.KeyEvent; | |
60 import android.view.LayoutInflater; | |
61 import android.view.Menu; | |
62 import android.view.MenuItem; | |
63 import android.view.MenuItem.OnMenuItemClickListener; | |
64 import android.view.View; | |
65 import android.view.View.OnKeyListener; | |
66 import android.view.ViewGroup; | |
67 import android.widget.AdapterView; | |
68 import android.widget.AdapterView.OnItemClickListener; | |
69 import android.widget.ArrayAdapter; | |
70 import android.widget.ImageView; | |
71 import android.widget.ListView; | |
72 import android.widget.Spinner; | |
73 import android.widget.TextView; | |
465
7c8aebcc882a
request permissions if not already granted
Carl Byington <carl@five-ten-sg.com>
parents:
457
diff
changeset
|
74 import android.content.pm.PackageManager; |
7c8aebcc882a
request permissions if not already granted
Carl Byington <carl@five-ten-sg.com>
parents:
457
diff
changeset
|
75 import android.os.Build; |
7c8aebcc882a
request permissions if not already granted
Carl Byington <carl@five-ten-sg.com>
parents:
457
diff
changeset
|
76 import android.Manifest; |
7c8aebcc882a
request permissions if not already granted
Carl Byington <carl@five-ten-sg.com>
parents:
457
diff
changeset
|
77 import android.support.v4.app.ActivityCompat; |
7c8aebcc882a
request permissions if not already granted
Carl Byington <carl@five-ten-sg.com>
parents:
457
diff
changeset
|
78 import android.support.v4.content.ContextCompat; |
0 | 79 |
80 public class HostListActivity extends ListActivity { | |
134
81cafbe7cd9b
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
132
diff
changeset
|
81 protected static final String TAG = "ConnectBot.HostListActivity"; |
0 | 82 public final static int REQUEST_EDIT = 1; |
83 public final static int REQUEST_EULA = 2; | |
84 | |
85 protected TerminalManager bound = null; | |
86 | |
87 protected HostDatabase hostdb; | |
88 private List<HostBean> hosts; | |
89 protected LayoutInflater inflater = null; | |
90 | |
91 protected boolean sortedByColor = false; | |
92 | |
93 private MenuItem sortcolor; | |
94 | |
95 private MenuItem sortlast; | |
96 | |
97 private Spinner transportSpinner; | |
98 private TextView quickconnect; | |
99 | |
100 private SharedPreferences prefs = null; | |
101 | |
102 protected boolean makingShortcut = false; | |
103 | |
104 protected Handler updateHandler = new Handler() { | |
105 @Override | |
106 public void handleMessage(Message msg) { | |
107 HostListActivity.this.updateList(); | |
108 } | |
109 }; | |
110 | |
111 private ServiceConnection connection = new ServiceConnection() { | |
112 public void onServiceConnected(ComponentName className, IBinder service) { | |
113 bound = ((TerminalManager.TerminalBinder) service).getService(); | |
114 // update our listview binder to find the service | |
34
75d86b7fd3f0
make hostlist and pubkeylist consistent
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
115 updateList(); |
0 | 116 } |
117 public void onServiceDisconnected(ComponentName className) { | |
118 bound = null; | |
34
75d86b7fd3f0
make hostlist and pubkeylist consistent
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
119 updateList(); |
0 | 120 } |
121 }; | |
122 | |
123 @Override | |
124 public void onStart() { | |
125 super.onStart(); | |
126 // start the terminal manager service | |
127 this.bindService(new Intent(this, TerminalManager.class), connection, Context.BIND_AUTO_CREATE); | |
128 | |
129 if (this.hostdb == null) | |
130 this.hostdb = new HostDatabase(this); | |
131 } | |
132 | |
133 @Override | |
134 public void onStop() { | |
135 super.onStop(); | |
136 this.unbindService(connection); | |
137 | |
138 if (this.hostdb != null) { | |
139 this.hostdb.close(); | |
140 this.hostdb = null; | |
141 } | |
142 } | |
143 | |
144 @Override | |
145 public void onResume() { | |
146 super.onResume(); | |
147 } | |
148 | |
149 @Override | |
150 protected void onActivityResult(int requestCode, int resultCode, Intent data) { | |
151 if (requestCode == REQUEST_EULA) { | |
152 if (resultCode == Activity.RESULT_OK) { | |
153 // yay they agreed, so store that info | |
198
a9fb5061cca3
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
197
diff
changeset
|
154 Editor editor = prefs.edit(); |
a9fb5061cca3
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
197
diff
changeset
|
155 editor.putBoolean(PreferenceConstants.EULA, true); |
a9fb5061cca3
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
197
diff
changeset
|
156 editor.commit(); |
0 | 157 } |
158 else { | |
159 // user didnt agree, so close | |
160 this.finish(); | |
161 } | |
162 } | |
163 else if (requestCode == REQUEST_EDIT) { | |
34
75d86b7fd3f0
make hostlist and pubkeylist consistent
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
164 updateList(); |
0 | 165 } |
166 } | |
167 | |
168 @Override | |
169 public void onCreate(Bundle icicle) { | |
170 super.onCreate(icicle); | |
171 setContentView(R.layout.act_hostlist); | |
172 this.setTitle(String.format("%s: %s", | |
173 getResources().getText(R.string.app_name), | |
174 getResources().getText(R.string.title_hosts_list))); | |
175 this.prefs = PreferenceManager.getDefaultSharedPreferences(this); | |
176 | |
465
7c8aebcc882a
request permissions if not already granted
Carl Byington <carl@five-ten-sg.com>
parents:
457
diff
changeset
|
177 // ask for permissions, must match AndroidManifest.xml |
7c8aebcc882a
request permissions if not already granted
Carl Byington <carl@five-ten-sg.com>
parents:
457
diff
changeset
|
178 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { |
499
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
179 get_permissions(new String[] {Manifest.permission.ACCESS_NETWORK_STATE, |
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
180 Manifest.permission.INTERNET, |
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
181 Manifest.permission.WAKE_LOCK}); |
498
3feac274a27b
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
497
diff
changeset
|
182 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { |
499
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
183 get_storage_manager(); |
498
3feac274a27b
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
497
diff
changeset
|
184 } |
3feac274a27b
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
497
diff
changeset
|
185 else { |
499
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
186 get_permissions(new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE}); |
498
3feac274a27b
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
497
diff
changeset
|
187 } |
465
7c8aebcc882a
request permissions if not already granted
Carl Byington <carl@five-ten-sg.com>
parents:
457
diff
changeset
|
188 } |
7c8aebcc882a
request permissions if not already granted
Carl Byington <carl@five-ten-sg.com>
parents:
457
diff
changeset
|
189 |
0 | 190 // detect HTC Dream and apply special preferences |
191 if (Build.MANUFACTURER.equals("HTC") && Build.DEVICE.equals("dream")) { | |
192 if (!prefs.contains(PreferenceConstants.SHIFT_FKEYS) && | |
193 !prefs.contains(PreferenceConstants.CTRL_FKEYS)) { | |
199
33928f24b40d
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
198
diff
changeset
|
194 Editor editor = prefs.edit(); |
0 | 195 editor.putBoolean(PreferenceConstants.SHIFT_FKEYS, true); |
196 editor.putBoolean(PreferenceConstants.CTRL_FKEYS, true); | |
197 editor.commit(); | |
198 } | |
199 } | |
200 | |
359
93621e963303
allow eula agreement to be set from deployment.connections
Carl Byington <carl@five-ten-sg.com>
parents:
307
diff
changeset
|
201 makingShortcut = Intent.ACTION_CREATE_SHORTCUT.equals(getIntent().getAction()) |
93621e963303
allow eula agreement to be set from deployment.connections
Carl Byington <carl@five-ten-sg.com>
parents:
307
diff
changeset
|
202 || Intent.ACTION_PICK.equals(getIntent().getAction()); |
93621e963303
allow eula agreement to be set from deployment.connections
Carl Byington <carl@five-ten-sg.com>
parents:
307
diff
changeset
|
203 |
93621e963303
allow eula agreement to be set from deployment.connections
Carl Byington <carl@five-ten-sg.com>
parents:
307
diff
changeset
|
204 // connect with hosts database, read deployment file, and populate list |
93621e963303
allow eula agreement to be set from deployment.connections
Carl Byington <carl@five-ten-sg.com>
parents:
307
diff
changeset
|
205 hostdb = new HostDatabase(this); |
466
12e2d9dd95df
add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
465
diff
changeset
|
206 // build hosts from a deployment text file |
12e2d9dd95df
add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
465
diff
changeset
|
207 Uri launch = createDeploymentHosts(); |
359
93621e963303
allow eula agreement to be set from deployment.connections
Carl Byington <carl@five-ten-sg.com>
parents:
307
diff
changeset
|
208 updateList(); |
93621e963303
allow eula agreement to be set from deployment.connections
Carl Byington <carl@five-ten-sg.com>
parents:
307
diff
changeset
|
209 |
93621e963303
allow eula agreement to be set from deployment.connections
Carl Byington <carl@five-ten-sg.com>
parents:
307
diff
changeset
|
210 // check for eula agreement, which might be set from the deployment file |
0 | 211 boolean agreed = prefs.getBoolean(PreferenceConstants.EULA, false); |
212 if (!agreed) { | |
34
75d86b7fd3f0
make hostlist and pubkeylist consistent
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
213 startActivityForResult(new Intent(this, WizardActivity.class), REQUEST_EULA); |
0 | 214 } |
215 | |
359
93621e963303
allow eula agreement to be set from deployment.connections
Carl Byington <carl@five-ten-sg.com>
parents:
307
diff
changeset
|
216 // show the list |
34
75d86b7fd3f0
make hostlist and pubkeylist consistent
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
217 sortedByColor = prefs.getBoolean(PreferenceConstants.SORT_BY_COLOR, false); |
75d86b7fd3f0
make hostlist and pubkeylist consistent
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
218 registerForContextMenu(getListView()); |
75d86b7fd3f0
make hostlist and pubkeylist consistent
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
219 getListView().setOnItemClickListener(new OnItemClickListener() { |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
35
diff
changeset
|
220 |
0 | 221 public synchronized void onItemClick(AdapterView<?> parent, View view, int position, long id) { |
222 // launch off to console details | |
34
75d86b7fd3f0
make hostlist and pubkeylist consistent
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
223 HostBean host = (HostBean) getListView().getItemAtPosition(position); |
0 | 224 Uri uri = host.getUri(); |
225 Intent contents = new Intent(Intent.ACTION_VIEW, uri); | |
226 contents.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); | |
227 | |
228 if (makingShortcut) { | |
229 // create shortcut if requested | |
230 ShortcutIconResource icon = Intent.ShortcutIconResource.fromContext(HostListActivity.this, R.drawable.icon); | |
231 Intent intent = new Intent(); | |
232 intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, contents); | |
233 intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, host.getNickname()); | |
234 intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon); | |
235 setResult(RESULT_OK, intent); | |
236 finish(); | |
237 } | |
238 else { | |
239 // otherwise just launch activity to show this host | |
34
75d86b7fd3f0
make hostlist and pubkeylist consistent
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
240 startActivity(contents); |
0 | 241 } |
242 } | |
243 }); | |
244 quickconnect = (TextView) this.findViewById(R.id.front_quickconnect); | |
245 quickconnect.setVisibility(makingShortcut ? View.GONE : View.VISIBLE); | |
246 quickconnect.setOnKeyListener(new OnKeyListener() { | |
247 public boolean onKey(View v, int keyCode, KeyEvent event) { | |
248 if (event.getAction() == KeyEvent.ACTION_UP) return false; | |
249 | |
250 if (keyCode != KeyEvent.KEYCODE_ENTER) return false; | |
251 | |
252 return startConsoleActivity(); | |
253 } | |
254 }); | |
255 transportSpinner = (Spinner)findViewById(R.id.transport_selection); | |
256 transportSpinner.setVisibility(makingShortcut ? View.GONE : View.VISIBLE); | |
257 ArrayAdapter<String> transportSelection = new ArrayAdapter<String> (this, | |
258 android.R.layout.simple_spinner_item, TransportFactory.getTransportNames()); | |
259 transportSelection.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); | |
260 transportSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { | |
261 public void onItemSelected(AdapterView<?> arg0, View view, int position, long id) { | |
262 String formatHint = TransportFactory.getFormatHint( | |
263 (String) transportSpinner.getSelectedItem(), | |
264 HostListActivity.this); | |
265 quickconnect.setHint(formatHint); | |
266 quickconnect.setError(null); | |
267 quickconnect.requestFocus(); | |
268 } | |
269 public void onNothingSelected(AdapterView<?> arg0) { } | |
270 }); | |
271 transportSpinner.setAdapter(transportSelection); | |
272 this.inflater = LayoutInflater.from(this); | |
466
12e2d9dd95df
add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
465
diff
changeset
|
273 |
12e2d9dd95df
add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
465
diff
changeset
|
274 if (launch != null) { |
12e2d9dd95df
add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
465
diff
changeset
|
275 Intent contents = new Intent(Intent.ACTION_VIEW, launch); |
12e2d9dd95df
add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
465
diff
changeset
|
276 contents.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); |
12e2d9dd95df
add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
465
diff
changeset
|
277 startActivity(contents); |
12e2d9dd95df
add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
465
diff
changeset
|
278 } |
0 | 279 } |
280 | |
499
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
281 public void get_storage_manager() { |
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
282 if (!Environment.isExternalStorageManager()) { |
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
283 try { |
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
284 Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION); |
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
285 intent.addCategory("android.intent.category.DEFAULT"); |
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
286 intent.setData(Uri.parse(String.format("package:%s",getApplicationContext().getPackageName()))); |
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
287 startActivityForResult(intent, 31415); |
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
288 } catch (Exception e) { |
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
289 Intent intent = new Intent(); |
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
290 intent.setAction(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION); |
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
291 startActivityForResult(intent, 31415); |
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
292 } |
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
293 } |
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
294 } |
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
295 |
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
296 @Override |
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
297 protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { |
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
298 super.onActivityResult(requestCode, resultCode, data); |
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
299 if (requestCode == 31415) { |
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
300 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { |
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
301 if (!Environment.isExternalStorageManager()) { |
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
302 Toast.makeText(this, "Allow permission for storage access!", Toast.LENGTH_SHORT).show(); |
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
303 } |
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
304 } |
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
305 } |
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
306 } |
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
307 |
267e72057707
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
498
diff
changeset
|
308 public void get_permissions(String [] perms) { |
465
7c8aebcc882a
request permissions if not already granted
Carl Byington <carl@five-ten-sg.com>
parents:
457
diff
changeset
|
309 boolean need = false; |
7c8aebcc882a
request permissions if not already granted
Carl Byington <carl@five-ten-sg.com>
parents:
457
diff
changeset
|
310 for (String perm : perms) { |
7c8aebcc882a
request permissions if not already granted
Carl Byington <carl@five-ten-sg.com>
parents:
457
diff
changeset
|
311 if (ContextCompat.checkSelfPermission(this, perm) != PackageManager.PERMISSION_GRANTED) { |
7c8aebcc882a
request permissions if not already granted
Carl Byington <carl@five-ten-sg.com>
parents:
457
diff
changeset
|
312 need = true; |
7c8aebcc882a
request permissions if not already granted
Carl Byington <carl@five-ten-sg.com>
parents:
457
diff
changeset
|
313 } |
7c8aebcc882a
request permissions if not already granted
Carl Byington <carl@five-ten-sg.com>
parents:
457
diff
changeset
|
314 } |
7c8aebcc882a
request permissions if not already granted
Carl Byington <carl@five-ten-sg.com>
parents:
457
diff
changeset
|
315 if (need) ActivityCompat.requestPermissions(this, perms, 1); |
7c8aebcc882a
request permissions if not already granted
Carl Byington <carl@five-ten-sg.com>
parents:
457
diff
changeset
|
316 } |
7c8aebcc882a
request permissions if not already granted
Carl Byington <carl@five-ten-sg.com>
parents:
457
diff
changeset
|
317 |
0 | 318 @Override |
319 public boolean onPrepareOptionsMenu(Menu menu) { | |
320 super.onPrepareOptionsMenu(menu); | |
321 | |
322 // don't offer menus when creating shortcut | |
323 if (makingShortcut) return true; | |
324 | |
325 sortcolor.setVisible(!sortedByColor); | |
326 sortlast.setVisible(sortedByColor); | |
327 return true; | |
328 } | |
329 | |
330 @Override | |
331 public boolean onCreateOptionsMenu(Menu menu) { | |
332 super.onCreateOptionsMenu(menu); | |
333 | |
334 // don't offer menus when creating shortcut | |
335 if (makingShortcut) return true; | |
336 | |
337 // add host, ssh keys, about | |
338 sortcolor = menu.add(R.string.list_menu_sortcolor); | |
339 sortcolor.setIcon(android.R.drawable.ic_menu_share); | |
340 sortcolor.setOnMenuItemClickListener(new OnMenuItemClickListener() { | |
341 public boolean onMenuItemClick(MenuItem item) { | |
342 sortedByColor = true; | |
343 updateList(); | |
344 return true; | |
345 } | |
346 }); | |
347 sortlast = menu.add(R.string.list_menu_sortname); | |
348 sortlast.setIcon(android.R.drawable.ic_menu_share); | |
349 sortlast.setOnMenuItemClickListener(new OnMenuItemClickListener() { | |
350 public boolean onMenuItemClick(MenuItem item) { | |
351 sortedByColor = false; | |
352 updateList(); | |
353 return true; | |
354 } | |
355 }); | |
356 MenuItem keys = menu.add(R.string.list_menu_pubkeys); | |
357 keys.setIcon(android.R.drawable.ic_lock_lock); | |
358 keys.setIntent(new Intent(HostListActivity.this, PubkeyListActivity.class)); | |
359 MenuItem colors = menu.add(R.string.title_colors); | |
360 colors.setIcon(android.R.drawable.ic_menu_slideshow); | |
361 colors.setIntent(new Intent(HostListActivity.this, ColorsActivity.class)); | |
362 MenuItem settings = menu.add(R.string.list_menu_settings); | |
363 settings.setIcon(android.R.drawable.ic_menu_preferences); | |
364 settings.setIntent(new Intent(HostListActivity.this, SettingsActivity.class)); | |
365 MenuItem help = menu.add(R.string.title_help); | |
366 help.setIcon(android.R.drawable.ic_menu_help); | |
367 help.setIntent(new Intent(HostListActivity.this, HelpActivity.class)); | |
368 return true; | |
369 } | |
370 | |
371 | |
372 @Override | |
373 public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { | |
374 // create menu to handle hosts | |
375 // create menu to handle deleting and sharing lists | |
376 AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; | |
377 final HostBean host = (HostBean) this.getListView().getItemAtPosition(info.position); | |
378 menu.setHeaderTitle(host.getNickname()); | |
379 // edit, disconnect, delete | |
380 MenuItem connect = menu.add(R.string.list_host_disconnect); | |
381 final TerminalBridge bridge = bound.getConnectedBridge(host); | |
382 connect.setEnabled((bridge != null)); | |
383 connect.setOnMenuItemClickListener(new OnMenuItemClickListener() { | |
384 public boolean onMenuItemClick(MenuItem item) { | |
385 bridge.dispatchDisconnect(true); | |
386 updateHandler.sendEmptyMessage(-1); | |
387 return true; | |
388 } | |
389 }); | |
390 MenuItem edit = menu.add(R.string.list_host_edit); | |
391 edit.setOnMenuItemClickListener(new OnMenuItemClickListener() { | |
392 public boolean onMenuItemClick(MenuItem item) { | |
393 Intent intent = new Intent(HostListActivity.this, HostEditorActivity.class); | |
394 intent.putExtra(Intent.EXTRA_TITLE, host.getId()); | |
395 HostListActivity.this.startActivityForResult(intent, REQUEST_EDIT); | |
396 return true; | |
397 } | |
398 }); | |
399 MenuItem portForwards = menu.add(R.string.list_host_portforwards); | |
400 portForwards.setOnMenuItemClickListener(new OnMenuItemClickListener() { | |
401 public boolean onMenuItemClick(MenuItem item) { | |
402 Intent intent = new Intent(HostListActivity.this, PortForwardListActivity.class); | |
403 intent.putExtra(Intent.EXTRA_TITLE, host.getId()); | |
404 HostListActivity.this.startActivityForResult(intent, REQUEST_EDIT); | |
405 return true; | |
406 } | |
407 }); | |
408 | |
409 if (!TransportFactory.canForwardPorts(host.getProtocol())) | |
410 portForwards.setEnabled(false); | |
411 | |
412 MenuItem delete = menu.add(R.string.list_host_delete); | |
413 delete.setOnMenuItemClickListener(new OnMenuItemClickListener() { | |
414 public boolean onMenuItemClick(MenuItem item) { | |
415 // prompt user to make sure they really want this | |
416 new AlertDialog.Builder(HostListActivity.this) | |
417 .setMessage(getString(R.string.delete_message, host.getNickname())) | |
418 .setPositiveButton(R.string.delete_pos, new DialogInterface.OnClickListener() { | |
419 public void onClick(DialogInterface dialog, int which) { | |
420 // make sure we disconnect | |
421 if (bridge != null) | |
422 bridge.dispatchDisconnect(true); | |
423 | |
424 hostdb.deleteHost(host); | |
425 updateHandler.sendEmptyMessage(-1); | |
426 } | |
427 }) | |
428 .setNegativeButton(R.string.delete_neg, null).create().show(); | |
429 return true; | |
430 } | |
431 }); | |
432 } | |
433 | |
434 /** | |
435 * @param text | |
436 * @return | |
437 */ | |
438 private boolean startConsoleActivity() { | |
439 Uri uri = TransportFactory.getUri((String) transportSpinner | |
440 .getSelectedItem(), quickconnect.getText().toString()); | |
441 | |
442 if (uri == null) { | |
443 quickconnect.setError(getString(R.string.list_format_error, | |
444 TransportFactory.getFormatHint( | |
445 (String) transportSpinner.getSelectedItem(), | |
446 HostListActivity.this))); | |
447 return false; | |
448 } | |
449 | |
450 HostBean host = TransportFactory.findHost(hostdb, uri); | |
451 | |
452 if (host == null) { | |
453 host = TransportFactory.getTransport(uri.getScheme()).createHost(uri); | |
454 host.setColor(HostDatabase.COLOR_GRAY); | |
455 host.setPubkeyId(HostDatabase.PUBKEYID_ANY); | |
456 hostdb.saveHost(host); | |
457 } | |
458 | |
459 Intent intent = new Intent(HostListActivity.this, ConsoleActivity.class); | |
460 intent.setData(uri); | |
461 startActivity(intent); | |
462 return true; | |
463 } | |
464 | |
466
12e2d9dd95df
add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
465
diff
changeset
|
465 private Uri createDeploymentHosts() { |
12e2d9dd95df
add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
465
diff
changeset
|
466 Uri launch = null; |
132
265a4733edcb
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
467 try { |
466
12e2d9dd95df
add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
465
diff
changeset
|
468 boolean del = true; |
473
ece82b571900
add fg/bg color setting to global:// section of deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
468
diff
changeset
|
469 int[] c = hostdb.getGlobalDefaultColors(); |
ece82b571900
add fg/bg color setting to global:// section of deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
468
diff
changeset
|
470 int fg = c[0]; |
ece82b571900
add fg/bg color setting to global:// section of deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
468
diff
changeset
|
471 int bg = c[1]; |
497
73fa7329dc87
updates for android10+
Carl Byington <carl@five-ten-sg.com>
parents:
476
diff
changeset
|
472 String fn = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath() + |
132
265a4733edcb
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
473 File.separator + "deployment.connections"; |
265a4733edcb
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
474 BufferedReader reader = new BufferedReader(new FileReader(fn)); |
265a4733edcb
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
475 String line = null; |
307 | 476 |
132
265a4733edcb
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
477 while ((line = reader.readLine()) != null) { |
265a4733edcb
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
478 if (line.length() == 0) continue; // empty |
307 | 479 |
480 if (line.substring(0, 1).equals("#")) continue; // comment | |
481 | |
132
265a4733edcb
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
482 if (!line.contains("://")) continue; // invalid uri |
307 | 483 |
132
265a4733edcb
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
484 Uri uri = Uri.parse(line); |
265a4733edcb
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
485 ContentValues values = null; |
307 | 486 |
468
74b507d491c9
fix parsing of global:: scheme
Carl Byington <carl@five-ten-sg.com>
parents:
466
diff
changeset
|
487 while ((line = reader.readLine()) != null) { |
74b507d491c9
fix parsing of global:: scheme
Carl Byington <carl@five-ten-sg.com>
parents:
466
diff
changeset
|
488 if (line.length() == 0) break; // empty |
74b507d491c9
fix parsing of global:: scheme
Carl Byington <carl@five-ten-sg.com>
parents:
466
diff
changeset
|
489 |
74b507d491c9
fix parsing of global:: scheme
Carl Byington <carl@five-ten-sg.com>
parents:
466
diff
changeset
|
490 if (line.substring(0, 1).equals("#")) continue; // comment |
74b507d491c9
fix parsing of global:: scheme
Carl Byington <carl@five-ten-sg.com>
parents:
466
diff
changeset
|
491 |
132
265a4733edcb
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
492 String [] parts = line.split("="); |
307 | 493 |
135
e251b3b679c3
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
134
diff
changeset
|
494 if (parts.length != 2) continue; |
307 | 495 |
132
265a4733edcb
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
496 if (values == null) values = new ContentValues(); |
307 | 497 |
197
e762997c3911
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
196
diff
changeset
|
498 values.put(parts[0].trim(), parts[1].trim()); |
132
265a4733edcb
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
499 } |
307 | 500 |
468
74b507d491c9
fix parsing of global:: scheme
Carl Byington <carl@five-ten-sg.com>
parents:
466
diff
changeset
|
501 String scheme = uri.getScheme(); |
74b507d491c9
fix parsing of global:: scheme
Carl Byington <carl@five-ten-sg.com>
parents:
466
diff
changeset
|
502 if (scheme.equals("global")) { |
466
12e2d9dd95df
add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
465
diff
changeset
|
503 String dd = "delete_deployment"; |
12e2d9dd95df
add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
465
diff
changeset
|
504 if (values.containsKey(dd)) { |
12e2d9dd95df
add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
465
diff
changeset
|
505 String sv = values.getAsString(dd); |
12e2d9dd95df
add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
465
diff
changeset
|
506 del = Boolean.parseBoolean(sv); |
12e2d9dd95df
add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
465
diff
changeset
|
507 } |
474
e5f8d879543f
add fg/bg color setting to global:// section of deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
473
diff
changeset
|
508 dd = "fg_color"; |
475
0fb80a0d6be9
add fg/bg color setting to global:// section of deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
474
diff
changeset
|
509 if (values.containsKey(dd)) { |
473
ece82b571900
add fg/bg color setting to global:// section of deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
468
diff
changeset
|
510 String sv = values.getAsString(dd); |
476
186d340afd3b
add fg/bg color setting to global:// section of deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
475
diff
changeset
|
511 fg = Integer.parseInt(sv) - 1; |
473
ece82b571900
add fg/bg color setting to global:// section of deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
468
diff
changeset
|
512 } |
ece82b571900
add fg/bg color setting to global:// section of deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
468
diff
changeset
|
513 dd = "bg_color"; |
475
0fb80a0d6be9
add fg/bg color setting to global:// section of deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
474
diff
changeset
|
514 if (values.containsKey(dd)) { |
473
ece82b571900
add fg/bg color setting to global:// section of deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
468
diff
changeset
|
515 String sv = values.getAsString(dd); |
476
186d340afd3b
add fg/bg color setting to global:// section of deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
475
diff
changeset
|
516 bg = Integer.parseInt(sv) - 1; |
473
ece82b571900
add fg/bg color setting to global:// section of deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
468
diff
changeset
|
517 } |
199
33928f24b40d
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
198
diff
changeset
|
518 Editor editor = prefs.edit(); |
307 | 519 HashMap<String, String> types = new HashMap<String, String>(); |
473
ece82b571900
add fg/bg color setting to global:// section of deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
468
diff
changeset
|
520 HashMap<String, String> types2 = new HashMap<String, String>(); |
192
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
521 types.put("memkeys", "boolean"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
522 types.put("connPersist", "boolean"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
523 types.put("emulation", "string"); |
364
fe0fbcf55ed9
allow eula agreement to be set from deployment.connections
Carl Byington <carl@five-ten-sg.com>
parents:
363
diff
changeset
|
524 types.put("scrollback", "string"); |
192
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
525 types.put("rotation", "string"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
526 types.put("shiftfkeys", "boolean"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
527 types.put("ctrlfkeys", "boolean"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
528 types.put("keymode", "string"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
529 types.put("camera", "string"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
530 types.put("volup", "string"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
531 types.put("voldn", "string"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
532 types.put("search", "string"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
533 types.put("ptt", "string"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
534 types.put("keepalive", "boolean"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
535 types.put("wifilock", "boolean"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
536 types.put("bumpyarrows", "boolean"); |
363
5b0636e6a910
allow eula agreement to be set from deployment.connections
Carl Byington <carl@five-ten-sg.com>
parents:
359
diff
changeset
|
537 types.put("eula", "boolean"); |
192
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
538 types.put("extended_longpress", "boolean"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
539 types.put("ctrl_string", "string"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
540 types.put("picker_string", "string"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
541 types.put("picker_keep_open", "boolean"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
542 types.put("list_custom_keymap", "string"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
543 types.put("bell", "boolean"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
544 types.put("bellVolume", "float"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
545 types.put("bellVibrate", "boolean"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
546 types.put("bellNotification", "boolean"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
547 types.put("screen_capture_folder", "string"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
548 types.put("screen_capture_popup", "boolean"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
549 types.put("file_dialog", "string"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
550 types.put("download_folder", "string"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
551 types.put("remote_upload_folder", "string"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
552 types.put("upload_dest_prompt", "boolean"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
553 types.put("background_file_transfer", "boolean"); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
554 types.put("debug_keycodes", "boolean"); |
307 | 555 |
192
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
556 for (String key : values.keySet()) { |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
557 if (types.containsKey(key)) { |
364
fe0fbcf55ed9
allow eula agreement to be set from deployment.connections
Carl Byington <carl@five-ten-sg.com>
parents:
363
diff
changeset
|
558 String t = types.get(key); |
202
b16288cbad37
configure hardware buttons for showing soft function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
201
diff
changeset
|
559 String sv = values.getAsString(key); |
364
fe0fbcf55ed9
allow eula agreement to be set from deployment.connections
Carl Byington <carl@five-ten-sg.com>
parents:
363
diff
changeset
|
560 if (t.equals("float")) { |
fe0fbcf55ed9
allow eula agreement to be set from deployment.connections
Carl Byington <carl@five-ten-sg.com>
parents:
363
diff
changeset
|
561 editor.putFloat(key, Float.parseFloat(sv)); |
fe0fbcf55ed9
allow eula agreement to be set from deployment.connections
Carl Byington <carl@five-ten-sg.com>
parents:
363
diff
changeset
|
562 } |
fe0fbcf55ed9
allow eula agreement to be set from deployment.connections
Carl Byington <carl@five-ten-sg.com>
parents:
363
diff
changeset
|
563 else if (t.equals("boolean")) { |
fe0fbcf55ed9
allow eula agreement to be set from deployment.connections
Carl Byington <carl@five-ten-sg.com>
parents:
363
diff
changeset
|
564 editor.putBoolean(key, Boolean.parseBoolean(sv)); |
fe0fbcf55ed9
allow eula agreement to be set from deployment.connections
Carl Byington <carl@five-ten-sg.com>
parents:
363
diff
changeset
|
565 } |
fe0fbcf55ed9
allow eula agreement to be set from deployment.connections
Carl Byington <carl@five-ten-sg.com>
parents:
363
diff
changeset
|
566 else if (t.equals("string")) { |
fe0fbcf55ed9
allow eula agreement to be set from deployment.connections
Carl Byington <carl@five-ten-sg.com>
parents:
363
diff
changeset
|
567 editor.putString(key, sv); |
fe0fbcf55ed9
allow eula agreement to be set from deployment.connections
Carl Byington <carl@five-ten-sg.com>
parents:
363
diff
changeset
|
568 } |
192
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
569 } |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
570 } |
307 | 571 |
192
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
572 editor.commit(); |
132
265a4733edcb
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
573 } |
192
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
574 else { |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
575 HostBean host = TransportFactory.findHost(hostdb, uri); |
307 | 576 |
192
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
577 if (host == null) { |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
578 host = TransportFactory.getTransport(uri.getScheme()).createHost(uri); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
579 host.setColor(HostDatabase.COLOR_GRAY); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
580 host.setPubkeyId(HostDatabase.PUBKEYID_ANY); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
581 hostdb.saveHost(host); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
582 } |
307 | 583 |
192
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
584 host = TransportFactory.findHost(hostdb, uri); |
307 | 585 |
192
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
586 if (host == null) continue; |
307 | 587 |
192
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
588 if (values == null) continue; |
307 | 589 |
466
12e2d9dd95df
add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
465
diff
changeset
|
590 String key = "autolaunch"; |
12e2d9dd95df
add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
465
diff
changeset
|
591 if (values.containsKey(key)) { |
12e2d9dd95df
add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
465
diff
changeset
|
592 String sv = values.getAsString(key); |
12e2d9dd95df
add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
465
diff
changeset
|
593 if (Boolean.parseBoolean(sv)) launch = uri; |
12e2d9dd95df
add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
465
diff
changeset
|
594 values.remove(key); |
12e2d9dd95df
add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
465
diff
changeset
|
595 } |
12e2d9dd95df
add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
465
diff
changeset
|
596 |
192
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
597 SQLiteDatabase db = hostdb.getWritableDatabase(); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
598 db.update(HostDatabase.TABLE_HOSTS, values, "_id = ?", new String[] { String.valueOf(host.getId()) }); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
599 db.close(); |
f0b9ea35711a
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
136
diff
changeset
|
600 } |
132
265a4733edcb
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
601 } |
307 | 602 |
132
265a4733edcb
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
603 reader.close(); |
466
12e2d9dd95df
add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
465
diff
changeset
|
604 if (del) (new File(fn)).delete(); |
473
ece82b571900
add fg/bg color setting to global:// section of deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
468
diff
changeset
|
605 hostdb.setDefaultColorsForScheme(hostdb.DEFAULT_COLOR_SCHEME, fg, bg); |
132
265a4733edcb
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
606 } |
265a4733edcb
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
607 catch (Exception e) { |
457
105815cce146
minimum version android 5, target and compile version api 28
Carl Byington <carl@five-ten-sg.com>
parents:
450
diff
changeset
|
608 Log.d(TAG, "Deployment scan failed."); |
132
265a4733edcb
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
609 } |
466
12e2d9dd95df
add delete_deployment and autolaunch keys to the deployment.connections file
Carl Byington <carl@five-ten-sg.com>
parents:
465
diff
changeset
|
610 return launch; |
132
265a4733edcb
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
611 } |
265a4733edcb
read deployment.connections on startup for new host entries
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
612 |
0 | 613 protected void updateList() { |
614 if (prefs.getBoolean(PreferenceConstants.SORT_BY_COLOR, false) != sortedByColor) { | |
198
a9fb5061cca3
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
197
diff
changeset
|
615 Editor editor = prefs.edit(); |
a9fb5061cca3
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
197
diff
changeset
|
616 editor.putBoolean(PreferenceConstants.SORT_BY_COLOR, sortedByColor); |
a9fb5061cca3
read deployment.connections on startup for global preferences also
Carl Byington <carl@five-ten-sg.com>
parents:
197
diff
changeset
|
617 editor.commit(); |
0 | 618 } |
619 | |
620 if (hostdb == null) | |
621 hostdb = new HostDatabase(this); | |
622 | |
623 hosts = hostdb.getHosts(sortedByColor); | |
624 | |
625 // Don't lose hosts that are connected via shortcuts but not in the database. | |
626 if (bound != null) { | |
627 for (TerminalBridge bridge : bound.bridges) { | |
628 if (!hosts.contains(bridge.host)) | |
629 hosts.add(0, bridge.host); | |
630 } | |
631 } | |
632 | |
633 HostAdapter adapter = new HostAdapter(this, hosts, bound); | |
634 this.setListAdapter(adapter); | |
635 } | |
636 | |
637 class HostAdapter extends ArrayAdapter<HostBean> { | |
638 private List<HostBean> hosts; | |
639 private final TerminalManager manager; | |
640 private final ColorStateList red, green, blue; | |
641 | |
642 public final static int STATE_UNKNOWN = 1, STATE_CONNECTED = 2, STATE_DISCONNECTED = 3; | |
643 | |
644 class ViewHolder { | |
645 public TextView nickname; | |
646 public TextView caption; | |
647 public ImageView icon; | |
648 } | |
649 | |
650 public HostAdapter(Context context, List<HostBean> hosts, TerminalManager manager) { | |
651 super(context, R.layout.item_host, hosts); | |
652 this.hosts = hosts; | |
653 this.manager = manager; | |
654 red = context.getResources().getColorStateList(R.color.red); | |
655 green = context.getResources().getColorStateList(R.color.green); | |
656 blue = context.getResources().getColorStateList(R.color.blue); | |
657 } | |
658 | |
659 /** | |
660 * Check if we're connected to a terminal with the given host. | |
661 */ | |
662 private int getConnectedState(HostBean host) { | |
663 // always disconnected if we dont have backend service | |
664 if (this.manager == null) | |
665 return STATE_UNKNOWN; | |
666 | |
667 if (manager.getConnectedBridge(host) != null) | |
668 return STATE_CONNECTED; | |
669 | |
670 if (manager.disconnected.contains(host)) | |
671 return STATE_DISCONNECTED; | |
672 | |
673 return STATE_UNKNOWN; | |
674 } | |
675 | |
676 @Override | |
677 public View getView(int position, View convertView, ViewGroup parent) { | |
678 ViewHolder holder; | |
679 | |
680 if (convertView == null) { | |
681 convertView = inflater.inflate(R.layout.item_host, null, false); | |
682 holder = new ViewHolder(); | |
683 holder.nickname = (TextView)convertView.findViewById(android.R.id.text1); | |
684 holder.caption = (TextView)convertView.findViewById(android.R.id.text2); | |
685 holder.icon = (ImageView)convertView.findViewById(android.R.id.icon); | |
686 convertView.setTag(holder); | |
687 } | |
688 else | |
689 holder = (ViewHolder) convertView.getTag(); | |
690 | |
691 HostBean host = hosts.get(position); | |
692 | |
693 if (host == null) { | |
694 // Well, something bad happened. We can't continue. | |
695 Log.e("HostAdapter", "Host bean is null!"); | |
696 holder.nickname.setText("Error during lookup"); | |
697 holder.caption.setText("see 'adb logcat' for more"); | |
698 return convertView; | |
699 } | |
700 | |
701 holder.nickname.setText(host.getNickname()); | |
702 | |
703 switch (this.getConnectedState(host)) { | |
704 case STATE_UNKNOWN: | |
705 holder.icon.setImageState(new int[] { }, true); | |
706 break; | |
707 | |
708 case STATE_CONNECTED: | |
709 holder.icon.setImageState(new int[] { android.R.attr.state_checked }, true); | |
710 break; | |
711 | |
712 case STATE_DISCONNECTED: | |
713 holder.icon.setImageState(new int[] { android.R.attr.state_expanded }, true); | |
714 break; | |
715 } | |
716 | |
717 ColorStateList chosen = null; | |
718 | |
719 if (HostDatabase.COLOR_RED.equals(host.getColor())) | |
720 chosen = this.red; | |
721 else if (HostDatabase.COLOR_GREEN.equals(host.getColor())) | |
722 chosen = this.green; | |
723 else if (HostDatabase.COLOR_BLUE.equals(host.getColor())) | |
724 chosen = this.blue; | |
725 | |
726 Context context = convertView.getContext(); | |
727 | |
728 if (chosen != null) { | |
729 // set color normally if not selected | |
730 holder.nickname.setTextColor(chosen); | |
731 holder.caption.setTextColor(chosen); | |
732 } | |
733 else { | |
734 // selected, so revert back to default black text | |
450 | 735 holder.nickname.setTextAppearance(context, android.R.style.TextAppearance_Large); |
736 holder.caption.setTextAppearance(context, android.R.style.TextAppearance_Small); | |
0 | 737 } |
738 | |
739 long now = System.currentTimeMillis() / 1000; | |
740 String nice = context.getString(R.string.bind_never); | |
741 | |
742 if (host.getLastConnect() > 0) { | |
743 int minutes = (int)((now - host.getLastConnect()) / 60); | |
744 | |
745 if (minutes >= 60) { | |
746 int hours = (minutes / 60); | |
747 | |
748 if (hours >= 24) { | |
749 int days = (hours / 24); | |
750 nice = context.getString(R.string.bind_days, days); | |
751 } | |
752 else | |
753 nice = context.getString(R.string.bind_hours, hours); | |
754 } | |
755 else | |
756 nice = context.getString(R.string.bind_minutes, minutes); | |
757 } | |
758 | |
759 holder.caption.setText(nice); | |
760 return convertView; | |
761 } | |
762 } | |
763 } |