aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorylecollen <ylecollen@amdocs.com>2016-12-21 13:06:51 +0100
committerylecollen <ylecollen@amdocs.com>2016-12-21 13:06:51 +0100
commitbacdc3c539b91ffdfb53f4f106747eb89e555400 (patch)
tree79644cccdba5d34718f14293b9a7c77a7dc346df
parent1c067b1cb64ee4d12d71a6c254d631aebd72ceb9 (diff)
Add an encoding type while converting byte[] to string
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmAccount.java26
1 files changed, 22 insertions, 4 deletions
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmAccount.java b/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmAccount.java
index 4863a06..82533c2 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmAccount.java
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmAccount.java
@@ -244,7 +244,16 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
if( null != (identityKeysBuffer = identityKeysJni())) {
try {
- identityKeysJsonObj = new JSONObject(new String(identityKeysBuffer));
+ String identityKeysString;
+
+ try {
+ identityKeysString = new String(identityKeysBuffer, "UTF-8");
+ } catch (Exception e) {
+ Log.e(LOG_TAG, "## identityKeys(): Exception : cannot convert with utf-8 charset " + e.getMessage());
+ identityKeysString = new String(identityKeysBuffer);
+ }
+
+ identityKeysJsonObj = new JSONObject(identityKeysString);
//Log.d(LOG_TAG, "## identityKeys(): Identity Json keys=" + identityKeysJsonObj.toString());
} catch (JSONException e) {
identityKeysJsonObj = null;
@@ -301,12 +310,21 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
* @return one time keys in string dictionary if operation succeed, null otherwise
*/
public Map<String, Map<String, String>> oneTimeKeys() {
- byte identityKeysBuffer[];
+ byte oneTimeKeysBuffer[];
JSONObject oneTimeKeysJsonObj = null;
- if( null != (identityKeysBuffer = oneTimeKeysJni())) {
+ if( null != (oneTimeKeysBuffer = oneTimeKeysJni())) {
try {
- oneTimeKeysJsonObj = new JSONObject(new String(identityKeysBuffer));
+ String oneTimeKeysString;
+
+ try {
+ oneTimeKeysString = new String(oneTimeKeysBuffer, "UTF-8");
+ } catch (Exception e) {
+ Log.e(LOG_TAG, "## oneTimeKeys(): Exception : cannot convert with utf-8 charset " + e.getMessage());
+ oneTimeKeysString = new String(oneTimeKeysBuffer);
+ }
+
+ oneTimeKeysJsonObj = new JSONObject(new String(oneTimeKeysString));
//Log.d(LOG_TAG, "## oneTimeKeys(): OneTime Json keys=" + oneTimeKeysJsonObj.toString());
} catch (JSONException e) {
oneTimeKeysJsonObj = null;