MainActivity.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  1. package de.tudarmstadt.informatik.hostage.ui;
  2. import java.io.BufferedReader;
  3. import java.io.InputStreamReader;
  4. import java.util.ArrayList;
  5. import java.util.HashMap;
  6. import android.app.Activity;
  7. import android.app.ActivityManager;
  8. import android.app.ActivityManager.RunningServiceInfo;
  9. import android.content.BroadcastReceiver;
  10. import android.content.ComponentName;
  11. import android.content.Context;
  12. import android.content.Intent;
  13. import android.content.IntentFilter;
  14. import android.content.ServiceConnection;
  15. import android.content.SharedPreferences;
  16. import android.os.Bundle;
  17. import android.os.Handler;
  18. import android.os.IBinder;
  19. import android.support.v4.content.LocalBroadcastManager;
  20. import android.util.Log;
  21. import android.view.GestureDetector;
  22. import android.view.GestureDetector.SimpleOnGestureListener;
  23. import android.view.Menu;
  24. import android.view.MenuItem;
  25. import android.view.MotionEvent;
  26. import android.view.View;
  27. import android.view.View.OnTouchListener;
  28. import android.view.animation.Animation;
  29. import android.view.animation.AnimationUtils;
  30. import android.widget.AdapterView;
  31. import android.widget.AdapterView.OnItemClickListener;
  32. import android.widget.CheckBox;
  33. import android.widget.ImageView;
  34. import android.widget.ListView;
  35. import android.widget.TextView;
  36. import android.widget.ToggleButton;
  37. import android.widget.ViewAnimator;
  38. import de.tudarmstadt.informatik.hostage.HoneyService;
  39. import de.tudarmstadt.informatik.hostage.HoneyService.LocalBinder;
  40. import de.tudarmstadt.informatik.hostage.R;
  41. import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
  42. import de.tudarmstadt.informatik.hostage.logging.LogResultReceiver;
  43. import de.tudarmstadt.informatik.hostage.logging.LogResultReceiver.Receiver;
  44. import de.tudarmstadt.informatik.hostage.logging.Logger;
  45. import de.tudarmstadt.informatik.hostage.logging.UglyDbHelper;
  46. /**
  47. * MainActivity is the central activity for the GUI of the application.
  48. * MainActivity is launched when the application is first started. It shows the
  49. * user: <br>
  50. * - information about the network<br>
  51. * - light indicators for recorded attacks on each protocol<br>
  52. * - amount of attacks on each protocols<br>
  53. * The user can start and stop services.
  54. *
  55. * @author Mihai Plasoianu
  56. * @author Lars Pandikow
  57. * @author Wulf Pfeiffer
  58. */
  59. public class MainActivity extends Activity implements Receiver {
  60. /**
  61. * Flag for root acces. True if phone has root acces, else false.
  62. */
  63. public static boolean isRooted = false;
  64. /**
  65. * Flag for porthack. True if porthack is installed, else false.
  66. */
  67. public static boolean porthackInstalled = false;
  68. /**
  69. * Integer representing a grey light.
  70. */
  71. public static final int LIGHT_GREY = 0x01;
  72. /**
  73. * Integer representing a green light.
  74. */
  75. public static final int LIGHT_GREEN = 0x02;
  76. /**
  77. * Integer representing a red light.
  78. */
  79. public static final int LIGHT_RED = 0x03;
  80. /**
  81. * Integer representing a yellow light.
  82. */
  83. public static final int LIGHT_YELLOW = 0x04;
  84. public LogResultReceiver logResultReceiver;
  85. private SharedPreferences connectionInfo;
  86. private HoneyService mService;
  87. private boolean serviceBound;
  88. // variables for the swipe animation
  89. private ViewAnimator viewAnimator;
  90. private GestureDetector gestureDetector;
  91. private Animation animFlipInLR;
  92. private Animation animFlipOutLR;
  93. private Animation animFlipInRL;
  94. private Animation animFlipOutRL;
  95. private ListView listView;
  96. private ListViewAdapter adapter;
  97. private boolean isBssidSeen = false;
  98. /**
  99. * Connection to bind the background service
  100. *
  101. * @see HoneyService
  102. */
  103. private ServiceConnection mConnection = new ServiceConnection() {
  104. /**
  105. * After the service is bound, check which has been clicked and start
  106. * it.
  107. *
  108. * @see android.content.ServiceConnection#onServiceConnected(android.content.ComponentName)
  109. */
  110. @Override
  111. public void onServiceConnected(ComponentName name, IBinder service) {
  112. mService = ((LocalBinder) service).getService();
  113. serviceBound = true;
  114. updateUI();
  115. }
  116. /**
  117. * After the service is unbound, delete reference.
  118. *
  119. * @see android.content.ServiceConnection#onServiceDisconnected(android.content.ComponentName)
  120. */
  121. @Override
  122. public void onServiceDisconnected(ComponentName name) {
  123. mService = null;
  124. serviceBound = false;
  125. }
  126. };
  127. /**
  128. * Receiver for custom broadcast.
  129. *
  130. * @see #BROADCAST
  131. */
  132. private BroadcastReceiver mReceiver = new BroadcastReceiver() {
  133. @Override
  134. public void onReceive(Context context, Intent intent) {
  135. // Update user interface.
  136. updateUI();
  137. updateConnectionInfText();
  138. }
  139. };
  140. SimpleOnGestureListener simpleOnGestureListener = new SimpleOnGestureListener() {
  141. @Override
  142. public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
  143. float velocityY) {
  144. float sensitvity = 50;
  145. if ((e1.getX() - e2.getX()) > sensitvity) {
  146. swipeRightToLeft();
  147. } else if ((e2.getX() - e1.getX()) > sensitvity) {
  148. swipeLeftToRight();
  149. }
  150. return true;
  151. }
  152. };
  153. /**
  154. * Called when User presses on/off button.
  155. *
  156. * @param view
  157. */
  158. public void buttonOnOffClick(View view) {
  159. if (((ToggleButton) view).isChecked()) {
  160. if (isParanoid()) {
  161. String[] protocols = getResources().getStringArray(
  162. R.array.protocols);
  163. for (String protocol : protocols) {
  164. mService.startListener(protocol);
  165. }
  166. } else {
  167. if (mService.isRunning("SMB")) {
  168. mService.stopListener("SMB");
  169. } else {
  170. mService.startListener("SMB");
  171. }
  172. }
  173. } else {
  174. mService.stopListeners();
  175. stopAndUnbind();
  176. }
  177. }
  178. @Override
  179. public boolean onCreateOptionsMenu(Menu menu) {
  180. getMenuInflater().inflate(R.menu.main, menu);
  181. return true;
  182. }
  183. @Override
  184. public boolean onOptionsItemSelected(MenuItem item) {
  185. // Handle item selection
  186. switch (item.getItemId()) {
  187. case R.id.action_settings:
  188. startActivity(new Intent(this, SettingsActivity.class));
  189. break;
  190. case R.id.action_about:
  191. startActivity(new Intent(this, AboutActivity.class));
  192. break;
  193. default:
  194. }
  195. return super.onOptionsItemSelected(item);
  196. }
  197. @Override
  198. public void onReceiveResult(int resultCode, Bundle resultData) {
  199. isBssidSeen = resultData.getBoolean("result");
  200. }
  201. @Override
  202. public boolean onTouchEvent(MotionEvent event) {
  203. return gestureDetector.onTouchEvent(event);
  204. }
  205. /**
  206. * Starts the ViewLog activity, when the Button is pressed.
  207. *
  208. * @see ViewLog
  209. * @param view
  210. * View elements which triggers the method call.
  211. */
  212. public void showLog(View view) {
  213. startActivity(new Intent(this, ViewLog.class));
  214. }
  215. public void startPlayGround(View view) {
  216. startActivity(new Intent(this, PlayGroundActivity.class));
  217. }
  218. /**
  219. * Binds service to Activity
  220. *
  221. * @see HoneyService
  222. */
  223. private void bindService() {
  224. bindService(getServiceIntent(), mConnection, BIND_AUTO_CREATE);
  225. }
  226. /**
  227. * Stops service and unbinds it.
  228. *
  229. * @see HoneyService
  230. */
  231. private void stopAndUnbind() {
  232. unbindService();
  233. stopService(getServiceIntent());
  234. }
  235. /**
  236. * Unbinds service.
  237. *
  238. * @see HoneyService
  239. */
  240. private void unbindService() {
  241. unbindService(mConnection);
  242. }
  243. /**
  244. * Connection to bind the background service
  245. *
  246. * @see HoneyService
  247. */
  248. private ServiceConnection mConnection = new ServiceConnection() {
  249. /**
  250. * After the service is bound, check which has been clicked and start
  251. * it.
  252. *
  253. * @see android.content.ServiceConnection#onServiceConnected(android.content.ComponentName)
  254. */
  255. //@Override
  256. public void onServiceConnected(ComponentName name, IBinder service) {
  257. mService = ((LocalBinder) service).getService();
  258. serviceBound = true;
  259. updateUI();
  260. }
  261. /**
  262. * After the service is unbound, delete reference.
  263. *
  264. * @see android.content.ServiceConnection#onServiceDisconnected(android.content.ComponentName)
  265. */
  266. //@Override
  267. public void onServiceDisconnected(ComponentName name) {
  268. mService = null;
  269. serviceBound = false;
  270. }
  271. };
  272. /**
  273. * Checks if the phone ist rooted and if porthack is installed. Sets flags
  274. * {@link isRooted} and {@link porthackInstalled}
  275. */
  276. private void checkRootAndPorthack() {
  277. isRooted = false;
  278. porthackInstalled = false;
  279. Process p;
  280. try {
  281. String found = "Found";
  282. String notFound = "Not found";
  283. String command = "[ -f /data/local/p ] && echo " + found
  284. + " || echo " + notFound;
  285. p = Runtime.getRuntime().exec(new String[] { "su", "-c", command });
  286. BufferedReader in = new BufferedReader(new InputStreamReader(
  287. p.getInputStream()));
  288. /*
  289. * int av = byte[] b = new byte[av]; if (av != 0) { in.read(b); }
  290. */
  291. String echoResponse = in.readLine();
  292. Log.i("MainAc", echoResponse);
  293. if (echoResponse.equals(found)) {
  294. isRooted = true;
  295. porthackInstalled = true;
  296. } else if (echoResponse.equals(notFound)) {
  297. isRooted = true;
  298. }
  299. } catch (Exception e) {
  300. e.printStackTrace();
  301. }
  302. Log.i("MainAc", "Rooted: " + isRooted + " Porthack: "
  303. + porthackInstalled);
  304. }
  305. /**
  306. * Returns an intent to start HoneyService.
  307. *
  308. * @return An Intent to start HoneyService
  309. */
  310. private Intent getServiceIntent() {
  311. return new Intent(this, HoneyService.class);
  312. }
  313. /**
  314. * Initializes the ListView. Creating its contents dynamic from protocol
  315. * res/values/protocols.xml
  316. */
  317. private void initListView() {
  318. ArrayList<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>();
  319. for (String protocol : getResources().getStringArray(R.array.protocols)) {
  320. HashMap<String, String> d = new HashMap<String, String>();
  321. d.put("light", String.valueOf(R.drawable.light_grey));
  322. d.put("protocol", protocol);
  323. d.put("connections", "-");
  324. data.add(d);
  325. }
  326. listView = (ListView) findViewById(R.id.listViewProtocols);
  327. adapter = new ListViewAdapter(getLayoutInflater(), data);
  328. listView.setAdapter(adapter);
  329. listView.setOnTouchListener(new OnTouchListener() {
  330. //@Override
  331. public boolean onTouch(View v, MotionEvent event) {
  332. return gestureDetector.onTouchEvent(event);
  333. }
  334. });
  335. listView.setOnItemClickListener(new OnItemClickListener() {
  336. //@Override
  337. public void onItemClick(AdapterView<?> parent, View view,
  338. int position, long id) {
  339. String protocolName = (String) ((HashMap<?, ?>) adapter
  340. .getItem(position)).get("protocol");
  341. if (mService.isRunning(protocolName)) {
  342. mService.stopListener(protocolName);
  343. } else {
  344. mService.startListener(protocolName);
  345. }
  346. }
  347. });
  348. }
  349. /**
  350. * Initializes variables for screen animation
  351. */
  352. private void initViewAnimator() {
  353. viewAnimator = (ViewAnimator) findViewById(R.id.viewAnimator);
  354. gestureDetector = new GestureDetector(this, simpleOnGestureListener);
  355. animFlipInLR = AnimationUtils.loadAnimation(this,
  356. R.anim.in_left_to_right);
  357. animFlipOutLR = AnimationUtils.loadAnimation(this,
  358. R.anim.out_left_to_right);
  359. animFlipInRL = AnimationUtils.loadAnimation(this,
  360. R.anim.in_right_to_left);
  361. animFlipOutRL = AnimationUtils.loadAnimation(this,
  362. R.anim.out_right_to_left);
  363. }
  364. /**
  365. * Checks if user selected paranoid mode.
  366. *
  367. * @return True when paranoid mode is selected, else returns false.
  368. */
  369. private boolean isParanoid() {
  370. return ((CheckBox) findViewById(R.id.checkBoxParanoid)).isChecked();
  371. }
  372. /**
  373. * Checks if a {@link HoneyService} instance is running.
  374. *
  375. * @return True if {@link HoneyService} is running, else false.
  376. */
  377. private boolean isServiceBound() {
  378. return serviceBound;
  379. }
  380. /**
  381. * Checks if a {@link HoneyService} instance is running.
  382. *
  383. * @return True if {@link HoneyService} is running, else false.
  384. */
  385. private boolean isServiceRunning() {
  386. ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
  387. for (RunningServiceInfo service : manager
  388. .getRunningServices(Integer.MAX_VALUE)) {
  389. if (service.service.getClassName().equals(
  390. HoneyService.class.getName())) {
  391. return true;
  392. }
  393. }
  394. return false;
  395. }
  396. /**
  397. * Register broadcast receiver for custom broadcast.
  398. *
  399. * @see #BROADCAST
  400. */
  401. private void registerReceiver() {
  402. LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver,
  403. new IntentFilter(getString(R.string.broadcast)));
  404. }
  405. /**
  406. * If mobile phone is connected to a wireless network starts the background
  407. * service ands binds itself to it. Else notifies the user that service
  408. * could not be started.
  409. */
  410. private void startAndBind() {
  411. startService(getServiceIntent());
  412. bindService();
  413. }
  414. /**
  415. * Stops service and unbinds it.
  416. *
  417. * @see HoneyService
  418. */
  419. private void stopAndUnbind() {
  420. unbindService();
  421. stopService(getServiceIntent());
  422. }
  423. /**
  424. * Called when a swipe to the Right is registered.
  425. */
  426. private void swipeLeftToRight() {
  427. if (viewAnimator.getDisplayedChild() == 1) {
  428. viewAnimator.setInAnimation(animFlipInLR);
  429. viewAnimator.setOutAnimation(animFlipOutLR);
  430. viewAnimator.setDisplayedChild(0);
  431. }
  432. }
  433. /**
  434. * Called when a swipe to the Left is registered.
  435. */
  436. private void swipeRightToLeft() {
  437. if (viewAnimator.getDisplayedChild() == 0) {
  438. viewAnimator.setInAnimation(animFlipInRL);
  439. viewAnimator.setOutAnimation(animFlipOutRL);
  440. viewAnimator.setDisplayedChild(1);
  441. }
  442. }
  443. /**
  444. * Unbinds service.
  445. *
  446. * @see HoneyService
  447. */
  448. private void unbindService() {
  449. unbindService(mConnection);
  450. }
  451. /**
  452. * Unregisters broadcast receiver for custom broadcast.
  453. *
  454. * @see #BROADCAST
  455. */
  456. private void unregisterReceiver() {
  457. LocalBroadcastManager.getInstance(this).unregisterReceiver(mReceiver);
  458. }
  459. /**
  460. * Gets Information about connection state and updates the GUI.
  461. */
  462. private void updateConnectionInfText() {
  463. TextView ssidView = (TextView) findViewById(R.id.textViewSSIDValue);
  464. TextView bssidView = (TextView) findViewById(R.id.textViewBSSIDValue);
  465. TextView internalIPView = (TextView) findViewById(R.id.textViewInternalIPValue);
  466. TextView externalIPView = (TextView) findViewById(R.id.textViewExternalIPValue);
  467. // externalIPView.setText("Loading...");
  468. // Get connection information
  469. String ssid = connectionInfo.getString(
  470. getString(R.string.connection_info_ssid), null);
  471. String bssid = connectionInfo.getString(
  472. getString(R.string.connection_info_bssid), null);
  473. String internalIP = connectionInfo.getString(
  474. getString(R.string.connection_info_internal_ip), null);
  475. String externalIP = connectionInfo.getString(
  476. getString(R.string.connection_info_external_ip), null);
  477. // Set text fields
  478. if (ssid != null)
  479. ssidView.setText(ssid);
  480. else
  481. ssidView.setText("-");
  482. if (bssid != null)
  483. bssidView.setText(bssid);
  484. else
  485. bssidView.setText("-");
  486. if (internalIP != null)
  487. internalIPView.setText(internalIP);
  488. else
  489. internalIPView.setText("-");
  490. if (externalIP != null)
  491. externalIPView.setText(externalIP);
  492. else
  493. externalIPView.setText("-");
  494. }
  495. /**
  496. * Sets the connections count for a given protocol.
  497. *
  498. * @param connections
  499. * New value for recorded connections.
  500. * @param protocolName
  501. * Name of the protocol which should be updated.
  502. */
  503. private void updateProtocolConnections(int connections, String protocolName) {
  504. for (int i = 0; i < adapter.getCount(); ++i) {
  505. HashMap<String, String> d = ((HashMap<String, String>) adapter
  506. .getItem(i));
  507. if (d.get("protocol").equals(protocolName)) {
  508. d.put("connections", String.valueOf(connections));
  509. }
  510. }
  511. adapter.notifyDataSetChanged();
  512. }
  513. /**
  514. * Sets the light indicator for a given protocol.
  515. *
  516. * @param light
  517. * Integer code to set the light color.
  518. * @param protocolName
  519. * Name of the protocol which should be updated.
  520. */
  521. private void updateProtocolLight(int light, String protocolName) {
  522. for (int i = 0; i < adapter.getCount(); ++i) {
  523. HashMap<String, String> d = (HashMap<String, String>) adapter
  524. .getItem(i);
  525. if (d.get("protocol").equals(protocolName)) {
  526. switch (light) {
  527. case LIGHT_GREY:
  528. d.put("light", String.valueOf(R.drawable.light_grey));
  529. d.put("connections", "-");
  530. break;
  531. case LIGHT_GREEN:
  532. d.put("light", String.valueOf(R.drawable.light_green));
  533. break;
  534. case LIGHT_RED:
  535. d.put("light", String.valueOf(R.drawable.light_red));
  536. break;
  537. case LIGHT_YELLOW:
  538. d.put("light", String.valueOf(R.drawable.light_yellow));
  539. break;
  540. }
  541. }
  542. }
  543. adapter.notifyDataSetChanged();
  544. }
  545. /**
  546. * Sets the big light indicator.
  547. *
  548. * @param light
  549. * Integer code to set the light color.
  550. * @see #LIGHT_GREY
  551. * @see #LIGHT_GREEN
  552. * @see #LIGHT_RED
  553. * @see #LIGHT_YELLOW
  554. */
  555. private void updateStatusLight(int light) {
  556. switch (light) {
  557. case LIGHT_GREY:
  558. ((ImageView) findViewById(R.id.imageViewLight))
  559. .setImageResource(R.drawable.light_grey_large);
  560. break;
  561. case LIGHT_GREEN:
  562. ((ImageView) findViewById(R.id.imageViewLight))
  563. .setImageResource(R.drawable.light_green_large);
  564. break;
  565. case LIGHT_RED:
  566. ((ImageView) findViewById(R.id.imageViewLight))
  567. .setImageResource(R.drawable.light_red_large);
  568. break;
  569. case LIGHT_YELLOW:
  570. ((ImageView) findViewById(R.id.imageViewLight))
  571. .setImageResource(R.drawable.light_yellow_large);
  572. break;
  573. }
  574. }
  575. /* ############# Help functions for animation ################## */
  576. /**
  577. * Updates Information shown by the GUI.
  578. */
  579. private void updateUI() {
  580. boolean activeListeners = false;
  581. boolean activeHandlers = false;
  582. boolean yellowLight = false;
  583. // Check for all protocols if listeners are active and attacks have been
  584. // recorded
  585. // Update protocol lights and connection information.
  586. for (String protocol : getResources().getStringArray(R.array.protocols)) {
  587. if (isServiceBound()) {
  588. // Check if protocol is active
  589. if (mService.isRunning(protocol)) {
  590. activeListeners = true;
  591. int handlerCount = mService
  592. .getNumberOfActiveConnections(protocol);
  593. // Check if attacks have been recorded in this session.
  594. if (handlerCount > 0) {
  595. activeHandlers = true;
  596. updateProtocolLight(LIGHT_RED, protocol);
  597. updateProtocolConnections(handlerCount, protocol);
  598. } else {
  599. // Check if the bssid of the wireless network has
  600. // already
  601. // been recorded as infected.
  602. Logger.isBssidSeen(getApplicationContext(), protocol,
  603. HelperUtils.getBSSID(getApplicationContext()),
  604. logResultReceiver);
  605. UglyDbHelper dbh = new UglyDbHelper(this);
  606. if (dbh.bssidSeen(
  607. protocol,
  608. connectionInfo
  609. .getString(
  610. getString(R.string.connection_info_bssid),
  611. null))) {
  612. updateProtocolLight(LIGHT_YELLOW, protocol);
  613. yellowLight = true;
  614. } else {
  615. updateProtocolLight(LIGHT_GREEN, protocol);
  616. }
  617. updateProtocolConnections(0, protocol);
  618. }
  619. } else {
  620. updateProtocolLight(LIGHT_GREY, protocol);
  621. }
  622. } else {
  623. updateProtocolLight(LIGHT_GREY, protocol);
  624. }
  625. }
  626. // Update the big attack indicator.
  627. if (activeListeners) {
  628. if (activeHandlers) {
  629. updateStatusLight(LIGHT_RED);
  630. } else {
  631. if (yellowLight) {
  632. updateStatusLight(LIGHT_YELLOW);
  633. } else {
  634. updateStatusLight(LIGHT_GREEN);
  635. }
  636. }
  637. ((ToggleButton) findViewById(R.id.toggleButtonOnOff))
  638. .setChecked(true);
  639. findViewById(R.id.checkBoxParanoid).setEnabled(false);
  640. } else {
  641. updateStatusLight(LIGHT_GREY);
  642. ((ToggleButton) findViewById(R.id.toggleButtonOnOff))
  643. .setChecked(false);
  644. findViewById(R.id.checkBoxParanoid).setEnabled(true);
  645. }
  646. }
  647. @Override
  648. protected void onCreate(Bundle savedInstanceState) {
  649. super.onCreate(savedInstanceState);
  650. logResultReceiver = new LogResultReceiver(new Handler());
  651. setContentView(R.layout.activity_main);
  652. connectionInfo = getSharedPreferences(
  653. getString(R.string.connection_info), Context.MODE_PRIVATE);
  654. // Create dynamic view elements
  655. initViewAnimator();
  656. initListView();
  657. // Initialize Class variables
  658. checkRootAndPorthack();
  659. startAndBind();
  660. }
  661. @Override
  662. protected void onDestroy() {
  663. // Unbind running service
  664. if (!mService.hasRunningListeners()) {
  665. stopAndUnbind();
  666. }
  667. super.onDestroy();
  668. }
  669. @Override
  670. protected void onStart() {
  671. super.onStart();
  672. // Register Broadcast Receiver
  673. registerReceiver();
  674. logResultReceiver.setReceiver(this);
  675. // Bind service if running, else check for connection change and delete
  676. // sessionData
  677. if (isServiceRunning()) {
  678. bindService(getServiceIntent(), mConnection, BIND_AUTO_CREATE);
  679. }
  680. // Update UI
  681. updateConnectionInfText();
  682. }
  683. @Override
  684. protected void onStop() {
  685. // Unregister Broadcast Receiver
  686. unregisterReceiver();
  687. logResultReceiver.setReceiver(null);
  688. super.onStop();
  689. }
  690. }