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

Commit

Permalink
[jsruntime] add runtime code (a/b) and build success
Browse files Browse the repository at this point in the history
[Android] rebuild jsc for initHeapTimer and jsruntme/old  code are work fine

[jsruntime] dom_wson switch fix

[Android] add args check fix && add a/b so load/update logic

[Android] build logic for a/b and __enable_native_promise__ flag
  • Loading branch information
lucky-chen committed Jul 2, 2019
1 parent 4d17cc6 commit d6dee7c
Show file tree
Hide file tree
Showing 131 changed files with 11,902 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ public void onCreate() {
if(!TextUtils.isEmpty(BuildConfig.externalLibraryName)){
builder.addNativeLibrary(BuildConfig.externalLibraryName);
}
WXSDKEngine.initialize(this, builder.build());
WXSDKManager.getInstance().setWxConfigAdapter(new DefaultConfigAdapter());
WXSDKEngine.initialize(this, builder.build());
WXSDKManager.getInstance().addWXAnalyzer(new WXAnalyzerDemoListener());
WXAnalyzerDataTransfer.isOpenPerformance = false;

Expand Down
5 changes: 4 additions & 1 deletion android/sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ android {

def android_project_dir = projectDir

def buildRuntimeApi = project.hasProperty('buildRuntimeApi') ? project.property('buildRuntimeApi') : false;

defaultConfig {
buildConfigField "String", "buildJavascriptFrameworkVersion", "\"${jsfmVersion}\""
buildConfigField "String", "buildVersion", "\"${version}\""
Expand All @@ -137,7 +139,8 @@ android {
'-DANDROID_STL=' + "${cxx_stl}",
'-DCMAKE_BUILD_TYPE=Release',
'-DANDROID_PROJECT_DIR=' + "${android_project_dir}",
'-DENABLE_ASAN=false'
'-DENABLE_ASAN=false',
'-DBUILD_RUNTIME_API='+"${buildRuntimeApi}"
}
}
}
Expand Down
Binary file modified android/sdk/libs/armeabi-v7a/libJavaScriptCore.so
Binary file not shown.
11 changes: 10 additions & 1 deletion android/sdk/src/main/java/com/taobao/weex/WXEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ public class WXEnvironment {

public static boolean AUTO_UPDATE_APPLICATION_SCREEN_SIZE = true;

public static volatile boolean sUseRunTimeApi = false;

/**
* Debug model
*/
Expand Down Expand Up @@ -137,6 +139,8 @@ public class WXEnvironment {

private static String CORE_JSS_SO_PATH = null;

public static String CORE_JSS_RUNTIME_SO_PATH = null;

private static String CORE_JSS_ICU_PATH = null;

private static String CORE_JSC_SO_PATH = null;
Expand Down Expand Up @@ -528,9 +532,14 @@ public static String getLibJScRealPath() {
}

public static String getLibJssRealPath() {
if (WXEnvironment.sUseRunTimeApi && !TextUtils.isEmpty(CORE_JSS_RUNTIME_SO_PATH)){
WXLogUtils.e("test-> findLibJssRuntimeRealPath " + CORE_JSS_RUNTIME_SO_PATH);
return CORE_JSS_RUNTIME_SO_PATH;
}

if(TextUtils.isEmpty(CORE_JSS_SO_PATH)) {
CORE_JSS_SO_PATH = findSoPath(CORE_JSS_SO_NAME);
WXLogUtils.e("findLibJssRealPath " + CORE_JSS_SO_PATH);
WXLogUtils.e("test-> findLibJssRealPath " + CORE_JSS_SO_PATH);
}

return CORE_JSS_SO_PATH;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package com.taobao.weex.bridge;

import com.taobao.weex.WXEnvironment;
import com.taobao.weex.base.CalledByNative;
import com.taobao.weex.utils.WXLogUtils;

Expand Down Expand Up @@ -244,6 +245,11 @@ public void setLibLdPath(String libLdPath) {
this.libLdPath = libLdPath;
}

@CalledByNative
public String getUseRunTimeApi() {
return String.valueOf(WXEnvironment.sUseRunTimeApi);
}

public Map<String, Object> toMap() {
HashMap<String, Object> map = new HashMap<>();
map.put("appName", appName);
Expand All @@ -266,6 +272,8 @@ public Map<String, Object> toMap() {
map.put("libIcuPath", libIcuPath);
map.put("libLdPath", libLdPath);
map.put("options", options);
map.put("useRunTimeApi",WXEnvironment.sUseRunTimeApi);
map.put("__enable_native_promise__",!WXEnvironment.sUseRunTimeApi);
return map;
}
}
30 changes: 30 additions & 0 deletions android/sdk/src/main/java/com/taobao/weex/utils/WXFileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
Expand Down Expand Up @@ -266,4 +267,33 @@ public static void copyFile(File oldFile, File newFile) {
}
}

public static void copyFileWithException(File oldFile,File newFile ) throws Exception{
FileInputStream inputStream = null;
FileOutputStream outputStream = null;
try {
inputStream = new FileInputStream(oldFile);
byte[] data = new byte[1024];
outputStream = new FileOutputStream(newFile);
while (inputStream.read(data) != -1) {
outputStream.write(data);
}
}catch (Exception e){
throw e;
}finally {
closeIo(inputStream);
closeIo(outputStream);
}
}

public static void closeIo(Closeable c){
if (null == c){
return;
}
try {
c.close();
}catch (Throwable e){
e.printStackTrace();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,26 @@
package com.taobao.weex.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.os.Build;
import android.preference.PreferenceManager;
import android.text.TextUtils;
import android.util.Log;

import com.taobao.weex.IWXStatisticsListener;
import com.taobao.weex.WXEnvironment;
import com.taobao.weex.WXSDKManager;
import com.taobao.weex.adapter.IWXConfigAdapter;
import com.taobao.weex.adapter.IWXSoLoaderAdapter;
import com.taobao.weex.adapter.IWXUserTrackAdapter;
import com.taobao.weex.common.WXErrorCode;
import dalvik.system.PathClassLoader;
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
Expand Down Expand Up @@ -119,6 +125,7 @@ public static boolean initSo(String libName, int version, IWXUserTrackAdapter ut

// copy startup so
copyStartUpSo();
copyJssRuntimeSo();

boolean InitSuc = false;
// if (checkSoIsValid(libName, BuildConfig.ARMEABI_Size) ||checkSoIsValid(libName, BuildConfig.X86_Size)) {
Expand Down Expand Up @@ -304,6 +311,61 @@ public static void copyStartUpSo() {
}
}

private static void copyJssRuntimeSo(){
Log.e("test->", "enter copyJssRuntimeSo: ");
boolean tryUseRunTimeApi = WXUtils.checkGreyConfig("wxapm","use_runtime_api","100");
Log.e("test->", "tryUseRunTimeApi ? "+ tryUseRunTimeApi);
if (!tryUseRunTimeApi){
return;
}
try {
Log.e("test->", "copyJssRuntimeSo: ");
Context c = WXEnvironment.getApplication();
String pkgName = c.getPackageName();
String toPath = "/data/data/" + pkgName + "/weex";
String cachePath = WXEnvironment.getApplication().getApplicationContext().getCacheDir().getPath();
if (cachePath != null && cachePath.indexOf("/cache") > 0) {
toPath = cachePath.replace("/cache", "/weex/libs");
}
File dir = new File(toPath);
if (!dir.exists()){
dir.mkdirs();
}
File targetFile = new File(toPath,"libweexjss.so");

/** 1. check so and versionCode. if update, then rm old jss.so(runtime) in pkg/libs, and copy new so from apk **/
String keyVersionCode = "app_version_code_weex";
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c);
PackageInfo info = c.getPackageManager().getPackageInfo(c.getPackageName(), 0);
if (targetFile.exists()){
if (prefs.getInt(keyVersionCode,-1) < info.versionCode){
targetFile.delete();
}else {
WXEnvironment.CORE_JSS_RUNTIME_SO_PATH= targetFile.getAbsolutePath();
WXEnvironment.sUseRunTimeApi = true;
Log.e("test->", "copyJssRuntimeSo: return");
return;
}
}
/** 2. copy jss(runtime) so **/
String fromPath = ((PathClassLoader) (WXSoInstallMgrSdk.class.getClassLoader())).findLibrary("weexjssr");
if (TextUtils.isEmpty(fromPath)){
return;
}
targetFile.createNewFile();
WXFileUtils.copyFileWithException(new File(fromPath),targetFile);
/**3. update flag **/
WXEnvironment.CORE_JSS_RUNTIME_SO_PATH= targetFile.getAbsolutePath();
prefs.edit().putInt(keyVersionCode,info.versionCode).apply();
WXEnvironment.sUseRunTimeApi = true;
Log.e("test->", "copyJssRuntimeSo: return 2");
}catch (Throwable e){
e.printStackTrace();
WXEnvironment.sUseRunTimeApi = false;
Log.e("test->", "copyJssRuntimeSo: exception" + e);
}
}

private static String _getFieldReflectively(Build build, String fieldName) {
try {
final Field field = Build.class.getField(fieldName);
Expand Down
22 changes: 22 additions & 0 deletions android/sdk/src/main/java/com/taobao/weex/utils/WXUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
import android.support.annotation.Nullable;
import android.support.v4.util.LruCache;
import android.text.TextUtils;
import android.util.Log;
import com.taobao.weex.WXEnvironment;
import com.taobao.weex.WXSDKManager;
import com.taobao.weex.adapter.IWXConfigAdapter;
import com.taobao.weex.common.Constants;
import com.taobao.weex.common.WXConfig;

Expand Down Expand Up @@ -569,6 +572,25 @@ public static int getNumberInt(Object value, int defaultValue){
}catch (Exception e){return defaultValue;}
}

public static boolean checkGreyConfig(String group,String key,String defaultValue){
Log.e("test->", "enter checkGreyConfig");
IWXConfigAdapter configAdapter = WXSDKManager.getInstance().getWxConfigAdapter();
if (null == configAdapter) {
Log.e("test->", "checkGreyConfig: configAdapter return false");
return false;
}
double randomValue = Math.random() * 100;
double max = 100;
try {
String configValue = configAdapter.getConfig(group, key, defaultValue);
max = Double.valueOf(configValue);
} catch (Exception e) {
e.printStackTrace();
}
Log.e("test->", "checkGreyConfig: "+ randomValue +", max:"+max);
return randomValue < max;
}

private static final long sInterval = System.currentTimeMillis() - SystemClock.uptimeMillis();

public static long getFixUnixTime(){
Expand Down
16 changes: 15 additions & 1 deletion weex_core/Source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ set(COMMON_SRCS
./core/bridge/platform/core_side_in_platform.cpp
./core/bridge/script/core_side_in_script.cpp
./core/parser/dom_wson.cpp
./core/parser/action_args_check.cpp

./core/network/http_module.cc
)
Expand All @@ -106,7 +107,20 @@ if(ANDROID)
add_definitions(-DOS_ANDROID=1)
## add_subdirectory for subdirectory has a CMakeLists.txt
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/third_party/IPC)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/android/jsengine)


message("check build jsc BUILD_RUNTIME_API flag: ${BUILD_RUNTIME_API}")
if ("${BUILD_RUNTIME_API}" STREQUAL "true")
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/js_runtime)
message("cmake build jsApi for runtime")
else()
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/android/jsengine)
message("cmake build jsApi for jsc")
endif()




## include_directories for include head file
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/third_party/IPC)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,15 @@ namespace weex {
// }
if (result->getType() != IPCType::VOID) {
if (result->getStringLength() > 0) {
#ifdef USE_JS_RUNTIME
return jString2String(result->getStringContent(),
result->getStringLength()).c_str();
#else
return jString2String(result->getStringContent(),
result->getStringLength())
.utf8()
.data();
#endif
}
}
} catch (IPCException &e) {
Expand Down Expand Up @@ -391,10 +396,15 @@ namespace weex {
// }
if (result->getType() != IPCType::VOID) {
if (result->getStringLength() > 0) {
#ifdef USE_JS_RUNTIME
return jString2String(result->getStringContent(),
result->getStringLength()).c_str();
#else
return jString2String(result->getStringContent(),
result->getStringLength())
.utf8()
.data();
#endif
}
}
return nullptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include "core/manager/weex_core_manager.h"
#include "core/render/manager/render_manager.h"
#include "third_party/IPC/IPCResult.h"
#include "core/config/core_environment.h"
#include "core/parser/action_args_check.h"

namespace weex {
namespace bridge {
Expand All @@ -38,6 +40,19 @@ CoreSideInSimple::~CoreSideInSimple() {}
void CoreSideInSimple::CallNative(const char *page_id, const char *task,
const char *callback) {
if (page_id == nullptr || task == nullptr) return;

if (WXCoreEnvironment::getInstance()->isUseRunTimeApi()){
if (isCallNativeToFinish(task)){
RenderManager::GetInstance()->CreateFinish(page_id);
} else {
WeexCoreManager::Instance()
->getPlatformBridge()
->platform_side()
->CallNative(page_id, task, callback);
}
return;
}

if (strcmp(
task,
"[{\"module\":\"dom\",\"method\":\"createFinish\",\"args\":[]}]") ==
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,13 @@ namespace weex {
init_framework_params->value = IPCByteArrayToWeexByteArray(ba);

if(!WeexEnv::getEnv()->enableBackupThread()) {
#ifdef USE_JS_RUNTIME
std::string type = init_framework_params->type->content;
std::string value = init_framework_params->value->content;
#else
auto type = String::fromUTF8(init_framework_params->type->content);
auto value = String::fromUTF8(init_framework_params->value->content);
#endif
if(type == "enableBackupThread") {
auto enable = value == "true";
LOGE("enable backupThread %d",enable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
#define WEEXV8_SCRIPT_SIDE_IN_QUEUE_H

#include "core/bridge/script_bridge.h"
#ifdef USE_JS_RUNTIME
#include "js_runtime/weex/task/weex_task_queue.h"
#else
#include "android/jsengine/task/weex_task_queue.h"
#endif

namespace weex {
namespace bridge {
Expand Down
4 changes: 4 additions & 0 deletions weex_core/Source/android/jsengine/object/args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
#ifdef USE_JS_RUNTIME
#include "js_runtime/weex/object/args.h"
#else
#include "android/jsengine/object/args.h"
#endif

namespace WeexCore{

Expand Down
Loading

0 comments on commit d6dee7c

Please sign in to comment.