LogFilter.java 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. package de.tudarmstadt.informatik.hostage.ui;
  2. import java.util.ArrayList;
  3. import java.util.HashMap;
  4. import de.tudarmstadt.informatik.hostage.R;
  5. import android.os.Parcel;
  6. import android.os.Parcelable;
  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.belowTimestamp = Long.MAX_VALUE;
  41. this.aboveTimestamp = Long.MIN_VALUE;
  42. this.sorttype = SortType.timestamp;
  43. this.BSSIDs = new ArrayList<String>();
  44. this.ESSIDs = new ArrayList<String>();
  45. this.protocols = new ArrayList<String>();
  46. }
  47. public int describeContents() {
  48. return 0;
  49. }
  50. // write your object's data to the passed-in Parcel
  51. public void writeToParcel(Parcel out, int flags) {
  52. HashMap<String, ArrayList<String>> values =new HashMap<String, ArrayList<String>>();
  53. if(this.BSSIDs != null && this.BSSIDs.size() > 0){
  54. values.put(BSSID_KEY , this.getBSSIDs() );
  55. }
  56. if(this.ESSIDs != null && this.ESSIDs.size() > 0){
  57. values.put(ESSID_KEY , this.getESSIDs() );
  58. }
  59. if(this.protocols != null && this.protocols.size() > 0){
  60. values.put(PROTOCOLS_KEY , this.getProtocols() );
  61. }
  62. long timeArray[] = new long[] {this.aboveTimestamp, this.belowTimestamp};
  63. out.writeMap(values);
  64. out.writeInt(this.sorttype.getValue());
  65. out.writeDouble(timeArray.length);
  66. out.writeLongArray(timeArray);
  67. out.writeString(this.isNotEditable? "true" : "false");
  68. }
  69. public static final Parcelable.Creator<LogFilter> CREATOR = new Parcelable.Creator<LogFilter>() {
  70. public LogFilter createFromParcel(Parcel in) {
  71. return new LogFilter(in);
  72. }
  73. public LogFilter[] newArray(int size) {
  74. return new LogFilter[size];
  75. }
  76. };
  77. // example constructor that takes a Parcel and gives you an object populated with it's values
  78. private LogFilter(Parcel in) {
  79. //mData = in.readInt();
  80. HashMap<String, ArrayList<String>> values = new HashMap<String, ArrayList<String>>();
  81. in.readMap(values, ArrayList.class.getClassLoader());
  82. this.BSSIDs = values.get(BSSID_KEY);
  83. this.ESSIDs = values.get(ESSID_KEY);
  84. this.protocols = values.get(protocols);
  85. if(this.BSSIDs == null) this.BSSIDs = new ArrayList<String>();
  86. if(this.ESSIDs == null) this.ESSIDs = new ArrayList<String>();
  87. if(this.protocols == null) this.protocols = new ArrayList<String>();
  88. this.sorttype = SortType.values()[Math.min(in.readInt(), SortType.values().length)];
  89. int size = (int)in.readDouble();
  90. long timeArray[] = new long[size];
  91. in.readLongArray(timeArray);
  92. this.belowTimestamp = timeArray[1];
  93. this.aboveTimestamp = timeArray[0];
  94. String bool = in.readString();
  95. if(bool.equals("true")) 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 key){
  140. return this.convertArrayListToQueryString(this.BSSIDs, key);
  141. }
  142. public String getESSIDQueryStatement(String key){
  143. return this.convertArrayListToQueryString(this.ESSIDs, key);
  144. }
  145. public String getProtocolsQueryStatement(String key){
  146. return this.convertArrayListToQueryString(this.protocols, key);
  147. }
  148. public String convertArrayListToQueryString(ArrayList<String> list, String key){
  149. String statement = "";
  150. if (list == null) return statement;
  151. statement = " ( ";
  152. int i = 0, max = list.size();
  153. for (String element : list){
  154. i++;
  155. statement = statement + key + " = " + "'" + element + "'";
  156. if (i == max) continue;
  157. statement = statement +" OR ";
  158. }
  159. statement = statement + " ) ";
  160. return statement;
  161. }
  162. }