RecordOverviewFragment.java 21 KB

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