@nativescript/android 8.8.0-alpha.11 → 8.8.0-alpha.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/framework/app/build.gradle +10 -4
- package/framework/app/libs/runtime-libs/nativescript-optimized-with-inspector.aar +0 -0
- package/framework/app/libs/runtime-libs/nativescript-optimized.aar +0 -0
- package/framework/app/libs/runtime-libs/nativescript-regular.aar +0 -0
- package/framework/app/src/main/assets/internal/ts_helpers.js +3 -1
- package/framework/build-tools/android-metadata-generator.jar +0 -0
- package/framework/build-tools/dts-generator.jar +0 -0
- package/framework/build-tools/jsparser/js_parser.js +1 -1
- package/framework/build-tools/static-binding-generator.jar +0 -0
- package/framework/settings.gradle +7 -0
- package/package.json +1 -1
- package/framework/app/src/debug/java/com/tns/ErrorReport.java +0 -512
- package/framework/app/src/debug/java/com/tns/ErrorReportActivity.java +0 -52
- package/framework/app/src/debug/java/com/tns/NativeScriptSyncService.java +0 -346
- package/framework/app/src/debug/java/com/tns/NativeScriptSyncServiceSocketImpl.java +0 -448
- package/framework/app/src/debug/res/layout/error_activity.xml +0 -62
- package/framework/app/src/debug/res/layout/exception_tab.xml +0 -71
- package/framework/app/src/debug/res/layout/logcat_tab.xml +0 -71
- package/framework/app/src/main/java/com/tns/AndroidJsV8Inspector.java +0 -361
- package/framework/app/src/main/java/com/tns/DefaultExtractPolicy.java +0 -151
- package/framework/app/src/main/java/com/tns/EqualityComparator.java +0 -7
- package/framework/app/src/main/java/com/tns/LogcatLogger.java +0 -45
- package/framework/app/src/main/java/com/tns/NativeScriptUncaughtExceptionHandler.java +0 -72
- package/framework/app/src/main/java/com/tns/RuntimeHelper.java +0 -343
- package/framework/app/src/main/java/com/tns/Util.java +0 -105
- package/framework/app/src/main/java/com/tns/internal/AppBuilderCallback.java +0 -21
- package/framework/app/src/main/java/com/tns/internal/Plugin.java +0 -5
|
@@ -1,361 +0,0 @@
|
|
|
1
|
-
package com.tns;
|
|
2
|
-
|
|
3
|
-
import android.os.Handler;
|
|
4
|
-
import android.util.Log;
|
|
5
|
-
import android.util.Pair;
|
|
6
|
-
import android.webkit.MimeTypeMap;
|
|
7
|
-
|
|
8
|
-
import org.json.JSONArray;
|
|
9
|
-
import org.json.JSONException;
|
|
10
|
-
import org.json.JSONObject;
|
|
11
|
-
|
|
12
|
-
import java.io.File;
|
|
13
|
-
import java.io.IOException;
|
|
14
|
-
import java.lang.reflect.Array;
|
|
15
|
-
import java.util.ArrayList;
|
|
16
|
-
import java.util.LinkedList;
|
|
17
|
-
import java.util.List;
|
|
18
|
-
import java.util.Queue;
|
|
19
|
-
import java.util.concurrent.LinkedBlockingQueue;
|
|
20
|
-
import java.util.concurrent.atomic.AtomicBoolean;
|
|
21
|
-
|
|
22
|
-
import fi.iki.elonen.NanoHTTPD;
|
|
23
|
-
import fi.iki.elonen.NanoWSD;
|
|
24
|
-
|
|
25
|
-
class AndroidJsV8Inspector {
|
|
26
|
-
private JsV8InspectorServer server;
|
|
27
|
-
private static String ApplicationDir;
|
|
28
|
-
private String packageName;
|
|
29
|
-
|
|
30
|
-
protected native final void init();
|
|
31
|
-
|
|
32
|
-
protected native final void connect(Object connection);
|
|
33
|
-
|
|
34
|
-
private native void scheduleBreak();
|
|
35
|
-
|
|
36
|
-
protected static native void disconnect();
|
|
37
|
-
|
|
38
|
-
protected native final void dispatchMessage(String message);
|
|
39
|
-
|
|
40
|
-
private Handler mainHandler;
|
|
41
|
-
|
|
42
|
-
private final Object debugBrkLock;
|
|
43
|
-
|
|
44
|
-
private Logger currentRuntimeLogger;
|
|
45
|
-
|
|
46
|
-
private static AtomicBoolean ReadyToProcessMessages = new AtomicBoolean(false);
|
|
47
|
-
|
|
48
|
-
private LinkedBlockingQueue<String> inspectorMessages = new LinkedBlockingQueue<String>();
|
|
49
|
-
private LinkedBlockingQueue<String> pendingInspectorMessages = new LinkedBlockingQueue<String>();
|
|
50
|
-
|
|
51
|
-
AndroidJsV8Inspector(String filesDir, String packageName) {
|
|
52
|
-
ApplicationDir = filesDir;
|
|
53
|
-
this.packageName = packageName;
|
|
54
|
-
this.debugBrkLock = new Object();
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
public void start() throws IOException {
|
|
58
|
-
if (this.server == null) {
|
|
59
|
-
Runtime currentRuntime = Runtime.getCurrentRuntime();
|
|
60
|
-
|
|
61
|
-
mainHandler = currentRuntime.getHandler();
|
|
62
|
-
|
|
63
|
-
currentRuntimeLogger = currentRuntime.getLogger();
|
|
64
|
-
|
|
65
|
-
this.server = new JsV8InspectorServer(this.packageName + "-inspectorServer", currentRuntimeLogger);
|
|
66
|
-
this.server.start(-1);
|
|
67
|
-
|
|
68
|
-
if (currentRuntimeLogger.isEnabled()) {
|
|
69
|
-
Log.d("V8Inspector", "start debugger ThreadId:" + Thread.currentThread().getId());
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
init();
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
@RuntimeCallable
|
|
77
|
-
private static void sendToDevToolsConsole(Object connection, String message, String level) {
|
|
78
|
-
try {
|
|
79
|
-
JSONObject consoleMessage = new JSONObject();
|
|
80
|
-
|
|
81
|
-
JSONObject params = new JSONObject();
|
|
82
|
-
params.put("type", level);
|
|
83
|
-
params.put("executionContextId", 0);
|
|
84
|
-
params.put("timestamp", 0.000000000000000);
|
|
85
|
-
|
|
86
|
-
JSONArray args = new JSONArray();
|
|
87
|
-
args.put(message);
|
|
88
|
-
params.put("args", args);
|
|
89
|
-
|
|
90
|
-
consoleMessage.put("method", "Runtime.consoleAPICalled");
|
|
91
|
-
consoleMessage.put("params", params);
|
|
92
|
-
|
|
93
|
-
String sendingText = consoleMessage.toString();
|
|
94
|
-
AndroidJsV8Inspector.send(connection, sendingText);
|
|
95
|
-
|
|
96
|
-
} catch (JSONException | IOException e) {
|
|
97
|
-
if (com.tns.Runtime.isDebuggable()) {
|
|
98
|
-
e.printStackTrace();
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
@RuntimeCallable
|
|
104
|
-
private static void send(Object connection, String payload) throws IOException {
|
|
105
|
-
JsV8InspectorWebSocket socketConnection = (JsV8InspectorWebSocket) connection;
|
|
106
|
-
if (socketConnection.isOpen()) {
|
|
107
|
-
socketConnection.send(payload);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
@RuntimeCallable
|
|
112
|
-
private static String getInspectorMessage(Object connection) {
|
|
113
|
-
return ((JsV8InspectorWebSocket) connection).getInspectorMessage();
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
@RuntimeCallable
|
|
117
|
-
public static Pair<String, String>[] getPageResources() {
|
|
118
|
-
// necessary to align the data dir returned by context (emulator) and that used by the v8 inspector
|
|
119
|
-
if (ApplicationDir.startsWith("/data/user/0/")) {
|
|
120
|
-
ApplicationDir = ApplicationDir.replaceFirst("/data/user/0/", "/data/data/");
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
String dataDir = ApplicationDir;
|
|
124
|
-
File rootFilesDir = new File(dataDir, "app");
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
List<Pair<String, String>> resources = traverseResources(rootFilesDir);
|
|
128
|
-
|
|
129
|
-
@SuppressWarnings("unchecked")
|
|
130
|
-
Pair<String, String>[] result = resources.toArray((Pair<String, String>[]) Array.newInstance(resources.get(0).getClass(), resources.size()));
|
|
131
|
-
return result;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
private static List<Pair<String, String>> traverseResources(File dir) {
|
|
135
|
-
List<Pair<String, String>> resources = new ArrayList<>();
|
|
136
|
-
|
|
137
|
-
Queue<File> directories = new LinkedList<>();
|
|
138
|
-
directories.add(dir);
|
|
139
|
-
|
|
140
|
-
while (!directories.isEmpty()) {
|
|
141
|
-
File currentDir = directories.poll();
|
|
142
|
-
|
|
143
|
-
File[] files = currentDir.listFiles();
|
|
144
|
-
for (File file : files) {
|
|
145
|
-
if (file.isDirectory()) {
|
|
146
|
-
directories.add(file);
|
|
147
|
-
} else {
|
|
148
|
-
resources.add(new Pair<>("file://" + file.getAbsolutePath(), getMimeType(file.getAbsolutePath())));
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
return resources;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
private static String getMimeType(String url) {
|
|
157
|
-
String type = null;
|
|
158
|
-
String extension = MimeTypeMap.getFileExtensionFromUrl(url);
|
|
159
|
-
if (!extension.isEmpty()) {
|
|
160
|
-
type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
|
|
161
|
-
|
|
162
|
-
// getMimeType may sometime return incorrect results in the context of NativeScript
|
|
163
|
-
// e.g. `.ts` returns video/MP2TS
|
|
164
|
-
switch (extension) {
|
|
165
|
-
case "js":
|
|
166
|
-
type = "text/javascript";
|
|
167
|
-
break;
|
|
168
|
-
case "json":
|
|
169
|
-
type = "application/json";
|
|
170
|
-
break;
|
|
171
|
-
case "css":
|
|
172
|
-
type = "text/css";
|
|
173
|
-
break;
|
|
174
|
-
case "ts":
|
|
175
|
-
type = "text/typescript";
|
|
176
|
-
break;
|
|
177
|
-
// handle shared libraries so they are marked properly and don't appear in the sources tab
|
|
178
|
-
case "so":
|
|
179
|
-
type = "application/binary";
|
|
180
|
-
break;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
return type;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
// pause the main thread for 30 seconds (30 * 1000 ms)
|
|
188
|
-
// allowing the devtools frontend to establish connection with the inspector
|
|
189
|
-
protected void waitForDebugger(boolean shouldBreak) {
|
|
190
|
-
if (shouldBreak) {
|
|
191
|
-
synchronized (this.debugBrkLock) {
|
|
192
|
-
try {
|
|
193
|
-
this.debugBrkLock.wait(1000 * 30);
|
|
194
|
-
} catch (InterruptedException e) {
|
|
195
|
-
if (com.tns.Runtime.isDebuggable()) {
|
|
196
|
-
e.printStackTrace();
|
|
197
|
-
}
|
|
198
|
-
} finally {
|
|
199
|
-
AndroidJsV8Inspector.ReadyToProcessMessages.set(true);
|
|
200
|
-
this.processDebugBreak();
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
} else {
|
|
204
|
-
AndroidJsV8Inspector.ReadyToProcessMessages.set(true);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// process all messages coming from the frontend necessary to initialize the inspector backend
|
|
209
|
-
// schedule a debug line break at first convenience
|
|
210
|
-
private void processDebugBreak() {
|
|
211
|
-
processDebugBreakMessages();
|
|
212
|
-
scheduleBreak();
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
private void processDebugBreakMessages() {
|
|
216
|
-
while (!pendingInspectorMessages.isEmpty()) {
|
|
217
|
-
String inspectorMessage = pendingInspectorMessages.poll();
|
|
218
|
-
dispatchMessage(inspectorMessage);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
private class JsV8InspectorServer extends NanoWSD {
|
|
223
|
-
private Logger currentRuntimeLogger;
|
|
224
|
-
|
|
225
|
-
JsV8InspectorServer(String name, Logger runtimeLogger) {
|
|
226
|
-
super(name);
|
|
227
|
-
currentRuntimeLogger = runtimeLogger;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
@Override
|
|
231
|
-
protected Response serveHttp(IHTTPSession session) {
|
|
232
|
-
if (currentRuntimeLogger.isEnabled()) {
|
|
233
|
-
Log.d("{N}.v8-inspector", "http request for " + session.getUri());
|
|
234
|
-
}
|
|
235
|
-
return super.serveHttp(session);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
private JsV8InspectorWebSocket webSocket;
|
|
239
|
-
|
|
240
|
-
@Override
|
|
241
|
-
protected WebSocket openWebSocket(IHTTPSession handshake) {
|
|
242
|
-
// close the previous webSocket
|
|
243
|
-
if(this.webSocket != null) {
|
|
244
|
-
try {
|
|
245
|
-
this.webSocket.close(WebSocketFrame.CloseCode.NormalClosure, "New browser connection is open", false);
|
|
246
|
-
} catch (IOException ioException) {
|
|
247
|
-
if(this.webSocket.getState() != State.CLOSED) {
|
|
248
|
-
Log.e("{N}.v8-inspector", "Error closing previous connection", ioException);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
this.webSocket = new JsV8InspectorWebSocket(handshake, currentRuntimeLogger);
|
|
253
|
-
return this.webSocket;
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
private class JsV8InspectorWebSocket extends NanoWSD.WebSocket {
|
|
258
|
-
private Logger currentRuntimeLogger;
|
|
259
|
-
|
|
260
|
-
JsV8InspectorWebSocket(NanoHTTPD.IHTTPSession handshakeRequest, Logger runtimeLogger) {
|
|
261
|
-
super(handshakeRequest);
|
|
262
|
-
currentRuntimeLogger = runtimeLogger;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
@Override
|
|
266
|
-
protected void onOpen() {
|
|
267
|
-
if (currentRuntimeLogger.isEnabled()) {
|
|
268
|
-
Log.d("V8Inspector", "onOpen: ThreadID: " + Thread.currentThread().getId());
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
connect(JsV8InspectorWebSocket.this);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
@Override
|
|
275
|
-
protected void onClose(NanoWSD.WebSocketFrame.CloseCode code, String reason, boolean initiatedByRemote) {
|
|
276
|
-
if (currentRuntimeLogger.isEnabled()) {
|
|
277
|
-
Log.d("V8Inspector", "onClose");
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
mainHandler.post(new Runnable() {
|
|
281
|
-
@Override
|
|
282
|
-
public void run() {
|
|
283
|
-
if (currentRuntimeLogger.isEnabled()) {
|
|
284
|
-
Log.d("V8Inspector", "Disconnecting");
|
|
285
|
-
}
|
|
286
|
-
disconnect();
|
|
287
|
-
}
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
@Override
|
|
292
|
-
protected void onMessage(final NanoWSD.WebSocketFrame message) {
|
|
293
|
-
if (currentRuntimeLogger.isEnabled()) {
|
|
294
|
-
Log.d("V8Inspector", "To dbg backend: " + message.getTextPayload() + " ThreadId:" + Thread.currentThread().getId());
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
inspectorMessages.offer(message.getTextPayload());
|
|
298
|
-
|
|
299
|
-
if (!AndroidJsV8Inspector.ReadyToProcessMessages.get()) {
|
|
300
|
-
String nextMessage = inspectorMessages.poll();
|
|
301
|
-
while (nextMessage != null) {
|
|
302
|
-
pendingInspectorMessages.offer(nextMessage);
|
|
303
|
-
nextMessage = inspectorMessages.poll();
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
if (message.getTextPayload().contains("Debugger.enable")) {
|
|
307
|
-
synchronized (debugBrkLock) {
|
|
308
|
-
debugBrkLock.notify();
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
} else {
|
|
312
|
-
mainHandler.postAtFrontOfQueue(new Runnable() {
|
|
313
|
-
@Override
|
|
314
|
-
public void run() {
|
|
315
|
-
String nextMessage = inspectorMessages.poll();
|
|
316
|
-
while (nextMessage != null) {
|
|
317
|
-
dispatchMessage(nextMessage);
|
|
318
|
-
nextMessage = inspectorMessages.poll();
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
@Override
|
|
326
|
-
public void send(String payload) throws IOException {
|
|
327
|
-
if (currentRuntimeLogger.isEnabled()) {
|
|
328
|
-
Log.d("V8Inspector", "To dbg client: " + payload);
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
super.send(payload);
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
public String getInspectorMessage() {
|
|
335
|
-
try {
|
|
336
|
-
return inspectorMessages.take();
|
|
337
|
-
} catch (InterruptedException e) {
|
|
338
|
-
if (com.tns.Runtime.isDebuggable()) {
|
|
339
|
-
e.printStackTrace();
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
return null;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
@Override
|
|
347
|
-
protected void onPong(NanoWSD.WebSocketFrame pong) {
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
@Override
|
|
351
|
-
protected void onException(IOException exception) {
|
|
352
|
-
// when the chrome inspector is disconnected by closing the tab a "Broken pipe" exception is thrown which we don't need to log, only in verbose logging mode
|
|
353
|
-
if(exception != null && !exception.getMessage().equals("Broken pipe") || currentRuntimeLogger.isEnabled()) {
|
|
354
|
-
if (com.tns.Runtime.isDebuggable()) {
|
|
355
|
-
exception.printStackTrace();
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
disconnect();
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
}
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
package com.tns;
|
|
2
|
-
|
|
3
|
-
import java.io.BufferedReader;
|
|
4
|
-
import java.io.BufferedWriter;
|
|
5
|
-
import java.io.File;
|
|
6
|
-
import java.io.FileInputStream;
|
|
7
|
-
import java.io.FileNotFoundException;
|
|
8
|
-
import java.io.FileOutputStream;
|
|
9
|
-
import java.io.IOException;
|
|
10
|
-
import java.io.InputStreamReader;
|
|
11
|
-
import java.io.OutputStreamWriter;
|
|
12
|
-
|
|
13
|
-
import android.content.Context;
|
|
14
|
-
import android.content.pm.PackageInfo;
|
|
15
|
-
import android.content.pm.PackageManager;
|
|
16
|
-
import android.content.pm.PackageManager.NameNotFoundException;
|
|
17
|
-
|
|
18
|
-
import androidx.core.content.pm.PackageInfoCompat;
|
|
19
|
-
|
|
20
|
-
import com.tns.Logger;
|
|
21
|
-
import com.tns.ExtractPolicy;
|
|
22
|
-
import com.tns.FileExtractor;
|
|
23
|
-
|
|
24
|
-
public class DefaultExtractPolicy implements ExtractPolicy {
|
|
25
|
-
private final Logger logger;
|
|
26
|
-
|
|
27
|
-
private final static String ASSETS_THUMB_FILENAME = "assetsThumb";
|
|
28
|
-
|
|
29
|
-
public DefaultExtractPolicy(Logger logger) {
|
|
30
|
-
this.logger = logger;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
public boolean shouldExtract(Context context) {
|
|
34
|
-
String assetsThumbFilePath = getFilesDir(context) + File.separatorChar + ASSETS_THUMB_FILENAME;
|
|
35
|
-
String oldAssetsThumb = getCachedAssetsThumb(assetsThumbFilePath);
|
|
36
|
-
if (oldAssetsThumb == null) {
|
|
37
|
-
return true;
|
|
38
|
-
} else {
|
|
39
|
-
String currentThumb = getAssetsThumb(context);
|
|
40
|
-
|
|
41
|
-
if (currentThumb != null && !currentThumb.equals(oldAssetsThumb)) {
|
|
42
|
-
return true;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
public void setAssetsThumb(Context context) {
|
|
50
|
-
String assetsThumb = generateAssetsThumb(context);
|
|
51
|
-
if (assetsThumb != null) {
|
|
52
|
-
String assetsThumbFilePath = getFilesDir(context) + File.separatorChar + ASSETS_THUMB_FILENAME;
|
|
53
|
-
saveNewAssetsThumb(assetsThumb, assetsThumbFilePath);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
public boolean forceOverwrite() {
|
|
58
|
-
return true;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
public FileExtractor extractor() {
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
public String getAssetsThumb(Context context) {
|
|
66
|
-
return generateAssetsThumb(context);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
private String generateAssetsThumb(Context context) {
|
|
70
|
-
try {
|
|
71
|
-
PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
|
|
72
|
-
long code = PackageInfoCompat.getLongVersionCode(packageInfo);
|
|
73
|
-
long updateTime = packageInfo.lastUpdateTime;
|
|
74
|
-
return updateTime + "-" + code;
|
|
75
|
-
} catch (NameNotFoundException e) {
|
|
76
|
-
logger.write("Error while getting current assets thumb");
|
|
77
|
-
if (com.tns.Runtime.isDebuggable()) {
|
|
78
|
-
e.printStackTrace();
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return null;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
private String getCachedAssetsThumb(String assetsThumbFilePath) {
|
|
86
|
-
try {
|
|
87
|
-
File cachedThumbFile = new File(assetsThumbFilePath);
|
|
88
|
-
if (cachedThumbFile.exists()) {
|
|
89
|
-
FileInputStream in = new FileInputStream(cachedThumbFile);
|
|
90
|
-
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
|
|
91
|
-
String cachedThumb = reader.readLine();
|
|
92
|
-
reader.close();
|
|
93
|
-
in.close();
|
|
94
|
-
return cachedThumb;
|
|
95
|
-
}
|
|
96
|
-
} catch (FileNotFoundException e) {
|
|
97
|
-
logger.write("Error while getting current assets thumb");
|
|
98
|
-
if (com.tns.Runtime.isDebuggable()) {
|
|
99
|
-
e.printStackTrace();
|
|
100
|
-
}
|
|
101
|
-
} catch (IOException e) {
|
|
102
|
-
logger.write("Error while getting current asstes thumb");
|
|
103
|
-
if (com.tns.Runtime.isDebuggable()) {
|
|
104
|
-
e.printStackTrace();
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return null;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
private void saveNewAssetsThumb(String newThumb, String assetsThumbFile) {
|
|
112
|
-
File cachedThumbFile = new File(assetsThumbFile);
|
|
113
|
-
try {
|
|
114
|
-
FileOutputStream out = new FileOutputStream(cachedThumbFile, false);
|
|
115
|
-
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out));
|
|
116
|
-
try {
|
|
117
|
-
writer.write(newThumb);
|
|
118
|
-
writer.newLine();
|
|
119
|
-
writer.flush();
|
|
120
|
-
} finally {
|
|
121
|
-
writer.close();
|
|
122
|
-
out.close();
|
|
123
|
-
}
|
|
124
|
-
} catch (FileNotFoundException e) {
|
|
125
|
-
logger.write("Error while writing current assets thumb");
|
|
126
|
-
if (com.tns.Runtime.isDebuggable()) {
|
|
127
|
-
e.printStackTrace();
|
|
128
|
-
}
|
|
129
|
-
} catch (IOException e) {
|
|
130
|
-
logger.write("Error while writing current assets thumb");
|
|
131
|
-
if (com.tns.Runtime.isDebuggable()) {
|
|
132
|
-
e.printStackTrace();
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/*
|
|
138
|
-
Write assetsThumb file to a no-backup directory to prevent the thumb from being
|
|
139
|
-
backed up on devices of API Level 23 and up.
|
|
140
|
-
Devices Level 22 and lower don't support the Auto Backup feature,
|
|
141
|
-
so it is safe to keep the thumb in the /files directory
|
|
142
|
-
*/
|
|
143
|
-
private static String getFilesDir(Context context) {
|
|
144
|
-
if (android.os.Build.VERSION.SDK_INT >= /* 21 */ android.os.Build.VERSION_CODES.LOLLIPOP) {
|
|
145
|
-
return context.getNoBackupFilesDir().getPath();
|
|
146
|
-
} else {
|
|
147
|
-
return context.getFilesDir().getPath();
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
package com.tns;
|
|
2
|
-
|
|
3
|
-
import android.content.Context;
|
|
4
|
-
import android.util.Log;
|
|
5
|
-
|
|
6
|
-
public final class LogcatLogger implements Logger {
|
|
7
|
-
private final static String DEFAULT_LOG_TAG = "TNS.Java";
|
|
8
|
-
|
|
9
|
-
private boolean enabled;
|
|
10
|
-
|
|
11
|
-
public LogcatLogger(Context context) {
|
|
12
|
-
this.initLogging(context);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
public final boolean isEnabled() {
|
|
16
|
-
return enabled;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
public final void setEnabled(boolean isEnabled) {
|
|
20
|
-
enabled = isEnabled;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
public final void write(String msg) {
|
|
24
|
-
if (this.enabled) {
|
|
25
|
-
Log.d(DEFAULT_LOG_TAG, msg);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
public final void write(String tag, String msg) {
|
|
30
|
-
if (this.enabled) {
|
|
31
|
-
Log.d(tag, msg);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
private void initLogging(Context context) {
|
|
36
|
-
boolean isDebuggableApp = Util.isDebuggableApp(context);
|
|
37
|
-
if (isDebuggableApp) {
|
|
38
|
-
String verboseLoggingProp = Util.readSystemProperty("nativescript.verbose.logging");
|
|
39
|
-
|
|
40
|
-
if (Util.isPositive(verboseLoggingProp)) {
|
|
41
|
-
setEnabled(true);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
package com.tns;
|
|
2
|
-
|
|
3
|
-
import java.lang.Thread.UncaughtExceptionHandler;
|
|
4
|
-
import android.content.Context;
|
|
5
|
-
|
|
6
|
-
public class NativeScriptUncaughtExceptionHandler implements UncaughtExceptionHandler {
|
|
7
|
-
private final Context context;
|
|
8
|
-
|
|
9
|
-
private final UncaughtExceptionHandler defaultHandler;
|
|
10
|
-
|
|
11
|
-
private final Logger logger;
|
|
12
|
-
|
|
13
|
-
public NativeScriptUncaughtExceptionHandler(Logger logger, Context context) {
|
|
14
|
-
this.logger = logger;
|
|
15
|
-
this.context = context;
|
|
16
|
-
defaultHandler = Thread.getDefaultUncaughtExceptionHandler();
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
@Override
|
|
20
|
-
public void uncaughtException(Thread thread, Throwable ex) {
|
|
21
|
-
String currentThreadMessage = String.format("An uncaught Exception occurred on \"%s\" thread.\n%s\n", thread.getName(), ex.getMessage());
|
|
22
|
-
String stackTraceErrorMessage = Runtime.getStackTraceErrorMessage(ex);
|
|
23
|
-
String errorMessage = String.format("%s\nStackTrace:\n%s", currentThreadMessage, stackTraceErrorMessage);
|
|
24
|
-
|
|
25
|
-
if (Runtime.isInitialized()) {
|
|
26
|
-
try {
|
|
27
|
-
if (Util.isDebuggableApp(context)) {
|
|
28
|
-
System.err.println(errorMessage);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
Runtime runtime = Runtime.getCurrentRuntime();
|
|
32
|
-
|
|
33
|
-
if (runtime != null) {
|
|
34
|
-
runtime.passUncaughtExceptionToJs(ex, ex.getMessage(), stackTraceErrorMessage, Runtime.getJSStackTrace(ex));
|
|
35
|
-
}
|
|
36
|
-
} catch (Throwable t) {
|
|
37
|
-
if (Util.isDebuggableApp(context)) {
|
|
38
|
-
t.printStackTrace();
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (logger.isEnabled()) {
|
|
44
|
-
logger.write("Uncaught Exception Message=" + errorMessage);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
boolean res = false;
|
|
48
|
-
|
|
49
|
-
if (Util.isDebuggableApp(context)) {
|
|
50
|
-
try {
|
|
51
|
-
Class<?> ErrReport = null;
|
|
52
|
-
java.lang.reflect.Method startActivity = null;
|
|
53
|
-
|
|
54
|
-
ErrReport = Class.forName("com.tns.ErrorReport");
|
|
55
|
-
|
|
56
|
-
startActivity = ErrReport.getDeclaredMethod("startActivity", Context.class, String.class);
|
|
57
|
-
|
|
58
|
-
res = (Boolean) startActivity.invoke(null, context, errorMessage);
|
|
59
|
-
} catch (Exception e) {
|
|
60
|
-
android.util.Log.v("Error", errorMessage);
|
|
61
|
-
if (Util.isDebuggableApp(context)) {
|
|
62
|
-
e.printStackTrace();
|
|
63
|
-
};
|
|
64
|
-
android.util.Log.v("Application Error", "ErrorActivity default implementation not found. Reinstall android platform to fix.");
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (!res && defaultHandler != null) {
|
|
69
|
-
defaultHandler.uncaughtException(thread, ex);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|