com.android.ddmlib.IShellOutputReceiver Java Examples

The following examples show how to use com.android.ddmlib.IShellOutputReceiver. 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: RealAndroidDeviceTest.java    From buck with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeviceStartActivityDoNotWaitForDebugger() {
  AtomicReference<String> runDeviceCommand = new AtomicReference<>();
  TestDevice device =
      new TestDevice() {
        @Override
        public void executeShellCommand(
            String command,
            IShellOutputReceiver receiver,
            long maxTimeToOutputResponse,
            TimeUnit maxTimeUnits) {
          runDeviceCommand.set(command);
        }
      };
  assertNull(createAndroidDevice(device).deviceStartActivity("com.foo/.Activity", false));
  assertFalse(runDeviceCommand.get().contains(" -D"));
}
 
Example #2
Source File: FakeDevice.java    From bundletool with Apache License 2.0 6 votes vote down vote up
@Override
public void executeShellCommand(
    String command,
    IShellOutputReceiver receiver,
    long maxTimeToOutputResponse,
    TimeUnit maxTimeUnits)
    throws TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException,
        IOException {

  checkState(
      commandInjections.containsKey(command),
      "Command %s not found in command injections.",
      command);
  byte[] data = commandInjections.get(command).onExecute().getBytes(UTF_8);
  receiver.addOutput(data, 0, data.length);
  receiver.flush();
}
 
Example #3
Source File: RealAndroidDeviceTest.java    From buck with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeviceStartActivityWaitForDebugger() {
  AtomicReference<String> runDeviceCommand = new AtomicReference<>();
  TestDevice device =
      new TestDevice() {
        @Override
        public void executeShellCommand(
            String command,
            IShellOutputReceiver receiver,
            long maxTimeToOutputResponse,
            TimeUnit maxTimeUnits) {
          runDeviceCommand.set(command);
        }
      };
  assertNull(createAndroidDevice(device).deviceStartActivity("com.foo/.Activity", true));
  assertTrue(runDeviceCommand.get().contains(" -D"));
}
 
Example #4
Source File: MonkeyTestDevice.java    From Android-Monkey-Adapter with Apache License 2.0 5 votes vote down vote up
/**
 * Executes a logcat command on the device, and sends the result to a
 * <var>receiver</var>.
 * 
 * @param receiver the {@link IShellOutputReceiver} that will receives the
 *            output of the shell command
 */
public boolean logcat(IShellOutputReceiver receiver) {
    boolean result = false;
    try {
        mDevice.executeShellCommand("logcat -v threadtime *:V", receiver,
                60000);
        result = true;
    } catch (ShellCommandUnresponsiveException mttor) {
        result = true;
    } catch (Exception ex) {
        result = false;
    }
    return result;
}
 
Example #5
Source File: TestDevice.java    From buck with Apache License 2.0 5 votes vote down vote up
@Override
public void executeShellCommand(
    String command,
    IShellOutputReceiver receiver,
    long maxTimeToOutputResponse,
    TimeUnit maxTimeUnits) {
  throw new UnsupportedOperationException();
}
 
Example #6
Source File: RealAndroidDeviceTest.java    From buck with Apache License 2.0 5 votes vote down vote up
private TestDevice createDeviceForShellCommandTest(String output) {
  return new TestDevice() {
    @Override
    public void executeShellCommand(
        String cmd, IShellOutputReceiver receiver, long timeout, TimeUnit timeoutUnit) {
      byte[] outputBytes = output.getBytes(StandardCharsets.UTF_8);
      receiver.addOutput(outputBytes, 0, outputBytes.length);
      receiver.flush();
    }
  };
}
 
Example #7
Source File: MonkeyTestDevice.java    From Android-Monkey-Adapter with Apache License 2.0 5 votes vote down vote up
/**
 * Executes a cat /data/anr/traces.txt command on the device, and sends the result to a
 * <var>receiver</var>.
 * 
 * @param receiver the {@link IShellOutputReceiver} that will receives the
 *            output of the shell command
 */
public boolean traces(IShellOutputReceiver receiver) {
    boolean result = false;
    try {
        mDevice.executeShellCommand("cat /data/anr/traces.txt", receiver,
                60000);
        result = true;
    } catch (ShellCommandUnresponsiveException mttor) {
        result = true;
    } catch (Exception ex) {
        result = false;
    }
    return result;
}
 
Example #8
Source File: MonkeyTestDevice.java    From Android-Monkey-Adapter with Apache License 2.0 5 votes vote down vote up
/**
 * Executes a bugreport command on the device, and sends the result to a
 * <var>receiver</var>.
 * 
 * @param receiver the {@link IShellOutputReceiver} that will receives the
 *            output of the shell command
 */
public boolean bugreport(IShellOutputReceiver receiver) {
    boolean result = false;
    try {
        mDevice.executeShellCommand("bugreport", receiver,
                60000);
        result = true;
    } catch (ShellCommandUnresponsiveException mttor) {
        result = true;
    } catch (Exception ex) {
        result = false;
    }
    return result;
}
 
Example #9
Source File: HJAdb.java    From HJMirror with MIT License 5 votes vote down vote up
/**
 * Send an ADB Shell Command to Device
 */
