コード例 #1
0
        /// <summary>
        /// Collect results of the dumpsys meminfo command restricted to this application process.
        /// </summary>
        /// <returns>The execution result.</returns>
        public static string CollectMemInfo()
        {
            var meminfo = new StringBuilder();

            try
            {
                var commandLine = new List <string> {
                    "dumpsys", "meminfo", Process.MyPid().ToString()
                };
                using (var process = Java.Lang.Runtime.GetRuntime().Exec(commandLine.ToArray()))
                {
                    using (var reader = new StreamReader(process.InputStream))
                    {
                        meminfo.Append(reader.ReadToEnd());
                        reader.Close();
                    }
                    process.Destroy();
                }
            }
            catch (IOException e)
            {
                Log.Error(Constants.LOG_TAG, Java.Lang.Throwable.FromException(e), "DumpSysCollector.meminfo could not retrieve data");
            }
            return(meminfo.ToString());
        }
コード例 #2
0
        private static DateTime?GetStartupTimeFromLogcat()
        {
            var pid = AProcess.MyPid();

            var process = new ProcessBuilder().
                          RedirectErrorStream(true).
                          Command("/system/bin/logcat", $"--pid={pid}", "-m", "1", "-v", "year").Start();

            using (var bufferedReader = new BufferedReader(new InputStreamReader(process.InputStream)))
            {
                string line = null;
                while ((line = bufferedReader.ReadLine()) != null)
                {
                    if (ParseLogDateTime(line, out DateTime date))
                    {
                        return(date);
                    }
                }
            }

            return(null);
        }
コード例 #3
0
        /// <summary>
        /// 当UncaughtException发生时会转入该函数来处理
        /// </summary>
        /// <param name="thread"></param>
        /// <param name="ex"></param>
        public void UncaughtException(Thread thread, Throwable ex)
        {
            if (!HandleException(ex) && mDefaultHandler != null)
            {
                //如果用户没有处理则让系统默认的异常处理器来处理
                mDefaultHandler.UncaughtException(thread, ex);
            }
            else
            {
                //new Thread(() =>
                //{
                //    Looper.Prepare();
                //    ToastUtils.ShowSingleToast($"很抱歉,程序出现异常,即将重启:{ex.Message}");
                //    Looper.Loop();
                //}).Start();

                ////展示的时间
                //Thread.Sleep(5000);

                //退出程序
                Process.KillProcess(Process.MyPid());
                JavaSystem.Exit(1);
            }
        }
コード例 #4
0
 /// <summary>
 /// 获取当前进程名称
 /// </summary>
 /// <param name="activityManager"></param>
 /// <returns></returns>
 public static string?GetCurrentProcessName(this ActivityManager activityManager)
 => activityManager.RunningAppProcesses?.
 FirstOrDefault(x => x != null && x.Pid == Process.MyPid())?.ProcessName;
コード例 #5
0
 public int GetCurrentSystemThreadId()
 {
     return(Process.MyTid());
 }