LogFilter.java 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. package de.tudarmstadt.informatik.hostage.ui;
  2. import java.util.ArrayList;
  3. import java.util.HashMap;
  4. import android.os.Parcel;
  5. import android.os.Parcelable;
  6. public class LogFilter implements Parcelable {
  7. public final static String LOG_FILTER_INTENT_KEY = "de.tudarmstadt.informatik.hostage.logfilter";
  8. private static final String TIMESTAMP_BELOW_KEY = "de.tudarmstadt.informatik.hostage.logfilter.timestampbelow";
  9. private static final String TIMESTAMP_ABOVE_KEY = "de.tudarmstadt.informatik.hostage.logfilter.timestampabove";
  10. private static final String PROTOCOLS_KEY = "de.tudarmstadt.informatik.hostage.logfilter.protocols";
  11. private static final String ESSID_KEY = "de.tudarmstadt.informatik.hostage.logfilter.essid";
  12. private static final String BSSID_KEY = "de.tudarmstadt.informatik.hostage.logfilter.bssid";
  13. private static final String SORTTYPE_KEY = "de.tudarmstadt.informatik.hostage.logfilter.sorttype";
  14. public enum SortType {
  15. packet_timestamp(0), protocol(1), _bssid(1), ssid(3), _attack_id(7), _id(8);
  16. private final int id;
  17. SortType(int id) {
  18. this.id = id;
  19. }
  20. public int getValue() {
  21. return id;
  22. }
  23. }
  24. public ArrayList<String> BSSIDs;
  25. public ArrayList<String> ESSIDs;
  26. public ArrayList<String> protocols;
  27. public boolean isNotEditable;
  28. public SortType sorttype;
  29. public long belowTimestamp;
  30. public long aboveTimestamp;
  31. public LogFilter() {
  32. this.clear();
  33. }
  34. public void clear() {
  35. this.belowTimestamp = Long.MAX_VALUE;
  36. this.aboveTimestamp = Long.MIN_VALUE;
  37. this.sorttype = SortType.packet_timestamp;
  38. this.BSSIDs = new ArrayList<String>();
  39. this.ESSIDs = new ArrayList<String>();
  40. this.protocols = new ArrayList<String>();
  41. }
  42. public int describeContents() {
  43. return 0;
  44. }
  45. // write your object's data to the passed-in Parcel
  46. public void writeToParcel(Parcel out, int flags) {
  47. HashMap<String, ArrayList<String>> values = new HashMap<String, ArrayList<String>>();
  48. if (this.BSSIDs != null && this.BSSIDs.size() > 0) {
  49. values.put(BSSID_KEY, this.getBSSIDs());
  50. }
  51. if (this.ESSIDs != null && this.ESSIDs.size() > 0) {
  52. values.put(ESSID_KEY, this.getESSIDs());
  53. }
  54. if (this.protocols != null && this.protocols.size() > 0) {
  55. values.put(PROTOCOLS_KEY, this.getProtocols());
  56. }
  57. long timeArray[] = new long[] { this.aboveTimestamp, this.belowTimestamp };
  58. out.writeMap(values);
  59. out.writeInt(this.sorttype.getValue());
  60. out.writeDouble(timeArray.length);
  61. out.writeLongArray(timeArray);
  62. out.writeString(this.isNotEditable ? "true" : "false");
  63. }
  64. public static final Parcelable.Creator<LogFilter> CREATOR = new Parcelable.Creator<LogFilter>() {
  65. public LogFilter createFromParcel(Parcel in) {
  66. return new LogFilter(in);
  67. }
  68. public LogFilter[] newArray(int size) {
  69. return new LogFilter[size];
  70. }
  71. };
  72. // example constructor that takes a Parcel and gives you an object populated
  73. // with it's values
  74. private LogFilter(Parcel in) {
  75. // mData = in.readInt();
  76. HashMap<String, ArrayList<String>> values = new HashMap<String, ArrayList<String>>();
  77. in.readMap(values, ArrayList.class.getClassLoader());
  78. this.BSSIDs = values.get(BSSID_KEY);
  79. this.ESSIDs = values.get(ESSID_KEY);
  80. this.protocols = values.get(protocols);
  81. if (this.BSSIDs == null)
  82. this.BSSIDs = new ArrayList<String>();
  83. if (this.ESSIDs == null)
  84. this.ESSIDs = new ArrayList<String>();
  85. if (this.protocols == null)
  86. this.protocols = new ArrayList<String>();
  87. this.sorttype = SortType.values()[Math.min(in.readInt(), SortType.values().length)];
  88. int size = (int) in.readDouble();
  89. long timeArray[] = new long[size];
  90. in.readLongArray(timeArray);
  91. this.belowTimestamp = timeArray[1];
  92. this.aboveTimestamp = timeArray[0];
  93. String bool = in.readString();
  94. if (bool.equals("true"))
  95. this.isNotEditable = true;
  96. }
  97. public boolean isNotEditable() {
  98. return this.isNotEditable;
  99. }
  100. public SortType getSorttype() {
  101. return this.sorttype;
  102. }
  103. public ArrayList<String> getBSSIDs() {
  104. return this.BSSIDs;
  105. }
  106. public ArrayList<String> getESSIDs() {
  107. return this.ESSIDs;
  108. }
  109. public ArrayList<String> getProtocols() {
  110. return this.protocols;
  111. }
  112. public void setIsNotEditable(boolean b) {
  113. this.isNotEditable = b;
  114. }
  115. public long getBelowTimestamp() {
  116. return this.belowTimestamp;
  117. }
  118. public long getAboveTimestamp() {
  119. return this.aboveTimestamp;
  120. }
  121. public void setProtocols(ArrayList<String> protocols) {
  122. this.protocols = protocols;
  123. }
  124. public void setBSSIDs(ArrayList<String> bssids) {
  125. this.BSSIDs = bssids;
  126. }
  127. public void setESSIDs(ArrayList<String> essids) {
  128. this.ESSIDs = essids;
  129. }
  130. public void setAboveTimestamp(long timestamp) {
  131. this.aboveTimestamp = timestamp;
  132. }
  133. public void setBelowTimestamp(long timestamp) {
  134. this.belowTimestamp = timestamp;
  135. }
  136. public void setSorttype(SortType type) {
  137. this.sorttype = type;
  138. }
  139. public String getBSSIDQueryStatement(String tablename, String key) {
  140. return this.convertArrayListToQueryString(this.BSSIDs, tablename, key);
  141. }
  142. public String getESSIDQueryStatement(String tablename, String key) {
  143. return this.convertArrayListToQueryString(this.ESSIDs, tablename, key);
  144. }
  145. public String getProtocolsQueryStatement(String tablename, String key) {
  146. return this.convertArrayListToQueryString(this.protocols, tablename, key);
  147. }
  148. public boolean isSet() {
  149. boolean hasTime = this.hasATimestamp();
  150. boolean hasBSSIDs = this.hasBSSIDs();
  151. boolean hasESSIDs = this.hasESSIDs();
  152. boolean hasProtocols = this.hasProtocols();
  153. return hasBSSIDs || hasESSIDs || hasProtocols | hasTime;
  154. }
  155. public boolean hasBSSIDs() {
  156. return this.getBSSIDs().size() > 0;
  157. }
  158. public boolean hasESSIDs() {
  159. return this.getESSIDs().size() > 0;
  160. }
  161. public boolean hasProtocols() {
  162. return this.getProtocols().size() > 0;
  163. }
  164. public boolean hasAboveTimestamp() {
  165. return this.aboveTimestamp != Long.MIN_VALUE;
  166. }
  167. public boolean hasBelowTimestamp() {
  168. return this.belowTimestamp != Long.MAX_VALUE;
  169. }
  170. public boolean hasATimestamp() {
  171. return this.hasBelowTimestamp() || this.hasAboveTimestamp();
  172. }
  173. public String convertArrayListToQueryString(ArrayList<String> list, String table, String key) {
  174. String statement = "";
  175. if (list == null)
  176. return statement;
  177. statement = " ( ";
  178. int i = 0, max = list.size();
  179. for (String element : list) {
  180. i++;
  181. statement = statement + table + "." + key + " = " + "'" + element + "'";
  182. if (i == max)
  183. continue;
  184. statement = statement + " OR ";
  185. }
  186. statement = statement + " ) ";
  187. return statement;
  188. }
  189. }