Search in sources :

Example 1 with Iptables

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

the class AppFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view;
    view = inflater.inflate(R.layout.fragment_tabbed_apps, container, false);
    Iptables iptables = new Iptables(getActivity());
    // Do we have root access ?
    if (RootCommands.rootAccessGiven()) {
        view.findViewById(R.id.warn_root).setVisibility(View.GONE);
    } else {
        view.findViewById(R.id.warn_root).setVisibility(View.VISIBLE);
    }
    // Hopefully there IS iptables on this device…
    if (Iptables.iptablesExists()) {
        view.findViewById(R.id.warn_iptables).setVisibility(View.GONE);
    } else {
        view.findViewById(R.id.warn_iptables).setVisibility(View.VISIBLE);
    }
    if (Iptables.initSupported() && !iptables.isInitialized()) {
        view.findViewById(R.id.warn_init).setVisibility(View.VISIBLE);
    }
    ListView listView = (ListView) view.findViewById(R.id.id_enabled_apps);
    // Toggle hint layer
    boolean hide_hint = Preferences.isHidePressHint(getActivity());
    if (hide_hint) {
        view.findViewById(R.id.hint_press).setVisibility(View.GONE);
    } else {
        view.findViewById(R.id.id_hide_hint).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                ((View) view.getParent()).setVisibility(View.GONE);
                Preferences.setHidePressHint(getActivity(), true);
            }
        });
    }
    // get enabled apps
    NatRules natRules = new NatRules(this.getActivity());
    List<AppRule> enabledApps = natRules.getAllRules();
    LongSparseArray<AppRule> rulesIndex = new LongSparseArray<>();
    for (AppRule app : enabledApps) rulesIndex.put(app.getAppUID(), app);
    // get disabled apps (filtered with enabled)
    List<AppRule> disabledApps = listDisabledApps(rulesIndex);
    // Get special, disabled apps
    List<AppRule> specialDisabled = listSpecialApps(rulesIndex);
    // Merge both disabled apps
    disabledApps.addAll(specialDisabled);
    // Sort collection using a dedicated method
    Collections.sort(enabledApps, new AppRuleComparator(getActivity().getPackageManager()));
    Collections.sort(disabledApps, new AppRuleComparator(getActivity().getPackageManager()));
    // merge both collections so that enabled apps are above disabled
    enabledApps.addAll(disabledApps);
    listView.setAdapter(new AppListAdapter(this.getActivity(), enabledApps));
    return view;
}
Also used : LongSparseArray(android.support.v4.util.LongSparseArray) Iptables(org.ethack.orwall.lib.Iptables) View(android.view.View) ListView(android.widget.ListView) AppRuleComparator(org.ethack.orwall.lib.AppRuleComparator) NatRules(org.ethack.orwall.lib.NatRules) ListView(android.widget.ListView) AppRule(org.ethack.orwall.lib.AppRule) AppListAdapter(org.ethack.orwall.adapter.AppListAdapter)

Example 2 with Iptables

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

the class BootBroadcast method onReceive.

@Override
public void onReceive(final Context context, final Intent intent) {
    Iptables iptables = new Iptables(context);
    // Enforce init-script if sharedpreference says it
    // We want to do it the earlier.
    // Also, we want to get a fresh status regarding the init-script support: this can be
    // a reboot after a ROM upgrade or change.
    boolean enforceInit = Preferences.isEnforceInitScript(context);
    if (Iptables.initSupported() && enforceInit) {
        Iptables.installInitScript(context);
    }
    if (Preferences.isOrwallEnabled(context)) {
        iptables.boot();
    }
}
Also used : Iptables(org.ethack.orwall.lib.Iptables)

Example 3 with Iptables

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

the class TabbedMain method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tabbed_main);
    // Import old settings to SQLite, and remove them from SharedPreferences
    NatRules natRules = new NatRules(this);
    Set oldRules = getSharedPreferences(Preferences.PREFERENCES, MODE_PRIVATE).getStringSet("nat_rules", null);
    if (natRules.getRuleCount() == 0 && oldRules != null) {
        natRules.importFromSharedPrefs(oldRules);
        getSharedPreferences(Preferences.PREFERENCES, MODE_PRIVATE).edit().remove("nat_rules").apply();
    }
    // Is it the first application run?
    if (Preferences.isFirstRun(this)) {
        // Initialize orWall iptables rules - #72 should be better after that
        Iptables iptables = new Iptables(this);
        iptables.boot();
        // Start Wizard
        Intent wizard = new Intent(this, WizardActivity.class);
        startActivity(wizard);
    }
    viewPager = (ViewPager) findViewById(R.id.pager);
    actionBar = getActionBar();
    mAdapter = new TabsPagerAdapter(getSupportFragmentManager());
    viewPager.setAdapter(mAdapter);
    actionBar.setHomeButtonEnabled(false);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    // create the tab header
    for (String tab : tabs) {
        actionBar.addTab(actionBar.newTab().setText(tab).setTabListener(this));
    }
    // changer in order to take care of tab switching
    viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {
        }

        @Override
        public void onPageScrollStateChanged(int arg0) {
        }
    });
}
Also used : NatRules(org.ethack.orwall.lib.NatRules) Set(java.util.Set) Iptables(org.ethack.orwall.lib.Iptables) Intent(android.content.Intent) TabsPagerAdapter(org.ethack.orwall.adapter.TabsPagerAdapter) ViewPager(android.support.v4.view.ViewPager)

Example 4 with Iptables

use of org.ethack.orwall.lib.Iptables 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 5 with Iptables

use of org.ethack.orwall.lib.Iptables 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

Iptables (org.ethack.orwall.lib.Iptables)7 View (android.view.View)3 Intent (android.content.Intent)2 CompoundButton (android.widget.CompoundButton)2 Switch (android.widget.Switch)2 TextView (android.widget.TextView)2 InstallScripts (org.ethack.orwall.lib.InstallScripts)2 NatRules (org.ethack.orwall.lib.NatRules)2 PendingIntent (android.app.PendingIntent)1 LongSparseArray (android.support.v4.util.LongSparseArray)1 ViewPager (android.support.v4.view.ViewPager)1 ViewGroup (android.view.ViewGroup)1 Button (android.widget.Button)1 ListView (android.widget.ListView)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 PreferencesActivity (org.ethack.orwall.PreferencesActivity)1 WizardActivity (org.ethack.orwall.WizardActivity)1 AppListAdapter (org.ethack.orwall.adapter.AppListAdapter)1 TabsPagerAdapter (org.ethack.orwall.adapter.TabsPagerAdapter)1