/**
         * Prints data out to the console using Android's native log mechanism.
         */
        public void WriteLine(LogPriority priority, string tag, string msg, Java.Lang.Throwable tr)
        {
            // There actually are log methods that don't take a msg parameter.  For now,
            // if that's the case, just convert null to the empty string and move on.
            String useMsg = msg;

            if (useMsg == null)
            {
                useMsg = "";
            }

            // If an exeption was provided, convert that exception to a usable string and attach
            // it to the end of the msg method.
            if (tr != null)
            {
                msg += "\n" + Android.Util.Log.GetStackTraceString(tr);
            }

            // This is functionally identical to Log.x(tag, useMsg);
            // For instance, if priority were Log.VERBOSE, this would be the same as Log.v(tag, useMsg)
            Android.Util.Log.WriteLine(priority, tag, useMsg);

            // If this isn't the last node in the chain, move things along.
            if (NextNode != null)
            {
                NextNode.WriteLine(priority, tag, msg, tr);
            }
        }
Example #2
0
 public void WriteLine(LogPriority priority, string tag, string msg, Java.Lang.Throwable tr)
 {
     if (NextNode != null)
     {
         NextNode.WriteLine(LogPriority.Info, null, msg, null);
     }
 }
Example #3
0
 /// <summary>
 /// Process handled exception
 /// </summary>
 /// <param name="tr">Handled <see cref="Java.Lang.Throwable"/> that caused exception</param>
 public static void HandleException(Java.Lang.Throwable tr)
 {
     if (_exceptionProcessor != null)
     {
         _exceptionProcessor.ProcessException(tr);
     }
 }
Example #4
0
        public static void LogException(Java.Lang.Throwable ex)
        {
            System.IO.DirectoryInfo myDir = new System.IO.DirectoryInfo(Android.OS.Environment.ExternalStorageDirectory.ToString());
            if (!myDir.Exists)
            {
                myDir.Create();
            }
            string saveFile = System.IO.Path.Combine(myDir.FullName, "errorLog.txt");

            Java.IO.File logFile = new Java.IO.File(saveFile);
            if (!logFile.Exists())
            {
                try
                {
                    logFile.CreateNewFile();
                }
                catch (Java.IO.IOException e)
                {
                    Android.Util.Log.Error("LogException unable to create file", e.Message);
                }
            }

            Java.IO.PrintWriter pw;
            try
            {
                pw = new Java.IO.PrintWriter(new Java.IO.FileWriter(saveFile, true));
                ex.PrintStackTrace(pw);
                pw.Flush();
                pw.Close();
            }
            catch (Java.IO.IOException e)
            {
                Android.Util.Log.Error("LogException unable to save file", e.Message);
            }
        }
Example #5
0
        public void UncaughtException(Java.Lang.Thread thread, Java.Lang.Throwable ex)
        {
            try {
                Initialize();
            } catch (Exception e) {
                Android.Runtime.AndroidEnvironment.FailFast($"Unable to initialize UncaughtExceptionHandler. Nested exception caught: {e}");
            }

            mono_unhandled_exception !(ex);
            if (AppDomain_DoUnhandledException != null)
            {
                try {
                    var       jltp           = ex as JavaProxyThrowable;
                    Exception?innerException = jltp?.InnerException;
                    var       args           = new UnhandledExceptionEventArgs(innerException ?? ex, isTerminating: true);
                    AppDomain_DoUnhandledException(AppDomain.CurrentDomain, args);
                }
                catch (Exception e) {
                    Logger.Log(LogLevel.Error, "monodroid", "Exception thrown while raising AppDomain.UnhandledException event: " + e.ToString());
                }
            }
            if (defaultHandler != null)
            {
                defaultHandler.UncaughtException(thread, ex);
            }
        }
Example #6
0
 public void UncaughtException(Java.Lang.Thread thread, Java.Lang.Throwable ex)
 {
     for (int i = 0; i < 100000; i++)
     {
         // Console.Write(i + " ");
     }
     Console.WriteLine("Java: Exception handling completed.");
 }
 public static void RaiseThrowable(Java.Lang.Throwable throwable)
 {
     if (throwable == null)
     {
         throw new ArgumentNullException("throwable");
     }
     JNIEnv.Throw(throwable.Handle);
 }
