44
55import android .app .Application ;
66import android .content .pm .PackageManager .NameNotFoundException ;
7+ import android .os .Build ;
78import android .os .Handler ;
89import android .os .Looper ;
910import android .util .Log ;
1011import 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 }
4440
@@ -49,76 +45,94 @@ public void initRuntime()
4945 }
5046
5147 System .loadLibrary ("NativeScript" );
52-
48+
5349 Logger logger = new LogcatLogger (app );
5450 Debugger debugger = new AndroidJsDebugger (app , logger );
55-
51+
5652 boolean showErrorIntent = hasErrorIntent ();
57- if (!showErrorIntent )
58- {
53+ if (!showErrorIntent ) {
5954 NativeScriptUncaughtExceptionHandler exHandler = new NativeScriptUncaughtExceptionHandler (logger , app );
6055
6156 Thread .setDefaultUncaughtExceptionHandler (exHandler );
62-
57+
6358 Async .Http .setApplicationContext (this .app );
64-
65- ExtractPolicy extractPolicy = new DefaultExtractPolicy (logger );
59+
60+ DefaultExtractPolicy extractPolicy = new DefaultExtractPolicy (logger );
6661 boolean skipAssetExtraction = Util .runPlugin (logger , app );
67- if (!skipAssetExtraction )
68- {
69- new AssetExtractor (null , logger ).extractAssets (app , extractPolicy );
70- }
71-
62+
7263 String appName = app .getPackageName ();
7364 File rootDir = new File (app .getApplicationInfo ().dataDir );
7465 File appDir = app .getFilesDir ();
75-
76- try
77- {
66+
67+ try {
7868 appDir = appDir .getCanonicalFile ();
69+ } catch (IOException e1 ) {
7970 }
80- catch (IOException e1 )
81- {
71+
72+ if (!skipAssetExtraction ) {
73+ if (logger .isEnabled ()) {
74+ logger .write ("Extracting assets..." );
75+ }
76+
77+ AssetExtractor aE = new AssetExtractor (null , logger );
78+
79+ String outputDir = app .getFilesDir ().getPath () + File .separator ;
80+
81+ aE .extractAssets (app , "app" , outputDir , extractPolicy );
82+ aE .extractAssets (app , "internal" , outputDir , extractPolicy );
83+ aE .extractAssets (app , "metadata" , outputDir , extractPolicy );
84+
85+ // enable with flags?
86+ boolean shouldExtractSnapshots = true ;
87+
88+ // will extract snapshot of the device appropriate architecture
89+ if (shouldExtractSnapshots ) {
90+ if (logger .isEnabled ()) {
91+ logger .write ("Extracting snapshot blob" );
92+ }
93+
94+ aE .extractAssets (app , "snapshots/" + Build .CPU_ABI , outputDir , extractPolicy );
95+ }
96+
97+ extractPolicy .setAssetsThumb (app );
8298 }
8399
100+ Object [] v8Config = V8Config .fromPackageJSON (appDir );
101+
84102 ClassLoader classLoader = app .getClassLoader ();
85103 File dexDir = new File (rootDir , "code_cache/secondary-dexes" );
86104 String dexThumb = null ;
87- try
88- {
105+ try {
89106 dexThumb = Util .getDexThumb (app );
90- }
91- catch (NameNotFoundException e )
92- {
93- if (logger .isEnabled ()) logger .write ("Error while getting current proxy thumb" );
107+ } catch (NameNotFoundException e ) {
108+ if (logger .isEnabled ())
109+ logger .write ("Error while getting current proxy thumb" );
94110 e .printStackTrace ();
95111 }
96112 ThreadScheduler workThreadScheduler = new WorkThreadScheduler (new Handler (Looper .getMainLooper ()));
97- Configuration config = new Configuration (workThreadScheduler , logger , debugger , appName , null , rootDir , appDir , classLoader , dexDir , dexThumb );
113+ Configuration config = new Configuration (workThreadScheduler , logger , debugger , appName , null , rootDir ,
114+ appDir , classLoader , dexDir , dexThumb , v8Config );
98115 Runtime runtime = new Runtime (config );
99-
116+
100117 exHandler .setRuntime (runtime );
101-
102- if (NativeScriptSyncService .isSyncEnabled (this .app ))
103- {
118+
119+ if (NativeScriptSyncService .isSyncEnabled (this .app )) {
104120 NativeScriptSyncService syncService = new NativeScriptSyncService (runtime , logger , this .app );
105121
106122 syncService .sync ();
107123 syncService .startServer ();
108124
109125 // preserve this instance as strong reference
110- // do not preserve in NativeScriptApplication field inorder to make the code more portable
126+ // do not preserve in NativeScriptApplication field inorder to
127+ // make the code more portable
111128 // @@@
112- //Runtime.getOrCreateJavaObjectID(syncService);
113- }
114- else
115- {
116- if (logger .isEnabled ())
117- {
129+ // Runtime.getOrCreateJavaObjectID(syncService);
130+ } else {
131+ if (logger .isEnabled ()) {
118132 logger .write ("NativeScript LiveSync is not enabled." );
119133 }
120134 }
121-
135+
122136 runtime .init ();
123137 runtime .runScript (new File (appDir , "internal/ts_helpers.js" ));
124138 try {
@@ -131,23 +145,6 @@ public void initRuntime()
131145 runtime .run ();
132146 }
133147 }
134-
135- /* public static boolean isDebuggableApp(Context context)
136- {
137- int flags;
138- try
139- {
140- flags = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).applicationInfo.flags;
141- }
142- catch (NameNotFoundException e)
143- {
144- flags = 0;
145- e.printStackTrace();
146- }
147148
148- boolean isDebuggableApp = ((flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0);
149- return isDebuggableApp;
150- }*/
151-
152149 private final String logTag = "MyApp" ;
153150}
0 commit comments