summaryrefslogtreecommitdiff
path: root/app/src/main/java/de/blinkt
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2021-02-24 23:23:47 +0100
committercyBerta <cyberta@riseup.net>2021-02-26 10:03:31 +0100
commit49b1539722063a53573fb859f543967ebff5ce14 (patch)
tree2cc2d13e3250faf91b977acc2c18676af80c6425 /app/src/main/java/de/blinkt
parentcf6e6f355cc71e43c69f20716a7aa6fd0d6990ce (diff)
implement service binding in order to fix remote service exception during foreground service start
Diffstat (limited to 'app/src/main/java/de/blinkt')
-rw-r--r--app/src/main/java/de/blinkt/openvpn/LaunchVPN.java3
-rw-r--r--app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java25
-rw-r--r--app/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java17
3 files changed, 11 insertions, 34 deletions
diff --git a/app/src/main/java/de/blinkt/openvpn/LaunchVPN.java b/app/src/main/java/de/blinkt/openvpn/LaunchVPN.java
index b148d04d..3f45f391 100644
--- a/app/src/main/java/de/blinkt/openvpn/LaunchVPN.java
+++ b/app/src/main/java/de/blinkt/openvpn/LaunchVPN.java
@@ -25,6 +25,7 @@ import de.blinkt.openvpn.core.VPNLaunchHelper;
import de.blinkt.openvpn.core.VpnStatus;
import se.leap.bitmaskclient.base.MainActivity;
import se.leap.bitmaskclient.R;
+import se.leap.bitmaskclient.eip.EipCommand;
import static se.leap.bitmaskclient.base.models.Constants.EIP_ACTION_PREPARE_VPN;
import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_PROFILE;
@@ -119,7 +120,7 @@ public class LaunchVPN extends Activity {
if(!mhideLog && showLogWindow)
showLogWindow();
- VPNLaunchHelper.startOpenVpn(mSelectedProfile, getBaseContext());
+ EipCommand.launchVPNProfile(getApplicationContext(), mSelectedProfile);
finish();
} else if (resultCode == Activity.RESULT_CANCELED) {
diff --git a/app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java b/app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java
index 1670c0be..6be8db25 100644
--- a/app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java
+++ b/app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java
@@ -46,6 +46,7 @@ import de.blinkt.openvpn.core.VpnStatus.StateListener;
import de.blinkt.openvpn.core.connection.Connection;
import de.blinkt.openvpn.core.connection.Obfs4Connection;
import se.leap.bitmaskclient.R;
+import se.leap.bitmaskclient.eip.EipStatus;
import se.leap.bitmaskclient.eip.VpnNotificationManager;
import se.leap.bitmaskclient.firewall.FirewallManager;
import se.leap.bitmaskclient.pluggableTransports.Shapeshifter;
@@ -92,11 +93,6 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
private Shapeshifter shapeshifter;
private FirewallManager firewallManager;
- private static final int PRIORITY_MIN = -2;
- private static final int PRIORITY_DEFAULT = 0;
- private static final int PRIORITY_MAX = 2;
-
-
private final IBinder mBinder = new IOpenVPNServiceInternal.Stub() {
@Override
@@ -118,6 +114,11 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
public boolean isVpnRunning() throws RemoteException {
return OpenVPNService.this.isVpnRunning();
}
+
+ @Override
+ public void startWithForegroundNotification() throws RemoteException {
+ OpenVPNService.this.startWithForegroundNotification();
+ }
};
// From: http://stackoverflow.com/questions/3758606/how-to-convert-byte-size-into-human-readable-format-in-java
@@ -280,18 +281,11 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
}
+ @Override
public void startWithForegroundNotification() {
// Always show notification here to avoid problem with startForeground timeout
notificationManager.createOpenVpnNotificationChannel();
- notificationManager.buildOpenVpnNotification(
- mProfile != null ? mProfile.mName : "",
- mProfile != null && mProfile.mUsePluggableTransports,
- VpnStatus.getLastCleanLogMessage(this),
- VpnStatus.getLastCleanLogMessage(this),
- ConnectionStatus.LEVEL_START,
- 0,
- NOTIFICATION_CHANNEL_NEWSTATUS_ID,
- this::onNotificationBuild);
+ notificationManager.buildForegroundServiceNotification(EipStatus.getInstance().getLevel(), this::onNotificationBuild);
}
@Override
@@ -539,7 +533,6 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
public void onCreate() {
super.onCreate();
notificationManager = new VpnNotificationManager(this);
- startWithForegroundNotification();
firewallManager = new FirewallManager(this, true);
}
@@ -558,7 +551,7 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
VpnStatus.removeStateListener(this);
VpnStatus.flushLog();
firewallManager.onDestroy();
- notificationManager.cancelAllNotifications();
+ notificationManager.deleteOpenvpnNotificationChannel();
}
private String getTunConfigString() {
diff --git a/app/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java b/app/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java
index 7c742746..540ca043 100644
--- a/app/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java
+++ b/app/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java
@@ -7,7 +7,6 @@ package de.blinkt.openvpn.core;
import android.annotation.TargetApi;
import android.content.Context;
-import android.content.Intent;
import android.os.Build;
import java.io.File;
@@ -18,7 +17,6 @@ import java.util.Arrays;
import java.util.Vector;
import se.leap.bitmaskclient.R;
-import de.blinkt.openvpn.VpnProfile;
public class VPNLaunchHelper {
private static final String MININONPIEVPN = "nopie_openvpn";
@@ -120,7 +118,6 @@ public class VPNLaunchHelper {
return false;
}
-
return true;
} catch (IOException e) {
VpnStatus.logException(e);
@@ -129,20 +126,6 @@ public class VPNLaunchHelper {
}
-
- public static void startOpenVpn(VpnProfile startprofile, Context context) {
- Intent startVPN = startprofile.prepareStartService(context);
- if (startVPN != null) {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
- //noinspection NewApi
- context.startForegroundService(startVPN);
- else
- context.startService(startVPN);
-
- }
- }
-
-
public static String getConfigFilePath(Context context) {
return context.getCacheDir().getAbsolutePath() + "/" + OVPNCONFIGFILE;
}