@@ -90,35 +90,44 @@ public static void scheduleKeepVPNAliveJobService(Context c, VpnProfile vp) {
90
90
* strange Android build that allows lower lmits.
91
91
*/
92
92
long initervalMillis = Math .max (getMinPeriodMillis (), 5 * 60 * 1000L );
93
- long flexMillis = Math .max (getMinFlexMillis (), 2 * 60 * 1000L );
94
- jib .setPeriodic (initervalMillis , flexMillis );
93
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .N ) {
94
+ long flexMillis = Math .max (JobInfo .getMinFlexMillis (), 2 * 60 * 1000L );
95
+ jib .setPeriodic (initervalMillis , flexMillis );
96
+ }
97
+ else
98
+ {
99
+ jib .setPeriodic (initervalMillis );
100
+ }
95
101
jib .setPersisted (true );
96
102
97
- JobScheduler jobScheduler = c .getSystemService (JobScheduler .class );
103
+ JobScheduler jobScheduler = null ;
104
+ jobScheduler = getJobScheduler (c );
105
+
98
106
jobScheduler .schedule (jib .build ());
99
107
VpnStatus .logDebug ("Scheduling VPN keep alive for VPN " + vp .mName );
100
108
}
101
109
102
- private static long getMinPeriodMillis () {
110
+ private static JobScheduler getJobScheduler (Context c ) {
111
+ JobScheduler jobScheduler ;
103
112
if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .N ) {
104
- return JobInfo .getMinPeriodMillis ();
113
+ jobScheduler = c .getSystemService (JobScheduler .class );
114
+
105
115
} else {
106
- return 15 * 60 * 1000L ; // 15 minutes
116
+ jobScheduler = ( JobScheduler ) c . getSystemService ( JOB_SCHEDULER_SERVICE );
107
117
}
118
+ return jobScheduler ;
108
119
}
109
120
110
- private static long getMinFlexMillis () {
121
+ private static long getMinPeriodMillis () {
111
122
if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .N ) {
112
- return JobInfo .getMinFlexMillis ();
113
- }
114
- else
115
- {
116
- return 5 * 60 * 1000L ; // 5 minutes
123
+ return JobInfo .getMinPeriodMillis ();
124
+ } else {
125
+ return 15 * 60 * 1000L ; // 15 minutes
117
126
}
118
127
}
119
128
120
129
public static void unscheduleKeepVPNAliveJobService (Context c ) {
121
- JobScheduler jobScheduler = c . getSystemService ( JobScheduler . class );
130
+ JobScheduler jobScheduler = getJobScheduler ( c );
122
131
jobScheduler .cancel (JOBID_KEEPVPNALIVE );
123
132
VpnStatus .logDebug ("Unscheduling VPN keep alive" );
124
133
}
0 commit comments