content: /**   Copyright (C) 2013  Louis Teboul (a.k.a Androguide)
   *
   *    admin@pimpmyrom.org  || louisteboul@gmail.com
   *    http://pimpmyrom.org || http://androguide.fr
   *    71 quai Clémenceau, 69300 Caluire-et-Cuire, FRANCE.
   *
   *     This program is free software; you can redistribute it and/or modify
   *     it under the terms of the GNU General Public License as published by
   *     the Free Software Foundation; either version 2 of the License, or
   *     (at your option) any later version.
   *
   *     This program is distributed in the hope that it will be useful,
   *     but WITHOUT ANY WARRANTY; without even the implied warranty of
   *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   *     GNU General Public License for more details.
   *
   *      You should have received a copy of the GNU General Public License along
   *      with this program; if not, write to the Free Software Foundation, Inc.,
   *      51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
   **/
  
  package zz.aimsicd.lite.utils;
  
  import android.util.Log;
  
  public final class CMDProcessor {
  
      public static final String TAG = "AICDL";
      public static final String mTAG = "CMDProcessor";
  
      public CMDProcessor() {
  
      }
  
      /* Run a system command with full redirection */
      public static ChildProcess startSysCmd(String[] cmdarray, String childStdin) {
          return new ChildProcess(cmdarray, childStdin);
      }
  
      public static CommandResult runSysCmd(String[] cmdarray, String childStdin) {
          ChildProcess proc = startSysCmd(cmdarray, childStdin);
          proc.waitFinished();
          return proc.getResult();
      }
  
      public static ChildProcess startShellCommand(String cmd) {
          String[] cmdarray = new String[3];
          cmdarray[0] = "sh";
          cmdarray[1] = "-c";
          cmdarray[2] = cmd;
          return startSysCmd(cmdarray, null);
      }
  
      public static CommandResult runShellCommand(String cmd) {
          ChildProcess proc = startShellCommand(cmd);
          proc.waitFinished();
          return proc.getResult();
      }
  
      public static ChildProcess startSuCommand(String cmd) {
          String[] cmdarray = new String[3];
          cmdarray[0] = "su";
          cmdarray[1] = "-c";
          cmdarray[2] = cmd;
          return startSysCmd(cmdarray, null);
      }
  
      public static CommandResult runSuCommand(String cmd) {
          ChildProcess proc = startSuCommand(cmd);
          proc.waitFinished();
          return proc.getResult();
      }
  
      public static boolean canSU() {
          // E:V:A Need fixing:
          //  - Result not shown in pop-up...
          CommandResult r = runShellCommand("id");
          StringBuilder out = new StringBuilder(0);
          out.append(r.getStdout());
          out.append(" ; ");
          out.append(r.getStderr());
         Log.d(TAG, mTAG + "canSU() su[" + r.getExitValue() + "]: " + out);
          return r.success();
      }
  }
  