From 3cf7a66c2837c858c74aeab7a660162855e034c2 Mon Sep 17 00:00:00 2001 From: Bill Napier Date: Mon, 17 May 2010 16:59:29 -0700 Subject: Add a reboot command to IDevice to allow ddmlib users to reboot devices. Change-Id: I8f8b792c68ec869980805c06aecf249558c6dc3f --- .../ddmlib/src/com/android/ddmlib/AdbHelper.java | 32 ++++++++++++++++++++++ .../libs/ddmlib/src/com/android/ddmlib/Device.java | 8 ++++++ .../ddmlib/src/com/android/ddmlib/IDevice.java | 7 +++++ 3 files changed, 47 insertions(+) (limited to 'ddms/libs/ddmlib/src/com') diff --git a/ddms/libs/ddmlib/src/com/android/ddmlib/AdbHelper.java b/ddms/libs/ddmlib/src/com/android/ddmlib/AdbHelper.java index ce8d366..7b39076 100644 --- a/ddms/libs/ddmlib/src/com/android/ddmlib/AdbHelper.java +++ b/ddms/libs/ddmlib/src/com/android/ddmlib/AdbHelper.java @@ -728,4 +728,36 @@ final class AdbHelper { } } + + /** + * Reboot the device. + * + * @param into what to reboot into (recovery, bootloader). Or null to just reboot. + */ + public static void reboot(String into, InetSocketAddress adbSockAddr, + Device device) throws IOException { + byte[] request; + if (into == null) { + request = formAdbRequest("reboot:"); //$NON-NLS-1$ + } else { + request = formAdbRequest("reboot:" + into); //$NON-NLS-1$ + } + + SocketChannel adbChan = null; + try { + adbChan = SocketChannel.open(adbSockAddr); + adbChan.configureBlocking(false); + + // if the device is not -1, then we first tell adb we're looking to talk + // to a specific device + setDevice(adbChan, device); + + if (write(adbChan, request) == false) + throw new IOException("failed asking for reboot"); + } finally { + if (adbChan != null) { + adbChan.close(); + } + } + } } diff --git a/ddms/libs/ddmlib/src/com/android/ddmlib/Device.java b/ddms/libs/ddmlib/src/com/android/ddmlib/Device.java index 4223248..a601c16 100644 --- a/ddms/libs/ddmlib/src/com/android/ddmlib/Device.java +++ b/ddms/libs/ddmlib/src/com/android/ddmlib/Device.java @@ -516,4 +516,12 @@ final class Device implements IDevice { executeShellCommand("pm uninstall " + packageName, receiver); return receiver.getErrorMessage(); } + + /* + * (non-Javadoc) + * @see com.android.ddmlib.IDevice#reboot() + */ + public void reboot(String into) throws IOException { + AdbHelper.reboot(into, AndroidDebugBridge.getSocketAddress(), this); + } } diff --git a/ddms/libs/ddmlib/src/com/android/ddmlib/IDevice.java b/ddms/libs/ddmlib/src/com/android/ddmlib/IDevice.java index 47db08a..bd6f436 100755 --- a/ddms/libs/ddmlib/src/com/android/ddmlib/IDevice.java +++ b/ddms/libs/ddmlib/src/com/android/ddmlib/IDevice.java @@ -275,4 +275,11 @@ public interface IDevice { */ public String uninstallPackage(String packageName) throws IOException; + /** + * Reboot the device. + * + * @param into the bootloader name to reboot into, or null to just reboot the device. + * @throws IOException + */ + public void reboot(String into) throws IOException; } -- cgit v1.1