You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by ky...@apache.org on 2018/06/04 09:51:48 UTC

incubator-weex git commit: [WEEX-432][Android] Fix emoji crash on JNI.

Repository: incubator-weex
Updated Branches:
  refs/heads/master 19a242971 -> 379bbdc2e


[WEEX-432][Android] Fix emoji crash on JNI.


Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/379bbdc2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/379bbdc2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/379bbdc2

Branch: refs/heads/master
Commit: 379bbdc2ebf4855d775f148281c8e66313bf5ee6
Parents: 19a2429
Author: miomin <mi...@foxmail.com>
Authored: Mon Jun 4 16:29:07 2018 +0800
Committer: YorkShen <sh...@gmail.com>
Committed: Mon Jun 4 17:51:36 2018 +0800

----------------------------------------------------------------------
 android/sdk/libs/armeabi-v7a/libweexcore.so     | Bin 632692 -> 636788 bytes
 android/sdk/libs/armeabi/libweexcore.so         | Bin 644980 -> 644980 bytes
 android/sdk/libs/x86/libweexcore.so             | Bin 1193884 -> 1202076 bytes
 .../main/java/com/taobao/weex/utils/WXMap.java  |  29 +++++++++
 .../android/bridge/impl/bridge_impl_android.cpp |  63 +++----------------
 .../bridge/impl/weexcore_impl_android.cpp       |  17 ++++-
 .../android/bridge/impl/weexcore_impl_android.h |   4 ++
 7 files changed, 56 insertions(+), 57 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/379bbdc2/android/sdk/libs/armeabi-v7a/libweexcore.so
