123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- package de.tudarmstadt.informatik.hostage.ui;
- import android.os.Parcel;
- import android.os.Parcelable;
- import java.util.ArrayList;
- import java.util.HashMap;
- import de.tudarmstadt.informatik.hostage.logging.UglyDbHelper;
- public class LogFilter implements Parcelable{
-
- public final static String LOG_FILTER_INTENT_KEY = "de.tudarmstadt.informatik.hostage.logfilter";
-
- private static final String TIMESTAMP_BELOW_KEY = "de.tudarmstadt.informatik.hostage.logfilter.timestampbelow";
- private static final String TIMESTAMP_ABOVE_KEY = "de.tudarmstadt.informatik.hostage.logfilter.timestampabove";
- private static final String PROTOCOLS_KEY = "de.tudarmstadt.informatik.hostage.logfilter.protocols";
- private static final String ESSID_KEY = "de.tudarmstadt.informatik.hostage.logfilter.essid";
- private static final String BSSID_KEY = "de.tudarmstadt.informatik.hostage.logfilter.bssid";
- private static final String SORTTYPE_KEY = "de.tudarmstadt.informatik.hostage.logfilter.sorttype";
- public enum SortType{
- timestamp(0),
- protocol(1),
- _bssid(1),
- ssid(3),
- //remoteHostName(5),
- //lcaolHostName(6),
- _attack_id(7),
- _id(8);
- private final int id;
- SortType(int id) {
- this.id = id;
- }
- public int getValue() {
- return id;
- }
- }
-
- public ArrayList<String> BSSIDs;
- public ArrayList<String> ESSIDs;
- public ArrayList<String> protocols;
-
- public boolean isNotEditable;
-
- public SortType sorttype;
- public long belowTimestamp;
- public long aboveTimestamp;
-
-
- public LogFilter(){
- this.clear();
- }
- public void clear(){
- this.belowTimestamp = Long.MAX_VALUE;
- this.aboveTimestamp = Long.MIN_VALUE;
- this.sorttype = SortType.timestamp;
- this.BSSIDs = new ArrayList<String>();
- this.ESSIDs = new ArrayList<String>();
- this.protocols = new ArrayList<String>();
- }
- public int describeContents() {
- return 0;
- }
- // write your object's data to the passed-in Parcel
- public void writeToParcel(Parcel out, int flags) {
- HashMap<String, ArrayList<String>> values =new HashMap<String, ArrayList<String>>();
- if(this.BSSIDs != null && this.BSSIDs.size() > 0){
- values.put(BSSID_KEY , this.getBSSIDs() );
- }
- if(this.ESSIDs != null && this.ESSIDs.size() > 0){
- values.put(ESSID_KEY , this.getESSIDs() );
- }
- if(this.protocols != null && this.protocols.size() > 0){
- values.put(PROTOCOLS_KEY , this.getProtocols() );
- }
- long timeArray[] = new long[] {this.aboveTimestamp, this.belowTimestamp};
- out.writeMap(values);
- out.writeInt(this.sorttype.getValue());
- out.writeDouble(timeArray.length);
- out.writeLongArray(timeArray);
- out.writeString(this.isNotEditable? "true" : "false");
- }
-
- public static final Parcelable.Creator<LogFilter> CREATOR = new Parcelable.Creator<LogFilter>() {
- public LogFilter createFromParcel(Parcel in) {
- return new LogFilter(in);
- }
- public LogFilter[] newArray(int size) {
- return new LogFilter[size];
- }
- };
- // example constructor that takes a Parcel and gives you an object populated with it's values
- private LogFilter(Parcel in) {
- //mData = in.readInt();
- HashMap<String, ArrayList<String>> values = new HashMap<String, ArrayList<String>>();
- in.readMap(values, ArrayList.class.getClassLoader());
-
- this.BSSIDs = values.get(BSSID_KEY);
- this.ESSIDs = values.get(ESSID_KEY);
- this.protocols = values.get(protocols);
-
- if(this.BSSIDs == null) this.BSSIDs = new ArrayList<String>();
- if(this.ESSIDs == null) this.ESSIDs = new ArrayList<String>();
- if(this.protocols == null) this.protocols = new ArrayList<String>();
-
- this.sorttype = SortType.values()[Math.min(in.readInt(), SortType.values().length)];
-
- int size = (int)in.readDouble();
- long timeArray[] = new long[size];
- in.readLongArray(timeArray);
-
- this.belowTimestamp = timeArray[1];
- this.aboveTimestamp = timeArray[0];
-
- String bool = in.readString();
- if(bool.equals("true")) this.isNotEditable = true;
- }
-
- public boolean isNotEditable(){
- return this.isNotEditable;
- }
- public SortType getSorttype(){
- return this.sorttype;
- }
- public ArrayList<String> getBSSIDs(){
- return this.BSSIDs;
- }
- public ArrayList<String> getESSIDs(){
- return this.ESSIDs;
- }
- public ArrayList<String> getProtocols(){
- return this.protocols;
- }
- public void setIsNotEditable(boolean b){
- this.isNotEditable = b;
- }
-
- public long getBelowTimestamp(){
- return this.belowTimestamp;
- }
- public long getAboveTimestamp(){
- return this.aboveTimestamp;
- }
- public void setProtocols(ArrayList<String> protocols){
- this.protocols = protocols;
- }
- public void setBSSIDs(ArrayList<String> bssids){
- this.BSSIDs = bssids;
- }
- public void setESSIDs(ArrayList<String> essids){
- this.ESSIDs = essids;
- }
- public void setAboveTimestamp(long timestamp){
- this.aboveTimestamp = timestamp;
- }
- public void setBelowTimestamp(long timestamp){
- this.belowTimestamp = timestamp;
- }
- public void setSorttype(SortType type){
- this.sorttype = type;
- }
-
-
- public String getBSSIDQueryStatement(String key){
- return this.convertArrayListToQueryString(this.BSSIDs, UglyDbHelper.TABLE_BSSIDS, key);
- }
- public String getESSIDQueryStatement(String key){
- return this.convertArrayListToQueryString(this.ESSIDs, UglyDbHelper.TABLE_BSSIDS ,key);
- }
- public String getProtocolsQueryStatement(String key){
- return this.convertArrayListToQueryString(this.protocols,UglyDbHelper.TABLE_ATTACK_INFO, key);
- }
- public boolean isSet(){
- boolean hasTime = this.belowTimestamp != Long.MAX_VALUE|| this.aboveTimestamp != Long.MIN_VALUE;
- boolean hasBSSIDs = this.getBSSIDs().size() > 0;
- boolean hasESSIDs = this.getBSSIDs().size() > 0;
- boolean hasProtocols = this.getProtocols().size() > 0;
- return hasBSSIDs || hasESSIDs || hasProtocols | hasTime;
- }
-
- public String convertArrayListToQueryString(ArrayList<String> list, String table, String key){
- String statement = "";
- if (list == null) return statement;
- statement = " ( ";
- int i = 0, max = list.size();
- for (String element : list){
- i++;
- statement = statement + table + "." + key + " = " + "'" + element + "'";
- if (i == max) continue;
- statement = statement +" OR ";
- }
- statement = statement + " ) ";
- return statement;
- }
-
- }
|