List of usage examples for java.net NetworkInterface equals
public boolean equals(Object obj)
From source file:org.kei.android.phone.netcap.OutputFragment.java
@Override public void onClick(final View v) { if (v.equals(refreshBT)) { adapter.clear();/*from w ww . ja va 2 s . c om*/ try { final List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces()); if (interfaces != null && interfaces.size() != 0) adapter.add(getResources().getText(R.string.any).toString()); for (final NetworkInterface ni : interfaces) if (ni.isUp()) adapter.add(ni.getName()); } catch (final Throwable e) { logException(e); } } else if (v.equals(browseOutputCaptureTV)) { final Map<String, String> extra = new HashMap<String, String>(); extra.put(FileChooser.FILECHOOSER_TYPE_KEY, "" + FileChooser.FILECHOOSER_TYPE_DIRECTORY_ONLY); extra.put(FileChooser.FILECHOOSER_TITLE_KEY, "Save"); extra.put(FileChooser.FILECHOOSER_MESSAGE_KEY, "Use this folder:? "); extra.put(FileChooser.FILECHOOSER_DEFAULT_DIR, browseOutputCaptureTV.getText().toString()); extra.put(FileChooser.FILECHOOSER_SHOW_KEY, "" + FileChooser.FILECHOOSER_SHOW_DIRECTORY_ONLY); extra.put(FileChooser.FILECHOOSER_USER_MESSAGE, getClass().getSimpleName()); Tools.switchToForResult(owner, FileChooserActivity.class, extra, FileChooserActivity.FILECHOOSER_SELECTION_TYPE_DIRECTORY); } else if (v.equals(captureBT)) { if (!captureBT.isChecked()) { captureBT.setChecked(true); delete(); } else { String sdest = browseOutputCaptureTV.getText().toString(); if (sdest.isEmpty()) { Tools.showAlertDialog(owner, "Error", "Empty destination folder!"); captureBT.setChecked(false); return; } File legacy = new File(sdest.replaceFirst("emulated/([0-9]+)/", "emulated/legacy/")); File fdest = new File(sdest); Log.i(getClass().getSimpleName(), "Test directory '" + legacy + "'"); if (legacy.isDirectory()) fdest = legacy; if (!fdest.isDirectory()) { Tools.showAlertDialog(owner, "Error", "The destination folder is not a valid directory!"); captureBT.setChecked(false); return; } else if (!fdest.canWrite()) { Tools.showAlertDialog(owner, "Error", "Unable to write into the destination folder!"); captureBT.setChecked(false); return; } if (!RootTools.isAccessGiven()) { Resources r = getResources(); Tools.toast(owner, R.drawable.ic_launcher, r.getString(R.string.root_toast_error)); showResult.setText(" " + r.getString(R.string.root_error)); captureBT.setChecked(false); return; } final PackageManager m = owner.getPackageManager(); String s = owner.getPackageName(); try { final PackageInfo p = m.getPackageInfo(s, 0); s = p.applicationInfo.dataDir; } catch (final PackageManager.NameNotFoundException e) { } s = s + "/netcap"; copyFile(Build.SUPPORTED_ABIS[0] + "/netcap", s, owner); final File netcap = new File(s); if (!netcap.exists()) { Tools.showAlertDialog(owner, "Error", "'netcap' for '" + Build.SUPPORTED_ABIS[0] + "' was not found!"); return; } pname = netcap.getAbsolutePath(); netcap.setExecutable(true); ifaces = ""; String ni = (String) devicesSp.getSelectedItem(); if (ni.equals(getResources().getText(R.string.any).toString())) { for (int i = 0; i < adapter.getCount(); i++) { ni = adapter.getItem(i); if (ni.equals(getResources().getText(R.string.any).toString())) continue; ifaces += ni; if (i < adapter.getCount() - 1) ifaces += ","; } } else ifaces = ni; final File outputFile = new File(fdest, new SimpleDateFormat("yyyyMMdd_hhmmssa'_netcap.pcap'", Locale.US).format(new Date())); buffer.clear(); new Thread(new Runnable() { public void run() { try { String cmd = netcap.getAbsolutePath() + " -i " + ifaces + " -f " + outputFile.getAbsolutePath() + " -d"; if (promiscuousCB.isChecked()) cmd += " -p"; cmd += " 2>&1"; command = new Command(0, cmd) { @Override public void commandOutput(int id, String line) { super.commandOutput(id, line); if (line.startsWith(NETCAP_READY)) pid = line.substring(NETCAP_READY.length()); buffer.add(line); owner.runOnUiThread(new Runnable() { @SuppressWarnings("unchecked") @Override public void run() { final String[] lines = (String[]) buffer.toArray(new String[] {}); final StringBuilder sb = new StringBuilder(); for (final String s : lines) sb.append(" ").append(s).append("\n"); showResult.setText(sb.toString()); } }); } public void commandCompleted(int id, int exitcode) { super.commandCompleted(id, exitcode); owner.runOnUiThread(new Runnable() { @Override public void run() { captureBT.setChecked(false); } }); } public void commandTerminated(int id, String reason) { super.commandTerminated(id, reason); } }; RootTools.getShell(true).add(command); } catch (final Exception e) { logException(e); } } }).start(); } } }