X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=src%2Fro%2Fieval%2Ffonbot%2FHeavy.java;h=b1f443c5f6067fb8a1366f2e51e71777d3504b32;hb=251aceaaa3379c65d66a975ff9e7524f7d2f1d73;hp=14b729deffd84d35f22a8cd3fcc32b31e7ece370;hpb=1b6a04801bb78479f9d010cc1d5d8fcca089e013;p=fonbot.git diff --git a/src/ro/ieval/fonbot/Heavy.java b/src/ro/ieval/fonbot/Heavy.java index 14b729d..b1f443c 100644 --- a/src/ro/ieval/fonbot/Heavy.java +++ b/src/ro/ieval/fonbot/Heavy.java @@ -3,11 +3,13 @@ package ro.ieval.fonbot; import static ro.ieval.fonbot.R.string.*; import static ro.ieval.fonbot.Utils.toNonNull; +import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.FileNotFoundException; import java.io.InputStream; +import java.io.InputStreamReader; import java.io.IOException; import java.io.OutputStream; import java.lang.reflect.InvocationTargetException; @@ -665,6 +667,12 @@ final class Heavy { case TORCH: Utils.sendMessage(context, replyTo, torch_help); break; + case SH: + Utils.sendMessage(context, replyTo, sh_help); + break; + case ROOTSH: + Utils.sendMessage(context, replyTo, rootsh_help); + break; } } @@ -1427,7 +1435,7 @@ final class Heavy { sent.putExtra(SmsStatusReceiver.EXTRA_PART, i+1); sent.putExtra(SmsStatusReceiver.EXTRA_TOTAL, messages.size()); sent.putExtra(SmsStatusReceiver.EXTRA_REPLY_TO, replyTo.toString()); - sent.setAction(SmsStatusReceiver.SENT_ACTION+i);//actions must be unique + sent.setAction(SmsStatusReceiver.SENT_ACTION+i+System.currentTimeMillis());//actions must be unique sents.add(PendingIntent.getBroadcast(context, 0, sent, PendingIntent.FLAG_UPDATE_CURRENT)); final Intent delivered=new Intent(context, SmsStatusReceiver.class); @@ -1435,7 +1443,7 @@ final class Heavy { delivered.putExtra(SmsStatusReceiver.EXTRA_PART, i+1); delivered.putExtra(SmsStatusReceiver.EXTRA_TOTAL, messages.size()); delivered.putExtra(SmsStatusReceiver.EXTRA_REPLY_TO, replyTo.toString()); - delivered.setAction(SmsStatusReceiver.DELIVERED_ACTION+i);//actions must be unique + delivered.setAction(SmsStatusReceiver.DELIVERED_ACTION+i+System.currentTimeMillis());//actions must be unique delivereds.add(PendingIntent.getBroadcast(context, 0, delivered, PendingIntent.FLAG_UPDATE_CURRENT)); } @@ -1465,11 +1473,16 @@ final class Heavy { do { final String fromNumber=cursor.getString(1); final String from; - final String name=Utils.callerId(context, Utils.toNonNull(fromNumber)); - if(name==null) - from=fromNumber; - else - from=fromNumber+" ("+name+')'; + if(fromNumber == null) + from = null; + else { + final String name=Utils.callerId(context, Utils.toNonNull(fromNumber)); + if(name==null) + from=fromNumber; + else + from=fromNumber+" ("+name+')'; + } + final String message=cursor.getString(2).replace("\n", "\n "); final Date date=new Date(cursor.getLong(3)); @@ -1838,8 +1851,22 @@ final class Heavy { */ public static void reboot(final Context context, final Address replyTo, final @Nullable String reason) { final PowerManager pm=(PowerManager) context.getSystemService(Context.POWER_SERVICE); - Utils.sendMessage(context, replyTo, rebooting); - pm.reboot(reason); + Utils.sendMessage(context, replyTo, rebooting); + try { + pm.reboot(reason); + } catch (final Exception e){ + e.printStackTrace(); + } + try { + Runtime.getRuntime().exec(new String[]{ + "su", + "-c", + "reboot" + }).waitFor(); + } catch (final Exception e){ + e.printStackTrace(); + } + Utils.sendMessage(toNonNull(context), toNonNull(replyTo), reboot_failed); } /** @@ -1908,4 +1935,30 @@ final class Heavy { public static void getfile(final Context context, final Address replyTo, final String filename, final String hostname, final int port){ new GetfileExecutableRunnable(context, replyTo, filename, hostname, port).execute(); } + + /** + * Execute a command using a given shell and reply with the output. + * + * @param context Context instance + * @param replyTo reply Address + * @param shell The shell to execute with. Usually sh or su. + * @param command The command to pass to the shell. + */ + public static void execute(final Context context, final Address replyTo, final String shell, final String command) { + try { + final Process proc = Runtime.getRuntime().exec(new String[]{ + shell, + "-c", + command + }); + final BufferedReader br = new BufferedReader (new InputStreamReader(proc.getInputStream())); + String line; + while((line = br.readLine()) != null) + Utils.sendMessage(context, replyTo, line); + proc.waitFor(); + } catch (final Exception e){ + Utils.sendMessage(context, replyTo, error_while_processing_command, e.getClass().getName(), e.getMessage()); + Log.w(Heavy.class.getName(), "Error while processing command", e); + } + } }