LogFilter.java 6.7 KB

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