use of org.ethack.orwall.lib.AppRule 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.AppRule 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);
}
}
}
use of org.ethack.orwall.lib.AppRule in project orWall by EthACKdotOrg.
the class AppListAdapter method saveAdvanced.
private void saveAdvanced(AppRule appRule, View view) {
// Update DB content
AppRule updated = new AppRule();
updated.setAppName(appRule.getAppName());
updated.setPkgName(appRule.getPkgName());
updated.setAppUID(appRule.getAppUID());
// none
if (!checkboxInternet.isChecked()) {
updated.setOnionType(Constants.DB_ONION_TYPE_NONE);
} else // Anonymity provider
if (radioTor.isChecked()) {
updated.setOnionType(Constants.DB_ONION_TYPE_TOR);
} else if (radioBypass.isChecked()) {
updated.setOnionType(Constants.DB_ONION_TYPE_BYPASS);
}
/*
else
if (radioI2p.isChecked()) {
updated.setOnionType(Constants.DB_ONION_TYPE_I2P);
}
*/
updated.setLocalHost(this.checkLocalHost.isChecked());
updated.setLocalNetwork(this.checkLocalNetwork.isChecked());
boolean done;
// CREATE
if (!appRule.isStored() && !updated.isEmpty()) {
done = natRules.addAppToRules(updated);
if (done) {
updated.install(this.context);
Toast.makeText(context, context.getString(R.string.toast_new_rule), Toast.LENGTH_SHORT).show();
}
} else // UPDATE
if (appRule.isStored() && !updated.isEmpty()) {
done = natRules.update(updated);
if (done) {
appRule.uninstall(this.context);
updated.install(this.context);
Toast.makeText(context, context.getString(R.string.toast_update_rule), Toast.LENGTH_SHORT).show();
}
} else //DELETE
if (appRule.isStored() && updated.isEmpty()) {
done = natRules.removeAppFromRules(updated.getAppUID());
if (done) {
appRule.uninstall(this.context);
Toast.makeText(context, context.getString(R.string.toast_remove_rule), Toast.LENGTH_SHORT).show();
}
} else {
// nothing to do
return;
}
if (done) {
appRule.setOnionType(updated.getOnionType());
appRule.setLocalHost(updated.getLocalHost());
appRule.setLocalNetwork(updated.getLocalNetwork());
if (appRule.isEmpty()) {
appRule.setStored(false);
appRule.setLabel(appRule.getAppName());
} else {
appRule.setStored(true);
appRule.setLabel(appRule.getDisplay());
}
CheckBox checkBox = (CheckBox) view;
checkBox.setText(appRule.getLabel());
checkBox.setChecked(appRule.isStored());
} else {
// error updating database
appRule.setOnionType(Constants.DB_ONION_TYPE_NONE);
Toast.makeText(context, String.format(context.getString(R.string.toast_error), 3), Toast.LENGTH_SHORT).show();
}
}
use of org.ethack.orwall.lib.AppRule in project orWall by EthACKdotOrg.
the class AppFragment method listDisabledApps.
/**
* List all disabled application. Meaning: installed app requiring Internet, but NOT in NatRules.
* It also filters out special apps like orbot and i2p.
*
* @return List of AppRule
*/
private List<AppRule> listDisabledApps(LongSparseArray<AppRule> index) {
PackageManager packageManager = this.getActivity().getPackageManager();
List<AppRule> pkgList = new ArrayList<>();
List<PackageInfo> pkgInstalled = packageManager.getInstalledPackages(PackageManager.GET_PERMISSIONS);
for (PackageInfo pkgInfo : pkgInstalled) {
if (needInternet(pkgInfo) && !isReservedApp(pkgInfo)) {
if (index.indexOfKey((long) pkgInfo.applicationInfo.uid) < 0) {
AppRule app = new AppRule(false, pkgInfo.packageName, (long) pkgInfo.applicationInfo.uid, Constants.DB_ONION_TYPE_NONE, false, false);
app.setAppName(packageManager.getApplicationLabel(pkgInfo.applicationInfo).toString());
pkgList.add(app);
}
}
}
return pkgList;
}
use of org.ethack.orwall.lib.AppRule in project orWall by EthACKdotOrg.
the class AppFragment method listSpecialApps.
private List<AppRule> listSpecialApps(LongSparseArray<AppRule> index) {
List<AppRule> pkgList = new ArrayList<>();
Map<String, PackageInfoData> specialApps = PackageInfoData.specialApps();
for (PackageInfoData pkgInfo : specialApps.values()) {
if (index.indexOfKey(pkgInfo.getUid()) < 0) {
AppRule app = new AppRule(false, pkgInfo.getPkgName(), pkgInfo.getUid(), Constants.DB_ONION_TYPE_NONE, false, false);
app.setAppName(pkgInfo.getName());
pkgList.add(app);
}
}
return pkgList;
}
Aggregations