@@ -90,35 +90,44 @@ public static void scheduleKeepVPNAliveJobService(Context c, VpnProfile vp) {
9090 * strange Android build that allows lower lmits.
9191 */
9292 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+ }
95101 jib .setPersisted (true );
96102
97- JobScheduler jobScheduler = c .getSystemService (JobScheduler .class );
103+ JobScheduler jobScheduler = null ;
104+ jobScheduler = getJobScheduler (c );
105+
98106 jobScheduler .schedule (jib .build ());
99107 VpnStatus .logDebug ("Scheduling VPN keep alive for VPN " + vp .mName );
100108 }
101109
102- private static long getMinPeriodMillis () {
110+ private static JobScheduler getJobScheduler (Context c ) {
111+ JobScheduler jobScheduler ;
103112 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .N ) {
104- return JobInfo .getMinPeriodMillis ();
113+ jobScheduler = c .getSystemService (JobScheduler .class );
114+
105115 } else {
106- return 15 * 60 * 1000L ; // 15 minutes
116+ jobScheduler = ( JobScheduler ) c . getSystemService ( JOB_SCHEDULER_SERVICE );
107117 }
118+ return jobScheduler ;
108119 }
109120
110- private static long getMinFlexMillis () {
121+ private static long getMinPeriodMillis () {
111122 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
117126 }
118127 }
119128
120129 public static void unscheduleKeepVPNAliveJobService (Context c ) {
121- JobScheduler jobScheduler = c . getSystemService ( JobScheduler . class );
130+ JobScheduler jobScheduler = getJobScheduler ( c );
122131 jobScheduler .cancel (JOBID_KEEPVPNALIVE );
123132 VpnStatus .logDebug ("Unscheduling VPN keep alive" );
124133 }
0 commit comments