Example #8
0
        public void InnerExceptionIsSet()
        {
            var ex = new InvalidOperationException("boo!");

            using (var source = new Java.Lang.Throwable("detailMessage", CreateJavaProxyThrowable(ex)))
                using (var alias = new Java.Lang.Throwable(source.Handle, JniHandleOwnership.DoNotTransfer)) {
                    Assert.AreEqual("detailMessage", alias.Message);
                    Assert.AreSame(ex, alias.InnerException);
                }
        }
 public void UncaughtException(Java.Lang.Thread thread, Java.Lang.Throwable ex)
 {
     if (client.AutoNotify)
     {
         client.Notify(ex, ErrorSeverity.Fatal);
     }
     if (nextHandler != null)
     {
         nextHandler.UncaughtException(thread, ex);
     }
 }
Example #10
0
 public void UncaughtException(Java.Lang.Thread t, Java.Lang.Throwable e)
 {
     if (!HandleException(e) && mDefaultHandler != null)
     {
         mDefaultHandler.UncaughtException(t, e);
     }
     else
     {
         Android.OS.Process.KillProcess(Android.OS.Process.MyPid());
         Java.Lang.JavaSystem.Exit(1);
     }
 }
Example #11
0
        private ExceptionInfo ConvertThrowable(Java.Lang.Throwable ex)
        {
            var type = ex.GetType();

            return(new ExceptionInfo()
            {
                Name = type.Name,
                Message = ex.LocalizedMessage,
                Stack = ex.GetStackTrace().Select((frame) => new StackInfo()
                {
                    Method = String.Format("{0}:{1}", frame.ClassName, frame.MethodName),
                    File = frame.FileName ?? "Unknown",
                    Line = frame.LineNumber,
                    InProject = IsInProject(frame.ClassName),
                }).ToList(),
            });
        }
Example #12
0
 public void UncaughtException(Java.Lang.Thread thread, Java.Lang.Throwable ex)
 {
     mono_unhandled_exception(ex);
     if (AppDomain_DoUnhandledException != null)
     {
         try {
             var args = new UnhandledExceptionEventArgs(ex, isTerminating: true);
             AppDomain_DoUnhandledException(AppDomain.CurrentDomain, args);
         }
         catch (Exception e) {
             Logger.Log(LogLevel.Error, "monodroid", "Exception thrown while raising AppDomain.UnhandledException event: " + e.ToString());
         }
     }
     if (defaultHandler != null)
     {
         defaultHandler.UncaughtException(thread, ex);
     }
 }
Example #13
0
        private static void InternalLog(LogLevel level, string message, Exception ex)
        {
#if __ANDROID__
            Java.Lang.Throwable throwable = null;
            if (ex != null)
            {
                throwable = new Java.Lang.Throwable(ex.Message);
            }

            switch (level)
            {
            case LogLevel.Debug:
            default:
                global::Android.Util.Log.Debug(GetCallerMethod(), message);
                break;

            case LogLevel.Warning:
                global::Android.Util.Log.Warn(GetCallerMethod(), throwable, message);
                break;

            case LogLevel.Error:
                global::Android.Util.Log.Error(GetCallerMethod(), throwable, message);
                break;
            }
#elif __IOS__
            Console.WriteLine("{0} {1} {2}", level, GetCallerMethod(), message);
            if (ex != null)
            {
                Console.WriteLine(ex);
            }
#elif WINDOWS_PHONE_APP
            System.Diagnostics.Debug.WriteLine("{0} {1} {2}", level, GetCallerMethod(), message);
            if (ex != null)
            {
                System.Diagnostics.Debug.WriteLine(ex);
            }
#elif DESKTOP
            //Swallow
#else
#error Unrecognized platform
#endif
        }
Example #14
0
        private void HandleActivityResultError(RequestCode requestCode, Intent data)
        {
            switch (requestCode)
            {
            case RequestCode.ImageOpen:
                System.Diagnostics.Debug.WriteLine("RequestImageOpen error");
                Snackbar.Make(rootView, Resource.String.image_input_result_error, Snackbar.LengthIndefinite).SetAction(Android.Resource.String.Ok, (v) => { }).Show();
                break;

            case RequestCode.Camera:
                Snackbar.Make(rootView, Resource.String.camera_result_error, Snackbar.LengthIndefinite).SetAction(Android.Resource.String.Ok, (v) => { }).Show();
                break;

            case RequestCode.Crop:
                Java.Lang.Throwable cropError = UCrop.GetError(data);
                cropError.PrintStackTrace();
                Snackbar.Make(rootView, Resource.String.crop_result_error, Snackbar.LengthIndefinite).SetAction(Android.Resource.String.Ok, (v) => { }).Show();
                break;
            }
        }
