Skip to content

Commit

Permalink
fix(android): remove deprecated JNI
Browse files Browse the repository at this point in the history
  • Loading branch information
siguangli2018 authored and churchill-zhang committed Apr 12, 2021
1 parent 384ac29 commit b6a46f1
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ public interface HippyBridge

public void initJSBridge(String gobalConfig, NativeCallback callback, int groupId);

public boolean runScriptFromFile(String filePath, String scriptName, boolean canUseCodeCache, String codeCacheTag, NativeCallback callback);

public boolean runScriptFromAssets(String fileName, AssetManager assetManager, boolean canUseCodeCache, String codeCacheTag, NativeCallback callback);

public boolean runScriptFromUri(String uri, AssetManager assetManager, boolean canUseCodeCache, String codeCacheTag, NativeCallback callback);

void onDestroy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@

public class HippyBridgeImpl implements HippyBridge, DevRemoteDebugProxy.OnReceiveDataListener
{
private static volatile ThreadPoolExecutor mCodeCacheThreadExecutor = null;
private static volatile int sBridgeNum = 0;
private static Object sBridgeSyncLock;
private static int TIMEOUT = 3000;

static
{
Expand Down Expand Up @@ -80,8 +77,6 @@ public HippyBridgeImpl(HippyEngineContext engineContext, BridgeCallback callback

synchronized (sBridgeSyncLock)
{
++sBridgeNum;

if (mCodeCacheRootDir == null)
{
Context context = mContext.getGlobalConfigs().getContext();
Expand All @@ -91,12 +86,6 @@ public HippyBridgeImpl(HippyEngineContext engineContext, BridgeCallback callback
this.mCodeCacheRootDir = hippyFile.getAbsolutePath() + File.separator + "codecache" + File.separator;
}
}

if (mCodeCacheThreadExecutor == null)
{
this.mCodeCacheThreadExecutor = new ThreadPoolExecutor(1, 1, 120L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
this.mCodeCacheThreadExecutor.allowCoreThreadTimeOut(true);
}
}

if (!mBridgeParamJson)
Expand Down Expand Up @@ -160,51 +149,6 @@ private void initJSEngine(int groupId)
}
}

@Override
public boolean runScriptFromFile(String filePath, String scriptName, boolean canUseCodeCache, String codeCacheTag, NativeCallback callback)
{
if (!mInit)
{
return false;
}
if (!TextUtils.isEmpty(codeCacheTag) && !TextUtils.isEmpty(mCodeCacheRootDir))
{
LogUtils.e("HippyEngineMonitor", "runScriptFromFile ======core====== " + codeCacheTag + ", canUseCodeCache == " + canUseCodeCache);
String codeCacheDir = mCodeCacheRootDir + codeCacheTag + File.separator;
File file = new File(codeCacheDir);
LogUtils.d("HippyEngineMonitor", "codeCacheDir file size : " + (file.listFiles() != null ? file.listFiles().length : 0));
return runScriptFromFile(filePath, scriptName, canUseCodeCache, codeCacheDir, mV8RuntimeId, callback);
}
else
{
LogUtils.e("HippyEngineMonitor", "runScriptFromFile codeCacheTag is null");
return runScriptFromFile(filePath, scriptName, false, "" + codeCacheTag + File.separator, mV8RuntimeId, callback);
}
}

@Override
public boolean runScriptFromAssets(String fileName, AssetManager assetManager, boolean canUseCodeCache, String codeCacheTag, NativeCallback callback)
{
if (!mInit)
{
return false;
}

if (!TextUtils.isEmpty(codeCacheTag) && !TextUtils.isEmpty(mCodeCacheRootDir))
{
LogUtils.e("HippyEngineMonitor", "runScriptFromAssets ======core====== " + codeCacheTag + ", canUseCodeCache == " + canUseCodeCache);
String codeCacheDir = mCodeCacheRootDir + codeCacheTag + File.separator;
File file = new File(codeCacheDir);
LogUtils.d("HippyEngineMonitor", "codeCacheDir file size : " + (file.listFiles() != null ? file.listFiles().length : 0));
return runScriptFromAssets(fileName, assetManager, canUseCodeCache, codeCacheDir, mV8RuntimeId, callback);
}
else
{
LogUtils.e("HippyEngineMonitor", "runScriptFromAssets codeCacheTag is null");
return runScriptFromAssets(fileName, assetManager, false, "" + codeCacheTag + File.separator, mV8RuntimeId, callback);
}
}

@Override
public boolean runScriptFromUri(String uri, AssetManager assetManager, boolean canUseCodeCache, String codeCacheTag, NativeCallback callback)
{
Expand Down Expand Up @@ -266,20 +210,6 @@ public void onDestroy() {
}

mInit = false;
synchronized (sBridgeSyncLock) {
--sBridgeNum;
if (sBridgeNum == 0) {
try {
if (mCodeCacheThreadExecutor != null) {
mCodeCacheThreadExecutor.shutdownNow();
}
} catch (Throwable e) {
LogUtils.d("HippyBridgeImpl", "onDestroy: " + e.getMessage());
}
mCodeCacheThreadExecutor = null;
}
}

if (!mBridgeParamJson && mHippyBuffer != null) {
mHippyBuffer.release();
}
Expand All @@ -299,22 +229,14 @@ public void destroy(NativeCallback callback) {
*/
public native long initJSFramework(byte[] gobalConfig, boolean useLowMemoryMode, boolean useBrigeParamJson, boolean isDevModule, NativeCallback callback, long groupId);

public native boolean runScriptFromFile(String filePath, String scriptName, boolean canUseCodeCache, String codeCacheDir, long V8RuntimId, NativeCallback callback);

public native boolean runScriptFromAssets(String fileName, AssetManager assetManager, boolean canUseCodeCache, String codeCacheDir, long V8RuntimId, NativeCallback callback);

public native boolean runScriptFromUri(String uri, AssetManager assetManager, boolean canUseCodeCache, String codeCacheDir, long V8RuntimId, NativeCallback callback);

public native void destroy(long runtimeId, boolean useLowMemoryMode, NativeCallback callback);

public native void callFunction(String action, byte[] params, int offset, int length, long V8RuntimId, NativeCallback callback);

public native void runNativeRunnable(String codeCacheFile, long nativeRunnableId, long V8RuntimId, NativeCallback callback);

public native void onResourceReady(ByteBuffer output, long runtimeId, long resId);

public native String getCrashMessage();

public void callNatives(String moduleName, String moduleFunc, String callId, byte[] params)
{
LogUtils.d("jni_callback", "callNatives [moduleName:" + moduleName + " , moduleFunc: " + moduleFunc + "]");
Expand Down Expand Up @@ -444,18 +366,6 @@ public void reportException(String exception, String stackTrace)
}
}

public void postCodeCacheRunnable(String codeCacheFile, long nativeRunnableId) {
try {
synchronized (sBridgeSyncLock) {
if (mCodeCacheThreadExecutor != null) {
mCodeCacheThreadExecutor.execute(new CodeCacheRunnable(codeCacheFile, nativeRunnableId));
}
}
} catch (Throwable e) {
LogUtils.d("HippyBridgeImpl", "postCodeCacheRunnable: " + e.getMessage());
}
}

static class CodeCacheFilter implements FilenameFilter
{
String fileName;
Expand Down Expand Up @@ -488,59 +398,6 @@ public boolean accept(File dir, String name)
}
}

public class CodeCacheRunnable implements Runnable
{
private String mPath;
private long mNativeId;

public CodeCacheRunnable(String path, long nativeId)
{
this.mPath = path;
this.mNativeId = nativeId;
}

@Override
public void run()
{
try
{
if (TextUtils.isEmpty(mPath))
{
return;
}
File dir = new File(mPath.substring(0, mPath.lastIndexOf(File.separator)));
deleteDirWithFile(dir);
dir.mkdirs();
File file = new File(mPath);
file.createNewFile();

runNativeRunnable(mPath, mNativeId, mV8RuntimeId, null);
}
catch (Throwable e)
{
e.printStackTrace();
}
}

public void deleteDirWithFile(File dir)
{
if (dir == null || !dir.exists() || !dir.isDirectory())
return;
File[] childs = dir.listFiles();
if (childs != null)
{
for (File file : childs)
{
if (file.isFile())
file.delete();
else if (file.isDirectory())
deleteDirWithFile(file);
}
}
dir.delete();
}
}

@Override
public void onReceiveData(String msg)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public boolean load(HippyBridge bridge, NativeCallback callback)

String uri = (!mFilePath.startsWith(URI_SCHEME_FILE)) ? (URI_SCHEME_FILE + mFilePath) : mFilePath;
return bridge.runScriptFromUri(uri, null, mCanUseCodeCache, mCodeCacheTag, callback);
//return bridge.runScriptFromFile(mFilePath, mFilePath,mCanUseCodeCache,mCodeCacheTag, callback);
}

@Override
Expand Down

0 comments on commit b6a46f1

Please sign in to comment.