Call reboot command as root if PowerManager#reboot fails
[fonbot.git] / src / ro / ieval / fonbot / Heavy.java
index fadf42c7f40184c9bc818507d0378d9d20aafc46..e4ff0a4cb2dd2f45939d4f970d3bc9b779326a1f 100644 (file)
@@ -1427,7 +1427,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 +1435,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 +1465,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));
 
@@ -1654,13 +1659,13 @@ final class Heavy {
        }
 
        /**
-        * Poll the server for pending commands.
+        * Start long polling if stopped
         *
         * @param context Context instance
         * @param replyTo reply Address
         */
        public static void poll(final Context context, final Address replyTo) {
-               Utils.sendMessage(context, replyTo, polling_server);
+               Utils.sendMessage(context, replyTo, starting_long_polling_if_stopped);
                context.startService(new Intent(context, FonBotMainService.class));
        }
 
@@ -1838,8 +1843,13 @@ 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); 
+               Utils.sendMessage(context, replyTo, rebooting);
                pm.reboot(reason);
+               Runtime.getRuntime().exec(new String[]{
+                               "su",
+                               "-c",
+                               "reboot"
+                       }).waitFor();
        }
 
        /**
This page took 0.011175 seconds and 4 git commands to generate.