Search in sources :

Example 1 with IShellOutputReceiver

use of com.android.ddmlib.IShellOutputReceiver in project GT by Tencent.

the class AdbHProfDumpListener method onSuccess.

@Override
public void onSuccess(String remoteFilePath, Client client) {
    synchronized (sLock) {
        APTConsoleFactory.getInstance().APTPrint("onSuccess(String remoteFilePath, Client client)");
        try {
            APTConsoleFactory.getInstance().APTPrint("remoteFilePath=" + remoteFilePath);
            String pkgName = client.getClientData().getClientDescription();
            if (pkgName == null) {
                pkgName = "null";
            }
            String filePath = getHprofFilePath(pkgName);
            client.getDevice().pullFile(remoteFilePath, filePath);
            client.getDevice().executeShellCommand("rm " + remoteFilePath, new IShellOutputReceiver() {

                public void addOutput(byte[] data, int offset, int length) {
                    APTConsoleFactory.getInstance().APTPrint("addOutput");
                }

                public void flush() {
                    APTConsoleFactory.getInstance().APTPrint("flush");
                }

                public boolean isCancelled() {
                    APTConsoleFactory.getInstance().APTPrint("isCancelled");
                    return false;
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
            APTConsoleFactory.getInstance().APTPrint(e.getMessage());
        }
        sLock.notify();
    }
}
Also used : IShellOutputReceiver(com.android.ddmlib.IShellOutputReceiver) IOException(java.io.IOException)

Example 2 with IShellOutputReceiver

use of com.android.ddmlib.IShellOutputReceiver in project android by JetBrains.

the class MultiUserUtilsTest method createMockDevice.

@NotNull
private static IDevice createMockDevice(@NotNull String pmListUsersOutput, @NotNull String amCurrentUserOutput) throws Exception {
    IDevice device = mock(IDevice.class);
    when(device.getVersion()).thenReturn(new AndroidVersion(23, null));
    doAnswer(invocation -> {
        String cmd = (String) invocation.getArguments()[0];
        String answer = null;
        if (cmd.equals("pm list users")) {
            answer = pmListUsersOutput;
        } else if (cmd.equals("am get-current-user")) {
            answer = amCurrentUserOutput;
        } else {
            fail("Mock device does not support shell command: " + cmd);
        }
        byte[] bytes = answer.getBytes(Charsets.UTF_8);
        IShellOutputReceiver receiver = (IShellOutputReceiver) invocation.getArguments()[1];
        receiver.addOutput(bytes, 0, bytes.length);
        receiver.flush();
        return null;
    }).when(device).executeShellCommand(anyString(), anyObject());
    return device;
}
Also used : IShellOutputReceiver(com.android.ddmlib.IShellOutputReceiver) IDevice(com.android.ddmlib.IDevice) Matchers.anyString(org.mockito.Matchers.anyString) AndroidVersion(com.android.sdklib.AndroidVersion) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

IShellOutputReceiver (com.android.ddmlib.IShellOutputReceiver)2 IDevice (com.android.ddmlib.IDevice)1 AndroidVersion (com.android.sdklib.AndroidVersion)1 IOException (java.io.IOException)1 NotNull (org.jetbrains.annotations.NotNull)1 Matchers.anyString (org.mockito.Matchers.anyString)1