Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 17EE5D3B6 for ; Fri, 15 Mar 2013 20:47:59 +0000 (UTC) Received: (qmail 79854 invoked by uid 500); 15 Mar 2013 20:47:59 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 79835 invoked by uid 500); 15 Mar 2013 20:47:59 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: callback-dev@cordova.apache.org Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 79826 invoked by uid 99); 15 Mar 2013 20:47:59 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 15 Mar 2013 20:47:59 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id A93D83516E; Fri, 15 Mar 2013 20:47:58 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: agrieve@apache.org To: commits@cordova.apache.org X-Mailer: ASF-Git Admin Mailer Subject: android commit: Add a new type to the Native->JS bridge for binary strings. Message-Id: <20130315204758.A93D83516E@tyr.zones.apache.org> Date: Fri, 15 Mar 2013 20:47:58 +0000 (UTC) Updated Branches: refs/heads/master d25b73f47 -> 7755a902d Add a new type to the Native->JS bridge for binary strings. It's needed since the bridge truncates strings that have null characters in them :(. Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/7755a902 Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/7755a902 Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/7755a902 Branch: refs/heads/master Commit: 7755a902dd8ce8e352f1388e0e5626886407a3aa Parents: d25b73f Author: Andrew Grieve Authored: Fri Mar 15 16:47:04 2013 -0400 Committer: Andrew Grieve Committed: Fri Mar 15 16:47:04 2013 -0400 ---------------------------------------------------------------------- .../org/apache/cordova/NativeToJsMessageQueue.java | 9 ++++++++- .../src/org/apache/cordova/api/PluginResult.java | 11 +++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-android/blob/7755a902/framework/src/org/apache/cordova/NativeToJsMessageQueue.java ---------------------------------------------------------------------- diff --git a/framework/src/org/apache/cordova/NativeToJsMessageQueue.java b/framework/src/org/apache/cordova/NativeToJsMessageQueue.java index 829f322..ea684a4 100755 --- a/framework/src/org/apache/cordova/NativeToJsMessageQueue.java +++ b/framework/src/org/apache/cordova/NativeToJsMessageQueue.java @@ -409,6 +409,9 @@ public class NativeToJsMessageQueue { case PluginResult.MESSAGE_TYPE_STRING: // s ret += 1 + pluginResult.getStrMessage().length(); break; + case PluginResult.MESSAGE_TYPE_BINARYSTRING: + ret += 1 + pluginResult.getMessage().length(); + break; case PluginResult.MESSAGE_TYPE_ARRAYBUFFER: ret += 1 + pluginResult.getMessage().length(); break; @@ -451,7 +454,11 @@ public class NativeToJsMessageQueue { sb.append('s'); sb.append(pluginResult.getStrMessage()); break; - case PluginResult.MESSAGE_TYPE_ARRAYBUFFER: + case PluginResult.MESSAGE_TYPE_BINARYSTRING: // S + sb.append('S'); + sb.append(pluginResult.getMessage()); + break; + case PluginResult.MESSAGE_TYPE_ARRAYBUFFER: // A sb.append('A'); sb.append(pluginResult.getMessage()); break; http://git-wip-us.apache.org/repos/asf/cordova-android/blob/7755a902/framework/src/org/apache/cordova/api/PluginResult.java ---------------------------------------------------------------------- diff --git a/framework/src/org/apache/cordova/api/PluginResult.java b/framework/src/org/apache/cordova/api/PluginResult.java index 4c1d833..a642200 100755 --- a/framework/src/org/apache/cordova/api/PluginResult.java +++ b/framework/src/org/apache/cordova/api/PluginResult.java @@ -71,11 +71,15 @@ public class PluginResult { } public PluginResult(Status status, byte[] data) { + this(status, data, false); + } + + public PluginResult(Status status, byte[] data, boolean binaryString) { this.status = status.ordinal(); - this.messageType = MESSAGE_TYPE_ARRAYBUFFER; + this.messageType = binaryString ? MESSAGE_TYPE_BINARYSTRING : MESSAGE_TYPE_ARRAYBUFFER; this.encodedMessage = Base64.encodeToString(data, Base64.NO_WRAP); } - + public void setKeepCallback(boolean b) { this.keepCallback = b; } @@ -143,6 +147,9 @@ public class PluginResult { public static final int MESSAGE_TYPE_BOOLEAN = 4; public static final int MESSAGE_TYPE_NULL = 5; public static final int MESSAGE_TYPE_ARRAYBUFFER = 6; + // Use BINARYSTRING when your string may contain null characters. + // This is required to work around a bug in the platform :(. + public static final int MESSAGE_TYPE_BINARYSTRING = 7; public static String[] StatusMessages = new String[] { "No result",