----------------------------------------------------------------------
diff --git a/android/sdk/libs/armeabi-v7a/libweexcore.so b/android/sdk/libs/armeabi-v7a/libweexcore.so
index 2d8b967..3be2444 100644
Binary files a/android/sdk/libs/armeabi-v7a/libweexcore.so and b/android/sdk/libs/armeabi-v7a/libweexcore.so differ

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/379bbdc2/android/sdk/libs/armeabi/libweexcore.so
----------------------------------------------------------------------
diff --git a/android/sdk/libs/armeabi/libweexcore.so b/android/sdk/libs/armeabi/libweexcore.so
index 2de9e8b..5afdbbc 100644
Binary files a/android/sdk/libs/armeabi/libweexcore.so and b/android/sdk/libs/armeabi/libweexcore.so differ

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/379bbdc2/android/sdk/libs/x86/libweexcore.so
----------------------------------------------------------------------
diff --git a/android/sdk/libs/x86/libweexcore.so b/android/sdk/libs/x86/libweexcore.so
index 5a6c37f..0c7b5d8 100644
Binary files a/android/sdk/libs/x86/libweexcore.so and b/android/sdk/libs/x86/libweexcore.so differ

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/379bbdc2/android/sdk/src/main/java/com/taobao/weex/utils/WXMap.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/utils/WXMap.java b/android/sdk/src/main/java/com/taobao/weex/utils/WXMap.java
new file mode 100644
index 0000000..a3b6088
--- /dev/null
+++ b/android/sdk/src/main/java/com/taobao/weex/utils/WXMap.java
@@ -0,0 +1,29 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package com.taobao.weex.utils;
+
+import java.io.Serializable;
+import java.util.HashMap;
+
+public class WXMap extends HashMap<String, String> implements Serializable {
+
+  public String put(String key, byte[] value) {
+    return super.put(key, new String(value));
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/379bbdc2/weex_core/Source/android/bridge/impl/bridge_impl_android.cpp
----------------------------------------------------------------------
diff --git a/weex_core/Source/android/bridge/impl/bridge_impl_android.cpp b/weex_core/Source/android/bridge/impl/bridge_impl_android.cpp
index 6cea477..439d5b1 100644
--- a/weex_core/Source/android/bridge/impl/bridge_impl_android.cpp
+++ b/weex_core/Source/android/bridge/impl/bridge_impl_android.cpp
@@ -41,12 +41,6 @@ static jmethodID jCallRemoveElementMethodId;
 static jmethodID jCallMoveElementMethodId;
 static jmethodID jCallAddEventMethodId;
 static jmethodID jCallRemoveEventMethodId;
-
-static jmethodID jMapConstructorMethodId;
-static jmethodID jMapPutMethodId;
-static jmethodID jSetConstructorMethodId;
-static jmethodID jSetAddMethodId;
-
 static jmethodID jCallCreateBodyMethodId;
 static jmethodID jCallAddElementMethodId;
 static jmethodID jCallUpdateStyleMethodId;
@@ -86,11 +80,6 @@ namespace WeexCore {
     jCallAddEventMethodId = NULL;
     jCallRemoveEventMethodId = NULL;
 
-    jMapConstructorMethodId = NULL;
-    jMapPutMethodId = NULL;
-    jSetConstructorMethodId = NULL;
-    jSetAddMethodId = NULL;
-
     jCallCreateBodyMethodId = NULL;
     jCallAddElementMethodId = NULL;
     jCallUpdateStyleMethodId = NULL;
@@ -104,33 +93,35 @@ namespace WeexCore {
   }
 
   void static cpyCMap2JMap(std::map<std::string, std::string> *cMap, jobject &jMap, JNIEnv *env) {
+
     std::map<std::string, std::string>::const_iterator it = cMap->begin();
     std::map<std::string, std::string>::const_iterator end = cMap->end();
     jstring jKey;
-    jstring jValue;
+    jbyteArray jValue;
 
     for (; it != end; ++it) {
       jKey = getKeyFromCache(env, it->first.c_str());
-
-      jValue = env->NewStringUTF(it->second.c_str());
+      jValue = newJByteArray(env, it->second.c_str());
       env->CallObjectMethod(jMap, jMapPutMethodId, jKey, jValue);
       env->DeleteLocalRef(jValue);
     }
   }
 
   void static cpyCVector2JMap(std::vector<std::pair<std::string, std::string>> *cVector, jobject &jMap, JNIEnv *env) {
+
     jstring jKey;
-    jstring jValue;
+    jbyteArray jValue;
 
     for (int i = 0; i < cVector->size(); ++i) {
       jKey = getKeyFromCache(env, (*cVector)[i].first.c_str());
-      jValue = env->NewStringUTF((*cVector)[i].second.c_str());
+      jValue = newJByteArray(env, (*cVector)[i].second.c_str());
       env->CallObjectMethod(jMap, jMapPutMethodId, jKey, jValue);
       env->DeleteLocalRef(jValue);
     }
   }
 
   void static cpyCSet2JSet(std::set<std::string> *cSet, jobject &jSet, JNIEnv *env) {
+
     jstring jValue;
     std::set<std::string>::const_iterator it = cSet->begin();
     std::set<std::string>::const_iterator end = cSet->end();
@@ -406,17 +397,6 @@ namespace WeexCore {
     jstring jPageId = getKeyFromCache(env, pageId);
     jstring jRef = getKeyFromCache(env, ref);
 
-    if (jMapConstructorMethodId == NULL)
-      jMapConstructorMethodId = env->GetMethodID(jMapClazz, "<init>", "()V");
-    if (jMapPutMethodId == NULL)
-      jMapPutMethodId = env->GetMethodID(jMapClazz, "put",
-                                         "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
-    if (jSetConstructorMethodId == NULL)
-      jSetConstructorMethodId = env->GetMethodID(jSetClazz, "<init>", "()V");
-    if (jSetAddMethodId == NULL)
-      jSetAddMethodId = env->GetMethodID(jSetClazz, "add",
-                                         "(Ljava/lang/Object;)Z");
-
     jobject jStyles = env->NewObject(jMapClazz, jMapConstructorMethodId);
     jobject jAttributes = env->NewObject(jMapClazz, jMapConstructorMethodId);
     jobject jEvents = env->NewObject(jSetClazz, jSetConstructorMethodId);
@@ -494,17 +474,6 @@ namespace WeexCore {
     jstring jRef = getKeyFromCache(env, ref);
     jstring jParentRef = getKeyFromCache(env, parentRef);
 
-    if (jMapConstructorMethodId == NULL)
-      jMapConstructorMethodId = env->GetMethodID(jMapClazz, "<init>", "()V");
-    if (jMapPutMethodId == NULL)
-      jMapPutMethodId = env->GetMethodID(jMapClazz, "put",
-                                         "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
-    if (jSetConstructorMethodId == NULL)
-      jSetConstructorMethodId = env->GetMethodID(jSetClazz, "<init>", "()V");
-    if (jSetAddMethodId == NULL)
-      jSetAddMethodId = env->GetMethodID(jSetClazz, "add",
-                                         "(Ljava/lang/Object;)Z");
-
     jobject jStyles = env->NewObject(jMapClazz, jMapConstructorMethodId);
     jobject jAttributes = env->NewObject(jMapClazz, jMapConstructorMethodId);
     jobject jEvents = env->NewObject(jSetClazz, jSetConstructorMethodId);
@@ -685,12 +654,6 @@ namespace WeexCore {
     jstring jPageId = getKeyFromCache(env, pageId);
     jstring jRef = getKeyFromCache(env, ref);
 
-    if (jMapConstructorMethodId == NULL)
-      jMapConstructorMethodId = env->GetMethodID(jMapClazz, "<init>", "()V");
-    if (jMapPutMethodId == NULL)
-      jMapPutMethodId = env->GetMethodID(jMapClazz, "put",
-                                         "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
-
     jobject jStyles = env->NewObject(jMapClazz, jMapConstructorMethodId);
     jobject jMargins = env->NewObject(jMapClazz, jMapConstructorMethodId);
     jobject jPaddings = env->NewObject(jMapClazz, jMapConstructorMethodId);
@@ -744,12 +707,6 @@ namespace WeexCore {
     jstring jPageId = getKeyFromCache(env, pageId);
     jstring jRef = getKeyFromCache(env, ref);
 
-    if (jMapConstructorMethodId == NULL)
-      jMapConstructorMethodId = env->GetMethodID(jMapClazz, "<init>", "()V");
-    if (jMapPutMethodId == NULL)
-      jMapPutMethodId = env->GetMethodID(jMapClazz, "put",
-                                         "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
-
     jobject jAttrs = env->NewObject(jMapClazz, jMapConstructorMethodId);
 
     if (attrs != nullptr) {
@@ -868,12 +825,6 @@ namespace WeexCore {
     jstring jPageId = getKeyFromCache(env, pageId);
     jstring jRef = getKeyFromCache(env, ref);
 
-    if (jMapConstructorMethodId == NULL)
-      jMapConstructorMethodId = env->GetMethodID(jMapClazz, "<init>", "()V");
-    if (jMapPutMethodId == NULL)
-      jMapPutMethodId = env->GetMethodID(jMapClazz, "put",
-                                         "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
-
     jobject jStyles = env->NewObject(jMapClazz, jMapConstructorMethodId);
 
     if (style != nullptr) {

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/379bbdc2/weex_core/Source/android/bridge/impl/weexcore_impl_android.cpp
----------------------------------------------------------------------
diff --git a/weex_core/Source/android/bridge/impl/weexcore_impl_android.cpp b/weex_core/Source/android/bridge/impl/weexcore_impl_android.cpp
index c73b7e7..0e5b44e 100644
--- a/weex_core/Source/android/bridge/impl/weexcore_impl_android.cpp
+++ b/weex_core/Source/android/bridge/impl/weexcore_impl_android.cpp
@@ -34,6 +34,11 @@ jclass jWXJSObject;
 jclass jWXLogUtils;
 jclass jMapClazz;
 jclass jSetClazz;
+jmethodID jMapConstructorMethodId = nullptr;
+jmethodID jMapPutMethodId = nullptr;
+jmethodID jSetConstructorMethodId = nullptr;
+jmethodID jSetAddMethodId = nullptr;
+
 jclass jWMBridgeClazz = nullptr;
 jmethodID jDoubleValueMethodId;
 jobject jThis;
@@ -529,12 +534,17 @@ jint OnLoad(JavaVM *vm, void *reserved) {
     tempClass = env->FindClass("com/taobao/weex/utils/WXLogUtils");
     jWXLogUtils = (jclass) env->NewGlobalRef(tempClass);
 
-    tempClass = env->FindClass("java/util/HashMap");
+    tempClass = env->FindClass("com/taobao/weex/utils/WXMap");
     jMapClazz = (jclass) env->NewGlobalRef(tempClass);
 
     tempClass = env->FindClass("java/util/HashSet");
     jSetClazz = (jclass) env->NewGlobalRef(tempClass);
 
+    jMapConstructorMethodId = env->GetMethodID(jMapClazz, "<init>", "()V");
+    jMapPutMethodId = env->GetMethodID(jMapClazz, "put", "(Ljava/lang/String;[B)Ljava/lang/String;");
+    jSetConstructorMethodId = env->GetMethodID(jSetClazz, "<init>", "()V");
+    jSetAddMethodId = env->GetMethodID(jSetClazz, "add", "(Ljava/lang/Object;)Z");
+
     // can use this code to manal register jni
     tempClass = nullptr;
     tempClass = env->FindClass("com/taobao/windmill/bridge/WMLBridge");
@@ -570,6 +580,11 @@ jint OnLoad(JavaVM *vm, void *reserved) {
     env->DeleteGlobalRef(jWXLogUtils);
     env->DeleteGlobalRef(jMapClazz);
 
+    jMapConstructorMethodId = nullptr;
+    jMapPutMethodId = nullptr;
+    jSetConstructorMethodId = nullptr;
+    jSetAddMethodId = nullptr;
+
     if (jFirstScreenRenderTime != nullptr) {
       env->DeleteLocalRef(jFirstScreenRenderTime);
       jFirstScreenRenderTime = nullptr;

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/379bbdc2/weex_core/Source/android/bridge/impl/weexcore_impl_android.h
----------------------------------------------------------------------
diff --git a/weex_core/Source/android/bridge/impl/weexcore_impl_android.h b/weex_core/Source/android/bridge/impl/weexcore_impl_android.h
index b88256d..1b3c1a1 100644
--- a/weex_core/Source/android/bridge/impl/weexcore_impl_android.h
+++ b/weex_core/Source/android/bridge/impl/weexcore_impl_android.h
@@ -38,6 +38,10 @@ extern jobject jThis;
 extern jobject jWMThis;
 extern jclass jMapClazz;
 extern jclass jSetClazz;
+extern jmethodID jMapConstructorMethodId;
+extern jmethodID jMapPutMethodId;
+extern jmethodID jSetConstructorMethodId;
+extern jmethodID jSetAddMethodId;
 extern jclass jWMBridgeClazz;
 extern JNIEnv *getJNIEnv();
 extern jstring getComponentTypeFromCache(const std::string type);