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

Commit

Permalink
[Android] Update for libweexjsb path (#2712)
Browse files Browse the repository at this point in the history
  • Loading branch information
Darin726 authored and YorkShen committed Jul 17, 2019
1 parent 1e40e9c commit 57bd65c
Show file tree
Hide file tree
Showing 8 changed files with 227 additions and 129 deletions.
116 changes: 106 additions & 10 deletions android/sdk/src/main/java/com/taobao/weex/WXEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Typeface;
import android.os.Environment;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;

import com.taobao.weex.common.WXConfig;
import com.taobao.weex.utils.FontDO;
Expand All @@ -49,6 +51,8 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import static android.content.Context.MODE_PRIVATE;

public class WXEnvironment {

public static final String OS = "android";
Expand Down Expand Up @@ -132,11 +136,6 @@ public class WXEnvironment {
public static final String CORE_JSB_SO_NAME = "weexjsb";
public static final String CORE_JST_SO_NAME = "weexjst";
public static final String CORE_JSC_SO_NAME = "JavaScriptCore";
/**
* this marked jsb.so's version, Change this if we want to update jsb.so
*/
public static final int CORE_JSB_SO_VERSION = 1;

private static String CORE_JSS_SO_PATH = null;

public static String CORE_JSS_RUNTIME_SO_PATH = null;
Expand All @@ -145,15 +144,46 @@ public class WXEnvironment {

private static String CORE_JSC_SO_PATH = null;

private static String LIB_LD_PATH = null;
public static String CORE_JSB_SO_PATH = null;

private static String COPY_SO_DES_DIR = null;

private static String LIB_LD_PATH = null;

private static Map<String, String> options = new ConcurrentHashMap<>();
static {
options.put(WXConfig.os, OS);
options.put(WXConfig.osName, OS);
}


public static synchronized WXDefaultSettings getWXDefaultSettings() {
if (mWXDefaultSettings == null && getApplication() != null) {
mWXDefaultSettings = new WXDefaultSettings(getApplication());
}
return mWXDefaultSettings;
}

public static synchronized String getDefaultSettingValue(String key, String defaultValue) {
WXDefaultSettings wxDefaultSettings = getWXDefaultSettings();
if (wxDefaultSettings == null || TextUtils.isEmpty(key)) {
return defaultValue;
}
return wxDefaultSettings.getValue(key, defaultValue);
}

public static synchronized void writeDefaultSettingsValue(String key, String value) {
WXDefaultSettings wxDefaultSettings = getWXDefaultSettings();
if (wxDefaultSettings == null
|| TextUtils.isEmpty(key)
|| TextUtils.isEmpty(value)) {
return;
}
wxDefaultSettings.saveValue(key, value);
}

private static WXDefaultSettings mWXDefaultSettings;

/**
* dynamic
*/
Expand Down Expand Up @@ -200,7 +230,7 @@ public static Map<String, String> getConfig() {
/**
* Get the version of the current app.
*/
private static String getAppVersionName() {
public static String getAppVersionName() {
String versionName = "";
PackageManager manager;
PackageInfo info = null;
Expand Down Expand Up @@ -247,6 +277,39 @@ public static String getCustomOptions(String key){
return options.get(key);
}


public static String copySoDesDir() {
try {
if (TextUtils.isEmpty(COPY_SO_DES_DIR)) {
if (sApplication == null) {
WXLogUtils.e("sApplication is null, so copy path will be null");
return null;
}

String dirName = "/cache/weex/libs";
File desDir = null;
String cachePath = WXEnvironment.getApplication().getApplicationContext().getCacheDir().getPath();

if (TextUtils.isEmpty(cachePath)) {
desDir = new File(cachePath, dirName);
} else {
String pkgName = sApplication.getPackageName();
String toPath = "/data/data/" + pkgName + dirName;
desDir = new File(toPath);
}

if (!desDir.exists()) {
desDir.mkdirs();
}
COPY_SO_DES_DIR = desDir.getAbsolutePath();
}
} catch (Throwable e) {
WXLogUtils.e(WXLogUtils.getStackTrace(e));
}
return COPY_SO_DES_DIR;

}

@Deprecated
/**
* Use {@link #isHardwareSupport()} if you want to see whether current hardware support Weex.
Expand Down Expand Up @@ -439,10 +502,10 @@ public static String getCacheDir() {

public static boolean extractSo() {
File sourceFile = new File(getApplication().getApplicationContext().getApplicationInfo().sourceDir);
final String cacheDir = getCacheDir();
if (sourceFile.exists() && !TextUtils.isEmpty(cacheDir)) {
final String soDesPath = copySoDesDir();
if (sourceFile.exists() && !TextUtils.isEmpty(soDesPath)) {
try {
WXFileUtils.extractSo(sourceFile.getAbsolutePath(), cacheDir);
WXFileUtils.extractSo(sourceFile.getAbsolutePath(), soDesPath);
} catch (IOException e) {
WXLogUtils.e("extractSo error " + e.getMessage());
// e.printStackTrace();
Expand Down Expand Up @@ -583,4 +646,37 @@ public static String getLibLdPath() {
WXLogUtils.e("getLibLdPath is " + LIB_LD_PATH);
return LIB_LD_PATH;
}

public static class WXDefaultSettings {
private String configName = "weex_default_settings";
private SharedPreferences sharedPreferences = null;
public WXDefaultSettings(Application application) {
if(application != null) {
sharedPreferences = application.getSharedPreferences(configName, MODE_PRIVATE);
}
}

public synchronized String getValue(String key, String defaultValue) {
if(sharedPreferences == null || TextUtils.isEmpty(key)) {
WXLogUtils.i("get default settings " + key + " return default value :" + defaultValue);
return defaultValue;
}

String result = sharedPreferences.getString(key, defaultValue);
WXLogUtils.i("get default settings " + key + " : " + result);
return result;
}

public synchronized void saveValue(String key, String value) {
if (sharedPreferences == null
|| TextUtils.isEmpty(key)
|| TextUtils.isEmpty(value)) {
return;
}
WXLogUtils.i("save default settings " + key + ":" + value);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(key, value);
editor.apply();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2166,6 +2166,7 @@ private WXParams assembleDefaultOptions() {
wxParams.setLayoutDirection(config.get(WXConfig.layoutDirection));
wxParams.setUseSingleProcess(isUseSingleProcess ? "true" : "false");
wxParams.setCrashFilePath(WXEnvironment.getCrashFilePath(WXEnvironment.getApplication().getApplicationContext()));
wxParams.setLibJsbPath(WXEnvironment.CORE_JSB_SO_PATH);
wxParams.setLibJssPath(WXEnvironment.getLibJssRealPath());
wxParams.setLibIcuPath(WXEnvironment.getLibJssIcuPath());
wxParams.setLibLdPath(WXEnvironment.getLibLdPath());
Expand Down
11 changes: 11 additions & 0 deletions android/sdk/src/main/java/com/taobao/weex/bridge/WXParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class WXParams implements Serializable {
private String libJscPath;
private String libIcuPath;
private String libLdPath;
private String libJsbPath;

private Map<String, String> options;

Expand Down Expand Up @@ -214,6 +215,16 @@ public String getLibJssPath() {
return libJssPath;
}

@CalledByNative
public String getLibJsbPath() {
WXLogUtils.e("getLibJsbPath is running " + libJsbPath);
return libJsbPath;
}

public void setLibJsbPath(String libJsbPath) {
this.libJsbPath = libJsbPath;
}

@CalledByNative
public String getLibJscPath() {
WXLogUtils.e("getLibJscPath is running " + libJscPath);
Expand Down
Loading

0 comments on commit 57bd65c

Please sign in to comment.