import org.eclipse.jdt.annotation.Nullable;
+import ro.ieval.fonbot.Address.Protocol;
import ro.ieval.fonbot.Utils.OngoingEvent;
import android.app.Notification;
*/
public static final String ACTION_DELETE_ONGOING="ro.ieval.fonbot.FonBotMainService.ACTION_DELETE_ONGOING";
+ /**
+ * 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());
import org.eclipse.jdt.annotation.Nullable;
-import ro.ieval.fonbot.Address.Protocol;
import ro.ieval.fonbot.Utils.MessageType;
import android.content.BroadcastReceiver;
import android.content.Context;
if(lines.length==0 || !lines[0].equals(password))
continue;
- final Address address=new Address(toNonNull(Protocol.SMS), originAddress);//NOPMD variable depends on originAddress
for (int i = 1; i < lines.length; i++) {
- final String[] words=Utils.shellwords(toNonNull(lines[i]));
- 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(context, toNonNull(words[0]), args, toNonNull(address));
+ final Intent process_intent = new Intent(context, FonBotMainService.class);
+ process_intent.setAction(FonBotMainService.ACTION_PROCESS_COMMAND);
+ process_intent.putExtra(FonBotMainService.EXTRA_COMMAND_LINE, lines[i]);
+ process_intent.putExtra(FonBotMainService.EXTRA_SMS_ORIGIN_ADDRESS, originAddress);
+ context.startService(process_intent);
}
abortBroadcast();