SettingsFragment.java 3.5 KB

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