LocalBroadcastRecevier and DynamicBroadcastRecevier used to call pollServer directly. Thus, processCommand was called from a BroadcastRecevier context, which broke some commands (e.g. SPEAK). Now, they call a new function, safePollServer, which calls pollServer from FonBotMainService.
if(action.equals(Intent.ACTION_SCREEN_ON)){
if(PreferenceManager.getDefaultSharedPreferences(context).getBoolean("poll_on_screen_on", false))
- Utils.pollServer(context);
+ Utils.safePollServer(context);
} else if(action.equals(Intent.ACTION_BATTERY_CHANGED))
Heavy.describeBatteryLevel(context, null, toNonNull(MessageType.BATTERY_CHANGED));
else if(action.equals(Intent.ACTION_HEADSET_PLUG)){
* 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";
/**
* Extra: ongoing event id
*
LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(ACTION_ONGOING_UPDATE));
}
+ if(intent!=null && intent.getAction()==ACTION_TRIGGER_POLL)
+ Utils.pollServer(this);
+
final boolean runForeground=PreferenceManager.getDefaultSharedPreferences(this).getBoolean("foreground", false);
if(!runForeground)
stopForeground(true);
final String action=intent.getAction();
if(action.equals(LocalBroadcastReceiver.ACTION_POLL_ALARM))
- Utils.pollServer(context);
+ Utils.safePollServer(context);
}
}
}
/**
- * Poll the server for pending commands.
+ * Poll the server for pending commands. This function must not be called from BroadcastReceivers
*
* @param context Context instance
*/
new HttpCallExecutableRunnable("/get", null, context, new PollResultCallback(context), false).execute();
}
+ /**
+ * Poll the server for pending commands from {@link FonBotMainService}. This function should be used from BroadcastReceviers instead of {@link #pollServer}
+ *
+ * @param context Context instance
+ */
+ public static void safePollServer(final Context context){
+ final Intent intent=new Intent(context, FonBotMainService.class);
+ intent.setAction(FonBotMainService.ACTION_TRIGGER_POLL);
+ context.startService(intent);
+ }
/**
* Executes a given command
*