本文整理汇总了Java中eu.chainfire.libsuperuser.Shell类的典型用法代码示例。如果您正苦于以下问题:Java Shell类的具体用法?Java Shell怎么用?Java Shell使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Shell类属于eu.chainfire.libsuperuser包,在下文中一共展示了Shell类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: waitForCommandFinished
import eu.chainfire.libsuperuser.Shell; //导入依赖的package包/类
private void waitForCommandFinished() {
synchronized (mCallbackThread) {
while (mCommandRunning) {
try {
mCallbackThread.wait();
} catch (Exception e) {
if (e instanceof InterruptedException) {
Log.i(TAG, "InterruptedException occurred while waiting for command to finish");
e.printStackTrace();
} else if (e instanceof NullPointerException) {
Log.i(TAG, "NPE occurred while waiting for command to finish");
e.printStackTrace();
}
}
}
}
if (mLastExitCode == Shell.OnCommandResultListener.WATCHDOG_EXIT || mLastExitCode == Shell.OnCommandResultListener.SHELL_DIED) {
dispose();
}
}
示例2: doInBackground
import eu.chainfire.libsuperuser.Shell; //导入依赖的package包/类
@Override
protected Boolean doInBackground(String... params) {
if (!Shell.SU.available()) {
return false;
}
List<String> output = Shell.SU.run(getCommands());
if (null == output) {
return false;
}
Map<String, Boolean> flags = processOutput(output);
availableCoreutils = flags.get(COMMAND_MV) && flags.get(COMMAND_RM) && flags.get(COMMAND_MKDIR) && flags.get(COMMAND_CHMOD);
availableBusybox = flags.get(COMMAND_BUSYBOX);
Log.i(getClass().getSimpleName(), "Coreutils available " + availableCoreutils);
Log.i(getClass().getSimpleName(), "Busybox available " + availableBusybox);
return true;
}
示例3: getUsers
import eu.chainfire.libsuperuser.Shell; //导入依赖的package包/类
public static ArrayList<Object[]> getUsers(Context context) {
if (IS_ROOTED()) {
ArrayList<Object[]> userList = new ArrayList<>();
List<String> tempList = Shell.SU.run("pm list users");
Object[] temp = tempList.toArray();
for (int i = 1; i < temp.length; i++) {
String userTemp = temp[i].toString();
Integer uId = Integer.parseInt(userTemp.substring(userTemp.indexOf('{') + 1, userTemp.indexOf(':')));
String uName = userTemp.substring(userTemp.indexOf(':') + 1, userTemp.lastIndexOf(':'));
userList.add(new Object[]{uId, uName});
}
return userList;
} else {
noRootToast(context);
return new ArrayList<>();
}
}
示例4: onReceive
import eu.chainfire.libsuperuser.Shell; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
Log.i(TAG, "com.suyashsrijan.forcedoze.ADD_WHITELIST broadcast intent received");
final String packageName = intent.getStringExtra("packageName");
Log.i(TAG, "Package name received: " + packageName);
if (packageName != null) {
AsyncTask.execute(new Runnable() {
@Override
public void run() {
List<String> output = Shell.SH.run("dumpsys deviceidle whitelist +" + packageName);
if (output != null) {
for (String s : output) {
Log.i(TAG, s);
}
} else {
Log.i(TAG, "Error occurred while executing command (" + "dumpsys deviceidle whitelist +packagename" + ")");
}
}
});
} else {
Log.i(TAG, "Package name null or empty");
}
}
示例5: onReceive
import eu.chainfire.libsuperuser.Shell; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
Log.i(TAG, "com.suyashsrijan.forcedoze.REMOVE_WHITELIST broadcast intent received");
final String packageName = intent.getStringExtra("packageName");
Log.i(TAG, "Package name received: " + packageName);
if (packageName != null) {
AsyncTask.execute(new Runnable() {
@Override
public void run() {
List<String> output = Shell.SH.run("dumpsys deviceidle whitelist -" + packageName);
if (output != null) {
for (String s : output) {
Log.i(TAG, s);
}
} else {
Log.i(TAG, "Error occurred while executing command (" + "dumpsys deviceidle whitelist -packagename" + ")");
}
}
});
} else {
Log.i(TAG, "Package name null or empty");
}
}
示例6: getDeviceIdleState
import eu.chainfire.libsuperuser.Shell; //导入依赖的package包/类
private String getDeviceIdleState() {
String state = "";
List<String> output = Shell.SH.run("dumpsys deviceidle");
String outputString = TextUtils.join(", ", output);
if (outputString.contains("mState=ACTIVE")) {
state = "ACTIVE";
} else if (outputString.contains("mState=INACTIVE")) {
state = "INACTIVE";
} else if (outputString.contains("mState=IDLE_PENDING")) {
state = "IDLE_PENDING";
} else if (outputString.contains("mState=SENSING")) {
state = "SENSING";
} else if (outputString.contains("mState=LOCATING")) {
state = "LOCATING";
} else if (outputString.contains("mState=IDLE")) {
state = "IDLE";
} else if (outputString.contains("mState=IDLE_MAINTENANCE")) {
state = "IDLE_MAINTENANCE";
}
return state;
}
示例7: uninstall
import eu.chainfire.libsuperuser.Shell; //导入依赖的package包/类
public static void uninstall(Context context, Prefs prefs) {
try {
ComponentName devAdminReceiver = new ComponentName(context, DAReceiver.class);
DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
dpm.removeActiveAdmin(devAdminReceiver);
if (prefs.proximityToLock && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP && !Shell.SU.available())
prefs.setBool(Prefs.KEYS.PROXIMITY_TO_LOCK.toString(), false);
} catch (Exception ignored) {
}
Uri packageUri = Uri.parse("package:" + context.getPackageName());
Intent uninstallIntent =
new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageUri);
uninstallIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(uninstallIntent);
}
示例8: forceStop
import eu.chainfire.libsuperuser.Shell; //导入依赖的package包/类
public static boolean forceStop (Activity context, final boolean restart) {
if (!Shell.SU.available()) {
Toast.makeText(context, R.string.err_need_root, Toast.LENGTH_SHORT).show();
return false;
}
new Thread(new Runnable() {
@Override
public void run() {
Shell.SU.run("am force-stop " + HookEntry.PKG_COOLAPK);
if (restart)
Shell.SU.run("am start -n " + HookEntry.PKG_COOLAPK + "/" + HookEntry.PKG_COOLAPK + HookEntry.CLASS_MAIN_ACTIVITY);
}
}).start();
Toast.makeText(context, R.string.text_killed, Toast.LENGTH_SHORT).show();
return true;
}
示例9: handleStart
import eu.chainfire.libsuperuser.Shell; //导入依赖的package包/类
public void handleStart() {
final String traceCmd = Constant.CMD.CMD_TRACE + " -d " + Constant.PARTITION.FLASH + " -o " + Constant.PATH.BLK_TRACE + " &";
// Need run in background thread?
if (mRootSession != null) {
sendCommand(traceCmd);
} else {
mRootSession = new Shell.Builder()
.useSU()
.setWantSTDERR(true)
.open(new Shell.OnCommandResultListener() {
@Override
public void onCommandResult(int commandCode, int exitCode, List<String> output) {
if (exitCode != Shell.OnCommandResultListener.SHELL_RUNNING) {
// open session failed
Log.e("yangjun", "open shell failed");
} else {
Log.e("yangjun", "shell is up, send request");
// execute our first request
sendCommand(traceCmd);
}
}
});
}
}
示例10: sendCommand
import eu.chainfire.libsuperuser.Shell; //导入依赖的package包/类
private void sendCommand(String cmd) {
Log.e("yangjun", "sendCommand:" + cmd);
mRootSession.addCommand(cmd, 0, new Shell.OnCommandResultListener() {
@Override
public void onCommandResult(int commandCode, int exitCode, List<String> output) {
Log.e("yangjun", "command exitCode:" + exitCode);
if (exitCode < 0) {
//TODO: this can happen, need handle it.
} else {
// for(String msg: output) Log.e("yangjun", "outPut:" + msg);
}
}
});
mRootSession.waitForIdle();
}
示例11: run
import eu.chainfire.libsuperuser.Shell; //导入依赖的package包/类
public Observable<String> run(final String... commands) {
return su().map(new Function<Boolean, List<String>>() {
@Override
public List<String> apply(Boolean aBoolean) throws Exception {
if (aBoolean) {
Timber.d("run: " + Arrays.toString(commands));
return Shell.SU.run(commands);
}
return null;
}
})
.flatMap(new Function<List<String>, Observable<String>>() {
@Override
public Observable<String> apply(List<String> list) {
return Observable.fromIterable(list);
}
});
}
示例12: getRoot
import eu.chainfire.libsuperuser.Shell; //导入依赖的package包/类
/**
* tries to gain root privilege. Will call the listener when it's done
*/
@UiThread
public void getRoot(@NonNull final IGotRootListener listener) {
if (hasRoot()) {
listener.onGotRootResult(true);
return;
}
final AtomicReference<Shell.Interactive> rootSessionRef = new AtomicReference<>();
rootSessionRef.set(new Shell.Builder().useSU().setWantSTDERR(true).setWatchdogTimeout(5).setMinimalLogging(true).open(//
new Shell.OnCommandResultListener() {
@Override
public void onCommandResult(final int commandCode, final int exitCode, final List<String> output) {
final boolean success = exitCode == Shell.OnCommandResultListener.SHELL_RUNNING;
if (success)
_rootSession = rootSessionRef.get();
_hasRoot = success;
listener.onGotRootResult(success);
}
}));
}
示例13: runCommandInBackground
import eu.chainfire.libsuperuser.Shell; //导入依赖的package包/类
/**
* Run a given command with the classpath from a given context
* @param su should it be run with su?
* @param uid the uid to run under
* @param codePath path to dex file
* @param command command string {@see #getCommandLineForMainClass}
* @return command output
*/
public static Thread runCommandInBackground(boolean su, int uid, String codePath, String command) {
String shell = "sh";
if (su) {
if (!Shell.SU.available()) {
throw new RuntimeException("su not available!");
}
shell = "su";
}
if (uid > 0) {
command = String.format("%d %s", uid, command);
}
// throw it in a thread and return that instead
final String finalShell = shell;
final String finalCommand = command;
final String finalCodePath = codePath;
final List<String> lines = new ArrayList<>();
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
lines.addAll(Shell.run(finalShell, new String[]{finalCommand}, new String[]{String.format("CLASSPATH=%s", finalCodePath)}, true));
}
});
thread.start();
return thread;
}
示例14: doInBackground
import eu.chainfire.libsuperuser.Shell; //导入依赖的package包/类
@Override
protected Void doInBackground(String... params) {
suAvailable = Shell.SU.available();
if (suAvailable) {
// suResult = Shell.SU.run(new String[] {"cd data; ls"}); Shell.SU.run("reboot");
switch (params[0]){
case "reboot" : Shell.SU.run("reboot");break;
case "recov" : Shell.SU.run("reboot recovery");break;
case "shutdown": Shell.SU.run("reboot -p");break;
//case "sysui" : Shell.SU.run("am startservice -n com.android.systemui/.SystemUIService");break;
case "sysui" : Shell.SU.run("pkill com.android.systemui");break;
}
}
else{
Toast.makeText(getApplicationContext(),"Phone not Rooted",Toast.LENGTH_SHORT).show();
}
return null;
}
示例15: installPackageInternal
import eu.chainfire.libsuperuser.Shell; //导入依赖的package包/类
@Override
protected void installPackageInternal(final File apkFile) throws AndroidNotCompatibleException {
rootSession = createShellBuilder().open(new Shell.OnCommandResultListener() {
// Callback to report whether the shell was successfully
// started up
@Override
public void onCommandResult(int commandCode, int exitCode, List<String> output) {
if (exitCode != Shell.OnCommandResultListener.SHELL_RUNNING) {
// NOTE: Additional exit codes:
// Shell.OnCommandResultListener.SHELL_WRONG_UID
// Shell.OnCommandResultListener.SHELL_EXEC_FAILED
Log.e(TAG, "Error opening root shell with exitCode " + exitCode);
mCallback.onError(InstallerCallback.OPERATION_INSTALL,
InstallerCallback.ERROR_CODE_OTHER);
} else {
addInstallCommand(apkFile);
}
}
});
}