private void sendCmd(IDevice device, String cmd, Callback callback) throws Exception {
    // 启动命令
    HJLog.i("[RUN]"+cmd);
    device.executeShellCommand(cmd, new IShellOutputReceiver() {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        @Override
        public void addOutput(byte[] data, int offset, int length) {
            bos.write(data, offset, length);
        }
        @Override
        public void flush() {
            try {
                bos.flush();
            } catch (IOException e) {
                e.printStackTrace();
            }
            String msg = new String(bos.toByteArray());
            if (callback != null) {
                callback.onCallback(msg);
            }
        }
        @Override
        public boolean isCancelled() {
            return false;
        }
    }, 1, TimeUnit.DAYS);
}
 
Example #10
Source File: MonkeyTestDevice.java    From Android-Monkey-Adapter with Apache License 2.0 5 votes vote down vote up
/**
 * Executes a monkey command on the device, and sends the result to a
 * <var>receiver</var>.
 * 
 * @param command the shell command to execute
 * @param receiver the {@link IShellOutputReceiver} that will receives the
 *            output of the shell command
 */
public boolean monkey(String command, IShellOutputReceiver receiver) {
    boolean result = false;
    try {
        mDevice.executeShellCommand(command, receiver, 60000);
        result = true;
    } catch (ShellCommandUnresponsiveException mttor) {
        result = true;
    } catch (Exception ex) {
        result = false;
    }
    return result;
}
 
Example #11
Source File: PropertyHelper.java    From ADB-Duang with MIT License 5 votes vote down vote up
public static void setShowOverdrawEnabled(IDevice device, boolean enabled, IShellOutputReceiver iShellOutputReceiver) {
    String cmd = "setprop " + Property.getDebugOverdrawPropertyKey(getApiLevel(device)) + " "
            + (enabled ? Property.getDebugOverdrawPropertyEnabledValue(getApiLevel(device)) : "false");
    System.out.println(cmd);
    executeShell(device, iShellOutputReceiver, cmd);
    executeShell(device, null, "am broadcast -a red.dim.updatesystemprop -n red.dim.duang/.UpdateReceiver");
}
 
Example #12
Source File: PropertyHelper.java    From ADB-Duang with MIT License 5 votes vote down vote up
public static void setDebugLayoutEnabled(IDevice device, boolean enabled, IShellOutputReceiver iShellOutputReceiver) {
    String cmd = "setprop " + Property.DEBUG_LAYOUT_PROPERTY + " " + (enabled ? "true" : "false");
    System.out.println(cmd);
    executeShell(device, iShellOutputReceiver, cmd);
    executeShell(device, null, "am broadcast -a red.dim.updatesystemprop -n red.dim.duang/.UpdateReceiver");

}
 
Example #13
Source File: DdmlibDevice.java    From bundletool with Apache License 2.0 5 votes vote down vote up
@Override
public void executeShellCommand(
    String command,
    IShellOutputReceiver receiver,
    long maxTimeToOutputResponse,
    TimeUnit maxTimeUnits)
    throws TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException,
        IOException {
  device.executeShellCommand(command, receiver, maxTimeToOutputResponse, maxTimeUnits);
}
 
Example #14
Source File: Device.java    From bundletool with Apache License 2.0 5 votes vote down vote up
public abstract void executeShellCommand(
String command,
IShellOutputReceiver receiver,
long maxTimeToOutputResponse,
TimeUnit maxTimeUnits)
throws TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException,
    IOException;
 
Example #15
Source File: PropertyHelper.java    From ADB-Duang with MIT License 4 votes vote down vote up
public static void setLayoutUpdateEnable(IDevice device, boolean enabled, IShellOutputReceiver iShellOutputReceiver) {
    String cmd = "setprop " + Property.DEBUG_SHOW_DIRTY_REGIONS + " " + (enabled ? "true" : "false");
    System.out.println(cmd);
    executeShell(device, iShellOutputReceiver, cmd);
    executeShell(device, null, "am broadcast -a red.dim.updatesystemprop -n red.dim.duang/.UpdateReceiver");
}
 
Example #16
Source File: PropertyHelper.java    From ADB-Duang with MIT License 4 votes vote down vote up
public static void setProfileGPURenderingEnabled(IDevice device, boolean enabled, IShellOutputReceiver iShellOutputReceiver) {
    String cmd = "setprop " + Property.PROFILE_PROPERTY + " " + (enabled ? "visual_bars" : "false");
    System.out.println(cmd);
    executeShell(device, iShellOutputReceiver, cmd);
    executeShell(device, null, "am broadcast -a red.dim.updatesystemprop -n red.dim.duang/.UpdateReceiver");
}
 
Example #17
Source File: TestDevice.java    From buck with Apache License 2.0 4 votes vote down vote up
@Override
public void startScreenRecorder(
    String remoteFilePath, ScreenRecorderOptions options, IShellOutputReceiver receiver) {
  throw new UnsupportedOperationException();
}
 
Example #18
Source File: TestDevice.java    From buck with Apache License 2.0 4 votes vote down vote up
@Override
public void executeShellCommand(String s, IShellOutputReceiver iShellOutputReceiver) {
  throw new UnsupportedOperationException();
}
 
Example #19
Source File: TestDevice.java    From buck with Apache License 2.0 4 votes vote down vote up
@Deprecated
@Override
public void executeShellCommand(String s, IShellOutputReceiver iShellOutputReceiver, int i) {
  throw new UnsupportedOperationException();
}