comparison app/src/main/java/com/five_ten_sg/connectbot/HostListActivity.java @ 466:12e2d9dd95df stable-1.9.3-6

add delete_deployment and autolaunch keys to the deployment.connections file
author Carl Byington <carl@five-ten-sg.com>
date Thu, 05 Sep 2019 09:24:55 -0700
parents 7c8aebcc882a
children 74b507d491c9
comparison
equal deleted inserted replaced
465:7c8aebcc882a 466:12e2d9dd95df
196 makingShortcut = Intent.ACTION_CREATE_SHORTCUT.equals(getIntent().getAction()) 196 makingShortcut = Intent.ACTION_CREATE_SHORTCUT.equals(getIntent().getAction())
197 || Intent.ACTION_PICK.equals(getIntent().getAction()); 197 || Intent.ACTION_PICK.equals(getIntent().getAction());
198 198
199 // connect with hosts database, read deployment file, and populate list 199 // connect with hosts database, read deployment file, and populate list
200 hostdb = new HostDatabase(this); 200 hostdb = new HostDatabase(this);
201 createDeploymentHosts(); // build hosts from a deployment text file 201 // build hosts from a deployment text file
202 Uri launch = createDeploymentHosts();
202 updateList(); 203 updateList();
203 204
204 // check for eula agreement, which might be set from the deployment file 205 // check for eula agreement, which might be set from the deployment file
205 boolean agreed = prefs.getBoolean(PreferenceConstants.EULA, false); 206 boolean agreed = prefs.getBoolean(PreferenceConstants.EULA, false);
206 if (!agreed) { 207 if (!agreed) {
262 } 263 }
263 public void onNothingSelected(AdapterView<?> arg0) { } 264 public void onNothingSelected(AdapterView<?> arg0) { }
264 }); 265 });
265 transportSpinner.setAdapter(transportSelection); 266 transportSpinner.setAdapter(transportSelection);
266 this.inflater = LayoutInflater.from(this); 267 this.inflater = LayoutInflater.from(this);
268
269 if (launch != null) {
270 Intent contents = new Intent(Intent.ACTION_VIEW, launch);
271 contents.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
272 startActivity(contents);
273 }
267 } 274 }
268 275
269 public void checkp(String [] perms) { 276 public void checkp(String [] perms) {
270 boolean need = false; 277 boolean need = false;
271 for (String perm : perms) { 278 for (String perm : perms) {
421 intent.setData(uri); 428 intent.setData(uri);
422 startActivity(intent); 429 startActivity(intent);
423 return true; 430 return true;
424 } 431 }
425 432
426 private void createDeploymentHosts() { 433 private Uri createDeploymentHosts() {
434 Uri launch = null;
427 try { 435 try {
436 boolean del = true;
428 String fn = Environment.getExternalStorageDirectory().getAbsolutePath() + 437 String fn = Environment.getExternalStorageDirectory().getAbsolutePath() +
429 File.separator + "deployment.connections"; 438 File.separator + "deployment.connections";
430 BufferedReader reader = new BufferedReader(new FileReader(fn)); 439 BufferedReader reader = new BufferedReader(new FileReader(fn));
431 String line = null; 440 String line = null;
432 441
449 458
450 values.put(parts[0].trim(), parts[1].trim()); 459 values.put(parts[0].trim(), parts[1].trim());
451 } 460 }
452 461
453 if (uri.getScheme().equals("global")) { 462 if (uri.getScheme().equals("global")) {
463 String dd = "delete_deployment";
464 if (values.containsKey(dd)) {
465 String sv = values.getAsString(dd);
466 del = Boolean.parseBoolean(sv);
467 }
454 Editor editor = prefs.edit(); 468 Editor editor = prefs.edit();
455 HashMap<String, String> types = new HashMap<String, String>(); 469 HashMap<String, String> types = new HashMap<String, String>();
456 types.put("memkeys", "boolean"); 470 types.put("memkeys", "boolean");
457 types.put("connPersist", "boolean"); 471 types.put("connPersist", "boolean");
458 types.put("emulation", "string"); 472 types.put("emulation", "string");
520 534
521 if (host == null) continue; 535 if (host == null) continue;
522 536
523 if (values == null) continue; 537 if (values == null) continue;
524 538
539 String key = "autolaunch";
540 if (values.containsKey(key)) {
541 String sv = values.getAsString(key);
542 if (Boolean.parseBoolean(sv)) launch = uri;
543 values.remove(key);
544 }
545
525 SQLiteDatabase db = hostdb.getWritableDatabase(); 546 SQLiteDatabase db = hostdb.getWritableDatabase();
526 db.update(HostDatabase.TABLE_HOSTS, values, "_id = ?", new String[] { String.valueOf(host.getId()) }); 547 db.update(HostDatabase.TABLE_HOSTS, values, "_id = ?", new String[] { String.valueOf(host.getId()) });
527 db.close(); 548 db.close();
528 } 549 }
529 } 550 }
530 551
531 reader.close(); 552 reader.close();
532 (new File(fn)).delete(); 553 if (del) (new File(fn)).delete();
533 } 554 }
534 catch (Exception e) { 555 catch (Exception e) {
535 Log.d(TAG, "Deployment scan failed."); 556 Log.d(TAG, "Deployment scan failed.");
536 } 557 }
558 return launch;
537 } 559 }
538 560
539 protected void updateList() { 561 protected void updateList() {
540 if (prefs.getBoolean(PreferenceConstants.SORT_BY_COLOR, false) != sortedByColor) { 562 if (prefs.getBoolean(PreferenceConstants.SORT_BY_COLOR, false) != sortedByColor) {
541 Editor editor = prefs.edit(); 563 Editor editor = prefs.edit();