X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=src%2Fro%2Fieval%2Ffonbot%2FUtils.java;h=79ff2e1e37236de3b571e246f434415827527ed0;hb=582cbf066b7c47eecef759ca0755649a6bc0e39e;hp=e14095ea4695e4301b33215e64731786b77a561c;hpb=2e5049c9c08b1989b4bfbbfbf479d83dbe2b75a9;p=fonbot.git diff --git a/src/ro/ieval/fonbot/Utils.java b/src/ro/ieval/fonbot/Utils.java index e14095e..79ff2e1 100644 --- a/src/ro/ieval/fonbot/Utils.java +++ b/src/ro/ieval/fonbot/Utils.java @@ -86,7 +86,8 @@ public final class Utils { NEXT, PREV, BATT, CALLLOG, SMSLOG, LS, RM, CONTACTS, DISABLE, ENABLE, POLL, HANGUP, ANSWER, LAUNCH, DATA, - GPS, GLOCATION, REBOOT, SHUTDOWN, NOTIFY + GPS, GLOCATION, REBOOT, NOTIFY, SCREENCAP, + TORCH } /** @@ -109,7 +110,9 @@ public final class Utils { /** Fine battery status notifications */ BATTERY_CHANGED, /** Headset plug/unplug notifications */ - HEADSET + HEADSET, + /** Phone booted notifications */ + BOOT, } /** @@ -317,7 +320,7 @@ public final class Utils { switch(address.protocol){ case HTTP: new HttpCallExecutableRunnable("/send", toNonNull(Arrays.asList( - new Header("X-Destination", toNonNull(address.data)))), context, null, message).execute(); + new Header("X-Destination", toNonNull(address.data)))), context, null, true, message).execute(); break; case SMS: @@ -335,21 +338,6 @@ public final class Utils { } } - /** - * Parses a HTTP response message of the form (part1) part2, returning part2. - * - * @param message the raw HTTP response message - * @return the extracted part - */ - public static String parseHttpMessage(final String message){ - final int indexOfParen=message.indexOf(')'); - if(indexOfParen==-1) - return message; - if(indexOfParen == message.length()-1) - return toNonNull(message.substring(1, indexOfParen)); - return toNonNull(message.substring(indexOfParen+2)); - } - /** * Splits a string into words. * @@ -419,21 +407,31 @@ public final class Utils { * @throws MalformedURLException if the user preferences create an invalid URL */ public static URL getServerURL(final Context context, final String path) throws MalformedURLException{ - final String hostname=PreferenceManager.getDefaultSharedPreferences(context).getString("hostname", "ieval.ro"); - final int port=Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(context).getString("port", "7777")); - final URL url=new URL("http", hostname, port, path); + final String hostname=PreferenceManager.getDefaultSharedPreferences(context).getString("hostname", "fonbot.ieval.ro"); + final int port=Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(context).getString("port", "443")); + final URL url=new URL("https", hostname, port, path); return url; } /** - * Poll the server for pending commands. + * Poll the server for pending commands. This function must not be called from BroadcastReceivers * * @param context Context instance */ public static void pollServer(final Context context){ - new HttpCallExecutableRunnable("/get", null, context, new PollResultCallback(context)).execute(); + 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 * @@ -444,7 +442,7 @@ public final class Utils { */ private static void processCommand(final Context context, final Command cmd,final String[] args,final Address replyTo){ if(Heavy.isCommandDisabled(context, cmd)){ - sendMessage(context, replyTo, command_disabled); + sendMessage(context, replyTo, command_disabled, cmd.toString()); return; } @@ -1008,13 +1006,10 @@ public final class Utils { Heavy.reboot(context, replyTo, args.length==0?null:args[0]); break; - case SHUTDOWN: - //TODO: implement command - break; - case NOTIFY: if(args.length!=1 && args.length!=3){ Heavy.help(context, replyTo, toNonNull(Command.NOTIFY)); + return; } final int id; @@ -1030,6 +1025,19 @@ public final class Utils { else Heavy.notify(context, replyTo, id, toNonNull(args[1]), toNonNull(args[2])); break; + + case SCREENCAP: + if(args.length != 1){ + Heavy.help(context, replyTo, toNonNull(Command.SCREENCAP)); + return; + } + + Heavy.screencap(context, replyTo, args[0]); + break; + + case TORCH: + Heavy.torch(context, replyTo); + break; } }