diff --git a/CHANGELOG.md b/CHANGELOG.md index 84932b341..b14aa10eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - [Enable AndroidX and Jetifier(#1370)](https://github.com/NativeScript/android-runtime/issues/1370) - [Upgrade v8 to 7.5.288.22(#1387)](https://github.com/NativeScript/android-runtime/issues/1387) - [Upgrade android gradle plugin to the latest 3.4.1 version(#1390)](https://github.com/NativeScript/android-runtime/issues/1390) +- [Remove printStackTrace method calls from the source code(#1359)](https://github.com/NativeScript/android-runtime/issues/1359) ## Bug Fixes diff --git a/test-app/app/src/debug/java/com/tns/ErrorReport.java b/test-app/app/src/debug/java/com/tns/ErrorReport.java index dea7df9a7..32308042e 100644 --- a/test-app/app/src/debug/java/com/tns/ErrorReport.java +++ b/test-app/app/src/debug/java/com/tns/ErrorReport.java @@ -88,7 +88,9 @@ public static void verifyStoragePermissions(Activity activity) { checkSelfPermissionMethod = ActivityCompat.class.getMethod("checkSelfPermission", Context.class, String.class); } catch (NoSuchMethodException e) { // method wasn't found, so there is no need to handle permissions explicitly - e.printStackTrace(); + if (Util.isDebuggableApp(activity)) { + e.printStackTrace(); + } return; } @@ -104,7 +106,9 @@ public static void verifyStoragePermissions(Activity activity) { } } catch (Exception e) { Toast.makeText(activity, "Couldn't resolve permissions", Toast.LENGTH_LONG).show(); - e.printStackTrace(); + if (Util.isDebuggableApp(activity)) { + e.printStackTrace(); + } return; } } @@ -410,7 +414,9 @@ public void onClick(View v) { } catch (Exception e) { String err = "Could not write logcat report to sdcard. Make sure you have allowed access to external storage!"; Toast.makeText(activity, err, Toast.LENGTH_LONG).show(); - e.printStackTrace(); + if (Util.isDebuggableApp(container.getContext())) { + e.printStackTrace(); + } } } } diff --git a/test-app/app/src/debug/java/com/tns/ErrorReportActivity.java b/test-app/app/src/debug/java/com/tns/ErrorReportActivity.java index 3add3792a..eacc8b0fa 100644 --- a/test-app/app/src/debug/java/com/tns/ErrorReportActivity.java +++ b/test-app/app/src/debug/java/com/tns/ErrorReportActivity.java @@ -41,7 +41,9 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis resetCheckingForPermissions(); } catch (Exception e) { - e.printStackTrace(); + if (Util.isDebuggableApp(this)) { + e.printStackTrace(); + } Toast.makeText(this, "Couldn't resolve permissions", Toast.LENGTH_LONG).show(); resetCheckingForPermissions(); } diff --git a/test-app/app/src/debug/java/com/tns/NativeScriptSyncService.java b/test-app/app/src/debug/java/com/tns/NativeScriptSyncService.java index 743d29891..5778025fa 100644 --- a/test-app/app/src/debug/java/com/tns/NativeScriptSyncService.java +++ b/test-app/app/src/debug/java/com/tns/NativeScriptSyncService.java @@ -90,7 +90,9 @@ public void stop() { try { serverSocket.close(); } catch (IOException e) { - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } } @@ -104,7 +106,9 @@ public void run() { new Thread(commThread).start(); } } catch (IOException e) { - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } } } @@ -131,11 +135,15 @@ public void run() { try { output.write(1); } catch (IOException e) { - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } socket.close(); } catch (IOException e) { - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } } } @@ -153,7 +161,9 @@ public static boolean isSyncEnabled(Context context) { flags = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).applicationInfo.flags; shouldExecuteSync = ((flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0); } catch (NameNotFoundException e) { - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } return false; } @@ -309,11 +319,15 @@ private boolean copyFile(String sourceFile, String destinationFile) { } } catch (FileNotFoundException e) { logger.write("Error copying file " + sourceFile); - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } return false; } catch (IOException e) { logger.write("Error copying file " + sourceFile); - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } return false; } finally { try { diff --git a/test-app/app/src/debug/java/com/tns/NativeScriptSyncServiceSocketImpl.java b/test-app/app/src/debug/java/com/tns/NativeScriptSyncServiceSocketImpl.java index 61c6a0bc8..989a8a86e 100644 --- a/test-app/app/src/debug/java/com/tns/NativeScriptSyncServiceSocketImpl.java +++ b/test-app/app/src/debug/java/com/tns/NativeScriptSyncServiceSocketImpl.java @@ -48,7 +48,9 @@ public void stop() { try { deviceSystemSocket.close(); } catch (IOException e) { - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } } @@ -63,10 +65,14 @@ public void run() { liveSyncThread.start(); } } catch (IOException e) { - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } catch (java.security.NoSuchAlgorithmException e) { - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } } @@ -136,7 +142,9 @@ public void run() { } catch (IOException e) { logger.write(String.format("Error while LiveSyncing: Client socket might be closed!", e.toString())); - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } try { do { @@ -426,7 +434,9 @@ private void closeWithError(String message) { logger.write(message); this.livesyncSocket.close(); } catch (IOException e) { - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } } diff --git a/test-app/app/src/main/java/com/tns/AndroidJsV8Inspector.java b/test-app/app/src/main/java/com/tns/AndroidJsV8Inspector.java index d7bd77dd8..c10715f58 100644 --- a/test-app/app/src/main/java/com/tns/AndroidJsV8Inspector.java +++ b/test-app/app/src/main/java/com/tns/AndroidJsV8Inspector.java @@ -94,7 +94,9 @@ private static void sendToDevToolsConsole(Object connection, String message, Str AndroidJsV8Inspector.send(connection, sendingText); } catch (JSONException | IOException e) { - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } } @@ -190,7 +192,9 @@ protected void waitForDebugger(boolean shouldBreak) { try { this.debugBrkLock.wait(1000 * 30); } catch (InterruptedException e) { - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } finally { AndroidJsV8Inspector.ReadyToProcessMessages.set(true); this.processDebugBreak(); @@ -331,7 +335,9 @@ public String getInspectorMessage() { try { return inspectorMessages.take(); } catch (InterruptedException e) { - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } return null; @@ -345,7 +351,9 @@ protected void onPong(NanoWSD.WebSocketFrame pong) { protected void onException(IOException exception) { // 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 if(!exception.getMessage().equals("Broken pipe") || currentRuntimeLogger.isEnabled()) { - exception.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + exception.printStackTrace(); + } } disconnect(); } diff --git a/test-app/app/src/main/java/com/tns/DefaultExtractPolicy.java b/test-app/app/src/main/java/com/tns/DefaultExtractPolicy.java index 4d1f54406..b60345b56 100644 --- a/test-app/app/src/main/java/com/tns/DefaultExtractPolicy.java +++ b/test-app/app/src/main/java/com/tns/DefaultExtractPolicy.java @@ -74,7 +74,9 @@ private String generateAssetsThumb(Context context) { return updateTime + "-" + code; } catch (NameNotFoundException e) { logger.write("Error while getting current assets thumb"); - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } return null; @@ -93,10 +95,14 @@ private String getCachedAssetsThumb(String assetsThumbFilePath) { } } catch (FileNotFoundException e) { logger.write("Error while getting current assets thumb"); - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } catch (IOException e) { logger.write("Error while getting current asstes thumb"); - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } return null; @@ -117,10 +123,14 @@ private void saveNewAssetsThumb(String newThumb, String assetsThumbFile) { } } catch (FileNotFoundException e) { logger.write("Error while writing current assets thumb"); - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } catch (IOException e) { logger.write("Error while writing current assets thumb"); - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } } diff --git a/test-app/app/src/main/java/com/tns/NativeScriptUncaughtExceptionHandler.java b/test-app/app/src/main/java/com/tns/NativeScriptUncaughtExceptionHandler.java index a56a4cfd5..4e2b2f3e6 100644 --- a/test-app/app/src/main/java/com/tns/NativeScriptUncaughtExceptionHandler.java +++ b/test-app/app/src/main/java/com/tns/NativeScriptUncaughtExceptionHandler.java @@ -24,8 +24,9 @@ public void uncaughtException(Thread thread, Throwable ex) { if (Runtime.isInitialized()) { try { - // print this only in debug - System.err.println(errorMessage); + if (Util.isDebuggableApp(context)) { + ex.printStackTrace(); + } Runtime runtime = Runtime.getCurrentRuntime(); @@ -33,7 +34,9 @@ public void uncaughtException(Thread thread, Throwable ex) { runtime.passUncaughtExceptionToJs(ex, ex.getMessage(), stackTraceErrorMessage); } } catch (Throwable t) { - t.printStackTrace(); + if (Util.isDebuggableApp(context)) { + t.printStackTrace(); + } } } @@ -55,7 +58,9 @@ public void uncaughtException(Thread thread, Throwable ex) { res = (Boolean) startActivity.invoke(null, context, errorMessage); } catch (Exception e) { android.util.Log.v("Error", errorMessage); - e.printStackTrace(); + if (Util.isDebuggableApp(context)) { + e.printStackTrace(); + }; android.util.Log.v("Application Error", "ErrorActivity default implementation not found. Reinstall android platform to fix."); } } diff --git a/test-app/app/src/main/java/com/tns/RuntimeHelper.java b/test-app/app/src/main/java/com/tns/RuntimeHelper.java index b4c6be267..f843729cf 100644 --- a/test-app/app/src/main/java/com/tns/RuntimeHelper.java +++ b/test-app/app/src/main/java/com/tns/RuntimeHelper.java @@ -142,14 +142,18 @@ public static Runtime initRuntime(Context context) { if (logger.isEnabled()) { logger.write("Error while getting current proxy thumb"); } - e.printStackTrace(); + if (Util.isDebuggableApp(context)) { + e.printStackTrace(); + } } String nativeLibDir = null; try { nativeLibDir = context.getPackageManager().getApplicationInfo(appName, 0).nativeLibraryDir; } catch (NameNotFoundException e) { - e.printStackTrace(); + if (Util.isDebuggableApp(context)) { + e.printStackTrace(); + } } boolean isDebuggable = Util.isDebuggableApp(context); @@ -186,7 +190,9 @@ public static Runtime initRuntime(Context context) { v8Inspector.waitForDebugger(shouldBreak); } catch (IOException e) { - e.printStackTrace(); + if (Util.isDebuggableApp(context)) { + e.printStackTrace(); + } } // if app is in debuggable mode run livesync service @@ -213,7 +219,9 @@ public static Runtime initRuntime(Context context) { if (logger.isEnabled()) { logger.write("Cannot initialize application instance."); } - e.printStackTrace(); + if (Util.isDebuggableApp(context)) { + e.printStackTrace(); + } } if (appConfig.handleTimeZoneChanges()) { @@ -320,15 +328,25 @@ public static void initLiveSync(Runtime runtime, Logger logger, Context context) Method startServerMethod = NativeScriptSyncService.getMethod("startServer"); startServerMethod.invoke(syncService); } catch (ClassNotFoundException e) { - e.printStackTrace(); + if (Util.isDebuggableApp(context)) { + e.printStackTrace(); + } } catch (NoSuchMethodException e) { - e.printStackTrace(); + if (Util.isDebuggableApp(context)) { + e.printStackTrace(); + } } catch (IllegalAccessException e) { - e.printStackTrace(); + if (Util.isDebuggableApp(context)) { + e.printStackTrace(); + } } catch (InvocationTargetException e) { - e.printStackTrace(); + if (Util.isDebuggableApp(context)) { + e.printStackTrace(); + } } catch (InstantiationException e) { - e.printStackTrace(); + if (Util.isDebuggableApp(context)) { + e.printStackTrace(); + } } } diff --git a/test-app/app/src/main/java/com/tns/Util.java b/test-app/app/src/main/java/com/tns/Util.java index d2a1d1d9d..250f2dfd6 100644 --- a/test-app/app/src/main/java/com/tns/Util.java +++ b/test-app/app/src/main/java/com/tns/Util.java @@ -10,6 +10,7 @@ import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.os.Bundle; +import android.util.Log; import androidx.core.content.pm.PackageInfoCompat; @@ -30,7 +31,9 @@ public static boolean isDebuggableApp(Context context) { flags = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).applicationInfo.flags; } catch (NameNotFoundException e) { flags = 0; - e.printStackTrace(); + if (Util.isDebuggableApp(context)) { + e.printStackTrace(); + } } boolean isDebuggableApp = ((flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0); @@ -47,7 +50,7 @@ static boolean runPlugin(Logger logger, Context context) { pluginClassName = metadataBundle.getString("com.tns.internal.Plugin"); } } catch (Exception e) { - if (logger.isEnabled()) { + if (Util.isDebuggableApp(context) && logger.isEnabled()) { e.printStackTrace(); } } @@ -57,7 +60,7 @@ static boolean runPlugin(Logger logger, Context context) { Plugin p = (Plugin) liveSyncPluginClass.newInstance(); success = p.execute(context); } catch (Exception e) { - if (logger.isEnabled()) { + if (Util.isDebuggableApp(context) && logger.isEnabled()) { e.printStackTrace(); } } diff --git a/test-app/build-tools/android-dts-generator b/test-app/build-tools/android-dts-generator index edc8465dc..cce79ede4 160000 --- a/test-app/build-tools/android-dts-generator +++ b/test-app/build-tools/android-dts-generator @@ -1 +1 @@ -Subproject commit edc8465dc5923118ff625b41bf6b812891d3a9f3 +Subproject commit cce79ede41dee84aee7e967dc5326a0e2d00f359 diff --git a/test-app/runtime-binding-generator/src/main/java/com/tns/bindings/Dump.java b/test-app/runtime-binding-generator/src/main/java/com/tns/bindings/Dump.java index ec874a6d5..4a11a3931 100644 --- a/test-app/runtime-binding-generator/src/main/java/com/tns/bindings/Dump.java +++ b/test-app/runtime-binding-generator/src/main/java/com/tns/bindings/Dump.java @@ -412,7 +412,9 @@ private void generateCtors(ClassVisitor cv, ClassDescriptor classTo, MethodDescr generateCtor(cv, classTo, defaultCtor, classSignature, tnsClassSignature, false); } catch (Exception e) { // TODO Auto-generated catch block - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } } else { for (MethodDescriptor ctor : ctors) { diff --git a/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/ApplicationReader.java b/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/ApplicationReader.java index eaf2405ba..aeff58275 100644 --- a/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/ApplicationReader.java +++ b/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/ApplicationReader.java @@ -222,9 +222,13 @@ public ApplicationReader(final int api, final byte[] byteCode, final int startOf try { dexFile.parse(this.byteCode); } catch (IllegalArgumentException e) { - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } catch (IOException e) { - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } } @@ -295,7 +299,9 @@ private static byte[] readApplication(final InputStream inputStream) throws IOEx buffer.flush(); result = buffer.toByteArray(); } catch (IOException e) { - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } finally { if (buffer != null) { buffer.close(); @@ -986,7 +992,9 @@ private Object interpretEncodedValue(int valueType, int valueArg) { try { throw new Exception("Unknown value format : 0x" + Integer.toHexString(valueType)); } catch (Exception e) { - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } } @@ -1136,7 +1144,9 @@ private Object decodeEncodedArray() { try { throw new Exception("Unhandled value format : " + Integer.toHexString(valueType)); } catch (Exception e) { - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } return null; } diff --git a/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/ApplicationWriter.java b/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/ApplicationWriter.java index 1d3bbe5f0..8150f356a 100644 --- a/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/ApplicationWriter.java +++ b/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/ApplicationWriter.java @@ -503,7 +503,9 @@ private void generateDexFile() { try { throw new Exception("Data Size isn't a multiple of (uint)."); } catch (Exception e) { - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } } out.putInt(dataSize, dataSizeOffset); @@ -534,7 +536,9 @@ private void addSHA1Signature() { try { sha = MessageDigest.getInstance("SHA-1"); } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } if (sha != null) { @@ -547,7 +551,9 @@ private void addSHA1Signature() { try { throw new Exception("SHA-1 digest has an unexpected size : " + digest.length); } catch (Exception e) { - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } } } diff --git a/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/MethodWriter.java b/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/MethodWriter.java index 22d18c704..420ec7531 100644 --- a/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/MethodWriter.java +++ b/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/MethodWriter.java @@ -904,7 +904,9 @@ private void checkAndCorrectLabelReferences() { try { throw new Exception("Opcode error : 0x" + Integer.toHexString(opcode)); } catch (Exception e) { - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } } @@ -939,7 +941,9 @@ private void checkAndCorrectLabelReferences() { try { throw new IllegalArgumentException("Instruction Range extension unhandled. Opcode : 0x" + Integer.toHexString(opcode)); } catch (Exception e) { - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } } } diff --git a/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/encodedValue/EncodedValueFactory.java b/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/encodedValue/EncodedValueFactory.java index 5ac9fc16e..820f92ab1 100644 --- a/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/encodedValue/EncodedValueFactory.java +++ b/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/encodedValue/EncodedValueFactory.java @@ -116,7 +116,9 @@ public static EncodedValue getEncodedValue(Object value, int type) { try { throw new Exception("Unknown type for this value."); } catch (Exception e) { - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } } @@ -250,7 +252,9 @@ else if (value instanceof int[]) { try { throw new Exception("Unable to find the type of this Value."); } catch (Exception e) { - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } return null; diff --git a/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/encodedValue/EncodedValueUtil.java b/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/encodedValue/EncodedValueUtil.java index 1448f86a1..02dcc8abc 100644 --- a/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/encodedValue/EncodedValueUtil.java +++ b/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/encodedValue/EncodedValueUtil.java @@ -228,7 +228,9 @@ public static int getTypeFromDescriptor(String desc) { try { throw new Exception("Unknown descriptor to convert: " + desc); } catch (Exception e) { - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } } diff --git a/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/instruction/InstructionFormat35C.java b/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/instruction/InstructionFormat35C.java index 03eaa4de0..6c41acd59 100644 --- a/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/instruction/InstructionFormat35C.java +++ b/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/instruction/InstructionFormat35C.java @@ -113,7 +113,9 @@ public static int[] getRegisters(IDalvikValueReader reader, int opcode) { try { throw new Exception("Abnormal arguments number : " + nbRegisters); } catch (Exception e) { - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } } } @@ -183,7 +185,9 @@ public void write(ByteVector out, ConstantPool constantPool) { try { throw new Exception("Abnormal arguments number : " + nbRegisters); } catch (Exception e) { - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } } int mask=0; diff --git a/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/structureWriter/AnnotationSetRefList.java b/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/structureWriter/AnnotationSetRefList.java index efebd3f00..62464eff1 100644 --- a/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/structureWriter/AnnotationSetRefList.java +++ b/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/structureWriter/AnnotationSetRefList.java @@ -101,7 +101,9 @@ public void addAnnotationItem(int parameterIndex, AnnotationItem annotationItem) try { throw new Exception("Annotation Parameter index >= Parameter count of this method."); } catch (Exception e) { - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } } diff --git a/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/structureWriter/CodeItem.java b/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/structureWriter/CodeItem.java index 0e3d86a7b..472ab5ba4 100644 --- a/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/structureWriter/CodeItem.java +++ b/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/structureWriter/CodeItem.java @@ -480,7 +480,9 @@ public void mapResolvedIndexesByteCode(ByteVector out, int offsetByteCode) { try { throw new Exception("Unknown Index type."); } catch (Exception e) { - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } } diff --git a/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/structureWriter/ConstantPool.java b/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/structureWriter/ConstantPool.java index 3ba2b39e7..f37009996 100644 --- a/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/structureWriter/ConstantPool.java +++ b/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/structureWriter/ConstantPool.java @@ -1082,7 +1082,9 @@ private void sortClasses() { try { throw new Exception("Sorted Classes list doesn't match the original list !"); } catch (Exception e) { - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } } } diff --git a/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/structureWriter/DebugInfoItem.java b/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/structureWriter/DebugInfoItem.java index ae240b434..dbac37484 100644 --- a/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/structureWriter/DebugInfoItem.java +++ b/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/structureWriter/DebugInfoItem.java @@ -301,7 +301,9 @@ public void initializeDebugInfoItem(String[] parameters, CodeItem codeItem, List try { throw new IllegalArgumentException("Unknown Local Variable type."); } catch (Exception e) { - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } } } diff --git a/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/structureWriter/TryCatch.java b/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/structureWriter/TryCatch.java index 08e4b764a..a654866dd 100644 --- a/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/structureWriter/TryCatch.java +++ b/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/structureWriter/TryCatch.java @@ -88,7 +88,9 @@ public void addExceptionHandler(ExceptionHandler exceptionHandler) { try { throw new Exception("A Try/Catch can't support more than one CatchAll."); } catch (Exception e) { - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } } else { catchAllHandler = exceptionHandler.getHandler(); diff --git a/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/util/AsmDexPrinter.java b/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/util/AsmDexPrinter.java index 7d805307b..30102f1c3 100644 --- a/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/util/AsmDexPrinter.java +++ b/test-app/runtime-binding-generator/src/main/java/org/ow2/asmdex/util/AsmDexPrinter.java @@ -317,7 +317,9 @@ else if (cst instanceof Byte[]) { try { throw new Exception ("Unhandled constant type."); } catch (Exception e) { - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } } diff --git a/test-app/runtime/src/main/java/com/tns/AppConfig.java b/test-app/runtime/src/main/java/com/tns/AppConfig.java index 1b6dc5cec..435193b53 100644 --- a/test-app/runtime/src/main/java/com/tns/AppConfig.java +++ b/test-app/runtime/src/main/java/com/tns/AppConfig.java @@ -104,8 +104,10 @@ public AppConfig(File appDir) { MarkingMode markingMode = MarkingMode.valueOf(markingModeString); values[KnownKeys.MarkingMode.ordinal()] = markingMode; } catch (Exception e) { - e.printStackTrace(); - Log.v("JS", "Failed to parse marking mode. The default " + ((MarkingMode)KnownKeys.MarkingMode.getDefaultValue()).name() + " will be used."); + Log.e("JS", String.format("Failed to parse marking mode: %s. The default %s will be used!", e.getMessage(), ((MarkingMode)KnownKeys.MarkingMode.getDefaultValue()).name())); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } } if (androidObject.has(KnownKeys.HandleTimeZoneChanges.getName())) { @@ -123,7 +125,9 @@ public AppConfig(File appDir) { } } } catch (Exception e) { - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } } diff --git a/test-app/runtime/src/main/java/com/tns/DexFactory.java b/test-app/runtime/src/main/java/com/tns/DexFactory.java index 7ba48edd8..48322d6f0 100644 --- a/test-app/runtime/src/main/java/com/tns/DexFactory.java +++ b/test-app/runtime/src/main/java/com/tns/DexFactory.java @@ -1,5 +1,7 @@ package com.tns; +import android.util.Log; + import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; @@ -173,7 +175,10 @@ public Class resolveClass(String baseClassName, String name, String className result = df.loadClass(desiredDexClassName, classLoader); } } catch (IOException e) { - e.printStackTrace(); + Log.w("JS", String.format("Error resolving class %s: %s. Fall back to DexClassLoader.")); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } // fall back to DexClassLoader DexClassLoader dexClassLoader = new DexClassLoader(jarFilePath, this.odexDir.getAbsolutePath(), null, classLoader); result = dexClassLoader.loadClass(fullClassName); @@ -317,11 +322,15 @@ private void saveNewDexThumb(String newDexThumb, File dexDir) { out.close(); } } catch (FileNotFoundException e) { - logger.write("Error while writting current proxy thumb"); - e.printStackTrace(); + Log.w("JS", String.format("Error while writing current proxy thumb: %s", e.getMessage())); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } catch (IOException e) { - logger.write("Error while writting current proxy thumb"); - e.printStackTrace(); + Log.w("JS", String.format("Error while writing current proxy thumb: %s", e.getMessage())); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } } @@ -366,11 +375,15 @@ private String getCachedProxyThumb(File proxyDir) { return cachedThumb; } } catch (FileNotFoundException e) { - logger.write("Error while getting current proxy thumb"); - e.printStackTrace(); + Log.w("JS", String.format("Error while writing current proxy thumb: %s", e.getMessage())); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } catch (IOException e) { - logger.write("Error while getting current proxy thumb"); - e.printStackTrace(); + Log.w("JS", String.format("Error while writing current proxy thumb: %s", e.getMessage())); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } return null; diff --git a/test-app/runtime/src/main/java/com/tns/GcListener.java b/test-app/runtime/src/main/java/com/tns/GcListener.java index e45558e83..161fe57e5 100644 --- a/test-app/runtime/src/main/java/com/tns/GcListener.java +++ b/test-app/runtime/src/main/java/com/tns/GcListener.java @@ -38,7 +38,9 @@ public void run() { lastUpdateTime = currentUpdateTime; } } catch (InterruptedException e) { - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } } } @@ -72,7 +74,9 @@ public void run() { } Thread.sleep(timeInterval); } catch (InterruptedException e) { - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } } } diff --git a/test-app/runtime/src/main/java/com/tns/Module.java b/test-app/runtime/src/main/java/com/tns/Module.java index a8a7b19d9..912086414 100644 --- a/test-app/runtime/src/main/java/com/tns/Module.java +++ b/test-app/runtime/src/main/java/com/tns/Module.java @@ -1,6 +1,7 @@ package com.tns; import android.text.TextUtils; +import android.util.Log; import java.io.File; import java.io.IOException; @@ -55,7 +56,9 @@ private static String resolvePath(String path, String baseDir) { file = resolvePathHelper(path, baseDir); } catch (IOException e) { //probably cache failed because of getCanonicalPath - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } String resolvedPath; @@ -63,7 +66,9 @@ private static String resolvePath(String path, String baseDir) { try { resolvedPath = file.getCanonicalPath(); } catch (IOException e) { - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } resolvedPath = file.getAbsolutePath(); } @@ -310,7 +315,9 @@ static String bootstrapApp() { } catch (NativeScriptException ex) { throw new NativeScriptException(notFoundMessage, ex); } catch (IOException e) { - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } if (bootstrapFile == null) { @@ -320,7 +327,9 @@ static String bootstrapApp() { } catch (NativeScriptException ex) { throw new NativeScriptException(notFoundMessage, ex); } catch (IOException e) { - e.printStackTrace(); + if (com.tns.Runtime.isDebuggable()) { + e.printStackTrace(); + } } } diff --git a/test-app/runtime/src/main/java/com/tns/Runtime.java b/test-app/runtime/src/main/java/com/tns/Runtime.java index 76c028699..e60e68a61 100644 --- a/test-app/runtime/src/main/java/com/tns/Runtime.java +++ b/test-app/runtime/src/main/java/com/tns/Runtime.java @@ -234,6 +234,15 @@ public static Runtime getCurrentRuntime() { return runtime; } + public static boolean isDebuggable() { + Runtime runtime = com.tns.Runtime.getCurrentRuntime(); + if(runtime != null) { + return runtime.config.isDebuggable; + } else { + return false; + } + } + private static Runtime getObjectRuntime(Object object) { Runtime runtime = null;