Example #15
0
        private bool HandleException(Java.Lang.Throwable e)
        {
            if (e == null)
            {
                return(false);
            }

            System.Threading.Tasks.Task.Run(() =>
            {
                Looper.Prepare();

                Toast.MakeText(mContext, "ThreadUncaughtException:" + e.Message, ToastLength.Long).Show();

                Looper.Loop();
            });

            System.Threading.Thread.Sleep(2000);

            return(true);
        }
        private static String BuildMessage(String format, params object[] args)
        {
            String msg = (args == null) ? format : String.Format(format, args);
            var trace = new Java.Lang.Throwable().FillInStackTrace().GetStackTrace();

            String caller = "<unknown>";
            Java.Lang.Class volleyLogClass = new VolleyLog().Class;

            for (int i = 2; i < trace.Length; i++)
            {
                var clazz = trace[i].Class;
                if (!clazz.Equals(volleyLogClass))
                {
                    String callingClass = trace[i].ClassName;
                    callingClass = callingClass.Substring(callingClass.LastIndexOf('.') + 1);
                    callingClass = callingClass.Substring(callingClass.LastIndexOf('$') + 1);

                    caller = callingClass + "." + trace[i].MethodName;
                    break;
                }
            }
            return String.Format("[{0}] {1}:{2}", Thread.CurrentThread.ManagedThreadId, caller, msg);
        }
        private static String BuildMessage(String format, params object[] args)
        {
            String msg   = (args == null) ? format : String.Format(format, args);
            var    trace = new Java.Lang.Throwable().FillInStackTrace().GetStackTrace();

            String caller = "<unknown>";

            Java.Lang.Class volleyLogClass = new VolleyLog().Class;

            for (int i = 2; i < trace.Length; i++)
            {
                var clazz = trace[i].Class;
                if (!clazz.Equals(volleyLogClass))
                {
                    String callingClass = trace[i].ClassName;
                    callingClass = callingClass.Substring(callingClass.LastIndexOf('.') + 1);
                    callingClass = callingClass.Substring(callingClass.LastIndexOf('$') + 1);

                    caller = callingClass + "." + trace[i].MethodName;
                    break;
                }
            }
            return(String.Format("[{0}] {1}:{2}", Thread.CurrentThread.ManagedThreadId, caller, msg));
        }
Example #18
0
 public static int Verbose(string tag, Java.Lang.Throwable tr, string msg)
 {
     return(Verbose(tag, msg, tr));
 }
Example #19
0
 public static string getStackTraceString(Java.Lang.Throwable throwable)
 {
     return(Android.Util.Log.GetStackTraceString(throwable));
 }
Example #20
0
 public static void setStackTrace(this Java.Lang.Throwable throwable, Java.Lang.StackTraceElement[] elements)
 {
     throwable.SetStackTrace(elements);
 }
Example #21
0
 public void OnResult(Java.Lang.Object p0, Java.Lang.Throwable p1)
 {
     callback(p0, p1);
 }
Example #22
0
            protected override void Log(LogPriority priority, string tag, string message, Java.Lang.Throwable t)
            {
                if (priority == LogPriority.Verbose || priority == LogPriority.Debug)
                {
                    return;
                }

                FakeCrashLibrary.Log(priority, tag, message);

                if (t != null)
                {
                    if (priority == LogPriority.Error)
                    {
                        FakeCrashLibrary.LogError(t);
                    }
                    else if (priority == LogPriority.Warn)
                    {
                        FakeCrashLibrary.LogWarning(t);
                    }
                }
            }
 public void UncaughtException(Java.Lang.Thread thread, Java.Lang.Throwable ex)
 {
 }
        /**
         * Formats the log data and prints it out to the LogView.
         */
        public void WriteLine(LogPriority priority, string tag, string msg, Java.Lang.Throwable tr)
        {
            string priorityStr = null;

            // For the purposes of this View, we want to print the priority as readable text.
            switch (priority)
            {
            case LogPriority.Verbose:
                priorityStr = "VERBOSE";
                break;

            case LogPriority.Debug:
                priorityStr = "DEBUG";
                break;

            case LogPriority.Info:
                priorityStr = "INFO";
                break;

            case LogPriority.Warn:
                priorityStr = "WARN";
                break;

            case LogPriority.Error:
                priorityStr = "ERROR";
                break;

            case LogPriority.Assert:
                priorityStr = "ASSERT";
                break;
            }

            // Handily, the Log class has a facility for converting a stack trace into a usable string.
            string exceptionStr = null;

            if (tr != null)
            {
                exceptionStr = Android.Util.Log.GetStackTraceString(tr);
            }

            // Take the priority, tag, message, and exception, and concatenate as necessary
            // into one usable line of text.
            var outputBuilder = new StringBuilder();

            const string delimiter = "\t";

            AppendIfNotNull(outputBuilder, priorityStr, delimiter);
            AppendIfNotNull(outputBuilder, tag, delimiter);
            AppendIfNotNull(outputBuilder, msg, delimiter);
            AppendIfNotNull(outputBuilder, exceptionStr, delimiter);

            // In case this was originally called from an AsyncTask or some other off-UI thread,
            // make sure the update occurs within the UI thread.

            ((Activity)Context).RunOnUiThread(new Action(delegate {
                AppendToLog(outputBuilder.ToString());
            }));

            if (NextNode != null)
            {
                NextNode.WriteLine(priority, tag, msg, tr);
            }
        }
