Search in sources :

Example 1 with InstallScripts

use of org.ethack.orwall.lib.InstallScripts in project orWall by EthACKdotOrg.

the class HomeFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    home = inflater.inflate(R.layout.fragment_tabbed_home, container, false);
    iptables = new Iptables(getActivity());
    boolean initSupported = Iptables.initSupported();
    Switch orwallStatus = (Switch) home.findViewById(R.id.orwall_status);
    // Status switches — most of them are read-only, as they just displays devices capabilities.
    Switch status_initscript = (Switch) home.findViewById(R.id.status_initscript);
    Switch status_root = (Switch) home.findViewById(R.id.status_root);
    Switch status_iptables = (Switch) home.findViewById(R.id.status_iptables);
    Switch status_ipt_comments = (Switch) home.findViewById(R.id.status_ipt_comments);
    Switch status_orbot = (Switch) home.findViewById(R.id.status_orbot);
    // Buttons
    Button settings = (Button) home.findViewById(R.id.id_settings);
    Button about = (Button) home.findViewById(R.id.id_about);
    Button wizard = (Button) home.findViewById(R.id.id_wizard);
    // If we know there is no init-script support, then don't show it.
    if (initSupported && !iptables.isInitialized()) {
        home.findViewById(R.id.warn_init).setVisibility(View.VISIBLE);
    }
    orwallStatus.setChecked(Preferences.isOrwallEnabled(getActivity()));
    // orWall might be deactivated. Let's test it!
    orwallStatus.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            toggleOrwall(view);
        }
    });
    // Set status switches in order to show the user what's working. Or not working.
    // Init script: try to install it and so on
    InstallScripts installScripts = new InstallScripts(getActivity());
    installScripts.run();
    boolean enforceInit = Preferences.isEnforceInitScript(getActivity());
    status_initscript.setChecked((enforceInit && initSupported));
    status_initscript.setEnabled(initSupported);
    // If init script cannot be enabled, display why
    if (!initSupported) {
        TextView explain = (TextView) home.findViewById(R.id.status_initscript_description);
        explain.setText(String.format(getString(R.string.explain_no_initscript), Iptables.DST_FILE));
        explain.setVisibility(View.VISIBLE);
    }
    // add a listener to this switch
    status_initscript.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            boolean checked = compoundButton.isChecked();
            if (checked) {
                Iptables.installInitScript(getActivity());
            } else {
                Iptables.removeIniScript(getActivity());
            }
        }
    });
    // Do we have root access ?
    if (RootCommands.rootAccessGiven()) {
        status_root.setChecked(true);
        home.findViewById(R.id.warn_root).setVisibility(View.GONE);
    } else {
        status_root.setChecked(false);
        home.findViewById(R.id.warn_root).setVisibility(View.VISIBLE);
    }
    // Hopefully there IS iptables on this device…
    if (Iptables.iptablesExists()) {
        status_iptables.setChecked(true);
        home.findViewById(R.id.warn_iptables).setVisibility(View.GONE);
        home.findViewById(R.id.status_iptables_description).setVisibility(View.GONE);
    } else {
        status_iptables.setChecked(false);
        home.findViewById(R.id.warn_iptables).setVisibility(View.VISIBLE);
        home.findViewById(R.id.status_iptables_description).setVisibility(View.VISIBLE);
    }
    status_ipt_comments.setChecked(iptables.getSupportComment());
    // Is orbot installed?
    status_orbot.setChecked(Util.isOrbotInstalled(getActivity()));
    // Shows settings
    settings.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Intent intent = new Intent(getActivity(), PreferencesActivity.class);
            startActivity(intent);
        }
    });
    // Shows alert dialog with "about" stuff
    about.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            showAbout();
        }
    });
    // Start wizard
    wizard.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Intent wizard = new Intent(getActivity(), WizardActivity.class);
            startActivity(wizard);
        }
    });
    return home;
}
Also used : PreferencesActivity(org.ethack.orwall.PreferencesActivity) Iptables(org.ethack.orwall.lib.Iptables) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) View(android.view.View) TextView(android.widget.TextView) Switch(android.widget.Switch) Button(android.widget.Button) CompoundButton(android.widget.CompoundButton) InstallScripts(org.ethack.orwall.lib.InstallScripts) WizardActivity(org.ethack.orwall.WizardActivity) TextView(android.widget.TextView) CompoundButton(android.widget.CompoundButton)

