RecordOverviewFragment.java 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. package de.tudarmstadt.informatik.hostage.ui2.fragment;
  2. import android.annotation.SuppressLint;
  3. import android.app.Fragment;
  4. import android.content.Context;
  5. import android.content.Intent;
  6. import android.graphics.Color;
  7. import android.os.Bundle;
  8. import android.text.SpannableString;
  9. import android.text.style.ForegroundColorSpan;
  10. import android.view.LayoutInflater;
  11. import android.view.Menu;
  12. import android.view.MenuInflater;
  13. import android.view.MenuItem;
  14. import android.view.View;
  15. import android.view.ViewGroup;
  16. import android.widget.AdapterView;
  17. import android.widget.ExpandableListView;
  18. import android.widget.ImageButton;
  19. import android.widget.PopupMenu;
  20. import android.widget.PopupMenu.OnMenuItemClickListener;
  21. import android.widget.Toast;
  22. import com.google.android.gms.maps.model.LatLng;
  23. import java.text.DateFormat;
  24. import java.text.SimpleDateFormat;
  25. import java.util.ArrayList;
  26. import java.util.Calendar;
  27. import java.util.Collections;
  28. import java.util.Comparator;
  29. import java.util.Date;
  30. import java.util.HashMap;
  31. import java.util.Random;
  32. import de.tudarmstadt.informatik.hostage.R;
  33. import de.tudarmstadt.informatik.hostage.logging.Record;
  34. import de.tudarmstadt.informatik.hostage.logging.Record.TYPE;
  35. import de.tudarmstadt.informatik.hostage.logging.UglyDbHelper;
  36. import de.tudarmstadt.informatik.hostage.ui.LogFilter;
  37. import de.tudarmstadt.informatik.hostage.ui.LogFilter.SortType;
  38. import de.tudarmstadt.informatik.hostage.ui2.adapter.RecordListAdapter;
  39. import de.tudarmstadt.informatik.hostage.ui2.dialog.ChecklistDialog;
  40. import de.tudarmstadt.informatik.hostage.ui2.dialog.DateTimeDialogFragment;
  41. import de.tudarmstadt.informatik.hostage.ui2.model.ExpandableListItem;
  42. public class RecordOverviewFragment extends Fragment implements ChecklistDialog.ChecklistDialogListener, DateTimeDialogFragment.DateTimeDialogFragmentListener {
  43. static final String SELECTED_KEY = "Selected";
  44. static final String OTHERS_KEY = "Other";
  45. static final String FILTER_MENU_TITLE_BSSID = "Filter by BSSID";
  46. static final String FILTER_MENU_TITLE_ESSID = "Filter by ESSID";
  47. static final String FILTER_MENU_TITLE_PROTOCOLS = "Filter by Protocol";
  48. static final String FILTER_MENU_TITLE_TIMESTAMP_BELOW = "To Date";
  49. static final String FILTER_MENU_TITLE_TIMESTAMP_ABOVE = "From Date";
  50. static final String FILTER_MENU_TITLE_SORTING = "Sort by";
  51. static final String FILTER_MENU_TITLE_REMOVE = "Reset Filter";
  52. static final String FILTER_MENU_TITLE_GROUP = "Group by";
  53. private boolean wasBelowTimePicker;
  54. private LogFilter filter;
  55. private boolean showFilterButton;
  56. public String groupingKey;
  57. private ExpandableListView expListView;
  58. UglyDbHelper dbh;
  59. public RecordOverviewFragment(){}
  60. @Override
  61. public void onCreate(Bundle savedInstanceState) {
  62. super.onCreate(savedInstanceState);
  63. setHasOptionsMenu(true);
  64. }
  65. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  66. Bundle savedInstanceState) {
  67. dbh = new UglyDbHelper(this.getActivity().getBaseContext());
  68. // Get the message from the intent
  69. if (this.filter == null){
  70. Intent intent = this.getActivity().getIntent();
  71. LogFilter filter = intent.getParcelableExtra(LogFilter.LOG_FILTER_INTENT_KEY);
  72. if(filter == null){
  73. this.clearFilter();
  74. } else {
  75. this.filter = filter;
  76. }
  77. }
  78. if (this.groupingKey == null) this.groupingKey = this.groupingTitles().get(0);
  79. this.setShowFilterButton(!this.filter.isNotEditable());
  80. this.addRecordToDB();
  81. View rootView = inflater.inflate(R.layout.fragment_record_list, container, false);
  82. ExpandableListView mylist = (ExpandableListView) rootView.findViewById(R.id.loglistview);
  83. this.expListView = mylist;
  84. populateListViewFromDB(mylist);
  85. registerListClickCallback(mylist);
  86. ImageButton filterButton = (ImageButton) rootView.findViewById(R.id.FilterButton);
  87. filterButton.setOnClickListener(new View.OnClickListener() {
  88. public void onClick(View v) {
  89. RecordOverviewFragment.this.openFilterPopupMenuOnView(v);
  90. }
  91. });
  92. filterButton.setVisibility(this.showFilterButton? View.VISIBLE : View.INVISIBLE);
  93. ImageButton sortButton = (ImageButton) rootView.findViewById(R.id.SortButton);
  94. sortButton.setOnClickListener(new View.OnClickListener() {
  95. public void onClick(View v) {
  96. // Open SortMenu
  97. RecordOverviewFragment.this.openSortingDialog();
  98. }
  99. });
  100. ImageButton groupButton = (ImageButton) rootView.findViewById(R.id.GroupButton);
  101. groupButton.setOnClickListener(new View.OnClickListener() {
  102. public void onClick(View v) {
  103. // Open SortMenu
  104. RecordOverviewFragment.this.openGroupingDialog();
  105. }
  106. });
  107. return rootView;
  108. }
  109. public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
  110. super.onCreateOptionsMenu(menu, inflater);
  111. }
  112. public boolean onFilterMenuItemSelected(MenuItem item) {
  113. String title = item.getTitle().toString();
  114. if(title.equals(FILTER_MENU_TITLE_BSSID)){
  115. this.openBSSIDFilterDialog();
  116. }
  117. if(title.equals(FILTER_MENU_TITLE_ESSID)){
  118. this.openESSIDFilterDialog();
  119. }
  120. if(title.equals(FILTER_MENU_TITLE_PROTOCOLS)){
  121. this.openProtocolsFilterDialog();
  122. }
  123. if(title.equals(FILTER_MENU_TITLE_SORTING)){
  124. this.openSortingDialog();
  125. }
  126. if(title.equals(FILTER_MENU_TITLE_REMOVE)){
  127. this.clearFilter();
  128. this.populateListViewFromDB(this.expListView);
  129. }
  130. if(title.equals(FILTER_MENU_TITLE_TIMESTAMP_BELOW)){
  131. this.openTimestampToFilterDialog();
  132. }
  133. if(title.equals(FILTER_MENU_TITLE_TIMESTAMP_ABOVE)){
  134. this.openTimestampFromFilterDialog();
  135. }
  136. return super.onOptionsItemSelected(item);
  137. }
  138. /*****************************
  139. *
  140. * ListView Stuff
  141. *
  142. * ***************************/
  143. private void populateListViewFromDB(ExpandableListView mylist) {
  144. HashMap<String, ArrayList<ExpandableListItem>> sectionData = new HashMap<String, ArrayList<ExpandableListItem>>();
  145. ArrayList<Record> data = dbh.getRecordsForFilter(this.filter);
  146. // Adding Items to ListView
  147. String keys[] = new String[] { this.getString(R.string.RecordBSSID), this.getString(R.string.RecordSSID), this.getString(R.string.RecordProtocol), this.getString(R.string.RecordTimestamp)};
  148. int ids[] = new int[] {R.id.RecordTextFieldBSSID, R.id.RecordTextFieldSSID, R.id.RecordTextFieldProtocol, R.id.RecordTextFieldTimestamp };
  149. HashMap<String, Integer> mapping = new HashMap<String, Integer>();
  150. int i = 0;
  151. for(String key : keys){
  152. mapping.put(key, ids[i]);
  153. i++;
  154. }
  155. ArrayList<String>groupTitle = new ArrayList<String>();
  156. for (Record val : data) {
  157. // DO GROUPING IN HERE
  158. HashMap<String, String> map = new HashMap<String, String>();
  159. map.put(this.getString(R.string.RecordBSSID), val.getBssid());
  160. map.put(this.getString(R.string.RecordSSID), val.getSsid());
  161. map.put(this.getString(R.string.RecordProtocol), val.getProtocol());
  162. map.put(this.getString(R.string.RecordTimestamp),
  163. this.getDateAsString(val.getTimestamp()));
  164. ExpandableListItem item = new ExpandableListItem();
  165. item.setData(map);
  166. item.setId_Mapping(mapping);
  167. String groupID = this.getGroupValue(val);
  168. ArrayList<ExpandableListItem> items = sectionData.get(groupID);
  169. if (items == null) {
  170. items = new ArrayList<ExpandableListItem>();
  171. sectionData.put(groupID, items);
  172. groupTitle.add(groupID);
  173. }
  174. items.add(item);
  175. }
  176. Collections.sort(groupTitle, new Comparator<String>() {
  177. @Override
  178. public int compare(String s1, String s2) {
  179. return s1.compareToIgnoreCase(s2);
  180. }
  181. });
  182. RecordListAdapter adapter = new RecordListAdapter(this.getApplicationContext(), groupTitle, sectionData);
  183. mylist.setAdapter(adapter);
  184. }
  185. private Context getBaseContext(){
  186. return this.getActivity().getBaseContext();
  187. }
  188. private Context getApplicationContext(){
  189. return this.getActivity().getApplicationContext();
  190. }
  191. private void registerListClickCallback(ExpandableListView mylist) {
  192. mylist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  193. public void onItemClick(AdapterView<?> parent, View viewClicked,
  194. int position, long idInDB) {
  195. UglyDbHelper dbh = new UglyDbHelper(getBaseContext());
  196. Record rec = dbh.getRecord((int) idInDB);
  197. String message = createInformationStringFromRecord(rec);
  198. Toast.makeText(getApplicationContext(), message,
  199. Toast.LENGTH_LONG).show();
  200. }
  201. private String createInformationStringFromRecord(Record rec) {
  202. String message = "id: " + rec.getId() + "\n" + "attack_id: "
  203. + rec.getAttack_id() + "\n" + "protocol: "
  204. + rec.getProtocol() + "\n" + "type: " + rec.getType()
  205. + "\n" + "externalIP: " + rec.getExternalIP() + "\n"
  206. + "localIP: " + rec.getLocalIP() + "\n"
  207. + "local port: " + rec.getLocalPort() + "\n"
  208. + "remoteIP: " + rec.getRemoteIP() + "\n" + "BSSID: "
  209. + rec.getBssid() + "\n" + "SSID: " + rec.getSsid()
  210. + "\n" + "latitude: " + rec.getLatitude() + "\n"
  211. + "longitude: " + rec.getLongitude() + "\n"
  212. + "accuracy: " + rec.getAccuracy() + "\n" + "packet: "
  213. + rec.getPacket() + "\n"
  214. + getDateAsString(rec.getTimestamp()) + "";
  215. return message;
  216. }
  217. });
  218. }
  219. /*****************************
  220. *
  221. * Date Transform
  222. *
  223. * ***************************/
  224. @SuppressLint("SimpleDateFormat")
  225. private String getDateAsString(long timeStamp) {
  226. try {
  227. DateFormat sdf = new SimpleDateFormat("H:mm dd/MM/yyyy");
  228. Date netDate = (new Date(timeStamp));
  229. return sdf.format(netDate);
  230. } catch (Exception ex) {
  231. return "xx";
  232. }
  233. }
  234. /*****************************
  235. *
  236. * Getter / Setter
  237. *
  238. * ***************************/
  239. public boolean isShowFilterButton() {
  240. return showFilterButton;
  241. }
  242. public void setShowFilterButton(boolean showFilterButton) {
  243. this.showFilterButton = showFilterButton;
  244. }
  245. /*****************************
  246. *
  247. * Open Dialog Methods
  248. *
  249. * ***************************/
  250. private void openGroupingDialog(){
  251. ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_TITLE_GROUP, this.groupingTitles(), this.selectedGroup(), false , this);
  252. newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_GROUP);
  253. }
  254. private void openBSSIDFilterDialog(){
  255. ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_TITLE_BSSID,this.bssids(), this.selectedBSSIDs(), true , this);
  256. newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_BSSID);
  257. }
  258. private void openESSIDFilterDialog(){
  259. ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_TITLE_ESSID,this.essids(), this.selectedESSIDs(), true , this);
  260. newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_ESSID);
  261. }
  262. private void openProtocolsFilterDialog(){
  263. ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_TITLE_PROTOCOLS,this.protocolTitles(), this.selectedProtocols(), true , this);
  264. newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_PROTOCOLS);
  265. }
  266. private void openTimestampFromFilterDialog(){
  267. this.wasBelowTimePicker = false;
  268. DateTimeDialogFragment newFragment = new DateTimeDialogFragment(this.getActivity());
  269. newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_SORTING);
  270. if (this.filter.aboveTimestamp != Long.MIN_VALUE)newFragment.setDate(this.filter.aboveTimestamp);
  271. }
  272. private void openTimestampToFilterDialog(){
  273. this.wasBelowTimePicker = true;
  274. DateTimeDialogFragment newFragment = new DateTimeDialogFragment(this.getActivity());
  275. newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_SORTING);
  276. if (this.filter.belowTimestamp != Long.MAX_VALUE) newFragment.setDate(this.filter.belowTimestamp);
  277. }
  278. private void openSortingDialog(){
  279. ChecklistDialog newFragment = new ChecklistDialog(FILTER_MENU_TITLE_SORTING,this.sortTypeTiles(), this.selectedSorttype(), false , this);
  280. newFragment.show(this.getActivity().getFragmentManager(), FILTER_MENU_TITLE_SORTING);
  281. }
  282. /*****************************
  283. *
  284. * Grouping Stuff
  285. *
  286. * ***************************/
  287. public String getGroupValue(Record rec){
  288. int index = this.groupingTitles().indexOf(this.groupingKey);
  289. switch (index){
  290. case 0:
  291. return rec.getProtocol();
  292. case 1:
  293. return rec.getBssid();
  294. case 2:
  295. return rec.getSsid();
  296. default:
  297. return rec.getProtocol();
  298. }
  299. }
  300. public ArrayList<String> getGroupTitle(){
  301. int index = this.groupingTitles().indexOf(this.groupingKey);
  302. switch (index){
  303. case 0:
  304. return this.protocolTitles();
  305. case 1:
  306. return this.bssids();
  307. case 2:
  308. return this.essids();
  309. default:
  310. return this.protocolTitles();
  311. }
  312. }
  313. /*****************************
  314. *
  315. * Filter Stuff
  316. *
  317. * ***************************/
  318. private void openFilterPopupMenuOnView(View v){
  319. // Open FilterMenu
  320. PopupMenu filterMenu = new PopupMenu(getBaseContext(), v);
  321. for(String title : RecordOverviewFragment.this.filterMenuTitles()){
  322. // Set a white Title
  323. SpannableString styledMenuTitle = new SpannableString(title);
  324. styledMenuTitle.setSpan(new ForegroundColorSpan(Color.parseColor("#FFFFFF")), 0, title.length(), 0);
  325. MenuItem item = filterMenu.getMenu().add(styledMenuTitle);
  326. item.setCheckable(this.isFilterSetForTitle(title));
  327. if (item.isCheckable()) item.setChecked(true);
  328. }
  329. filterMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
  330. public boolean onMenuItemClick(MenuItem item) {
  331. RecordOverviewFragment.this.onFilterMenuItemSelected(item);
  332. return true;
  333. }
  334. });
  335. filterMenu.show();
  336. }
  337. private boolean isFilterSetForTitle(String title){
  338. if (title.equals(FILTER_MENU_TITLE_BSSID)){
  339. return this.filter.hasBSSIDs();
  340. }
  341. if (title.equals(FILTER_MENU_TITLE_ESSID)){
  342. return this.filter.hasESSIDs();
  343. }
  344. if (title.equals(FILTER_MENU_TITLE_PROTOCOLS)){
  345. return this.filter.hasProtocols();
  346. }
  347. if (title.equals(FILTER_MENU_TITLE_TIMESTAMP_BELOW)){
  348. return this.filter.hasBelowTimestamp();
  349. }
  350. if (title.equals(FILTER_MENU_TITLE_TIMESTAMP_ABOVE)){
  351. return this.filter.hasAboveTimestamp();
  352. }
  353. return false;
  354. }
  355. private void clearFilter(){
  356. if(filter == null) this.filter = new LogFilter();
  357. this.filter.clear();
  358. }
  359. public ArrayList<String> groupingTitles(){
  360. ArrayList<String> titles = new ArrayList<String>();
  361. for (String groupTitle : this.getResources().getStringArray(
  362. R.array.Grouping)) {
  363. titles.add(groupTitle);
  364. }
  365. return titles;
  366. }
  367. public boolean[] selectedGroup(){
  368. ArrayList<String> groups = this.groupingTitles();
  369. boolean[] selected = new boolean[groups.size()];
  370. int i = 0;
  371. for(String group : groups){
  372. selected[i] =(group.equals(this.groupingKey));
  373. i++;
  374. }
  375. return selected;
  376. }
  377. public ArrayList<String> protocolTitles(){
  378. ArrayList<String> titles = new ArrayList<String>();
  379. for (String protocol : this.getResources().getStringArray(
  380. R.array.protocols)) {
  381. titles.add(protocol);
  382. }
  383. return titles;
  384. }
  385. public boolean[] selectedProtocols(){
  386. ArrayList<String> protocols = this.protocolTitles();
  387. boolean[] selected = new boolean[protocols.size()];
  388. int i = 0;
  389. for(String protocol : protocols){
  390. selected[i] =(this.filter.protocols.contains(protocol));
  391. i++;
  392. }
  393. return selected;
  394. }
  395. public ArrayList<String> sortTypeTiles(){
  396. ArrayList<String> titles = new ArrayList<String>();
  397. titles.add("Time");
  398. titles.add("Protocol");
  399. titles.add("BSSID");
  400. titles.add("ESSID");
  401. //titles.add("Remote Host Name");
  402. //titles.add("Local Host Name");
  403. //titles.add("Attack ID");
  404. //titles.add("ID");
  405. return titles;
  406. }
  407. public boolean[] selectedSorttype(){
  408. ArrayList<String> types = this.sortTypeTiles();
  409. boolean[] selected = new boolean[types.size()];
  410. int i = 0;
  411. for(String sorttype : types){
  412. selected[i] =(this.filter.sorttype.toString() == sorttype);
  413. i++;
  414. }
  415. return selected;
  416. }
  417. public ArrayList<String> bssids(){
  418. ArrayList<String> records = dbh.getUniqueBSSIDRecords();
  419. return records;
  420. }
  421. public boolean[] selectedBSSIDs(){
  422. ArrayList<String> bssids = this.bssids();
  423. boolean[] selected = new boolean[bssids.size()];
  424. int i = 0;
  425. for(String bssid : bssids){
  426. selected[i] =(this.filter.BSSIDs.contains(bssid));
  427. i++;
  428. }
  429. return selected;
  430. }
  431. public ArrayList<String> essids(){
  432. ArrayList<String> records = dbh.getUniqueESSIDRecords();
  433. return records;
  434. }
  435. public boolean[] selectedESSIDs(){
  436. ArrayList<String> essids = this.essids();
  437. boolean[] selected = new boolean[essids.size()];
  438. int i = 0;
  439. for(String essid : essids){
  440. selected[i] =(this.filter.ESSIDs.contains(essid));
  441. i++;
  442. }
  443. return selected;
  444. }
  445. private ArrayList<String> filterMenuTitles(){
  446. ArrayList<String> titles = new ArrayList<String>();
  447. titles.add(FILTER_MENU_TITLE_BSSID);
  448. titles.add(FILTER_MENU_TITLE_ESSID);
  449. titles.add(FILTER_MENU_TITLE_PROTOCOLS);
  450. titles.add(FILTER_MENU_TITLE_TIMESTAMP_ABOVE);
  451. titles.add(FILTER_MENU_TITLE_TIMESTAMP_BELOW);
  452. if (this.filter.isSet())titles.add(FILTER_MENU_TITLE_REMOVE);
  453. return titles;
  454. }
  455. /*****************************
  456. *
  457. * Listener Actions
  458. *
  459. * ***************************/
  460. public void onDateTimePickerPositiveClick(DateTimeDialogFragment dialog) {
  461. if(this.wasBelowTimePicker){
  462. this.filter.setBelowTimestamp(dialog.getDate());
  463. } else {
  464. this.filter.setAboveTimestamp(dialog.getDate());
  465. }
  466. this.populateListViewFromDB(this.expListView);
  467. }
  468. public void onDateTimePickerNegativeClick(DateTimeDialogFragment dialog) {
  469. if(this.wasBelowTimePicker){
  470. this.filter.setBelowTimestamp(Long.MAX_VALUE);
  471. } else {
  472. this.filter.setAboveTimestamp(Long.MIN_VALUE);
  473. }
  474. }
  475. public void onDialogPositiveClick(ChecklistDialog dialog) {
  476. String title = dialog.getTitle();
  477. if(title.equals(FILTER_MENU_TITLE_BSSID)){
  478. ArrayList<String> titles =dialog.getSelectedItemTitles();
  479. if (titles.size() == this.bssids().size()){
  480. this.filter.setBSSIDs(new ArrayList<String>());
  481. } else {
  482. this.filter.setBSSIDs(titles);
  483. }
  484. }
  485. if(title.equals(FILTER_MENU_TITLE_ESSID)){
  486. ArrayList<String> titles =dialog.getSelectedItemTitles();
  487. if (titles.size() == this.essids().size()){
  488. this.filter.setESSIDs(new ArrayList<String>());
  489. } else {
  490. this.filter.setESSIDs(titles);
  491. }
  492. }
  493. if(title.equals(FILTER_MENU_TITLE_PROTOCOLS)){
  494. ArrayList<String> protocols = dialog.getSelectedItemTitles();
  495. if (protocols.size() == this.protocolTitles().size()){
  496. this.filter.setProtocols(new ArrayList<String>());
  497. } else {
  498. this.filter.setProtocols(dialog.getSelectedItemTitles());
  499. }
  500. }
  501. if(title.equals(FILTER_MENU_TITLE_SORTING)){
  502. ArrayList<String> titles = dialog.getSelectedItemTitles();
  503. if (titles.size() == 0) return;
  504. String t = titles.get(0);
  505. int sortType = this.sortTypeTiles().indexOf(t);
  506. this.filter.setSorttype(SortType.values()[sortType]);
  507. }
  508. if (title.equals(FILTER_MENU_TITLE_GROUP)){
  509. ArrayList<String> titles = dialog.getSelectedItemTitles();
  510. if (titles.size() == 0) return;
  511. this.groupingKey = titles.get(0);
  512. }
  513. this.populateListViewFromDB(this.expListView);
  514. }
  515. public void onDialogNegativeClick(ChecklistDialog dialog) {
  516. }
  517. /*****************************
  518. *
  519. * TEST
  520. *
  521. * ***************************/
  522. private void addRecordToDB() {
  523. if ((dbh.getRecordCount() > 0)) return;
  524. Calendar cal = Calendar.getInstance();
  525. int maxProtocolsIndex = this.getResources().getStringArray(
  526. R.array.protocols).length;
  527. Random random = new Random();
  528. LatLng tudarmstadtLoc = new LatLng(49.86923, 8.6632768);
  529. int numberofRecords = (int) (Math.random() * (50 - 10));
  530. for (int i = 0; i < numberofRecords; i++) {
  531. Record record = new Record();
  532. record.setId(i);
  533. record.setAttack_id(i);
  534. record.setBssid("BSSID: " + i);
  535. record.setSsid("SSID: w" + i);
  536. record.setTimestamp(cal.getTimeInMillis()
  537. + ((i * 60 * 60 * 60 * 24) * 1000));
  538. int index = i % maxProtocolsIndex;
  539. String protocolName = this.getResources().getStringArray(
  540. R.array.protocols)[index];
  541. record.setProtocol(protocolName);
  542. record.setLocalIP("127.0.0.1");
  543. record.setType(TYPE.SEND);
  544. record.setLatitude(tudarmstadtLoc.latitude + -0.01 + 0.02 * random.nextDouble());
  545. record.setLongitude(tudarmstadtLoc.longitude + -0.01 + 0.02 * random.nextDouble());
  546. dbh.addRecord(record);
  547. }
  548. int countAllLogs = dbh.getAllRecords().size();
  549. int countRecords = dbh.getRecordCount();
  550. int countAttacks = dbh.getAttackCount();
  551. if ((countRecords == 0)) {
  552. Record rec = dbh.getRecordOfAttackId(0);
  553. Record rec2 = dbh.getRecord(0);
  554. System.out.println("" + "Could not create logs!");
  555. }
  556. }
  557. }