summaryrefslogtreecommitdiff
path: root/main/src
diff options
context:
space:
mode:
Diffstat (limited to 'main/src')
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/keepVPNAlive.java23
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);