Java Code Examples for com.stericson.RootShell.execution.Shell#add()
The following examples show how to use
com.stericson.RootShell.execution.Shell#add() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UsbBroadcastReceiver.java From USB_Mass_Storage_Enabler with MIT License | 6 votes |
boolean enableUMS(Context context) { try { String enableCommand = data.getString(Constants.setPermissionCmds, "")+"\n"+data.getString(Constants.enableUMScmds, ""); if(enableCommand.isEmpty()) { Toast.makeText(context, context.getString(R.string.toast_open_app_once), Toast.LENGTH_SHORT).show(); return false; } Shell rootShell = RootTools.getShell(true); Command cmd = new Command(0, "setenforce 0\n"+enableCommand); rootShell.add(cmd); //if(!rootShell.isExecuting) rootShell.close(); } catch (Exception e) { e.printStackTrace(); Toast.makeText(context, context.getString(R.string.error_ums), Toast.LENGTH_SHORT).show(); openApp(context); return false; } Toast.makeText(context, context.getString(R.string.toast_ums_enabled), Toast.LENGTH_SHORT).show(); isUMSdisabled = false; showNotification(context); return true; }
Example 2
Source File: UsbBroadcastReceiver.java From USB_Mass_Storage_Enabler with MIT License | 6 votes |
boolean disableUMS(Context context, boolean removeNotif) { try { String disableCommand = data.getString(Constants.disableUMScmds, ""); if(disableCommand.isEmpty()) { Toast.makeText(context, context.getString(R.string.toast_open_app_once), Toast.LENGTH_SHORT).show(); return false; } Shell rootShell = RootTools.getShell(true); Command cmd = new Command(0, disableCommand); rootShell.add(cmd); //if(!rootShell.isExecuting) rootShell.close(); } catch (Exception e) { e.printStackTrace(); Toast.makeText(context, context.getString(R.string.error_ums_disable), Toast.LENGTH_SHORT).show(); return false; } Toast.makeText(context, context.getString(R.string.toast_ums_disabled), Toast.LENGTH_SHORT).show(); isUMSdisabled = true; if(removeNotif) removeNotification(context); else showNotification(context); //TODO: if(MainActivity.isAppOpen) MainActivity.updateUSBconfig(); //When toggled from notif return true; }
Example 3
Source File: RootToolsInternalMethods.java From PhoneProfilesPlus with Apache License 2.0 | 5 votes |
/** * This will return an ArrayList of the class Mount. The class mount contains the following * property's: device mountPoint type flags * <p/> * These will provide you with any information you need to work with the mount points. * * @return <code>ArrayList<Mount></code> an ArrayList of the class Mount. * @throws Exception if we cannot return the mount points. */ public ArrayList<Mount> getMounts() throws Exception { InternalVariables.mounts = new ArrayList<>(); //noinspection ConstantConditions if(null == InternalVariables.mounts || InternalVariables.mounts.isEmpty()) { Shell shell = RootTools.getShell(true); Command cmd = new Command(Constants.GET_MOUNTS, false, "cat /proc/mounts") { @Override public void commandOutput(int id, String line) { if (id == Constants.GET_MOUNTS) { RootTools.log(line); String[] fields = line.split(" "); if(fields.length > 3) { InternalVariables.mounts.add(new Mount(new File(fields[0]), // device new File(fields[1]), // mountPoint fields[2], // fstype fields[3] // flags )); } } super.commandOutput(id, line); } }; shell.add(cmd); this.commandWait(shell, cmd); } return InternalVariables.mounts; }
Example 4
Source File: RootShell.java From PhoneProfilesPlus with Apache License 2.0 | 5 votes |
/** * Control how many time of retries should request * * @param timeout The timeout * @param retries The number of retries * * @return <code>true</code> if your app has been given root access. * @throws TimeoutException if this operation times out. (cannot determine if access is given) */ public static boolean isAccessGiven(int timeout, int retries) { final Set<String> ID = new HashSet<>(); final int IAG = 158; try { RootShell.log("Checking for Root access"); Command command = new Command(IAG, false, "id") { @Override public void commandOutput(int id, String line) { if (id == IAG) { ID.addAll(Arrays.asList(line.split(" "))); } super.commandOutput(id, line); } }; Shell shell = Shell.startRootShell(timeout, retries); shell.add(command); commandWait(shell, command); //parse the userid for (String userid : ID) { RootShell.log(userid); if (userid.toLowerCase().contains("uid=0")) { RootShell.log("Access Given"); return true; } } return false; } catch (Exception e) { e.printStackTrace(); return false; } }
Example 5
Source File: RootTools.java From PhoneProfilesPlus with Apache License 2.0 | 2 votes |
/** * Executes a given command with root access or without depending on the value of the boolean passed. * This will also start a root shell or a standard shell without you having to open it specifically. * <p/> * You will still need to close the shell after you are done using the shell. * * @param shell The shell to execute the command on, this can be a root shell or a standard shell. * @param command The command to execute in the shell * * @throws IOException */ @SuppressWarnings("unused") public static void runShellCommand(Shell shell, Command command) throws IOException { shell.add(command); }