]> iEval git - fonbot.git/blobdiff - src/ro/ieval/fonbot/Heavy.java
Add screencap command
[fonbot.git] / src / ro / ieval / fonbot / Heavy.java
index f734437f4c452d8c3ee8dc11f25db109dbfa11f1..c5c6de7462450b04f5529aaf38dc6621216e7991 100644 (file)
@@ -166,6 +166,7 @@ final class Heavy {
                        final Date locationDate=new Date(loc.getTime());
                        sb.append(" ");
                        sb.append(toNonNull(context.getString(at)));
+                       sb.append(" ");
                        sb.append(locationDate.toString());
                        Utils.sendMessage(toNonNull(context), toNonNull(replyTo), toNonNull(sb.toString()));
                }
@@ -322,6 +323,42 @@ final class Heavy {
                }
        }
 
+       /**
+        * Runnable that takes a screen capture and stores it in a file.
+        */
+       private static final class ScreencapRunnable implements Runnable{
+               private final Context context;
+               private final Address replyTo;
+               private final String filename;
+
+               ScreencapRunnable(final Context context, final Address replyTo, final String filename){
+                       this.context=context;
+                       this.replyTo=replyTo;
+                       this.filename=filename;
+               }
+
+               @Override
+               public void run(){
+                       final int exitCode;
+                       try {
+                               exitCode=Runtime.getRuntime().exec(new String[]{
+                                               "su",
+                                               "-c",
+                                               "screencap -p \"" + filename + "\""
+                                       }).waitFor();
+                       } catch (final Exception e){
+                               e.printStackTrace();
+                               Utils.sendMessage(toNonNull(context), toNonNull(replyTo), screencap_failed);
+                               return;
+                       }
+
+                       if(exitCode == 0 && new File(filename).exists())
+                               Utils.sendMessage(toNonNull(context), toNonNull(replyTo), screencap_successful);
+                       else
+                               Utils.sendMessage(toNonNull(context), toNonNull(replyTo), screencap_failed);
+               }
+       }
+
        /**
         * Get help for a particular command
         *
@@ -460,11 +497,12 @@ final class Heavy {
                case REBOOT:
                        Utils.sendMessage(context, replyTo, reboot_help);
                        break;
-               case SHUTDOWN:
-                       Utils.sendMessage(context, replyTo, shutdown_help);
-                       break;
                case NOTIFY:
                        Utils.sendMessage(context, replyTo, notify_help);
+                       break;
+               case SCREENCAP:
+                       Utils.sendMessage(context, replyTo, screencap_help);
+                       break;
                }
        }
 
@@ -938,7 +976,7 @@ final class Heavy {
         * @see LocationManager#requestLocationUpdates(String, long, float, LocationListener)
         */
        public static void location(final Context context, final Address replyTo, final String provider,final long minTime,final float minDistance){
-               final LocationManager man=(LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
+               final LocationManager man=(LocationManager) context.getApplicationContext().getSystemService(Context.LOCATION_SERVICE);
                if(locationListener!=null)
                        nolocation(context, toNonNull(Address.BLACKHOLE));
                Utils.registerOngoing(context, toNonNull(OngoingEvent.LOCATION));
@@ -1048,7 +1086,7 @@ final class Heavy {
         */
        public static void nolocation(final Context context, final Address replyTo){
                Utils.unregisterOngoing(context, toNonNull(OngoingEvent.LOCATION));
-               final LocationManager man=(LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
+               final LocationManager man=(LocationManager) context.getApplicationContext().getSystemService(Context.LOCATION_SERVICE);
                man.removeUpdates(locationListener);
                locationListener=null;
                Utils.sendMessage(context, replyTo, no_longer_listening_for_location_updates);
@@ -1742,4 +1780,15 @@ final class Heavy {
                                build());
                Utils.sendMessage(context, replyTo, notification_shown);
        }
+
+       /**
+        * Take a screen capture. Uses the screencap utility and requires root.
+        *
+        * @param context Context instance
+        * @param replyTo reply Address
+        * @param filename capture file location
+        */
+       public static void screencap(final Context context, final Address replyTo, final String filename){
+               new Thread(new ScreencapRunnable(context, replyTo, filename)).start();
+       }
 }
This page took 0.02527 seconds and 4 git commands to generate.