SettingsFragment.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. package de.tudarmstadt.informatik.hostage.ui.fragment;
  2. import android.app.AlarmManager;
  3. import android.app.AlertDialog;
  4. import android.app.FragmentManager;
  5. import android.app.PendingIntent;
  6. import android.content.Context;
  7. import android.content.Intent;
  8. import android.os.Bundle;
  9. import android.preference.CheckBoxPreference;
  10. import android.preference.Preference;
  11. import android.text.Html;
  12. import android.view.LayoutInflater;
  13. import android.view.View;
  14. import android.view.ViewGroup;
  15. import android.widget.Button;
  16. import android.widget.TextView;
  17. import de.tudarmstadt.informatik.hostage.R;
  18. import de.tudarmstadt.informatik.hostage.services.MultiStage;
  19. import de.tudarmstadt.informatik.hostage.services.MultiStageAlarm;
  20. import de.tudarmstadt.informatik.hostage.system.Device;
  21. import de.tudarmstadt.informatik.hostage.ui.activity.MainActivity;
  22. /**
  23. * @author Alexander Brakowski
  24. * @created 24.02.14 23:37
  25. * @modified Shreyas Srinivasa
  26. */
  27. public class SettingsFragment extends UpNavigatibleFragment {
  28. private TextView mPorthackText;
  29. private Button mPorthackInstallButton;
  30. private Button mPorthackUninstallButton;
  31. private Button MultiStageEnabled;
  32. public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  33. super.onCreateView(inflater, container, savedInstanceState);
  34. getActivity().setTitle(getResources().getString(R.string.drawer_settings));
  35. View v = inflater.inflate(R.layout.fragment_settings, container, false);
  36. TextView rootedText = (TextView) v.findViewById(R.id.settings_device_rooted);
  37. TextView iptablesText = (TextView) v.findViewById(R.id.settings_iptables_available);
  38. mPorthackText = (TextView) v.findViewById(R.id.settings_porthack_installed);
  39. mPorthackInstallButton = (Button) v.findViewById(R.id.settings_deploy_porthack);
  40. mPorthackUninstallButton = (Button) v.findViewById(R.id.settings_uninstall_porthack);
  41. if (Device.isRooted()) {
  42. rootedText.setText(R.string.yes);
  43. rootedText.setTextColor(getResources().getColor(R.color.holo_dark_green));
  44. } else {
  45. rootedText.setText(R.string.no);
  46. rootedText.setTextColor(getResources().getColor(R.color.holo_red));
  47. }
  48. if (Device.isPortRedirectionAvailable()) {
  49. iptablesText.setText(R.string.yes);
  50. iptablesText.setTextColor(getResources().getColor(R.color.holo_dark_green));
  51. } else {
  52. iptablesText.setText(R.string.no);
  53. iptablesText.setTextColor(getResources().getColor(R.color.holo_red));
  54. }
  55. updatePorthackStatus();
  56. mPorthackInstallButton.setOnClickListener(new View.OnClickListener() {
  57. @Override
  58. public void onClick(View v) {
  59. Device.deployPorthack();
  60. updatePorthackStatus();
  61. }
  62. });
  63. mPorthackUninstallButton.setOnClickListener(new View.OnClickListener() {
  64. @Override
  65. public void onClick(View v) {
  66. Device.uninstallPorthack();
  67. updatePorthackStatus();
  68. }
  69. });
  70. v.findViewById(R.id.porthack_info_button).setOnClickListener(new View.OnClickListener() {
  71. @Override
  72. public void onClick(View v) {
  73. AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.getInstance());
  74. builder.setMessage(Html.fromHtml(getString(R.string.porthack_explanation)));
  75. AlertDialog alert = builder.create();
  76. alert.show();
  77. }
  78. });
  79. return v;
  80. }
  81. private void updatePorthackStatus() {
  82. Device.checkCapabilities(); // get current situation
  83. if (Device.isPorthackInstalled()) {
  84. mPorthackText.setText(R.string.yes);
  85. mPorthackText.setTextColor(getResources().getColor(R.color.holo_dark_green));
  86. mPorthackInstallButton.setEnabled(false); // we're only able to deploy if the device is rooted
  87. mPorthackInstallButton.setVisibility(View.GONE);
  88. mPorthackUninstallButton.setEnabled(true);
  89. mPorthackUninstallButton.setVisibility(View.VISIBLE);
  90. } else {
  91. mPorthackText.setText(R.string.no);
  92. mPorthackText.setTextColor(getResources().getColor(R.color.holo_red));
  93. // we're only able to deploy if the device is rooted
  94. mPorthackInstallButton.setEnabled(Device.isRooted());
  95. mPorthackInstallButton.setVisibility(Device.isRooted() ? View.VISIBLE : View.GONE);
  96. mPorthackUninstallButton.setEnabled(false);
  97. mPorthackUninstallButton.setVisibility(View.GONE);
  98. }
  99. }
  100. public void onViewCreated(View view, Bundle savedInstanceState) {
  101. super.onViewCreated(view, savedInstanceState);
  102. FragmentManager manager = this.getFragmentManager();
  103. manager.beginTransaction().replace(R.id.settings_fragment_container, new PreferenceHostageFragment()).commit();
  104. }
  105. }