diff options
author | Siva Velusamy <vsiva@google.com> | 2012-09-10 14:35:25 -0700 |
---|---|---|
committer | Siva Velusamy <vsiva@google.com> | 2012-09-10 15:48:29 -0700 |
commit | 2da27350e6d5226d5b61720d0d4fbdf32ee0f976 (patch) | |
tree | 4a4e9c6dc455288bca8e96bfc43f1cacb2cd2eb5 /ddms/libs/ddmlib/src/com | |
parent | 72000161fbccf626fe171e74489cc72923d670aa (diff) | |
download | sdk-2da27350e6d5226d5b61720d0d4fbdf32ee0f976.zip sdk-2da27350e6d5226d5b61720d0d4fbdf32ee0f976.tar.gz sdk-2da27350e6d5226d5b61720d0d4fbdf32ee0f976.tar.bz2 |
ddms: report user id if available
The HELO and APNM packets may append the user id at the end of the
packet. If that data is available, display it as part of the
application name.
Change-Id: Ie353c2cc2895db649fc6ab6054f1c88f5d2f247f
Diffstat (limited to 'ddms/libs/ddmlib/src/com')
3 files changed, 72 insertions, 0 deletions
diff --git a/ddms/libs/ddmlib/src/com/android/ddmlib/ClientData.java b/ddms/libs/ddmlib/src/com/android/ddmlib/ClientData.java index d1156a4..ff83c37 100644 --- a/ddms/libs/ddmlib/src/com/android/ddmlib/ClientData.java +++ b/ddms/libs/ddmlib/src/com/android/ddmlib/ClientData.java @@ -156,6 +156,12 @@ public class ClientData { // client's self-description private String mClientDescription; + // client's user id (on device in a multi user environment) + private int mUserId; + + // client's user id is valid + private boolean mValidUserId; + // how interested are we in a debugger? private DebuggerStatus mDebuggerInterest; @@ -430,6 +436,23 @@ public class ClientData { } /** + * Returns the client's user id. + * @return user id if set, -1 otherwise + */ + public int getUserId() { + return mUserId; + } + + /** + * Returns true if the user id of this client was set. Only devices that support multiple + * users will actually return the user id to ddms. For other/older devices, this will not + * be set. + */ + public boolean isValidUserId() { + return mValidUserId; + } + + /** * Sets client description. * * There may be a race between HELO and APNM. Rather than try @@ -451,6 +474,11 @@ public class ClientData { } } + void setUserId(int id) { + mUserId = id; + mValidUserId = true; + } + /** * Returns the debugger connection status. */ diff --git a/ddms/libs/ddmlib/src/com/android/ddmlib/HandleAppName.java b/ddms/libs/ddmlib/src/com/android/ddmlib/HandleAppName.java index c821dfc..da4ade3 100644 --- a/ddms/libs/ddmlib/src/com/android/ddmlib/HandleAppName.java +++ b/ddms/libs/ddmlib/src/com/android/ddmlib/HandleAppName.java @@ -17,6 +17,7 @@ package com.android.ddmlib; import java.io.IOException; +import java.nio.BufferUnderflowException; import java.nio.ByteBuffer; /** @@ -77,11 +78,32 @@ final class HandleAppName extends ChunkHandler { appNameLen = data.getInt(); appName = getString(data, appNameLen); + // Newer devices send user id in the APNM packet. + int userId = -1; + boolean validUserId = false; + if (data.hasRemaining()) { + try { + userId = data.getInt(); + validUserId = true; + } catch (BufferUnderflowException e) { + // two integers + utf-16 string + int expectedPacketLength = 8 + appNameLen * 2; + + Log.e("ddm-appname", "Insufficient data in APNM chunk to retrieve user id."); + Log.e("ddm-appname", "Actual chunk length: " + data.capacity()); + Log.e("ddm-appname", "Expected chunk length: " + expectedPacketLength); + } + } + Log.d("ddm-appname", "APNM: app='" + appName + "'"); ClientData cd = client.getClientData(); synchronized (cd) { cd.setClientDescription(appName); + + if (validUserId) { + cd.setUserId(userId); + } } client = checkDebuggerPortForAppName(client, appName); diff --git a/ddms/libs/ddmlib/src/com/android/ddmlib/HandleHello.java b/ddms/libs/ddmlib/src/com/android/ddmlib/HandleHello.java index 4e62bca..b5c2968 100644 --- a/ddms/libs/ddmlib/src/com/android/ddmlib/HandleHello.java +++ b/ddms/libs/ddmlib/src/com/android/ddmlib/HandleHello.java @@ -17,6 +17,7 @@ package com.android.ddmlib; import java.io.IOException; +import java.nio.BufferUnderflowException; import java.nio.ByteBuffer; /** @@ -100,6 +101,23 @@ final class HandleHello extends ChunkHandler { vmIdent = getString(data, vmIdentLen); appName = getString(data, appNameLen); + // Newer devices send user id in the APNM packet. + int userId = -1; + boolean validUserId = false; + if (data.hasRemaining()) { + try { + userId = data.getInt(); + validUserId = true; + } catch (BufferUnderflowException e) { + // five integers + two utf-16 strings + int expectedPacketLength = 20 + appNameLen * 2 + vmIdentLen * 2; + + Log.e("ddm-hello", "Insufficient data in HELO chunk to retrieve user id."); + Log.e("ddm-hello", "Actual chunk length: " + data.capacity()); + Log.e("ddm-hello", "Expected chunk length: " + expectedPacketLength); + } + } + Log.d("ddm-hello", "HELO: v=" + version + ", pid=" + pid + ", vm='" + vmIdent + "', app='" + appName + "'"); @@ -110,6 +128,10 @@ final class HandleHello extends ChunkHandler { cd.setVmIdentifier(vmIdent); cd.setClientDescription(appName); cd.isDdmAware(true); + + if (validUserId) { + cd.setUserId(userId); + } } else { Log.e("ddm-hello", "Received pid (" + pid + ") does not match client pid (" + cd.getPid() + ")"); |