Skip to content

Commit a8cf073

Browse files
committed
add check if snapshot blobs are enabled in package.json, and extract if true
1 parent a4988a8 commit a8cf073

4 files changed

Lines changed: 24 additions & 26 deletions

File tree

src/jni/AssetExtractor.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ void AssetExtractor::ExtractAssets(JNIEnv *env, jobject obj, jstring apk, jstrin
4141
zip_stat_index(z, i, ZIP_STAT_MTIME, &sb);
4242
if (strstr(sb.name, prfx) == sb.name)
4343
{
44-
45-
46-
DEBUG_WRITE("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ %s", sb.name);
47-
4844
auto name = sb.name + prefixLen; // strlen("assets/") == 7
4945

5046
std::string assetFullname(baseDir);

src/src/com/tns/Configuration.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ public class Configuration
1616
public final ClassLoader classLoader;
1717
public final File dexDir;
1818
public final String dexThumb;
19+
public final Object[] v8Config;
1920

2021
public Configuration(ThreadScheduler threadScheduler, Logger logger, Debugger debugger,
2122
String appName, File runtimeLibPath, File rootDir, File appDir, ClassLoader classLoader,
22-
File dexDir, String dexThumb)
23+
File dexDir, String dexThumb, Object[] v8Config)
2324
{
2425
this.threadScheduler = threadScheduler;
2526
this.logger = logger;
@@ -31,5 +32,6 @@ public Configuration(ThreadScheduler threadScheduler, Logger logger, Debugger d
3132
this.classLoader = classLoader;
3233
this.dexDir = dexDir;
3334
this.dexThumb = dexThumb;
35+
this.v8Config = v8Config;
3436
}
3537
}

src/src/com/tns/Runtime.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,10 @@ private boolean isInitializedImpl()
159159

160160
public void init()
161161
{
162-
init(config.threadScheduler, config.logger, config.debugger, config.appName, config.runtimeLibPath, config.rootDir, config.appDir, config.classLoader, config.dexDir, config.dexThumb);
162+
init(config.threadScheduler, config.logger, config.debugger, config.appName, config.runtimeLibPath, config.rootDir, config.appDir, config.classLoader, config.dexDir, config.dexThumb, config.v8Config);
163163
}
164164

165-
private void init(ThreadScheduler threadScheduler, Logger logger, Debugger debugger, String appName, File runtimeLibPath, File rootDir, File appDir, ClassLoader classLoader, File dexDir, String dexThumb) throws RuntimeException
165+
private void init(ThreadScheduler threadScheduler, Logger logger, Debugger debugger, String appName, File runtimeLibPath, File rootDir, File appDir, ClassLoader classLoader, File dexDir, String dexThumb, Object[] v8Config) throws RuntimeException
166166
{
167167
if (initialized)
168168
{
@@ -188,7 +188,6 @@ private void init(ThreadScheduler threadScheduler, Logger logger, Debugger debug
188188
{
189189
throw new RuntimeException("Fail to initialize Require class", ex);
190190
}
191-
Object[] v8Config = V8Config.fromPackageJSON(appDir);
192191

193192
if (debugger != null)//JsDebugger.isDebuggableApp(application))
194193
{

test-app/src/com/tns/RuntimeHelper.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,19 @@ public void initRuntime() {
5454

5555
DefaultExtractPolicy extractPolicy = new DefaultExtractPolicy(logger);
5656
boolean skipAssetExtraction = Util.runPlugin(logger, app);
57+
58+
String appName = app.getPackageName();
59+
File rootDir = new File(app.getApplicationInfo().dataDir);
60+
File appDir = app.getFilesDir();
61+
62+
try {
63+
appDir = appDir.getCanonicalFile();
64+
} catch (IOException e1) {
65+
}
66+
67+
Object[] v8Config = V8Config.fromPackageJSON(appDir);
68+
5769
if (!skipAssetExtraction) {
58-
long startTime = System.currentTimeMillis();
5970
AssetExtractor aE = new AssetExtractor(null, logger);
6071

6172
String outputDir = app.getFilesDir().getPath() + File.separator;
@@ -64,25 +75,15 @@ public void initRuntime() {
6475
aE.extractAssets(app, "internal", outputDir, extractPolicy);
6576
aE.extractAssets(app, "metadata", outputDir, extractPolicy);
6677

67-
// if(true) {
68-
// aE.extractAssets(app, "snapshots/" + Build.CPU_ABI + "/snapshot.blob", outputDir, extractPolicy);
69-
// }
78+
boolean shouldExtractSnapshots = !v8Config[3].toString().isEmpty();
79+
if(shouldExtractSnapshots) {
80+
System.out.println("EXTRACTING A SNAPSHOT!");
81+
aE.extractAssets(app, "snapshots/" + Build.CPU_ABI + "/snapshot.blob", outputDir, extractPolicy);
82+
}
7083

7184
extractPolicy.setAssetsThumb(app);
72-
73-
long endTime = System.currentTimeMillis();
74-
System.out.println("Total execution time: " + (endTime - startTime) + "ms");
7585
}
76-
77-
String appName = app.getPackageName();
78-
File rootDir = new File(app.getApplicationInfo().dataDir);
79-
File appDir = app.getFilesDir();
80-
81-
try {
82-
appDir = appDir.getCanonicalFile();
83-
} catch (IOException e1) {
84-
}
85-
86+
8687
ClassLoader classLoader = app.getClassLoader();
8788
File dexDir = new File(rootDir, "code_cache/secondary-dexes");
8889
String dexThumb = null;
@@ -95,7 +96,7 @@ public void initRuntime() {
9596
}
9697
ThreadScheduler workThreadScheduler = new WorkThreadScheduler(new Handler(Looper.getMainLooper()));
9798
Configuration config = new Configuration(workThreadScheduler, logger, debugger, appName, null, rootDir,
98-
appDir, classLoader, dexDir, dexThumb);
99+
appDir, classLoader, dexDir, dexThumb, v8Config);
99100
Runtime runtime = new Runtime(config);
100101

101102
exHandler.setRuntime(runtime);

0 commit comments

Comments
 (0)