Example 2 with InstallScripts

use of org.ethack.orwall.lib.InstallScripts in project orWall by EthACKdotOrg.

the class WizardFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_wizard, container, false);
    int[] titles = { R.string.wizard_title_one, R.string.wizard_title_two, R.string.wizard_title_three };
    String title = getString(R.string.wizard_title_one);
    String step = "Step 1: ";
    if (mPageNumber < titles.length) {
        title = getString(titles[mPageNumber]);
        step = String.format(Locale.US, "Step %d: ", mPageNumber + 1);
    }
    ((TextView) rootView.findViewById(R.id.wizard_step_title)).setText(step + title);
    int[] fragments = { R.string.wizard_first, R.string.wizard_second, R.string.wizard_third };
    String fragment = getString(fragments[0]);
    if (mPageNumber < fragments.length) {
        fragment = getString(fragments[mPageNumber]);
    }
    ((TextView) rootView.findViewById(R.id.wizard_fragment_content)).setText(fragment);
    rootView.findViewById(R.id.wizard_close).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Preferences.setFirstRun(getActivity(), false);
            getActivity().finish();
        }
    });
    // Add some stuff on the very first Wizard page
    if (mPageNumber == 0) {
        ViewGroup main_content = (ViewGroup) rootView.findViewById(R.id.id_main_content);
        final Iptables iptables = new Iptables(getActivity());
        // Extract scripts
        InstallScripts installScripts = new InstallScripts(getActivity());
        installScripts.run();
        // init-script installation
        // install init as default behavior
        Iptables.installInitScript(getActivity());
        boolean enforceInit = Preferences.isEnforceInitScript(getActivity());
        boolean initSupported = Iptables.initSupported();
        Switch initScript = new Switch(getActivity());
        initScript.setChecked((enforceInit && initSupported));
        initScript.setText(getString(R.string.wizard_init_script_text));
        initScript.setEnabled(initSupported);
        initScript.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                boolean checked = compoundButton.isChecked();
                if (checked) {
                    Iptables.installInitScript(getActivity());
                } else {
                    Iptables.removeIniScript(getActivity());
                }
            }
        });
        main_content.addView(initScript);
        // Root status
        Switch rootStatus = new Switch(getActivity());
        rootStatus.setChecked(RootCommands.rootAccessGiven());
        rootStatus.setEnabled(false);
        rootStatus.setText(getString(R.string.wizard_init_root_text));
        main_content.addView(rootStatus);
        // Does iptables exist?
        Switch iptablesStatus = new Switch(getActivity());
        iptablesStatus.setChecked(Iptables.iptablesExists());
        iptablesStatus.setEnabled(false);
        iptablesStatus.setText(getString(R.string.wizard_init_iptables_text));
        main_content.addView(iptablesStatus);
        // Does current kernel support IPTables comments?
        Switch iptablesComments = new Switch(getActivity());
        iptablesComments.setChecked(iptables.getSupportComment());
        iptablesComments.setEnabled(false);
        iptablesComments.setText(getString(R.string.wizard_init_ipt_comments_text));
        main_content.addView(iptablesComments);
        // Is orbot installed?
        Switch orbotStatus = new Switch(getActivity());
        orbotStatus.setChecked(Util.isOrbotInstalled(getActivity()));
        orbotStatus.setEnabled(false);
        orbotStatus.setText(getString(R.string.wizard_orbot_status_text));
        main_content.addView(orbotStatus);
    }
    return rootView;
}
Also used : ViewGroup(android.view.ViewGroup) Iptables(org.ethack.orwall.lib.Iptables) TextView(android.widget.TextView) View(android.view.View) Switch(android.widget.Switch) InstallScripts(org.ethack.orwall.lib.InstallScripts) TextView(android.widget.TextView) CompoundButton(android.widget.CompoundButton)

Aggregations

View (android.view.View)2 CompoundButton (android.widget.CompoundButton)2 Switch (android.widget.Switch)2 TextView (android.widget.TextView)2 InstallScripts (org.ethack.orwall.lib.InstallScripts)2 Iptables (org.ethack.orwall.lib.Iptables)2 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 ViewGroup (android.view.ViewGroup)1 Button (android.widget.Button)1 PreferencesActivity (org.ethack.orwall.PreferencesActivity)1 WizardActivity (org.ethack.orwall.WizardActivity)1