本文整理汇总了Java中com.android.ddmlib.CollectingOutputReceiver.getOutput方法的典型用法代码示例。如果您正苦于以下问题:Java CollectingOutputReceiver.getOutput方法的具体用法?Java CollectingOutputReceiver.getOutput怎么用?Java CollectingOutputReceiver.getOutput使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.android.ddmlib.CollectingOutputReceiver
的用法示例。
在下文中一共展示了CollectingOutputReceiver.getOutput方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import com.android.ddmlib.CollectingOutputReceiver; //导入方法依赖的package包/类
/**
* Executes a command with a specified timeout on the device's shell and returns the result of the execution. If the
* default timeout is grater than the requested one, default will be used.
*
* @param command
* - Shell command to be executed.
* @param timeout
* - timeout to be used in the adb connection, when executing a command on the device.
* @return Shell response from the command execution.
* @throws CommandFailedException
* In case of an error in the execution
*/
public String execute(String command, int timeout) throws CommandFailedException {
String response = "";
int commandExecutionTimeout = Math.max(timeout, COMMAND_EXECUTION_TIMEOUT);
try {
CollectingOutputReceiver outputReceiver = new CollectingOutputReceiver();
device.executeShellCommand(command, outputReceiver, commandExecutionTimeout);
response = outputReceiver.getOutput();
} catch (TimeoutException | AdbCommandRejectedException | ShellCommandUnresponsiveException | IOException e) {
throw new CommandFailedException("Shell command execution failed.", e);
}
return response;
}
示例2: getWorkProfileId
import com.android.ddmlib.CollectingOutputReceiver; //导入方法依赖的package包/类
@Nullable
public static Integer getWorkProfileId(IDevice device)
throws TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException,
IOException {
CollectingOutputReceiver receiver = new CollectingOutputReceiver();
device.executeShellCommand("pm list users", receiver);
String result = receiver.getOutput();
Matcher matcher = USER_ID_REGEX.matcher(result);
if (matcher.find()) {
return Integer.parseInt(matcher.group(1));
}
return null;
}
示例3: checkReceiverOutput
import com.android.ddmlib.CollectingOutputReceiver; //导入方法依赖的package包/类
/**
* This was made public for one specific call site in ExopackageInstaller.
* If you're reading this, you probably shouldn't call it. Pretend this method is private.
*/
public static String checkReceiverOutput(
String command,
CollectingOutputReceiver receiver) throws CommandFailedException {
String fullOutput = receiver.getOutput();
int colon = fullOutput.lastIndexOf(':');
String realOutput = fullOutput.substring(0, colon);
String exitCodeStr = fullOutput.substring(colon + 1);
int exitCode = Integer.parseInt(exitCodeStr);
if (exitCode != 0) {
throw new CommandFailedException(command, exitCode, realOutput);
}
return realOutput;
}
示例4: checkReceiverOutput
import com.android.ddmlib.CollectingOutputReceiver; //导入方法依赖的package包/类
private static String checkReceiverOutput(String command, CollectingOutputReceiver receiver)
throws AdbHelper.CommandFailedException {
String fullOutput = receiver.getOutput();
int colon = fullOutput.lastIndexOf(':');
String realOutput = fullOutput.substring(0, colon);
String exitCodeStr = fullOutput.substring(colon + 1);
int exitCode = Integer.parseInt(exitCodeStr);
if (exitCode != 0) {
throw new AdbHelper.CommandFailedException(command, exitCode, realOutput);
}
return realOutput;
}