SettingsFragment.java 4.0 KB

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