Skip to content

Commit b912a35

Browse files
committed
perform check for flag in package.json
1 parent a8cf073 commit b912a35

4 files changed

Lines changed: 41 additions & 7 deletions

File tree

src/src/com/tns/AssetExtractor.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import java.io.File;
44

5-
65
import android.content.Context;
6+
import android.util.Log;
77

88
public class AssetExtractor
99
{
@@ -34,5 +34,13 @@ else if (extractPolicy.shouldExtract(context))
3434

3535
extractAssets(apkPath, inputPath, outputPath, forceOverwrite);
3636
}
37+
else
38+
{
39+
Log.d("~~~~~~~~", "SKIPPED EXTRACTION");
40+
if (logger.isEnabled())
41+
{
42+
logger.write("Skipped extraction of assets in " + inputPath);
43+
}
44+
}
3745
}
3846
}

src/src/com/tns/V8Config.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class V8Config
1111
private static final String AndroidKey = "android";
1212
private static final String V8FlagsKey = "v8Flags";
1313
private static final String CodeCacheKey = "codeCache";
14+
// TODO: EnableHeapSnapshotKey is subject to approval and change
15+
private static final String EnableHeapSnapshotKey = "heapSnapshotEnable";
1416
private static final String HeapSnapshotScriptKey = "heapSnapshotScript";
1517
private static final String HeapSnapshotBlobKey = "heapSnapshotBlob";
1618
private static final String SnapshotFile = "snapshot.blob";
@@ -22,6 +24,7 @@ public static Object[] fromPackageJSON(File appDir)
2224
File packageInfo = new File(appDir, "/app/package.json");
2325
if (!packageInfo.exists())
2426
{
27+
android.util.Log.d("~~~~~~~~", "A PACKAGE INFO DOES NOT EXIST");
2528
return result;
2629
}
2730

@@ -31,6 +34,8 @@ public static Object[] fromPackageJSON(File appDir)
3134
rootObject = FileSystem.readJSONFile(packageInfo);
3235
if (rootObject != null && rootObject.has(AndroidKey))
3336
{
37+
android.util.Log.d("~~~~~~~~", "Getting keys inside android");
38+
3439
JSONObject androidObject = rootObject.getJSONObject(AndroidKey);
3540
if (androidObject.has(V8FlagsKey))
3641
{
@@ -61,6 +66,12 @@ public static Object[] fromPackageJSON(File appDir)
6166
{
6267
result[4] = androidObject.getString(ProfilerOutputDirKey);
6368
}
69+
if(androidObject.has(EnableHeapSnapshotKey))
70+
{
71+
72+
android.util.Log.d("~~~~~~~~", "Found thy key");
73+
result[5] = androidObject.getBoolean(EnableHeapSnapshotKey);
74+
}
6475
}
6576
}
6677
catch (Exception e)
@@ -83,7 +94,9 @@ private static Object[] makeDefaultOptions()
8394
// a binary file containing an already saved snapshot
8495
"",
8596
// V8 profiler output directory
86-
""
97+
"",
98+
// enable heapsnapshots extraction, false by default
99+
false
87100
};
88101

89102
return result;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public boolean shouldExtract(Context context)
3535
if (oldAssetsThumb == null) {
3636
return true;
3737
} else {
38-
String currentThumb = getAssetThumb(context);
38+
String currentThumb = getAssetsThumb(context);
3939

4040
if(currentThumb != null && !currentThumb.equals(oldAssetsThumb)) {
4141
return true;
@@ -61,7 +61,7 @@ public FileExtractor extractor() {
6161
return null;
6262
}
6363

64-
public String getAssetThumb(Context context) {
64+
public String getAssetsThumb(Context context) {
6565
return generateAssetsThumb(context);
6666
}
6767

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,23 +67,36 @@ public void initRuntime() {
6767
Object[] v8Config = V8Config.fromPackageJSON(appDir);
6868

6969
if (!skipAssetExtraction) {
70+
if(logger.isEnabled()) {
71+
logger.write("Extracting assets...");
72+
}
73+
7074
AssetExtractor aE = new AssetExtractor(null, logger);
7175

7276
String outputDir = app.getFilesDir().getPath() + File.separator;
73-
77+
78+
Log.d("~~~~~~~~", "EXTRACTING LE APP CRAP");
7479
aE.extractAssets(app, "app", outputDir, extractPolicy);
7580
aE.extractAssets(app, "internal", outputDir, extractPolicy);
7681
aE.extractAssets(app, "metadata", outputDir, extractPolicy);
7782

78-
boolean shouldExtractSnapshots = !v8Config[3].toString().isEmpty();
83+
// at earlier point the package.json will not have been extracted, so we now fetch the real, non-default values from the file
84+
v8Config = V8Config.fromPackageJSON(appDir);
85+
86+
boolean shouldExtractSnapshots = (Boolean)v8Config[5];
7987
if(shouldExtractSnapshots) {
80-
System.out.println("EXTRACTING A SNAPSHOT!");
88+
if(logger.isEnabled()) {
89+
logger.write("Extracting snapshot blob");
90+
}
91+
8192
aE.extractAssets(app, "snapshots/" + Build.CPU_ABI + "/snapshot.blob", outputDir, extractPolicy);
8293
}
8394

8495
extractPolicy.setAssetsThumb(app);
8596
}
8697

98+
99+
87100
ClassLoader classLoader = app.getClassLoader();
88101
File dexDir = new File(rootDir, "code_cache/secondary-dexes");
89102
String dexThumb = null;

0 commit comments

Comments
 (0)