summaryrefslogtreecommitdiff
path: root/main/src
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2021-10-04 04:48:57 +0200
committerArne Schwabe <arne@rfc2549.org>2021-10-04 04:48:57 +0200
commit04054693df7778141dc6411f05fd2075d1778ff9 (patch)
treef88f9285fde3b8a25920e2f8866e84e75158033a /main/src
parentd54ba7a09d0fd1301f0122070005b914ef70d128 (diff)
Avoid ANR when starting OpenVPNService and fetching profile
Diffstat (limited to 'main/src')
-rw-r--r--main/src/main/java/de/blinkt/openvpn/VpnProfile.java8
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java51
2 files changed, 26 insertions, 33 deletions
diff --git a/main/src/main/java/de/blinkt/openvpn/VpnProfile.java b/main/src/main/java/de/blinkt/openvpn/VpnProfile.java
index e82f508c..1561b1cc 100644
--- a/main/src/main/java/de/blinkt/openvpn/VpnProfile.java
+++ b/main/src/main/java/de/blinkt/openvpn/VpnProfile.java
@@ -823,13 +823,7 @@ public class VpnProfile implements Serializable, Cloneable {
if ((mAuthenticationType == VpnProfile.TYPE_KEYSTORE || mAuthenticationType == VpnProfile.TYPE_USERPASS_KEYSTORE)
&& mPrivateKey == null) {
- new Thread(new Runnable() {
- @Override
- public void run() {
- getExternalCertificates(context);
-
- }
- }).start();
+ new Thread(() -> getExternalCertificates(context)).start();
}
}
diff --git a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java
index c98bb127..3fd08553 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java
@@ -524,6 +524,23 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
showNotification(VpnStatus.getLastCleanLogMessage(this),
VpnStatus.getLastCleanLogMessage(this), NOTIFICATION_CHANNEL_NEWSTATUS_ID, 0, ConnectionStatus.LEVEL_START, null);
+
+ /* start the OpenVPN process itself in a background thread */
+ new Thread(() -> startOpenVPN(intent, startId)).start();
+
+ return START_STICKY;
+ }
+
+ @RequiresApi(Build.VERSION_CODES.N_MR1)
+ private void updateShortCutUsage(VpnProfile profile) {
+ if (profile == null)
+ return;
+ ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
+ shortcutManager.reportShortcutUsed(profile.getUUIDString());
+ }
+
+ private VpnProfile fetchVPNProfile(Intent intent)
+ {
if (intent != null && intent.hasExtra(getPackageName() + ".profileUUID")) {
String profileUUID = intent.getStringExtra(getPackageName() + ".profileUUID");
int profileVersion = intent.getIntExtra(getPackageName() + ".profileVersion", 0);
@@ -543,45 +560,27 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
Log.d("OpenVPN", "Got no last connected profile on null intent. Assuming always on.");
mProfile = ProfileManager.getAlwaysOnVPN(this);
+
if (mProfile == null) {
- stopSelf(startId);
- return START_NOT_STICKY;
+ return null;
}
}
/* Do the asynchronous keychain certificate stuff */
mProfile.checkForRestart(this);
}
+ return mProfile;
+ }
- if (mProfile == null) {
+ private void startOpenVPN(Intent intent, int startId) {
+ VpnProfile vp = fetchVPNProfile(intent);
+ if (vp == null) {
stopSelf(startId);
- return START_NOT_STICKY;
+ return;
}
-
- /* start the OpenVPN process itself in a background thread */
- new Thread(new Runnable() {
- @Override
- public void run() {
- startOpenVPN();
- }
- }).start();
-
-
ProfileManager.setConnectedVpnProfile(this, mProfile);
VpnStatus.setConnectedVPNProfile(mProfile.getUUIDString());
- return START_STICKY;
- }
-
- @RequiresApi(Build.VERSION_CODES.N_MR1)
- private void updateShortCutUsage(VpnProfile profile) {
- if (profile == null)
- return;
- ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
- shortcutManager.reportShortcutUsed(profile.getUUIDString());
- }
-
- private void startOpenVPN() {
try {
mProfile.writeConfigFile(this);
} catch (IOException e) {