summaryrefslogtreecommitdiff
path: root/app/src/main/java/se/leap/bitmaskclient/firewall/FirewallManager.java
diff options
context:
space:
mode:
authorcyberta <cyberta@riseup.net>2020-01-24 14:21:34 -0600
committercyberta <cyberta@riseup.net>2020-01-24 14:21:34 -0600
commit0fe9d37a223b388103e2924e6d1a28bcb0ae38fd (patch)
tree655c25f7cc02ac0fa374ecc8a00cab840553e3ee /app/src/main/java/se/leap/bitmaskclient/firewall/FirewallManager.java
parent2ff2358861bcd0c05586f972724ef76e5a67060c (diff)
rearrange firewalling code, move to separate package
Diffstat (limited to 'app/src/main/java/se/leap/bitmaskclient/firewall/FirewallManager.java')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/firewall/FirewallManager.java73
1 files changed, 73 insertions, 0 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/firewall/FirewallManager.java b/app/src/main/java/se/leap/bitmaskclient/firewall/FirewallManager.java
new file mode 100644
index 00000000..a3be46e6
--- /dev/null
+++ b/app/src/main/java/se/leap/bitmaskclient/firewall/FirewallManager.java
@@ -0,0 +1,73 @@
+package se.leap.bitmaskclient.firewall;
+/**
+ * Copyright (c) 2019 LEAP Encryption Access Project and contributers
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+import android.content.Context;
+
+import de.blinkt.openvpn.core.VpnStatus;
+import se.leap.bitmaskclient.utils.PreferenceHelper;
+
+
+public class FirewallManager implements FirewallCallback {
+ public static String BITMASK_CHAIN = "bitmask_fw";
+ static final String TAG = FirewallManager.class.getSimpleName();
+
+ private Context context;
+
+ public FirewallManager(Context context) {
+ this.context = context;
+ }
+
+
+ @Override
+ public void onFirewallStarted(boolean success) {
+ if (success) {
+ VpnStatus.logInfo("[FIREWALL] Custom rules established");
+ } else {
+ VpnStatus.logError("[FIREWALL] Could not establish custom rules.");
+ }
+ }
+
+ @Override
+ public void onFirewallStopped(boolean success) {
+ if (success) {
+ VpnStatus.logInfo("[FIREWALL] Custom rules deleted");
+ } else {
+ VpnStatus.logError("[FIREWALL] Could not delete custom rules");
+ }
+ }
+
+ @Override
+ public void onSuRequested(boolean success) {
+ PreferenceHelper.setSuPermission(context, success);
+ if (!success) {
+ VpnStatus.logError("[FIREWALL] Root permission needed to execute custom firewall rules.");
+ }
+ }
+
+
+ public void startFirewall() {
+ StartFirewallTask task = new StartFirewallTask(this);
+ task.execute();
+ }
+
+ public void shutdownFirewall() {
+ ShutdownFirewallTask task = new ShutdownFirewallTask(this);
+ task.execute();
+ }
+
+}