Hi,

I'm having problems executing shell commands properly from android
built from the rowboat-android source project. I have two specific
problems that I want to share and see if anyone has possible
solutions.

1. Setting the date with date 134355500 sets the date in the local
shell, but running date in another shell does not see the change. If I
execute the same command into adb shell, the change does seem to
persist. What is the correct way to set the system date / time using
the shell provided by getRuntime().exec?

2. Trying to reboot the device using /system/bin/reboot will lock up
the application (ANR) and no other shell commands will work (using
getRuntime().exec) until the device is restarted. Shell commands still
work via adb shell.

The application already requests both perimssions of RESTART and
SET_TIME. A good number of commands do work fine, like ls and netcfg
but restarting (and hopefull powering off with the -p flag) and
setting the time are two that I need that don't work correctly.

Below is the code that I use to try and do either of these two tasks.
The firmware seems to be pre-rooted, I'm able to install the Super
User apk, run su etc.

Hope to hear from someone soon.
Kevin

public class ExecShell {

        public static enum SHELL_CMD {
                restart_device, set_datetime,
        }

        public static boolean executeCommand(SHELL_CMD iShellCmd, String
iShellArguments){
                String cmd = null;
        String line = null;
        String fullResponse = null;
                Process lPs = null;
                Runtime lRuntime;

                lRuntime = Runtime.getRuntime();

                Log.d(Global.TAG,"--> !!!!! Running shell command");

                if (iShellCmd == SHELL_CMD.restart_device){
                        cmd = "/system/bin/reboot";
                }
                if (iShellCmd == SHELL_CMD.set_datetime){
                        cmd = "date " + iShellArguments;
                }

                Log.d(Global.TAG,"--> About to exec: " + cmd);

                try {
                        lPs = lRuntime.exec("su");
                        lPs = lRuntime.exec(cmd);
                } catch (Exception e) {
                        e.printStackTrace();
                }

        BufferedWriter out = new BufferedWriter(new
OutputStreamWriter(lPs.getOutputStream()));
        BufferedReader in = new BufferedReader(new
InputStreamReader(lPs.getInputStream()));

        try {
                        while ((line = in.readLine()) != null) {
                                Log.d(Global.TAG,"--> Command result line: " + 
line);
                                if (fullResponse == null){
                                        fullResponse = line;
                                }else{
                                        fullResponse = fullResponse + "\n" + 
line;
                                }
                        }
                } catch (Exception e) {
                        e.printStackTrace();
                }

                Log.d(Global.TAG,"--> Full response was: " + fullResponse);

                return true;
        }

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to