package org.adaptlab.chpir.android.activerecordcloudsync;

import android.app.AlarmManager;
import android.app.IntentService;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.util.Log;

public class PollService extends IntentService {
    private static final String TAG = "PollService";
    private static final int POLL_INTERVAL = 1000 * 15;

    public PollService() {
        super(TAG);
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        ConnectivityManager cm = (ConnectivityManager)
                getSystemService(Context.CONNECTIVITY_SERVICE);
        @SuppressWarnings("deprecation")
        boolean isNetworkAvailable = cm.getBackgroundDataSetting() &&
            cm.getActiveNetworkInfo() != null;
        if (!isNetworkAvailable) { 
            Log.i(TAG, "Network is not available, short circuiting PollService...");
            return;
        }
        
        ActiveRecordCloudSync.syncReceiveTables();
        ActiveRecordCloudSync.syncSendTables();
        Log.i(TAG, "Received an intent: " + intent);
    }
    
    // Control polling of api, set isOn to true to enable polling
    public static void setServiceAlarm(Context context, boolean isOn) {
        Intent i = new Intent(context, PollService.class);
        PendingIntent pi = PendingIntent.getService(
            context, 0, i, 0);
        
        AlarmManager alarmManager = (AlarmManager)
                context.getSystemService(Context.ALARM_SERVICE);
        
        if (isOn) {
            alarmManager.setRepeating(AlarmManager.RTC,
                    System.currentTimeMillis(), POLL_INTERVAL, pi);
        } else {
            alarmManager.cancel(pi);
            pi.cancel();
        }
    }
    
    public static boolean isServiceAlarmOn(Context context) {
        Intent i = new Intent(context, PollService.class);
        PendingIntent pi = PendingIntent.getService(
                context, 0, i, PendingIntent.FLAG_NO_CREATE);
        return pi != null;
    }
}

@@ -407,18 +407,20 @@
 tic 
-final int 
+int DEFAULT_
 POLL
@@ -441,16 +441,54 @@
 00 * 15;
+%0A    private static int sPollInterval;
 %0A%0A    pu
@@ -528,16 +528,63 @@
 r(TAG);%0A
+        sPollInterval = DEFAULT_POLL_INTERVAL;%0A
     %7D%0A%0A 
@@ -1786,29 +1786,29 @@
 llis(), 
-POLL_INTERVAL
+sPollInterval
 , pi);%0A 
@@ -2175,10 +2175,110 @@
 ;%0A    %7D%0A
+    %0A    public static void setPollInterval(int interval) %7B%0A        sPollInterval = interval;%0A    %7D%0A
 %7D%0A

Make poll interval adjustable