示例#1
0
  public void myCommand0() {
    // Run this command (root optional) capturing the output
    // to show which connection mode we are CURRENTLY using
    Command command0 =
        new Command(1, "getprop persist.sys.usb.config") {
          @Override
          public void commandOutput(int id, String line) {
            if (line.contains("adb")) {
              myADB = true;
            }
            if (line.contains("mass_storage")) {
              mySwitch.setChecked(true);
            }
            // MUST call the super method when overriding!
            super.commandOutput(id, line);
          }

          @Override
          public void commandTerminated(int id, String reason) {}

          @Override
          public void commandCompleted(int id, int exitcode) {
            mySwitch.setEnabled(true);
          }
        };

    try {
      if (rootPref) {
        // If its preferred to check root immediately upon startup,
        // then do it here, even though is not actually needed
        RootShell.getShell(true).add(command0);
      } else {
        // Otherwise just run the command without root,
        // and worry about permissions later ...
        RootShell.getShell(false).add(command0);
      }

    } catch (RootDeniedException | TimeoutException | IOException exc) {
      exc.printStackTrace();
    } finally {
      if (debugMode) Log.d(TAG, "Command0 done!");
    }
  }
示例#2
0
  public void myCommand() {
    // Try running this command WITHOUT root to check for app compatibility
    Command command =
        new Command(
            0,
            "if [ -d "
                + sysFolder
                + " ]; then echo "
                + getString(R.string.success)
                + "; else echo "
                + getString(R.string.hsusbfail)
                + "; fi") {

          @Override
          public void commandOutput(int id, String line) {
            try {
              if (line.equals(getString(R.string.success))) {
                // Success ... we can continue
                Checking =
                    Toast.makeText(
                        MainActivity.this, "Checking current state ...", Toast.LENGTH_SHORT);
                Checking.setGravity(
                    Gravity.CENTER, Checking.getXOffset() / 2, Checking.getYOffset() / 2);
                Checking.show();
                myCommand0();
              } else {
                // No such folder, so nothing to achieve
                textView5.setVisibility(View.VISIBLE);
              }
            } catch (NullPointerException e) {
              e.printStackTrace();
            }
            // MUST call the super method when overriding!
            super.commandOutput(id, line);
          }

          @Override
          public void commandTerminated(int id, String reason) {}

          @Override
          public void commandCompleted(int id, int exitcode) {}
        };

    try {
      RootShell.getShell(false).add(command);
    } catch (RootDeniedException | TimeoutException | IOException exc) {
      exc.printStackTrace();
    } finally {
      if (debugMode) Log.d(TAG, "Command done!");
    }
  }
示例#3
0
  public void myCommand2(final Boolean isOn) {
    // Specific input for the destination file, depending on connection method chosen
    String longCommand;
    if (isOn) {
      // Turn it on
      longCommand =
          "if [ -d "
              + sysFolder
              + " ]; then echo "
              + devFolder
              + " > "
              + sysFile
              + "; echo "
              + getString(R.string.success)
              + "; else echo "
              + getString(R.string.hsusbfail)
              + "; fi";
    } else {
      // Turn it off
      longCommand =
          "if [ -d "
              + sysFolder
              + " ]; then echo "
              + devNull
              + " > "
              + sysFile
              + "; echo "
              + getString(R.string.success)
              + "; else echo "
              + getString(R.string.hsusbfail)
              + "; fi";
    }

    // Now do all that here
    Command command2 =
        new Command(3, longCommand) {
          @Override
          public void commandOutput(int id, String line) {
            // Change the text colour to GREEN if all is peachy
            if (line.equals(getString(R.string.success))) {
              textView2.setTextColor(Color.parseColor(getString(R.string.green)));
              mSuccess2 = true;
            }
            textView2.setText(line);
            // MUST call the super method when overriding!
            super.commandOutput(id, line);
          }

          @Override
          public void commandTerminated(int id, String reason) {
            tvText2 = getString(R.string.terminated) + " " + reason;
            textView2.setText(tvText2);
          }

          @Override
          public void commandCompleted(int id, int exitcode) {
            tvText2 = textView2.getText() + " " + getString(R.string.complete);
            textView2.setText(tvText2);
            if (mSuccess1 && mSuccess2) {
              String tmpText;
              if (isOn) {
                tmpText = getString(R.string.textview4);
                if (myADB) {
                  tmpText += getString(R.string.method_plus_adb);
                }
              } else {
                tmpText = getString(R.string.textview4a) + " (" + protocolPref.toUpperCase() + ")";
              }
              textView4.setTextColor(Color.parseColor(getString(R.string.black)));
              textView4.setVisibility(View.VISIBLE);
              textView4.setText(tmpText);
              mySwitch.setEnabled(true);
            } else {
              textView2.setTextColor(Color.RED);
              textView2.setText(getString(R.string.error));
            }
          }
        };

    try {
      RootShell.getShell(true).add(command2);
    } catch (RootDeniedException | TimeoutException | IOException exc) {
      exc.printStackTrace();
      mSuccess2 = false;
    } finally {
      if (debugMode) Log.d(TAG, "Command2 done!");
    }
  }
示例#4
0
  public void myCommand1(Boolean isOn) {
    String method;
    // This is the base of the command we're going to run as Root
    String shortCommand = "setprop persist.sys.usb.config";
    // Add parameters to the base command, as appropriate
    if (isOn) {
      // Release the MTP/PTP client connection
      final MtpClient mtpClient = new MtpClient(this.getApplicationContext());
      mtpClient.close();
      // Turn on UMS mode
      method = "mass_storage";
    } else {
      // Restore preferred communications protocol
      if (protocolPref.equals("mtp")) {
        method = "mtp";
      } else {
        method = "ptp";
      }
    }

    if (myADB) {
      // If ADB was previously set, append it to the setprop options
      method += ",adb";
    }

    String longCommand = shortCommand + " " + method + "; echo $?";
    Command command1 =
        new Command(2, longCommand) {
          @Override
          public void commandOutput(int id, String line) {
            try {
              mResult = Integer.parseInt(line);
            } catch (NumberFormatException e) {
              e.printStackTrace();
            } finally {
              if (mResult > 0) {
                textView1.setTextColor(Color.RED);
                tvText1 = getString(R.string.setpropfail);
              } else {
                textView1.setTextColor(Color.parseColor(getString(R.string.green)));
                tvText1 = getString(R.string.success);
                mSuccess1 = true;
              }
              textView1.setText(tvText1);
              // MUST call the super method when overriding!
              super.commandOutput(id, line);
            }
          }

          @Override
          public void commandTerminated(int id, String reason) {
            tvText1 = getString(R.string.terminated) + " " + reason;
            textView1.setTextColor(Color.RED);
            textView1.setText(tvText1);
          }

          @Override
          public void commandCompleted(int id, int exitcode) {
            tvText1 = textView1.getText() + " " + getString(R.string.exit_code) + " " + exitcode;
            textView1.setText(tvText1);
          }
        };

    try {
      textView1.setText(null);
      textView2.setText(null);
      RootShell.getShell(true).add(command1);
    } catch (RootDeniedException | TimeoutException | IOException exc) {
      exc.printStackTrace();
      mSuccess1 = false;
    } finally {
      if (debugMode) Log.d(TAG, "Command1 done!");
    }
  }