Skip to content

Commit 65e6d1e

Browse files
committed
revert to not using additional key in package.json in order to extract sshots
1 parent f01fc68 commit 65e6d1e

3 files changed

Lines changed: 79 additions & 91 deletions

File tree

build/project-template-gradle/src/main/java/com/tns/RuntimeHelper.java

Lines changed: 72 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -4,140 +4,136 @@
44

55
import android.app.Application;
66
import android.content.pm.PackageManager.NameNotFoundException;
7+
import android.os.Build;
78
import android.os.Handler;
89
import android.os.Looper;
910
import android.util.Log;
1011
import java.io.IOException;
1112

12-
public class RuntimeHelper
13-
{
13+
public class RuntimeHelper {
1414
private final Application app;
15-
16-
public RuntimeHelper(Application app)
17-
{
15+
16+
public RuntimeHelper(Application app) {
1817
this.app = app;
1918
}
20-
21-
// hasErrorIntent tells you if there was an event (with an uncaught exception) raised from ErrorReport
22-
public boolean hasErrorIntent()
23-
{
19+
20+
// hasErrorIntent tells you if there was an event (with an uncaught
21+
// exception) raised from ErrorReport
22+
public boolean hasErrorIntent() {
2423
boolean hasErrorIntent = false;
25-
26-
try
27-
{
28-
//empty file just to check if there was a raised uncaught error by ErrorReport
24+
25+
try {
26+
// empty file just to check if there was a raised uncaught error by
27+
// ErrorReport
2928
File errFile = new File(app.getFilesDir(), ErrorReport.ERROR_FILE_NAME);
30-
31-
if (errFile.exists())
32-
{
29+
30+
if (errFile.exists()) {
3331
errFile.delete();
3432
hasErrorIntent = true;
3533
}
36-
}
37-
catch (Exception e)
38-
{
34+
} catch (Exception e) {
3935
Log.d(logTag, e.getMessage());
4036
}
41-
37+
4238
return hasErrorIntent;
4339
}
44-
45-
public void initRuntime()
46-
{
40+
41+
public void initRuntime() {
4742
System.loadLibrary("NativeScript");
48-
43+
4944
Logger logger = new LogcatLogger(app);
5045
Debugger debugger = new AndroidJsDebugger(app, logger);
51-
46+
5247
boolean showErrorIntent = hasErrorIntent();
53-
if (!showErrorIntent)
54-
{
48+
if (!showErrorIntent) {
5549
NativeScriptUncaughtExceptionHandler exHandler = new NativeScriptUncaughtExceptionHandler(logger, app);
5650

5751
Thread.setDefaultUncaughtExceptionHandler(exHandler);
58-
52+
5953
Async.Http.setApplicationContext(this.app);
60-
61-
ExtractPolicy extractPolicy = new DefaultExtractPolicy(logger);
54+
55+
DefaultExtractPolicy extractPolicy = new DefaultExtractPolicy(logger);
6256
boolean skipAssetExtraction = Util.runPlugin(logger, app);
63-
if (!skipAssetExtraction)
64-
{
65-
new AssetExtractor(null, logger).extractAssets(app, extractPolicy);
66-
}
67-
57+
6858
String appName = app.getPackageName();
6959
File rootDir = new File(app.getApplicationInfo().dataDir);
7060
File appDir = app.getFilesDir();
71-
72-
try
73-
{
61+
62+
try {
7463
appDir = appDir.getCanonicalFile();
64+
} catch (IOException e1) {
7565
}
76-
catch (IOException e1)
77-
{
66+
67+
if (!skipAssetExtraction) {
68+
if(logger.isEnabled()) {
69+
logger.write("Extracting assets...");
70+
}
71+
72+
AssetExtractor aE = new AssetExtractor(null, logger);
73+
74+
String outputDir = app.getFilesDir().getPath() + File.separator;
75+
76+
aE.extractAssets(app, "app", outputDir, extractPolicy);
77+
aE.extractAssets(app, "internal", outputDir, extractPolicy);
78+
aE.extractAssets(app, "metadata", outputDir, extractPolicy);
79+
80+
// enable with flags?
81+
boolean shouldExtractSnapshots = true;
82+
83+
// will extract snapshot of the device appropriate architecture
84+
if(shouldExtractSnapshots) {
85+
if(logger.isEnabled()) {
86+
logger.write("Extracting snapshot blob");
87+
}
88+
89+
aE.extractAssets(app, "snapshots/" + Build.CPU_ABI, outputDir, extractPolicy);
90+
}
91+
92+
extractPolicy.setAssetsThumb(app);
7893
}
7994

95+
Object[] v8Config = V8Config.fromPackageJSON(appDir);
96+
8097
ClassLoader classLoader = app.getClassLoader();
8198
File dexDir = new File(rootDir, "code_cache/secondary-dexes");
8299
String dexThumb = null;
83-
try
84-
{
100+
try {
85101
dexThumb = Util.getDexThumb(app);
86-
}
87-
catch (NameNotFoundException e)
88-
{
89-
if (logger.isEnabled()) logger.write("Error while getting current proxy thumb");
102+
} catch (NameNotFoundException e) {
103+
if (logger.isEnabled())
104+
logger.write("Error while getting current proxy thumb");
90105
e.printStackTrace();
91106
}
92107
ThreadScheduler workThreadScheduler = new WorkThreadScheduler(new Handler(Looper.getMainLooper()));
93-
Configuration config = new Configuration(workThreadScheduler, logger, debugger, appName, null, rootDir, appDir, classLoader, dexDir, dexThumb);
108+
Configuration config = new Configuration(workThreadScheduler, logger, debugger, appName, null, rootDir,
109+
appDir, classLoader, dexDir, dexThumb, v8Config);
94110
Runtime runtime = new Runtime(config);
95-
111+
96112
exHandler.setRuntime(runtime);
97-
98-
if (NativeScriptSyncService.isSyncEnabled(this.app))
99-
{
113+
114+
if (NativeScriptSyncService.isSyncEnabled(this.app)) {
100115
NativeScriptSyncService syncService = new NativeScriptSyncService(runtime, logger, this.app);
101116

102117
syncService.sync();
103118
syncService.startServer();
104119

105120
// preserve this instance as strong reference
106-
// do not preserve in NativeScriptApplication field inorder to make the code more portable
121+
// do not preserve in NativeScriptApplication field inorder to
122+
// make the code more portable
107123
// @@@
108-
//Runtime.getOrCreateJavaObjectID(syncService);
109-
}
110-
else
111-
{
112-
if (logger.isEnabled())
113-
{
124+
// Runtime.getOrCreateJavaObjectID(syncService);
125+
} else {
126+
if (logger.isEnabled()) {
114127
logger.write("NativeScript LiveSync is not enabled.");
115128
}
116129
}
117-
130+
118131
runtime.init();
119132
runtime.runScript(new File(appDir, "internal/ts_helpers.js"));
120133
Runtime.initInstance(this.app);
121134
runtime.run();
122135
}
123136
}
124-
125-
/* public static boolean isDebuggableApp(Context context)
126-
{
127-
int flags;
128-
try
129-
{
130-
flags = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).applicationInfo.flags;
131-
}
132-
catch (NameNotFoundException e)
133-
{
134-
flags = 0;
135-
e.printStackTrace();
136-
}
137137

138-
boolean isDebuggableApp = ((flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0);
139-
return isDebuggableApp;
140-
}*/
141-
142138
private final String logTag = "MyApp";
143139
}

src/src/com/tns/V8Config.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ 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";
1614
private static final String HeapSnapshotScriptKey = "heapSnapshotScript";
1715
private static final String HeapSnapshotBlobKey = "heapSnapshotBlob";
1816
private static final String SnapshotFile = "snapshot.blob";
@@ -63,10 +61,6 @@ public static Object[] fromPackageJSON(File appDir)
6361
{
6462
result[4] = androidObject.getString(ProfilerOutputDirKey);
6563
}
66-
if(androidObject.has(EnableHeapSnapshotKey))
67-
{
68-
result[5] = androidObject.getBoolean(EnableHeapSnapshotKey);
69-
}
7064
}
7165
}
7266
catch (Exception e)
@@ -89,9 +83,7 @@ private static Object[] makeDefaultOptions()
8983
// a binary file containing an already saved snapshot
9084
"",
9185
// V8 profiler output directory
92-
"",
93-
// enable heapsnapshots extraction, false by default
94-
false
86+
""
9587
};
9688

9789
return result;

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ public void initRuntime() {
6464
} catch (IOException e1) {
6565
}
6666

67-
Object[] v8Config = V8Config.fromPackageJSON(appDir);
68-
6967
if (!skipAssetExtraction) {
7068
if(logger.isEnabled()) {
7169
logger.write("Extracting assets...");
@@ -79,20 +77,22 @@ public void initRuntime() {
7977
aE.extractAssets(app, "internal", outputDir, extractPolicy);
8078
aE.extractAssets(app, "metadata", outputDir, extractPolicy);
8179

82-
// at earlier point the package.json will not have been extracted, so we now fetch the real, non-default values from the file
83-
v8Config = V8Config.fromPackageJSON(appDir);
80+
// enable with flags?
81+
boolean shouldExtractSnapshots = true;
8482

85-
boolean shouldExtractSnapshots = (Boolean)v8Config[5];
83+
// will extract snapshot of the device appropriate architecture
8684
if(shouldExtractSnapshots) {
8785
if(logger.isEnabled()) {
8886
logger.write("Extracting snapshot blob");
8987
}
9088

91-
aE.extractAssets(app, "snapshots/" + Build.CPU_ABI + "/snapshot.blob", outputDir, extractPolicy);
89+
aE.extractAssets(app, "snapshots/" + Build.CPU_ABI, outputDir, extractPolicy);
9290
}
9391

9492
extractPolicy.setAssetsThumb(app);
9593
}
94+
95+
Object[] v8Config = V8Config.fromPackageJSON(appDir);
9696

9797
ClassLoader classLoader = app.getClassLoader();
9898
File dexDir = new File(rootDir, "code_cache/secondary-dexes");

0 commit comments

Comments
 (0)