Example #25
0
 public static int Debug(string tag, Java.Lang.Throwable tr, string msg)
 {
     return(Debug(tag, msg, tr));
 }
Example #26
0
 public static int Error(string tag, Java.Lang.Throwable tr, string msg)
 {
     return(Error(tag, msg, tr));
 }
Example #27
0
        /// <summary>
        /// Collects crash data.
        /// </summary>
        /// <param name="context"><see cref="Context"/> for the application being reported.</param>
        /// <param name="reportFields"><see cref="Array"/> of <see cref="ReportField"/> to include in report</param>
        /// <param name="appStartDate"><see cref="Time"/> of application start</param>
        /// <param name="initialConfiguration">Application initial configuration</param>
        /// <param name="th"><see cref="Java.Lang.Throwable"/> that caused the crash.</param>
        /// <param name="isSilentReport">Whether to report this report as being sent silently.</param>
        /// <returns>Builded report data</returns>
        public static ReportData BuildReportData(Context context, ReportField[] reportFields, Time appStartDate, string initialConfiguration, Java.Lang.Throwable th, bool isSilentReport)
        {
            var crashReportData = new ReportData();

            try
            {
                crashReportData.Add(ReportField.StackTrace, th.StackTrace);
                crashReportData.Add(ReportField.UserAppStartDate, appStartDate.Format3339(false));

                if (isSilentReport)
                {
                    crashReportData.Add(ReportField.IsSilent, "true");
                }

                if (reportFields.Contains(ReportField.ReportID))
                {
                    crashReportData.Add(ReportField.ReportID, Guid.NewGuid().ToString());
                }

                if (reportFields.Contains(ReportField.InstallationID))
                {
                    crashReportData.Add(ReportField.InstallationID, Installation.Id(context));
                }

                if (reportFields.Contains(ReportField.InitialConfiguration))
                {
                    crashReportData.Add(ReportField.InitialConfiguration, initialConfiguration);
                }

                if (reportFields.Contains(ReportField.CrashConfiguration))
                {
                    crashReportData.Add(ReportField.CrashConfiguration, ReportUtils.GetCrashConfiguration(context));
                }

                if (reportFields.Contains(ReportField.DumpsysMeminfo))
                {
                    crashReportData.Add(ReportField.DumpsysMeminfo, DumpSysCollector.CollectMemInfo());
                }

                if (reportFields.Contains(ReportField.PackageName))
                {
                    crashReportData.Add(ReportField.PackageName, context.PackageName);
                }

                if (reportFields.Contains(ReportField.Build))
                {
                    crashReportData.Add(ReportField.Build, ReflectionCollector.CollectStaticProperties(typeof(Build)));
                }

                if (reportFields.Contains(ReportField.PhoneModel))
                {
                    crashReportData.Add(ReportField.PhoneModel, Build.Model);
                }

                if (reportFields.Contains(ReportField.AndroidVersion))
                {
                    crashReportData.Add(ReportField.AndroidVersion, Build.VERSION.Release);
                }

                if (reportFields.Contains(ReportField.Brand))
                {
                    crashReportData.Add(ReportField.Brand, Build.Brand);
                }

                if (reportFields.Contains(ReportField.Product))
                {
                    crashReportData.Add(ReportField.Product, Build.Product);
                }

                if (reportFields.Contains(ReportField.TotalMemSize))
                {
                    crashReportData.Add(ReportField.TotalMemSize, ReportUtils.TotalInternalMemorySize.ToString());
                }

                if (reportFields.Contains(ReportField.AvailableMemSize))
                {
                    crashReportData.Add(ReportField.AvailableMemSize, ReportUtils.AvailableInternalMemorySize.ToString());
                }

                if (reportFields.Contains(ReportField.FilePath))
                {
                    crashReportData.Add(ReportField.FilePath, ReportUtils.GetApplicationFilePath(context));
                }

                if (reportFields.Contains(ReportField.Display))
                {
                    crashReportData.Add(ReportField.Display, ReportUtils.GetDisplayDetails(context));
                }

                if (reportFields.Contains(ReportField.UserCrashDate))
                {
                    var curDate = new Time();
                    curDate.SetToNow();
                    crashReportData.Add(ReportField.UserCrashDate, curDate.Format3339(false));
                }

                if (reportFields.Contains(ReportField.DeviceFeatures))
                {
                    crashReportData.Add(ReportField.DeviceFeatures, DeviceFeaturesCollector.GetFeatures(context));
                }

                if (reportFields.Contains(ReportField.Environment))
                {
                    crashReportData.Add(ReportField.Environment, ReflectionCollector.CollectStaticProperties(typeof(Environment)));
                }

                if (reportFields.Contains(ReportField.SettingsSystem))
                {
                    crashReportData.Add(ReportField.SettingsSystem, SettingsCollector.CollectSystemSettings(context));
                }

                if (reportFields.Contains(ReportField.SettingsSecure))
                {
                    crashReportData.Add(ReportField.SettingsSecure, SettingsCollector.CollectSecureSettings(context));
                }

                if (reportFields.Contains(ReportField.SharedPreferences))
                {
                    crashReportData.Add(ReportField.SharedPreferences, SharedPreferencesCollector.Collect(context));
                }

                var pm = new PackageManagerWrapper(context);
                var pi = pm.GetPackageInfo();
                if (pi != null)
                {
                    if (reportFields.Contains(ReportField.AppVersionCode))
                    {
                        crashReportData.Add(ReportField.AppVersionCode, pi.VersionCode.ToString());
                    }
                    if (reportFields.Contains(ReportField.AppVersionName))
                    {
                        crashReportData.Add(ReportField.AppVersionName, pi.VersionName ?? "not set");
                    }
                }
                else
                {
                    crashReportData.Add(ReportField.AppVersionName, "Package info unavailable");
                }

                if (reportFields.Contains(ReportField.DeviceID) && pm.HasPermission(Manifest.Permission.ReadPhoneState))
                {
                    var deviceId = ReportUtils.GetDeviceId(context);
                    if (deviceId != null)
                    {
                        crashReportData.Add(ReportField.DeviceID, deviceId);
                    }
                }

                if (pm.HasPermission(Manifest.Permission.ReadLogs))
                {
                    Log.Info(Constants.LOG_TAG, "READ_LOGS granted! Crasher can include LogCat and DropBox data.");
                    if (reportFields.Contains(ReportField.Logcat))
                    {
                        crashReportData.Add(ReportField.Logcat, LogCatCollector.CollectLogCat(null));
                    }
                    if (reportFields.Contains(ReportField.Eventslog))
                    {
                        crashReportData.Add(ReportField.Eventslog, LogCatCollector.CollectLogCat("events"));
                    }
                    if (reportFields.Contains(ReportField.Radiolog))
                    {
                        crashReportData.Add(ReportField.Radiolog, LogCatCollector.CollectLogCat("radio"));
                    }
                }
                else
                {
                    Log.Info(Constants.LOG_TAG, "READ_LOGS not allowed. Crasher will not include LogCat and DropBox data.");
                }
            }
            catch (Java.Lang.RuntimeException e)
            {
                Log.Error(Constants.LOG_TAG, e, "Error while retrieving crash data");
            }
            return(crashReportData);
        }
Example #28
0
 public static void PrintStackTraceWhenDebug(this JThrowable throwable)
 => throwable.PrintStackTrace();
Example #29
0
 public static int Wtf(string tag, Java.Lang.Throwable tr, string format, params object[] args)
 {
     return(Wtf(tag, string.Format(format, args), tr));
 }
 public void UncaughtException(Java.Lang.Thread t, Java.Lang.Throwable e)
 {
     System.Diagnostics.Debugger.Break();
 }
Example #31
0
 public static int Wtf(string tag, Java.Lang.Throwable tr, string msg)
 {
     return(Wtf(tag, msg, tr));
 }