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;
}
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) {
}
});
}
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);
}
}
}
Aggregations