Search in sources :

Example 1 with NatRules

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

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

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

the class UninstallBroadcast method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    Uri data = intent.getData();
    if (!data.getScheme().equals("package")) {
        Log.d(TAG, "Intent scheme was not 'package'");
        return;
    }
    boolean replacing = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
    if (Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction()) && !replacing) {
        final long uid = intent.getIntExtra(Intent.EXTRA_UID, -123);
        final String appName = intent.getData().getSchemeSpecificPart();
        Log.d("UninstallBroadcast", "AppName: " + appName + ", AppUID: " + uid);
        // is the app present in rules?
        NatRules natRules = new NatRules(context);
        AppRule rule = natRules.getAppRule(uid);
        if (rule.isStored()) {
            // First: remove rule from firewall if any
            rule.uninstall(context);
            // Second: remove app from NatRules if present
            natRules.removeAppFromRules(uid);
        }
    }
}
Also used : NatRules(org.ethack.orwall.lib.NatRules) AppRule(org.ethack.orwall.lib.AppRule) Uri(android.net.Uri)

Aggregations

NatRules (org.ethack.orwall.lib.NatRules)3 AppRule (org.ethack.orwall.lib.AppRule)2 Iptables (org.ethack.orwall.lib.Iptables)2 Intent (android.content.Intent)1 Uri (android.net.Uri)1 LongSparseArray (android.support.v4.util.LongSparseArray)1 ViewPager (android.support.v4.view.ViewPager)1 View (android.view.View)1 ListView (android.widget.ListView)1 Set (java.util.Set)1 AppListAdapter (org.ethack.orwall.adapter.AppListAdapter)1 TabsPagerAdapter (org.ethack.orwall.adapter.TabsPagerAdapter)1 AppRuleComparator (org.ethack.orwall.lib.AppRuleComparator)1