RecordOverviewFragment.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. package de.tudarmstadt.informatik.hostage.ui2.fragment;
  2. import com.google.android.gms.maps.model.LatLng;
  3. import android.annotation.SuppressLint;
  4. import android.app.Fragment;
  5. import android.content.Context;
  6. import android.content.Intent;
  7. import android.graphics.Color;
  8. import android.os.Bundle;
  9. import android.text.SpannableString;
  10. import android.text.style.ForegroundColorSpan;
  11. import android.view.LayoutInflater;
  12. import android.view.Menu;
  13. import android.view.MenuInflater;
  14. import android.view.MenuItem;
  15. import android.view.View;
  16. import android.view.ViewGroup;
  17. import android.widget.AdapterView;
  18. import android.widget.ExpandableListView;
  19. import android.widget.ImageButton;
  20. import android.widget.PopupMenu;
  21. import android.widget.PopupMenu.OnMenuItemClickListener;
  22. import android.widget.Toast;
  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 = "BSSID";
  46. static final String FILTER_MENU_TITLE_ESSID = "ESSID";
  47. static final String FILTER_MENU_TITLE_PROTOCOLS = "Protocols";
  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.sortTypeTtiles(), 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. filterMenu.getMenu().add(styledMenuTitle);
  326. }
  327. filterMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
  328. public boolean onMenuItemClick(MenuItem item) {
  329. RecordOverviewFragment.this.onFilterMenuItemSelected(item);
  330. return true;
  331. }
  332. });
  333. filterMenu.show();
  334. }
  335. private void clearFilter(){
  336. if(filter == null) this.filter = new LogFilter();
  337. this.filter.clear();
  338. }
  339. public ArrayList<String> groupingTitles(){
  340. ArrayList<String> titles = new ArrayList<String>();
  341. for (String groupTitle : this.getResources().getStringArray(
  342. R.array.Grouping)) {
  343. titles.add(groupTitle);
  344. }
  345. return titles;
  346. }
  347. public boolean[] selectedGroup(){
  348. ArrayList<String> groups = this.groupingTitles();
  349. boolean[] selected = new boolean[groups.size()];
  350. int i = 0;
  351. for(String group : groups){
  352. selected[i] =(group.equals(this.groupingKey));
  353. i++;
  354. }
  355. return selected;
  356. }
  357. public ArrayList<String> protocolTitles(){
  358. ArrayList<String> titles = new ArrayList<String>();
  359. for (String protocol : this.getResources().getStringArray(
  360. R.array.protocols)) {
  361. titles.add(protocol);
  362. }
  363. return titles;
  364. }
  365. public boolean[] selectedProtocols(){
  366. ArrayList<String> protocols = this.protocolTitles();
  367. boolean[] selected = new boolean[protocols.size()];
  368. int i = 0;
  369. for(String protocol : protocols){
  370. selected[i] =(this.filter.protocols.contains(protocol));
  371. i++;
  372. }
  373. return selected;
  374. }
  375. public ArrayList<String> sortTypeTtiles(){
  376. ArrayList<String> titles = new ArrayList<String>();
  377. titles.add("Time");
  378. titles.add("Protocol");
  379. titles.add("BSSID");
  380. titles.add("ESSID");
  381. //titles.add("Remote Host Name");
  382. //titles.add("Local Host Name");
  383. //titles.add("Attack ID");
  384. //titles.add("ID");
  385. return titles;
  386. }
  387. public boolean[] selectedSorttype(){
  388. ArrayList<String> types = this.sortTypeTtiles();
  389. boolean[] selected = new boolean[types.size()];
  390. int i = 0;
  391. for(String sorttype : types){
  392. selected[i] =(this.filter.sorttype.toString() == sorttype);
  393. i++;
  394. }
  395. return selected;
  396. }
  397. public ArrayList<String> bssids(){
  398. ArrayList<String> records = dbh.getUniqueBSSIDRecords();
  399. return records;
  400. }
  401. public boolean[] selectedBSSIDs(){
  402. ArrayList<String> bssids = this.bssids();
  403. boolean[] selected = new boolean[bssids.size()];
  404. int i = 0;
  405. for(String bssid : bssids){
  406. selected[i] =(this.filter.BSSIDs.contains(bssid));
  407. i++;
  408. }
  409. return selected;
  410. }
  411. public ArrayList<String> essids(){
  412. ArrayList<String> records = dbh.getUniqueESSIDRecords();
  413. return records;
  414. }
  415. public boolean[] selectedESSIDs(){
  416. ArrayList<String> essids = this.essids();
  417. boolean[] selected = new boolean[essids.size()];
  418. int i = 0;
  419. for(String essid : essids){
  420. selected[i] =(this.filter.ESSIDs.contains(essid));
  421. i++;
  422. }
  423. return selected;
  424. }
  425. private ArrayList<String> filterMenuTitles(){
  426. ArrayList<String> titles = new ArrayList<String>();
  427. titles.add(FILTER_MENU_TITLE_BSSID);
  428. titles.add(FILTER_MENU_TITLE_ESSID);
  429. titles.add(FILTER_MENU_TITLE_PROTOCOLS);
  430. titles.add(FILTER_MENU_TITLE_TIMESTAMP_ABOVE);
  431. titles.add(FILTER_MENU_TITLE_TIMESTAMP_BELOW);
  432. if (this.filter.isSet())titles.add(FILTER_MENU_TITLE_REMOVE);
  433. return titles;
  434. }
  435. /*****************************
  436. *
  437. * Listener Actions
  438. *
  439. * ***************************/
  440. public void onDateTimePickerPositiveClick(DateTimeDialogFragment dialog) {
  441. if(this.wasBelowTimePicker){
  442. this.filter.setBelowTimestamp(dialog.getDate());
  443. } else {
  444. this.filter.setAboveTimestamp(dialog.getDate());
  445. }
  446. this.populateListViewFromDB(this.expListView);
  447. }
  448. public void onDateTimePickerNegativeClick(DateTimeDialogFragment dialog) {
  449. if(this.wasBelowTimePicker){
  450. this.filter.setBelowTimestamp(Long.MAX_VALUE);
  451. } else {
  452. this.filter.setAboveTimestamp(Long.MIN_VALUE);
  453. }
  454. }
  455. public void onDialogPositiveClick(ChecklistDialog dialog) {
  456. String title = dialog.getTitle();
  457. if(title.equals(FILTER_MENU_TITLE_BSSID)){
  458. ArrayList<String> titles =dialog.getSelectedItemTitles();
  459. if (titles.size() == this.bssids().size()){
  460. this.filter.setBSSIDs(new ArrayList<String>());
  461. } else {
  462. this.filter.setBSSIDs(titles);
  463. }
  464. }
  465. if(title.equals(FILTER_MENU_TITLE_ESSID)){
  466. ArrayList<String> titles =dialog.getSelectedItemTitles();
  467. if (titles.size() == this.essids().size()){
  468. this.filter.setESSIDs(new ArrayList<String>());
  469. } else {
  470. this.filter.setESSIDs(titles);
  471. }
  472. }
  473. if(title.equals(FILTER_MENU_TITLE_PROTOCOLS)){
  474. ArrayList<String> protocols = dialog.getSelectedItemTitles();
  475. if (protocols.size() == this.protocolTitles().size()){
  476. this.filter.setProtocols(new ArrayList<String>());
  477. } else {
  478. this.filter.setProtocols(dialog.getSelectedItemTitles());
  479. }
  480. }
  481. if(title.equals(FILTER_MENU_TITLE_SORTING)){
  482. ArrayList<String> titles = dialog.getSelectedItemTitles();
  483. String t = titles.get(0);
  484. int sortType = this.sortTypeTtiles().indexOf(t);
  485. this.filter.setSorttype(SortType.values()[sortType]);
  486. }
  487. if (title.equals(FILTER_MENU_TITLE_GROUP)){
  488. ArrayList<String> titles = dialog.getSelectedItemTitles();
  489. this.groupingKey = titles.get(0);
  490. }
  491. this.populateListViewFromDB(this.expListView);
  492. }
  493. public void onDialogNegativeClick(ChecklistDialog dialog) {
  494. }
  495. /*****************************
  496. *
  497. * TEST
  498. *
  499. * ***************************/
  500. private void addRecordToDB() {
  501. if ((dbh.getRecordCount() > 0)) return;
  502. Calendar cal = Calendar.getInstance();
  503. int maxProtocolsIndex = this.getResources().getStringArray(
  504. R.array.protocols).length;
  505. Random random = new Random();
  506. LatLng tudarmstadtLoc = new LatLng(49.86923, 8.6632768);
  507. int numberofRecords = (int) (Math.random() * (50 - 10));
  508. for (int i = 0; i < numberofRecords; i++) {
  509. Record record = new Record();
  510. record.setId(i);
  511. record.setAttack_id(i);
  512. record.setBssid("BSSID: " + i);
  513. record.setSsid("SSID: w" + i);
  514. record.setTimestamp(cal.getTimeInMillis()
  515. + ((i * 60 * 60 * 60 * 24) * 1000));
  516. int index = i % maxProtocolsIndex;
  517. String protocolName = this.getResources().getStringArray(
  518. R.array.protocols)[index];
  519. record.setProtocol(protocolName);
  520. record.setLocalIP("127.0.0.1");
  521. record.setType(TYPE.SEND);
  522. record.setLatitude(tudarmstadtLoc.latitude + -0.01 + 0.02 * random.nextDouble());
  523. record.setLongitude(tudarmstadtLoc.longitude + -0.01 + 0.02 * random.nextDouble());
  524. dbh.addRecord(record);
  525. }
  526. int countAllLogs = dbh.getAllRecords().size();
  527. int countRecords = dbh.getRecordCount();
  528. int countAttacks = dbh.getAttackCount();
  529. if ((countRecords == 0)) {
  530. Record rec = dbh.getRecordOfAttackId(0);
  531. Record rec2 = dbh.getRecord(0);
  532. System.out.println("" + "Could not create logs!");
  533. }
  534. }
  535. }