RecordOverviewFragment.java 21 KB

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