import static ro.ieval.fonbot.R.string.*;
import static ro.ieval.fonbot.Utils.toNonNull;
+import java.net.SocketTimeoutException;
import java.util.Collections;
import java.util.EnumSet;
import java.util.Set;
+import javax.net.ssl.SSLException;
+
import org.eclipse.jdt.annotation.Nullable;
+import ro.ieval.fonbot.Address.Protocol;
import ro.ieval.fonbot.Utils.OngoingEvent;
import android.app.Notification;
Log.d("LongPollRunnable", "Long polling started");
while(man.getActiveNetworkInfo() != null && man.getActiveNetworkInfo().isConnected())
try {
- runnable.run();
+ runnable.doRun();
+ } catch (final SocketTimeoutException e){
+ Log.d("LongPollRunnable", "Socket timeout, refreshing connection");
+ } catch (final SSLException e){
+ Log.d("LongPollRunnable", "Got SSLException, refreshing connection");
} catch (final Exception ex){
ex.printStackTrace();
+ break;
}
Log.d("LongPollRunnable", "Long polling stopped");
}
* Broadcast action: remove an ongoing event
*/
public static final String ACTION_DELETE_ONGOING="ro.ieval.fonbot.FonBotMainService.ACTION_DELETE_ONGOING";
- /** Broadcast action: trigger a server poll */
- public static final String ACTION_TRIGGER_POLL="ro.ieval.fonbot.FonBotMainService.ACTION_TRIGGER_POLL";
+
+ /**
+ * Broadcast action: process a command received via SMS
+ */
+ public static final String ACTION_PROCESS_COMMAND="ro.ieval.fonbot.FonBotMainService.ACTION_PROCESS_COMMAND";
+
+ /**
+ * Extra: command line
+ */
+ public static final String EXTRA_COMMAND_LINE="ro.ieval.fonbot.FonBotMainService.EXTRA_COMMAND_LINE";
+
+ /**
+ * Extra: SMS originating address
+ */
+ public static final String EXTRA_SMS_ORIGIN_ADDRESS="ro.ieval.fonbot.FonBotMainService.EXTRA_SMS_ORIGIN_ADDRESS";
+
/**
* Extra: ongoing event id
*
LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(ACTION_ONGOING_UPDATE));
updateNotification=true;
}
+ if(intent!=null && intent.getAction()==ACTION_PROCESS_COMMAND) {
+ final String cmdline = intent.getStringExtra(EXTRA_COMMAND_LINE);
+ final String origin = intent.getStringExtra(EXTRA_SMS_ORIGIN_ADDRESS);
+ final Address address= new Address(toNonNull(Protocol.SMS), origin);//NOPMD variable depends on originAddress
+ final String[] words=Utils.shellwords(toNonNull(cmdline));
+ final String[] args=new String[words.length-1];//NOPMD variable size depends on words.length
+ System.arraycopy(words, 1, args, 0, args.length);
+
+ Utils.processCommand(this, toNonNull(words[0]), args, toNonNull(address));
+ }
if(longPollThread == null || !longPollThread.isAlive()){
longPollThread = new Thread(new LongPollRunnable());
longPollThread.start();
}
+ ExecutableRunnable.retryTasks();
+
final boolean runForeground=PreferenceManager.getDefaultSharedPreferences(this).getBoolean("foreground", false);
if(!runForeground)
stopForeground(true);