diff options
author | Fil <fil.bergamo@riseup.net> | 2017-08-25 17:24:07 +0200 |
---|---|---|
committer | Fil <fil.bergamo@riseup.net> | 2017-08-25 17:24:07 +0200 |
commit | 9775f8d93d2c49a9844ca4dcbf11433e09419df1 (patch) | |
tree | 586461727ae778de6d97bd911b7c9f33bd9a9f82 /app/src/fil/libre/repwifiapp/helpers/AccessPointInfo.java | |
parent | 5b71fe514e7650b392a01cc2c4398a68062b32cb (diff) | |
download | RepWifiApp-9775f8d93d2c49a9844ca4dcbf11433e09419df1.tar.gz RepWifiApp-9775f8d93d2c49a9844ca4dcbf11433e09419df1.tar.bz2 RepWifiApp-9775f8d93d2c49a9844ca4dcbf11433e09419df1.zip |
new version 0.5 - add various features
This commit introduces a whole new version, v0.5.
Various new features were added, along with a massive graphical restyling.
Diffstat (limited to 'app/src/fil/libre/repwifiapp/helpers/AccessPointInfo.java')
-rw-r--r-- | app/src/fil/libre/repwifiapp/helpers/AccessPointInfo.java | 359 |
1 files changed, 194 insertions, 165 deletions
diff --git a/app/src/fil/libre/repwifiapp/helpers/AccessPointInfo.java b/app/src/fil/libre/repwifiapp/helpers/AccessPointInfo.java index 65c8b24..d6e2eb3 100644 --- a/app/src/fil/libre/repwifiapp/helpers/AccessPointInfo.java +++ b/app/src/fil/libre/repwifiapp/helpers/AccessPointInfo.java @@ -24,173 +24,202 @@ import java.io.File; import java.io.Serializable; import java.util.ArrayList; import java.util.List; - import fil.libre.repwifiapp.Commons; +public class AccessPointInfo implements Serializable { + + private static final long serialVersionUID = 1L; + private static final int MAX_SSID_LENGTH = 32; + + private String _ssid; + private String _bssid; + private String _auth; + private String _level; + private String _freq; + private String _password; + private boolean _isHidden = false; + private long _lastTimeUsed; + + public AccessPointInfo(String ssid, String bssid, String authType, String level, String freq) { + + this._ssid = ssid; + this._bssid = bssid; + this._auth = authType; + this._level = level; + this._freq = freq; + + } + + public String getSsid() { + return this._ssid; + } + + public String getSsid(int maxLength) { + String txt = getSsid(); + if (maxLength > 4 && txt.length() > maxLength) { + txt = txt.substring(0, maxLength - 3) + "..."; + } + return txt; + } + + public void setHidden(boolean hidden) { + this._isHidden = hidden; + } + + public boolean isHidden() { + return this._isHidden; + } + + public String getBssid() { + return this._bssid; + } + + public void setBssid(String bssid) { + this._bssid = bssid; + } + + public String getAuthType() { + return this._auth; + } + + public String getSignlalStrength() { + return this._level; + } + + public String getFrequency() { + return this._freq; + } + + public long getLastTimeUsed() { + return this._lastTimeUsed; + } + + public void setLastTimeUsed(long timeStampInMillis) { + this._lastTimeUsed = timeStampInMillis; + } + + public boolean isOlderThan(int days) { + + if (this._lastTimeUsed == 0) { + return false; + } + + long timeDiff = System.currentTimeMillis() - this._lastTimeUsed; + long spanMillis = Utils.daysToMilliseconds(days); + + if (timeDiff > spanMillis) { + return true; + } else { + return false; + } + + } + + public String getPassword() { + return this._password; + } + + public void setPassword(String password) { + this._password = password; + } + + public boolean needsPassword() { + + if ((this._auth == null) || (this._auth.equals(""))) { + // TODO + // check if default behavior should be with or without password, + // when no auth info is available. + return false; + } + + if (this._auth.contains("WPA2") || this._auth.contains("WPA")) { + return true; + } else { + return false; + } + + } + + protected static AccessPointInfo parseLine(String line) { + + try { + + String[] params = line.split("\t"); + if (params.length != 5) { + return null; + } + + String bssid = params[0]; + String freq = params[1]; + String level = params[2]; + String auth = params[3]; + String ssid = params[4]; + + if (ssid.length() == 0 || ssid.length() > MAX_SSID_LENGTH) { + // invalid SSID. + return null; + } + + AccessPointInfo info = new AccessPointInfo(ssid, bssid, auth, level, freq); + return info; + + } catch (Exception e) { + Utils.logError("Error while parsing line: " + line, e); + return null; + } + + } + + public static AccessPointInfo[] parseScanResult(String scanResultFile) { + + try { + + Utils.logDebug("AccesPointInfo trying to parse file: " + scanResultFile); + + File f = new File(scanResultFile); + if (!f.exists()) { + Utils.logError("AccessPointInfo.parseScanResult(): The provided scan result file doesn't exist"); + return null; + } + + String[] lines = Utils.readFileLines(scanResultFile); + List<AccessPointInfo> nets = new ArrayList<AccessPointInfo>(); + + if (lines == null) { + return null; + } + + for (String l : lines) { + if (l.startsWith(Commons.SCAN_FILE_HDR)) { + // strip off the header + continue; + } + + if (l.trim().equals("")) { + // empty line, skip. + continue; + } + + // try to parse line into network info + AccessPointInfo info = AccessPointInfo.parseLine(l); + if (info == null) { + Utils.logError("Failed to parse line into AccessPointInfo: " + l); + continue; + } + + nets.add(info); + + } + + AccessPointInfo[] a = new AccessPointInfo[nets.size()]; + a = nets.toArray(a); + return a; + + } catch (Exception e) { + Utils.logError("Error while parsing scan results in class AccessPointInfo", e); + return null; + } -public class AccessPointInfo implements Serializable{ - - private static final long serialVersionUID = 1L; - - private String _ssid; - private String _bssid; - private String _auth; - private String _level; - private String _freq; - private String _password; - private long _lastTimeUsed; - - public AccessPointInfo(String ssid, String bssid, String authType, String level, String freq){ - - this._ssid = ssid; - this._bssid = bssid; - this._auth = authType; - this._level = level; - this._freq = freq; - - } - - public String getSSID(){ - return this._ssid; - } - - public String getBSSID(){ - return this._bssid; - } - - public String getAuthType(){ - return this._auth; - } - - public String getSignlalStrength(){ - return this._level; - } - - public String getFrequency(){ - return this._freq; - } - - public long getLastTimeUsed(){ - return this._lastTimeUsed; - } - - public void setLastTimeUsed(long timeStampInMillis){ - this._lastTimeUsed = timeStampInMillis; - } - - public boolean isOlderThan(int days){ - - if (this._lastTimeUsed == 0){ - return false; - } - - long timeDiff = System.currentTimeMillis() - this._lastTimeUsed; - long spanMillis = Utils.daysToMilliseconds(days); - - if (timeDiff > spanMillis){ - return true; - }else{ - return false; - } - - - } - - public String getPassword(){ - return this._password; - } - - public void setPassword(String password){ - this._password = password; - } - - public boolean needsPassword(){ - - if ( (this._auth == null) || (this._auth.equals("")) ){ - //TODO - //check if default behavior should be with or without password, - //when no auth info is available. - return false; - } - - if (this._auth.contains("WPA2") || this._auth.contains("WPA")){ - return true; - } - else { - return false; - } - - } - - protected static AccessPointInfo parseLine(String line){ - - try{ - - String[] params = line.split("\t"); - if (params.length != 5){ - return null; - } - - String bssid = params[0]; - String freq = params[1]; - String level = params[2]; - String auth = params[3]; - String ssid = params [4]; - - AccessPointInfo info = new AccessPointInfo(ssid, bssid, auth, level, freq); - return info; - - }catch (Exception e){ - Utils.logError("Error while parsing line: " + line, e); - return null; - } - - } - - public static AccessPointInfo[] parseScanResult(String scanResultFile){ - - try { - - File f = new File(scanResultFile); - if (! f.exists()){ - Utils.logError("AccessPointInfo.parseScanResult(): The provided scan result file doesn't exist"); - return null; - } - - String[] lines = Utils.readFileLines(Commons.getScanFile()); - List<AccessPointInfo> nets = new ArrayList<AccessPointInfo>(); - - for(String l : lines){ - if (l.startsWith(Commons.SCAN_FILE_HDR)){ - //strip off the header - continue; - } - - if (l.trim().equals("")){ - //empty line, skip. - continue; - } - - //try to parse line into network info - AccessPointInfo info = AccessPointInfo.parseLine(l); - if (info == null){ - Utils.logError("Failed to parse line into AccessPointInfo: " + l); - continue; - } - - nets.add(info); - - } - - AccessPointInfo[] a = new AccessPointInfo[nets.size()]; - a = nets.toArray(a); - return a; - - } catch (Exception e) { - Utils.logError("Error while parsing scan results in class AccessPointInfo",e); - return null; - } - - } + } } |