diff options
author | Hung-ying Tyan <tyanh@google.com> | 2009-09-11 18:34:28 +0800 |
---|---|---|
committer | Hung-ying Tyan <tyanh@google.com> | 2009-09-11 19:30:13 +0800 |
commit | a7df557aa2573a4718c7bbd069268e62bc036753 (patch) | |
tree | 606824416def47dd79b782fb4037aa180fca8d93 /keystore/java/android/security/ServiceCommand.java | |
parent | d304ae583d862250a21b5949fc3dbdf3af1febac (diff) |
Add tests and misc fixes on keystore.
* Refactor netkeystore.c to make client and server code testable.
* Add a client test for setting new passwd and changing passwd.
* Exclude "." and ".." from reset_keystore().
* Change ServerCommand.executeCommand() to accept variable length of
arguments and add convert() to marshalling the args to bytes.
* Keystore.java is revised accordingly.
Diffstat (limited to 'keystore/java/android/security/ServiceCommand.java')
-rw-r--r-- | keystore/java/android/security/ServiceCommand.java | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/keystore/java/android/security/ServiceCommand.java b/keystore/java/android/security/ServiceCommand.java index cefae400271c..ee800143d8c9 100644 --- a/keystore/java/android/security/ServiceCommand.java +++ b/keystore/java/android/security/ServiceCommand.java @@ -141,10 +141,18 @@ public class ServiceCommand { return reply; } - private boolean writeCommand(int cmd, String _data) { + private byte[] convert(String... data) { + StringBuilder sb = new StringBuilder(); + if (data.length >=1) sb.append(data[0]).append("\0"); + if (data.length >=2) sb.append(data[1]).append("\0"); + if (data.length >=3) sb.append(data[2]); + return sb.toString().getBytes(); + } + + private boolean writeCommand(int cmd, String... data) { byte buf[] = new byte[8]; - byte[] data = (_data == null) ? new byte[0] : _data.getBytes(); - int len = data.length; + byte[] dataBytes = convert(data); + int len = dataBytes.length; // the length of data buf[0] = (byte) ((len >> 24) & 0xff); buf[1] = (byte) ((len >> 16) & 0xff); @@ -157,7 +165,7 @@ public class ServiceCommand { buf[7] = (byte) (cmd & 0xff); try { mOut.write(buf, 0, 8); - mOut.write(data, 0, len); + mOut.write(dataBytes, 0, len); } catch (IOException ex) { Log.e(mTag,"write error", ex); disconnect(); @@ -166,7 +174,7 @@ public class ServiceCommand { return true; } - private Reply executeCommand(int cmd, String data) { + private Reply executeCommand(int cmd, String... data) { if (!writeCommand(cmd, data)) { /* If service died and restarted in the background * (unlikely but possible) we'll fail on the next @@ -181,7 +189,7 @@ public class ServiceCommand { return readReply(); } - public synchronized Reply execute(int cmd, String data) { + public synchronized Reply execute(int cmd, String... data) { Reply result; if (!connect()) { Log.e(mTag, "connection failed"); |