/** * Reads an error message from the opened {@link #mChannel}. * @param result the current adb result. Must contain both FAIL and the length of the message. * @param timeOut * @return * @throws TimeoutException in case of a timeout reading responses from the device. * @throws IOException */ private String readErrorMessage(byte[] result, final int timeOut) throws TimeoutException, IOException { if (checkResult(result, ID_FAIL)) { int len = ArrayHelper.swap32bitFromArray(result, 4); if (len > 0) { AdbHelper.read(mChannel, mBuffer, len, timeOut); String message = new String(mBuffer, 0, len); Log.e("ddms", "transfer error: " + message); return message; } } return null; }
/** * Reads an error message from the opened {@link #mChannel}. * @param result the current adb result. Must contain both FAIL and the length of the message. * @param timeOut * @return * @throws TimeoutException in case of a timeout reading responses from the device. * @throws IOException */ private String readErrorMessage(byte[] result, final int timeOut) throws TimeoutException, IOException { if (checkResult(result, ID_FAIL)) { int len = ArrayHelper.swap32bitFromArray(result, 4); if (len > 0) { AdbHelper.read(mChannel, getBuffer(), len, timeOut); String message = new String(getBuffer(), 0, len); Log.e("ddms", "transfer error: " + message); return message; } } return null; }
/** * Reads an error message from the opened {@link #mChannel}. * @param result the current adb result. Must contain both FAIL and the length of the message. * @param timeOut * @return * @throws TimeoutException in case of a timeout reading responses from the device. * @throws IOException */ private String readErrorMessage(byte[] result, final int timeOut) throws TimeoutException, IOException { if (checkResult(result, ID_FAIL)) { int len = ArrayHelper.swap32bitFromArray(result, 4); if (len > 0) { AdbHelper.read(mChannel, getBuffer(), len, timeOut); String message = new String(getBuffer(), 0, len); Log.e("ddms", "transfer error: " + message); return message; } } return null; }
if (!checkResult(pullResult, ID_DATA) && !checkResult(pullResult, ID_DONE)) { throw new SyncException(SyncError.TRANSFER_PROTOCOL_ERROR, readErrorMessage(pullResult, timeOut)); if (checkResult(pullResult, ID_DONE)) { break; if (!checkResult(pullResult, ID_DATA)) {
if (!checkResult(pullResult, ID_DATA) && !checkResult(pullResult, ID_DONE)) { throw new SyncException(SyncError.TRANSFER_PROTOCOL_ERROR, readErrorMessage(pullResult, timeOut)); if (checkResult(pullResult, ID_DONE)) { break; if (!checkResult(pullResult, ID_DATA)) {
if (checkResult(pullResult, ID_DATA) == false && checkResult(pullResult, ID_DONE) == false) { throw new SyncException(SyncError.TRANSFER_PROTOCOL_ERROR, readErrorMessage(pullResult, timeOut)); if (checkResult(pullResult, ID_DONE)) { break; if (checkResult(pullResult, ID_DATA) == false) {
/** * Returns the mode of the remote file. * @param path the remote file * @return an Integer containing the mode if all went well or null * otherwise * @throws IOException * @throws TimeoutException in case of a timeout reading responses from the device. */ private Integer readMode(String path) throws TimeoutException, IOException { // create the stat request message. byte[] msg = createFileReq(ID_STAT, path); AdbHelper.write(mChannel, msg, -1 /* full length */, DdmPreferences.getTimeOut()); // read the result, in a byte array containing 4 ints // (id, mode, size, time) byte[] statResult = new byte[16]; AdbHelper.read(mChannel, statResult, -1 /* full length */, DdmPreferences.getTimeOut()); // check we have the proper data back if (!checkResult(statResult, ID_STAT)) { return null; } // we return the mode (2nd int in the array) return ArrayHelper.swap32bitFromArray(statResult, 4); }
/** * Returns the mode of the remote file. * @param path the remote file * @return an Integer containing the mode if all went well or null * otherwise * @throws IOException * @throws TimeoutException in case of a timeout reading responses from the device. */ private Integer readMode(String path) throws TimeoutException, IOException { // create the stat request message. byte[] msg = createFileReq(ID_STAT, path); AdbHelper.write(mChannel, msg, -1 /* full length */, DdmPreferences.getTimeOut()); // read the result, in a byte array containing 4 ints // (id, mode, size, time) byte[] statResult = new byte[16]; AdbHelper.read(mChannel, statResult, -1 /* full length */, DdmPreferences.getTimeOut()); // check we have the proper data back if (checkResult(statResult, ID_STAT) == false) { return null; } // we return the mode (2nd int in the array) return ArrayHelper.swap32bitFromArray(statResult, 4); }
AdbHelper.read(mChannel, result, -1 /* full length */, timeOut); if (checkResult(result, ID_OKAY) == false) { throw new SyncException(SyncError.TRANSFER_PROTOCOL_ERROR, readErrorMessage(result, timeOut));
AdbHelper.read(mChannel, result, -1 /* full length */, timeOut); if (!checkResult(result, ID_OKAY)) { throw new SyncException(SyncError.TRANSFER_PROTOCOL_ERROR, readErrorMessage(result, timeOut));
AdbHelper.read(mChannel, result, -1 /* full length */, timeOut); if (!checkResult(result, ID_OKAY)) { throw new SyncException(SyncError.TRANSFER_PROTOCOL_ERROR, readErrorMessage(result, timeOut));
/** * Returns the stat info of the remote file. * @param path the remote file * @return an FileStat containing the mode, size and last modified info if all went well or null * otherwise * @throws IOException * @throws TimeoutException in case of a timeout reading responses from the device. */ @Nullable public FileStat statFile(@NonNull String path) throws TimeoutException, IOException { // create the stat request message. byte[] msg = createFileReq(ID_STAT, path); AdbHelper.write(mChannel, msg, -1 /* full length */, DdmPreferences.getTimeOut()); // read the result, in a byte array containing 4 ints // (id, mode, size, time) byte[] statResult = new byte[16]; AdbHelper.read(mChannel, statResult, -1 /* full length */, DdmPreferences.getTimeOut()); // check we have the proper data back if (!checkResult(statResult, ID_STAT)) { return null; } final int mode = ArrayHelper.swap32bitFromArray(statResult, 4); final int size = ArrayHelper.swap32bitFromArray(statResult, 8); final int lastModifiedSecs = ArrayHelper.swap32bitFromArray(statResult, 12); return new FileStat(mode, size, lastModifiedSecs); }