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