diff options
author | Arne Schwabe <arne@rfc2549.org> | 2023-06-12 09:11:40 +0200 |
---|---|---|
committer | Arne Schwabe <arne@rfc2549.org> | 2023-06-12 09:11:40 +0200 |
commit | 43dfbc377f6f7feab3e8cf610b61c7e258127ab9 (patch) | |
tree | 245da02dc7411d8edfa6493ec826b5bd3bf7752d /main/src | |
parent | 244dc458004a4fe33a88c597e569139ce4f5b9f9 (diff) |
Fix crashes with keepalive job with API <= 23 (closes #1619)
Diffstat (limited to 'main/src')
-rw-r--r-- | main/src/main/java/de/blinkt/openvpn/core/keepVPNAlive.java | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/main/src/main/java/de/blinkt/openvpn/core/keepVPNAlive.java b/main/src/main/java/de/blinkt/openvpn/core/keepVPNAlive.java index 2b75b2fe..5bff9eb2 100644 --- a/main/src/main/java/de/blinkt/openvpn/core/keepVPNAlive.java +++ b/main/src/main/java/de/blinkt/openvpn/core/keepVPNAlive.java @@ -13,6 +13,7 @@ import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.net.VpnService; +import android.os.Build; import android.os.PersistableBundle; import de.blinkt.openvpn.LaunchVPN; @@ -88,8 +89,8 @@ public class keepVPNAlive extends JobService implements VpnStatus.StateListener * but we use a minimum of 5 minutes and 2 minutes to avoid problems if there is some * strange Android build that allows lower lmits. */ - long initervalMillis = Math.max(JobInfo.getMinPeriodMillis(), 5 * 60 * 1000L); - long flexMillis = Math.max(JobInfo.getMinFlexMillis(), 2 * 60 * 1000L); + long initervalMillis = Math.max(getMinPeriodMillis(), 5 * 60 * 1000L); + long flexMillis = Math.max(getMinFlexMillis(), 2 * 60 * 1000L); jib.setPeriodic(initervalMillis, flexMillis); jib.setPersisted(true); @@ -98,6 +99,24 @@ public class keepVPNAlive extends JobService implements VpnStatus.StateListener VpnStatus.logDebug("Scheduling VPN keep alive for VPN " + vp.mName); } + private static long getMinPeriodMillis() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + return JobInfo.getMinPeriodMillis(); + } else { + return 15 * 60 * 1000L; // 15 minutes + } + } + + private static long getMinFlexMillis() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + return JobInfo.getMinFlexMillis(); + } + else + { + return 5 * 60 * 1000L; // 5 minutes + } + } + public static void unscheduleKeepVPNAliveJobService(Context c) { JobScheduler jobScheduler = c.getSystemService(JobScheduler.class); jobScheduler.cancel(JOBID_KEEPVPNALIVE); |