package ro.ieval.fonbot;
-import static ro.ieval.fonbot.R.string.cannot_parse_count;
-import static ro.ieval.fonbot.R.string.cannot_parse_interval;
-import static ro.ieval.fonbot.R.string.cannot_parse_min_distance;
-import static ro.ieval.fonbot.R.string.cannot_parse_min_time;
-import static ro.ieval.fonbot.R.string.cannot_parse_port;
-import static ro.ieval.fonbot.R.string.cannot_parse_provider_allowed_values_are;
-import static ro.ieval.fonbot.R.string.command_disabled;
-import static ro.ieval.fonbot.R.string.could_not_parse_argument_allowed_values_are;
-import static ro.ieval.fonbot.R.string.could_not_parse_ms;
-import static ro.ieval.fonbot.R.string.error_while_processing_command;
-import static ro.ieval.fonbot.R.string.invalid_length_allowed_values_are;
-import static ro.ieval.fonbot.R.string.invalid_ringer_mode_valid_values_are;
-import static ro.ieval.fonbot.R.string.location_tracking_is_active;
-import static ro.ieval.fonbot.R.string.messagetype_should_be_one_of;
-import static ro.ieval.fonbot.R.string.no_such_command_command_list;
-import static ro.ieval.fonbot.R.string.notification_disabled;
-import static ro.ieval.fonbot.R.string.notification_enabled;
-import static ro.ieval.fonbot.R.string.ringing;
-import static ro.ieval.fonbot.R.string.security_exception;
-import static ro.ieval.fonbot.R.string.the_polling_service_is_running;
-import static ro.ieval.fonbot.R.string.the_second_argument_to_wipe_must_be;
-import static ro.ieval.fonbot.R.string.unknown_command;
-import static ro.ieval.fonbot.R.string.wipetype_should_be_one_of;
+import static ro.ieval.fonbot.R.string.*;
import java.net.MalformedURLException;
import java.net.URL;
import android.location.LocationManager;
import android.media.AudioManager;
import android.net.Uri;
+import android.os.Handler;
+import android.os.Looper;
import android.preference.PreferenceManager;
import android.provider.ContactsContract.PhoneLookup;
import android.telephony.SmsManager;
LS, RM, CONTACTS, DISABLE, ENABLE,
POLL, HANGUP, ANSWER, LAUNCH, DATA,
GPS, GLOCATION, REBOOT, NOTIFY, SCREENCAP,
- TORCH
+ TORCH, GETFILE
}
/**
public static void sendMessage(final Context context, final Address address, final String message){
switch(address.protocol){
case HTTP:
- new HttpCallExecutableRunnable("/send", toNonNull(Arrays.asList(
- new Header("X-Destination", toNonNull(address.data)))), context, null, true, message).execute();
+ new HttpCallExecutableRunnable("/send", toNonNull(Arrays.asList(new Header("X-Destination", toNonNull(address.data)))), context, null, true, address.requestId == null ? message : address.requestId + " " + message).execute();
break;
case SMS:
- SmsManager.getDefault().sendTextMessage(address.data, null, message, null, null);
+ new Handler(Looper.getMainLooper()).post(new Runnable(){
+ @Override
+ public void run(){
+ SmsManager.getDefault().sendTextMessage(address.data, null, message, null, null);
+ }
+ });
break;
case LOCAL:
* @throws MalformedURLException if the user preferences create an invalid URL
*/
public static URL getServerURL(final Context context, final String path) throws MalformedURLException{
+ final String protocol=PreferenceManager.getDefaultSharedPreferences(context).getString("protocol", "https");
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("http", hostname, port, path);
+ final URL url=new URL(protocol, hostname, port, path);
return url;
}
break;
case PHOTO:
- if(args.length!=2){
+ if(args.length!=3){
Heavy.help(context, replyTo, toNonNull(Command.PHOTO));
break;
}
+
+ final int cameraNumber;
+ try{
+ cameraNumber=Integer.parseInt(args[0]);
+ } catch (NumberFormatException e){
+ sendMessage(context, replyTo, cannot_parse_camera_number);
+ break;
+ }
+
final int photoPort;
try{
- photoPort=Integer.parseInt(args[1]);
+ photoPort=Integer.parseInt(args[2]);
} catch (NumberFormatException e){
sendMessage(context, replyTo, cannot_parse_port);
break;
}
- Heavy.photo(context, replyTo, toNonNull(args[0]), photoPort);
+ Heavy.photo(context, replyTo, cameraNumber, toNonNull(args[1]), photoPort);
break;
case SETNOTIFICATION:
case TORCH:
Heavy.torch(context, replyTo);
break;
+
+ case GETFILE:
+ if(args.length != 3){
+ Heavy.help(context, replyTo, toNonNull(Command.GETFILE));
+ return;
+ }
+
+ final int getfilePort;
+ try{
+ getfilePort=Integer.parseInt(args[2]);
+ } catch (NumberFormatException e){
+ sendMessage(context, replyTo, cannot_parse_port);
+ break;
+ }
+ Heavy.getfile(context, replyTo, toNonNull(args[0]), toNonNull(args[1]), getfilePort);
+ break;
}
}