SDL_Android/SmartDeviceLinkAndroidProxy - added the correct version of the proxy
[profile/ivi/smartdevicelink.git] / SDL_Android / SmartDeviceLinkProxyAndroid / src / com / smartdevicelink / util / DebugTool.java
index f8e0001..9321155 100755 (executable)
-//
-// Copyright (c) 2013 Ford Motor Company
-//
-package com.smartdevicelink.util;
-
-import java.util.Vector;
-
-import android.util.Log;
-
-import com.smartdevicelink.exception.SmartDeviceLinkException;
-import com.smartdevicelink.proxy.Version;
-import com.smartdevicelink.transport.SiphonServer;
-
-public class DebugTool {
-       
-       public static final String TAG = "SmartDeviceLinkProxy";
-
-       private static boolean isErrorEnabled = false;
-       private static boolean isWarningEnabled = false;
-       private static boolean isInfoEnabled = false;
-       
-       public static void enableDebugTool() {
-               isErrorEnabled = true;
-               isWarningEnabled = true;
-               isInfoEnabled = true;
-       }
-
-       public static void disableDebugTool() {
-               isErrorEnabled = false;
-               isWarningEnabled = false;
-               isInfoEnabled = false;
-       }
-       
-       private static String prependProxyVersionNumberToString(String string) {
-               if (Version.VERSION != null && string != null) {
-                       string = Version.VERSION + ": " + string;
-               }
-               
-               return string;
-       }
-
-       public static void logError(String msg) {
-               
-               Boolean wasWritten = false;
-               
-               msg = prependProxyVersionNumberToString(msg);
-               
-               wasWritten = logToSiphon(msg);
-               
-               if (isErrorEnabled && !wasWritten) {
-                       NativeLogTool.logError(TAG, msg);
-               }
-       }
-
-       public static void logError(String msg, Throwable ex) {
-               Boolean wasWritten = false;
-               
-               msg = prependProxyVersionNumberToString(msg);
-               
-               if (ex != null) {
-                       wasWritten = logToSiphon(msg + " Exception String: " + ex.toString());
-               } else {
-                       wasWritten = logToSiphon(msg);
-               }
-               
-               if (isErrorEnabled && !wasWritten) {
-                       NativeLogTool.logError(TAG, msg, ex);
-               }
-       }
-       
-       public static void logWarning(String msg) {
-               Boolean wasWritten = false;
-               
-               msg = prependProxyVersionNumberToString(msg);
-               
-               wasWritten = logToSiphon(msg);
-               
-               if (isWarningEnabled && !wasWritten) {
-                       NativeLogTool.logWarning(TAG, msg);
-               }
-       }
-
-       public static void logInfo(String msg) {
-               Boolean wasWritten = false;
-               
-               msg = prependProxyVersionNumberToString(msg);
-               
-               wasWritten = logToSiphon(msg);
-               
-               if (isInfoEnabled && !wasWritten) {
-                       NativeLogTool.logInfo(TAG, msg);
-               }
-       }
-       
-       protected static Boolean logToSiphon(String msg) {
-               // Initialize the SiphonServer, will be ignored if already initialized
-               SiphonServer.init();
-               
-               // Write to the SiphonServer
-               return SiphonServer.sendSiphonLogData(msg);
-       }
-
-       protected static String getLine(Throwable ex) {
-               if (ex == null) { return null; }
-               String toPrint = ex.toString() + " :" + ex.getMessage();
-               for (int i=0; i<ex.getStackTrace().length; i++) {
-                       StackTraceElement elem = ex.getStackTrace()[i];
-                       toPrint += "\n  " + elem.toString();
-               }
-               
-               if (ex instanceof SmartDeviceLinkException) {
-                       SmartDeviceLinkException SmartDeviceLinkEx = (SmartDeviceLinkException) ex;
-                       if (SmartDeviceLinkEx.getInnerException() != null && SmartDeviceLinkEx != SmartDeviceLinkEx.getInnerException()) {
-                               toPrint += "\n  nested:\n";
-                               toPrint += getLine(SmartDeviceLinkEx.getInnerException());
-                       }
-               }
-               
-               return toPrint;
-       }
-
-
-       protected static Vector<IConsole> consoleListenerList = new Vector<IConsole>();
-
-       protected final static boolean isTransportEnabled = false;
-       protected final static boolean isRPCEnabled = false;
-
-       public static void addConsole(IConsole console) {
-               synchronized(consoleListenerList) {
-                       consoleListenerList.addElement(console);
-               }
-       }
-
-       public static void removeConsole(IConsole console) {
-               synchronized(consoleListenerList) {
-                       consoleListenerList.removeElement(console);
-               }
-       }
-
-       public static void clearConsoles() {
-               synchronized(consoleListenerList) {
-                       consoleListenerList.removeAllElements();
-               }
-       }
-       
-       public static void logTransport(String msg) {
-               if (isTransportEnabled) {
-                       Log.d(TAG, msg);
-                       logInfoToConsole(msg);
-               }
-       }
-
-       public static void logRPCSend(String rpcMsg) {
-               if (isRPCEnabled) {
-                       Log.d(TAG, "Sending RPC message: " + rpcMsg);
-                       logRPCSendToConsole(rpcMsg);
-               }
-       }
-
-       public static void logRPCReceive(String rpcMsg) {
-               if (isRPCEnabled) {
-                       Log.d(TAG, "Received RPC message: " + rpcMsg);
-                       logRPCSendToConsole(rpcMsg);
-               }
-       }
-
-       protected static void logInfoToConsole(String msg) {
-               Vector<IConsole> localList;
-               synchronized(consoleListenerList) {
-                       localList = (Vector<IConsole>) consoleListenerList.clone();
-               }
-               
-               for (int i = 0; i < localList.size(); i++) {
-                       IConsole consoleListener = (IConsole) localList.elementAt(i);
-                       try {
-                               consoleListener.logInfo(msg);
-                       } catch (Exception ex) {
-                               Log.e(TAG, "Failure propagating logInfo: " + ex.toString(), ex);
-                       } // end-catch
-               }
-       }
-       
-       protected static void logErrorToConsole(String msg) {
-               Vector<IConsole> localList;
-               synchronized(consoleListenerList) {
-                       localList = (Vector<IConsole>) consoleListenerList.clone();
-               }
-               for (int i = 0; i < localList.size(); i++) {
-                       IConsole consoleListener = (IConsole) localList.elementAt(i);
-                       try {
-                               consoleListener.logError(msg);
-                       } catch (Exception ex) {
-                               Log.e(TAG, "Failure propagating logError: " + ex.toString(), ex);
-                       } // end-catch
-               }
-       }
-       
-       protected static void logErrorToConsole(String msg, Throwable e) {
-               Vector<IConsole> localList;
-               synchronized(consoleListenerList) {
-                       localList = (Vector<IConsole>) consoleListenerList.clone();
-               }
-               
-               for (int i = 0; i < localList.size(); i++) {
-                       IConsole consoleListener = (IConsole) localList.elementAt(i);
-                       try {
-                               consoleListener.logError(msg, e);
-                       } catch (Exception ex) {
-                               Log.e(TAG, "Failure propagating logError: " + ex.toString(), ex);
-                       } // end-catch
-               }
-       }
-       
-       protected static void logRPCSendToConsole(String msg) {
-               Vector<IConsole> localList;
-               synchronized(consoleListenerList) {
-                       localList = (Vector<IConsole>) consoleListenerList.clone();
-               }
-               
-               for (int i = 0; i < localList.size(); i++) {
-                       IConsole consoleListener = (IConsole) localList.elementAt(i);
-                       try {
-                               consoleListener.logRPCSend(msg);
-                       } catch (Exception ex) {
-                               Log.e(TAG, "Failure propagating logRPCSend: " + ex.toString(), ex);
-                       } // end-catch
-               }
-       }
-       
-       protected static void logRPCReceiveToConsole(String msg) {
-               Vector<IConsole> localList;
-               synchronized(consoleListenerList) {
-                       localList = (Vector<IConsole>) consoleListenerList.clone();
-               }
-               
-               for (int i = 0; i < localList.size(); i++) {
-                       IConsole consoleListener = (IConsole) localList.elementAt(i);
-                       try {
-                               consoleListener.logRPCReceive(msg);
-                       } catch (Exception ex) {
-                               Log.e(TAG, "Failure propagating logRPCReceive: " + ex.toString(), ex);
-                       } // end-catch
-               }
-       }
-}
+package com.smartdevicelink.util;\r
+\r
+import java.util.Vector;\r
+\r
+import android.util.Log;\r
+\r
+import com.smartdevicelink.exception.SmartDeviceLinkException;\r
+import com.smartdevicelink.proxy.Version;\r
+import com.smartdevicelink.transport.SiphonServer;\r
+\r
+public class DebugTool {\r
+       \r
+\r
+       public static final String TAG = "SmartDeviceLinkProxy";\r
+\r
+       private static boolean isErrorEnabled = false;\r
+       private static boolean isWarningEnabled = false;\r
+       private static boolean isInfoEnabled = false;\r
+       \r
+       public static void enableDebugTool() {\r
+               isErrorEnabled = true;\r
+               isWarningEnabled = true;\r
+               isInfoEnabled = true;\r
+       }\r
+\r
+       public static void disableDebugTool() {\r
+               isErrorEnabled = true;\r
+               isWarningEnabled = false;\r
+               isInfoEnabled = false;\r
+       }\r
+       \r
+       public static boolean isDebugEnabled() \r
+       {\r
+               if (isWarningEnabled && isInfoEnabled) return true;\r
+               \r
+               return false;           \r
+       }\r
+       \r
+       private static String prependProxyVersionNumberToString(String string) {\r
+               if (Version.VERSION != null && string != null) {\r
+                       string = Version.VERSION + ": " + string;\r
+               }\r
+               \r
+               return string;\r
+       }\r
+\r
+       public static void logError(String msg) {\r
+               \r
+               Boolean wasWritten = false;\r
+               \r
+               msg = prependProxyVersionNumberToString(msg);\r
+               \r
+               wasWritten = logToSiphon(msg);\r
+               \r
+               if (isErrorEnabled && !wasWritten) {\r
+                       NativeLogTool.logError(TAG, msg);\r
+               }\r
+       }\r
+\r
+       public static void logError(String msg, Throwable ex) {\r
+               Boolean wasWritten = false;\r
+               \r
+               msg = prependProxyVersionNumberToString(msg);\r
+               \r
+               if (ex != null) {\r
+                       wasWritten = logToSiphon(msg + " Exception String: " + ex.toString());\r
+               } else {\r
+                       wasWritten = logToSiphon(msg);\r
+               }\r
+               \r
+               if (isErrorEnabled && !wasWritten) {\r
+                       NativeLogTool.logError(TAG, msg, ex);\r
+               }\r
+       }\r
+       \r
+       public static void logWarning(String msg) {\r
+               Boolean wasWritten = false;\r
+               \r
+               msg = prependProxyVersionNumberToString(msg);\r
+               \r
+               wasWritten = logToSiphon(msg);\r
+               \r
+               if (isWarningEnabled && !wasWritten) {\r
+                       NativeLogTool.logWarning(TAG, msg);\r
+               }\r
+       }\r
+\r
+       public static void logInfo(String msg) {\r
+               Boolean wasWritten = false;\r
+               \r
+               msg = prependProxyVersionNumberToString(msg);\r
+               \r
+               wasWritten = logToSiphon(msg);\r
+               \r
+               if (isInfoEnabled && !wasWritten) {\r
+                       NativeLogTool.logInfo(TAG, msg);\r
+               }\r
+       }\r
+\r
+       public static void logInfo(String msg, boolean bPrependVersion) {\r
+               Boolean wasWritten = false;\r
+               \r
+               if (bPrependVersion) msg = prependProxyVersionNumberToString(msg);\r
+               \r
+               wasWritten = logToSiphon(msg);\r
+               \r
+               if (isInfoEnabled && !wasWritten) {\r
+                       NativeLogTool.logInfo(TAG, msg);\r
+               }\r
+       }\r
+       \r
+       protected static Boolean logToSiphon(String msg) {\r
+               // Initialize the SiphonServer, will be ignored if already initialized\r
+               SiphonServer.init();\r
+               \r
+               // Write to the SiphonServer\r
+               return SiphonServer.sendSiphonLogData(msg);\r
+       }\r
+\r
+       protected static String getLine(Throwable ex) {\r
+               if (ex == null) { return null; }\r
+               String toPrint = ex.toString() + " :" + ex.getMessage();\r
+               for (int i=0; i<ex.getStackTrace().length; i++) {\r
+                       StackTraceElement elem = ex.getStackTrace()[i];\r
+                       toPrint += "\n  " + elem.toString();\r
+               }\r
+               \r
+               if (ex instanceof SmartDeviceLinkException) {\r
+                       SmartDeviceLinkException smartDeviceLinkEx = (SmartDeviceLinkException) ex;\r
+                       if (smartDeviceLinkEx.getInnerException() != null && smartDeviceLinkEx != smartDeviceLinkEx.getInnerException()) {\r
+                               toPrint += "\n  nested:\n";\r
+                               toPrint += getLine(smartDeviceLinkEx.getInnerException());\r
+                       }\r
+               }\r
+               \r
+               return toPrint;\r
+       }\r
+\r
+\r
+       protected static Vector<IConsole> consoleListenerList = new Vector<IConsole>();\r
+\r
+       protected final static boolean isTransportEnabled = false;\r
+       protected final static boolean isRPCEnabled = false;\r
+\r
+       public static void addConsole(IConsole console) {\r
+               synchronized(consoleListenerList) {\r
+                       consoleListenerList.addElement(console);\r
+               }\r
+       }\r
+\r
+       public static void removeConsole(IConsole console) {\r
+               synchronized(consoleListenerList) {\r
+                       consoleListenerList.removeElement(console);\r
+               }\r
+       }\r
+\r
+       public static void clearConsoles() {\r
+               synchronized(consoleListenerList) {\r
+                       consoleListenerList.removeAllElements();\r
+               }\r
+       }\r
+       \r
+       public static void logTransport(String msg) {\r
+               if (isTransportEnabled) {\r
+                       Log.d(TAG, msg);\r
+                       logInfoToConsole(msg);\r
+               }\r
+       }\r
+\r
+       public static void logRPCSend(String rpcMsg) {\r
+               if (isRPCEnabled) {\r
+                       Log.d(TAG, "Sending RPC message: " + rpcMsg);\r
+                       logRPCSendToConsole(rpcMsg);\r
+               }\r
+       }\r
+\r
+       public static void logRPCReceive(String rpcMsg) {\r
+               if (isRPCEnabled) {\r
+                       Log.d(TAG, "Received RPC message: " + rpcMsg);\r
+                       logRPCSendToConsole(rpcMsg);\r
+               }\r
+       }\r
+\r
+       protected static void logInfoToConsole(String msg) {\r
+               Vector<IConsole> localList;\r
+               synchronized(consoleListenerList) {\r
+                       localList = (Vector<IConsole>) consoleListenerList.clone();\r
+               }\r
+               \r
+               for (int i = 0; i < localList.size(); i++) {\r
+                       IConsole consoleListener = (IConsole) localList.elementAt(i);\r
+                       try {\r
+                               consoleListener.logInfo(msg);\r
+                       } catch (Exception ex) {\r
+                               Log.e(TAG, "Failure propagating logInfo: " + ex.toString(), ex);\r
+                       } // end-catch\r
+               }\r
+       }\r
+       \r
+       protected static void logErrorToConsole(String msg) {\r
+               Vector<IConsole> localList;\r
+               synchronized(consoleListenerList) {\r
+                       localList = (Vector<IConsole>) consoleListenerList.clone();\r
+               }\r
+               for (int i = 0; i < localList.size(); i++) {\r
+                       IConsole consoleListener = (IConsole) localList.elementAt(i);\r
+                       try {\r
+                               consoleListener.logError(msg);\r
+                       } catch (Exception ex) {\r
+                               Log.e(TAG, "Failure propagating logError: " + ex.toString(), ex);\r
+                       } // end-catch\r
+               }\r
+       }\r
+       \r
+       protected static void logErrorToConsole(String msg, Throwable e) {\r
+               Vector<IConsole> localList;\r
+               synchronized(consoleListenerList) {\r
+                       localList = (Vector<IConsole>) consoleListenerList.clone();\r
+               }\r
+               \r
+               for (int i = 0; i < localList.size(); i++) {\r
+                       IConsole consoleListener = (IConsole) localList.elementAt(i);\r
+                       try {\r
+                               consoleListener.logError(msg, e);\r
+                       } catch (Exception ex) {\r
+                               Log.e(TAG, "Failure propagating logError: " + ex.toString(), ex);\r
+                       } // end-catch\r
+               }\r
+       }\r
+       \r
+       protected static void logRPCSendToConsole(String msg) {\r
+               Vector<IConsole> localList;\r
+               synchronized(consoleListenerList) {\r
+                       localList = (Vector<IConsole>) consoleListenerList.clone();\r
+               }\r
+               \r
+               for (int i = 0; i < localList.size(); i++) {\r
+                       IConsole consoleListener = (IConsole) localList.elementAt(i);\r
+                       try {\r
+                               consoleListener.logRPCSend(msg);\r
+                       } catch (Exception ex) {\r
+                               Log.e(TAG, "Failure propagating logRPCSend: " + ex.toString(), ex);\r
+                       } // end-catch\r
+               }\r
+       }\r
+       \r
+       protected static void logRPCReceiveToConsole(String msg) {\r
+               Vector<IConsole> localList;\r
+               synchronized(consoleListenerList) {\r
+                       localList = (Vector<IConsole>) consoleListenerList.clone();\r
+               }\r
+               \r
+               for (int i = 0; i < localList.size(); i++) {\r
+                       IConsole consoleListener = (IConsole) localList.elementAt(i);\r
+                       try {\r
+                               consoleListener.logRPCReceive(msg);\r
+                       } catch (Exception ex) {\r
+                               Log.e(TAG, "Failure propagating logRPCReceive: " + ex.toString(), ex);\r
+                       } // end-catch\r
+               }\r
+       }\r
+}\r