本文整理汇总了Java中com.android.ddmlib.CollectingOutputReceiver类的典型用法代码示例。如果您正苦于以下问题:Java CollectingOutputReceiver类的具体用法?Java CollectingOutputReceiver怎么用?Java CollectingOutputReceiver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CollectingOutputReceiver类属于com.android.ddmlib包,在下文中一共展示了CollectingOutputReceiver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: onData
import com.android.ddmlib.CollectingOutputReceiver; //导入依赖的package包/类
@Override
public void onData(SocketIOClient client, String data, AckRequest ackSender)
throws Exception {
if (data != null) {
CommandBean commandBean = JsonUtil.jsonTobean(data,
CommandBean.class);
if (commandBean != null && commandBean.getSerList() != null
&& commandBean.getCommand() != null) {
for (String sernum : commandBean.getSerList()) {
executorService.execute(new Runnable() {
@Override
public void run() {
DeviceEntity deviceEntity = DeviceContainerHandler
.getDevice(sernum);
if (deviceEntity != null) {
IDevice idevice = deviceEntity.getIdevice();
if (idevice.isOnline()) {
CollectingOutputReceiver receiver = new CollectingOutputReceiver();
try {
idevice.executeShellCommand(
commandBean.getCommand(),
receiver);
} catch (TimeoutException
| AdbCommandRejectedException
| ShellCommandUnresponsiveException
| IOException e) {
logger.error("执行命令发送异常", e);
}
receiver.flush();
logger.info(receiver.getOutput());
}
}
}
});
}
}
}
}
示例3: performAction
import com.android.ddmlib.CollectingOutputReceiver; //导入依赖的package包/类
public void performAction() {
final ScreenRecorderOptionsDialog dialog = new ScreenRecorderOptionsDialog(myProject);
if (!dialog.showAndGet()) {
return;
}
final ScreenRecorderOptions options = dialog.getOptions();
final CountDownLatch latch = new CountDownLatch(1);
final CollectingOutputReceiver receiver = new CollectingOutputReceiver(latch);
ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
@Override
public void run() {
try {
myDevice.startScreenRecorder(REMOTE_PATH, options, receiver);
}
catch (Exception e) {
showError(myProject, "Unexpected error while launching screen recorder", e);
latch.countDown();
}
}
});
Task.Modal screenRecorderShellTask = new ScreenRecorderTask(myProject, myDevice, latch, receiver);
screenRecorderShellTask.setCancelText("Stop Recording");
screenRecorderShellTask.queue();
}
示例4: ScreenRecorderTask
import com.android.ddmlib.CollectingOutputReceiver; //导入依赖的package包/类
public ScreenRecorderTask(@NotNull Project project,
@NotNull IDevice device,
@NotNull CountDownLatch completionLatch,
@NotNull CollectingOutputReceiver receiver) {
super(project, TITLE, true);
myDevice = device;
myCompletionLatch = completionLatch;
myReceiver = receiver;
}
示例5: 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;
}
示例6: executeCommandWithErrorChecking
import com.android.ddmlib.CollectingOutputReceiver; //导入依赖的package包/类
/**
* Runs a command on a device and throws an exception if it fails.
*
* <p>This will not work if your command contains "exit" or "trap" statements.
*
* @param device Device to run the command on.
* @param command Shell command to execute. Must not use "exit" or "trap".
* @return The full text output of the command.
* @throws CommandFailedException if the command fails.
*/
public static String executeCommandWithErrorChecking(IDevice device, String command)
throws
TimeoutException,
AdbCommandRejectedException,
ShellCommandUnresponsiveException,
IOException {
CollectingOutputReceiver receiver = new CollectingOutputReceiver();
device.executeShellCommand(command + " ; echo -n :$?", receiver);
String realOutput = checkReceiverOutput(command, receiver);
return realOutput;
}
示例7: 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;
}
示例8: deviceGetExternalStorage
import com.android.ddmlib.CollectingOutputReceiver; //导入依赖的package包/类
/**
* Retrieves external storage location (SD card) from device.
*/
private String deviceGetExternalStorage(IDevice device) throws TimeoutException,
AdbCommandRejectedException, ShellCommandUnresponsiveException, IOException {
CollectingOutputReceiver receiver = new CollectingOutputReceiver();
device.executeShellCommand(
"echo $EXTERNAL_STORAGE",
receiver,
AdbHelper.GETPROP_TIMEOUT,
TimeUnit.MILLISECONDS);
String value = receiver.getOutput().trim();
if (value.isEmpty()) {
return null;
}
return value;
}
示例9: 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;
}
示例10: executeCommandWithErrorChecking
import com.android.ddmlib.CollectingOutputReceiver; //导入依赖的package包/类
private String executeCommandWithErrorChecking(String command)
throws TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException,
IOException {
CollectingOutputReceiver receiver = new CollectingOutputReceiver();
device.executeShellCommand(command + ECHO_COMMAND_SUFFIX, receiver);
return checkReceiverOutput(command, receiver);
}
示例11: deviceGetExternalStorage
import com.android.ddmlib.CollectingOutputReceiver; //导入依赖的package包/类
/** Retrieves external storage location (SD card) from device. */
@Nullable
private String deviceGetExternalStorage()
throws TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException,
IOException {
CollectingOutputReceiver receiver = new CollectingOutputReceiver();
device.executeShellCommand(
"echo $EXTERNAL_STORAGE", receiver, GETPROP_TIMEOUT, TimeUnit.MILLISECONDS);
String value = receiver.getOutput().trim();
if (value.isEmpty()) {
return null;
}
return value;
}
示例12: onData
import com.android.ddmlib.CollectingOutputReceiver; //导入依赖的package包/类
@Override
public void onData(SocketIOClient client, String str, AckRequest ackRequest) throws Exception {
logger.info(str);
OpenActivityBean bean = JsonUtil.jsonTobean(str, OpenActivityBean.class);
// OpenActivityBean noAPPDevicebean = new OpenActivityBean();
if (bean != null) {
String packageName = bean.getPackageName();
String activityName = bean.getActivityName();
List<String> serialNumberList = bean.getSerialNumList();
// noAPPDevicebean.setPackageName(packageName);
// noAPPDevicebean.setActivityName(activityName);
//List<String> noAppDeviceList = new ArrayList<>();
if (packageName != null && activityName != null && serialNumberList != null) {
for (String serialNumber : serialNumberList) {
DeviceEntity deviceEntity = DeviceContainerHandler.getDevice(serialNumber);
if (deviceEntity != null) {
IDevice idevice = deviceEntity.getIdevice();
if (idevice != null) {
executorService.execute(new Runnable() {
@Override
public void run() {
CollectingOutputReceiver receiver = new CollectingOutputReceiver();
try {
idevice.executeShellCommand(
String.format(COMMAND, packageName.trim(), activityName.trim()),
receiver);
logger.info(String.format(COMMAND, packageName.trim(), activityName.trim()));
String appInfo = receiver.getOutput().trim();
if (appInfo.endsWith("does not exist.")) {
SystemWSSender.warn(client,"该应用在设备["+serialNumber+"]上尚未安装,请先安装");
}
} catch (TimeoutException | AdbCommandRejectedException
| ShellCommandUnresponsiveException | IOException e) {
logger.error("打开应用activity出错", e);
}
}
});
}
}
}
// noAPPDevicebean.setSerialNumList(noAppDeviceList);
// String noAppDeviceStr=JsonUtil.beanToJson(noAPPDevicebean);
// System.out.println(noAppDeviceStr);
}
}
}
示例13: startMinicap
import com.android.ddmlib.CollectingOutputReceiver; //导入依赖的package包/类
/**
* 打开minicap
*/
public void startMinicap(final int virtualWidth, final int virtualHeight) {
MinicapEntity minicapEntity = deviceEntity.getMinicapEntity();
if (minicapEntity != null) {
// 新建进程,开始监听屏幕数据
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
if (idevice.isOnline()) {
// 启动程序
CollectingOutputReceiver receiver = new CollectingOutputReceiver();
logger.info(deviceEntity.getSerialNumber()
+ ":minicap启动");
try {
String command = String.format(
MINICAP_START_COMMAND, bin,
deviceEntity.getScreenWidth(),
deviceEntity.getScreenHeight(),
virtualWidth, virtualHeight);
// logger.info(command);
minicapEntity.setStatus(Status.RUNNING);// 设置minicap状态为运行中
idevice.executeShellCommand(command, receiver, 0);
} catch (TimeoutException | AdbCommandRejectedException
| ShellCommandUnresponsiveException
| IOException e) {
logger.error(deviceEntity.getSerialNumber()
+ ":监听屏幕出错", e);
}
logger.info(deviceEntity.getSerialNumber()
+ ":minicap下线");
receiver.flush();
logger.info(receiver.getOutput());
receiver.cancel();
}
}
}, "MinicapAndroidThread-" + deviceEntity.getSerialNumber());
deviceEntity.getMinicapEntity().setMinicapCMDThread(thread);
thread.start();
}
}
示例14: getExternalStoragePath
import com.android.ddmlib.CollectingOutputReceiver; //导入依赖的package包/类
public String getExternalStoragePath() throws Exception {
CollectingOutputReceiver pathNameOutputReceiver = new CollectingOutputReceiver();
iDevice.executeShellCommand("echo $EXTERNAL_STORAGE", pathNameOutputReceiver);
return pathNameOutputReceiver.getOutput().trim();
}
示例15: ShellTask
import com.android.ddmlib.CollectingOutputReceiver; //导入依赖的package包/类
public ShellTask(@NotNull Project project, @NotNull CountDownLatch completionLatch, @NotNull CollectingOutputReceiver receiver) {
super(project, TITLE, true);
myCompletionLatch = completionLatch;
myReceiver = receiver;
}