Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
* [Android] Fix problem of ConcurrentModificaiton (#2043)
Browse files Browse the repository at this point in the history
* [Android] Fix Problem of ConcurrentModificaion
* [Android] Change WXEnvironment.getCustomOptions().put() to WXEnvironment.addCustomOptions();
  • Loading branch information
YorkShen committed Jan 17, 2019
1 parent 79f93b2 commit 8ae9853
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
34 changes: 19 additions & 15 deletions android/sdk/src/main/java/com/taobao/weex/WXEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
import android.os.Environment;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;

import com.taobao.weex.BuildConfig;
import com.taobao.weex.common.WXConfig;
import com.taobao.weex.utils.FontDO;
import com.taobao.weex.utils.LogLevel;
Expand All @@ -37,21 +36,16 @@
import com.taobao.weex.utils.WXLogUtils;
import com.taobao.weex.utils.WXSoInstallMgrSdk;
import com.taobao.weex.utils.WXUtils;

import org.w3c.dom.Text;

import dalvik.system.PathClassLoader;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

import dalvik.system.PathClassLoader;
import java.util.concurrent.ConcurrentHashMap;

public class WXEnvironment {

Expand Down Expand Up @@ -135,7 +129,7 @@ public class WXEnvironment {
private static String LIB_LD_PATH = null;


private static Map<String, String> options = new HashMap<>();
private static Map<String, String> options = new ConcurrentHashMap<>();
static {
options.put(WXConfig.os, OS);
options.put(WXConfig.osName, OS);
Expand Down Expand Up @@ -170,15 +164,15 @@ public static Map<String, String> getConfig() {

try {
if (isApkDebugable()) {
options.put(WXConfig.debugMode, "true");
addCustomOptions(WXConfig.debugMode, "true");
}
options.put(WXConfig.scale, Float.toString(sApplication.getResources().getDisplayMetrics().density));
addCustomOptions(WXConfig.scale, Float.toString(sApplication.getResources().getDisplayMetrics().density));
}catch (NullPointerException e){
//There is little chance of NullPointerException as sApplication may be null.
WXLogUtils.e("WXEnvironment scale Exception: ", e);
}
configs.putAll(options);
if(configs!=null&&configs.get(WXConfig.appName)==null && sApplication!=null){
configs.putAll(getCustomOptions());
if(configs.get(WXConfig.appName)==null && sApplication!=null){
configs.put(WXConfig.appName, sApplication.getPackageName());
}
return configs;
Expand Down Expand Up @@ -216,6 +210,12 @@ private static String getAppCacheFile() {
}


/**
* Use {@link #addCustomOptions(String, String)} to add custom options.
* Use {@link #getCustomOptions(String)} to get custom options
* @return
*/
@Deprecated
public static Map<String, String> getCustomOptions() {
return options;
}
Expand All @@ -224,6 +224,10 @@ public static void addCustomOptions(String key, String value) {
options.put(key, value);
}

public static String getCustomOptions(String key){
return options.get(key);
}

@Deprecated
/**
* Use {@link #isHardwareSupport()} if you want to see whether current hardware support Weex.
Expand Down Expand Up @@ -261,7 +265,7 @@ public static boolean isHardwareSupport() {
* @return true when support
*/
public static boolean isCPUSupport(){
boolean excludeX86 = "true".equals(options.get(SETTING_EXCLUDE_X86SUPPORT));
boolean excludeX86 = "true".equals(getCustomOptions().get(SETTING_EXCLUDE_X86SUPPORT));
boolean isX86AndExcluded = WXSoInstallMgrSdk.isX86() && excludeX86;
boolean isCPUSupport = WXSoInstallMgrSdk.isCPUSupport() && !isX86AndExcluded;
if (WXEnvironment.isApkDebugable()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2363,7 +2363,7 @@ public static void updateGlobalConfig(String config) {
}
if(!TextUtils.equals(config, globalConfig)){
globalConfig = config;
WXEnvironment.getCustomOptions().put(GLOBAL_CONFIG_KEY, globalConfig);
WXEnvironment.addCustomOptions(GLOBAL_CONFIG_KEY, globalConfig);
Runnable runnable = new Runnable() {
@Override
public void run() {
Expand Down
2 changes: 1 addition & 1 deletion weex_core/Source/android/utils/params_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ std::vector<INIT_FRAMEWORK_PARAMS*> initFromParam(
return initFrameworkParams;
}

jclass jmapclass = env->FindClass("java/util/HashMap");
jclass jmapclass = env->FindClass("java/util/Map");
jmethodID jkeysetmid =
env->GetMethodID(jmapclass, "keySet", "()Ljava/util/Set;");
jmethodID jgetmid = env->GetMethodID(
Expand Down

0 comments on commit 8ae9853

Please sign in to comment.