| 
						
						
							
								
							
						
						
					 | 
					 | 
					@ -20,18 +20,14 @@ import java.util.concurrent.TimeUnit | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 * 异常管理类 | 
					 | 
					 | 
					 | 
					 * 异常管理类 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 */ | 
					 | 
					 | 
					 | 
					 */ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					@Suppress("DEPRECATION") | 
					 | 
					 | 
					 | 
					@Suppress("DEPRECATION") | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					class CrashHandler : Thread.UncaughtExceptionHandler { | 
					 | 
					 | 
					 | 
					class CrashHandler(val context: Context) : Thread.UncaughtExceptionHandler { | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    private val tag = this.javaClass.simpleName | 
					 | 
					 | 
					 | 
					    private val tag = this.javaClass.simpleName | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    /** | 
					 | 
					 | 
					 | 
					    /** | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					     * 系统默认UncaughtExceptionHandler | 
					 | 
					 | 
					 | 
					     * 系统默认UncaughtExceptionHandler | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					     */ | 
					 | 
					 | 
					 | 
					     */ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    private var mDefaultHandler: Thread.UncaughtExceptionHandler? = null | 
					 | 
					 | 
					 | 
					    private var mDefaultHandler: Thread.UncaughtExceptionHandler? = null | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    /** | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					     * context | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					     */ | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    private var mContext: Context? = null | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    /** | 
					 | 
					 | 
					 | 
					    /** | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					     * 存储异常和参数信息 | 
					 | 
					 | 
					 | 
					     * 存储异常和参数信息 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					     */ | 
					 | 
					 | 
					 | 
					     */ | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -43,8 +39,7 @@ class CrashHandler : Thread.UncaughtExceptionHandler { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    @SuppressLint("SimpleDateFormat") | 
					 | 
					 | 
					 | 
					    @SuppressLint("SimpleDateFormat") | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    private val format = SimpleDateFormat("yyyy-MM-dd-HH-mm-ss") | 
					 | 
					 | 
					 | 
					    private val format = SimpleDateFormat("yyyy-MM-dd-HH-mm-ss") | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    fun init(context: Context) { | 
					 | 
					 | 
					 | 
					    init { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        mContext = context | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        mDefaultHandler = Thread.getDefaultUncaughtExceptionHandler() | 
					 | 
					 | 
					 | 
					        mDefaultHandler = Thread.getDefaultUncaughtExceptionHandler() | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        //设置该CrashHandler为系统默认的 | 
					 | 
					 | 
					 | 
					        //设置该CrashHandler为系统默认的 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        Thread.setDefaultUncaughtExceptionHandler(this) | 
					 | 
					 | 
					 | 
					        Thread.setDefaultUncaughtExceptionHandler(this) | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -65,14 +60,14 @@ class CrashHandler : Thread.UncaughtExceptionHandler { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    private fun handleException(ex: Throwable?) { | 
					 | 
					 | 
					 | 
					    private fun handleException(ex: Throwable?) { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        if (ex == null) return | 
					 | 
					 | 
					 | 
					        if (ex == null) return | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        //收集设备参数信息 | 
					 | 
					 | 
					 | 
					        //收集设备参数信息 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        collectDeviceInfo(mContext!!) | 
					 | 
					 | 
					 | 
					        collectDeviceInfo(context) | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        //添加自定义信息 | 
					 | 
					 | 
					 | 
					        //添加自定义信息 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        addCustomInfo() | 
					 | 
					 | 
					 | 
					        addCustomInfo() | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        kotlin.runCatching { | 
					 | 
					 | 
					 | 
					        kotlin.runCatching { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            //使用Toast来显示异常信息 | 
					 | 
					 | 
					 | 
					            //使用Toast来显示异常信息 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            Handler(Looper.getMainLooper()).post { | 
					 | 
					 | 
					 | 
					            Handler(Looper.getMainLooper()).post { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                Toast.makeText( | 
					 | 
					 | 
					 | 
					                Toast.makeText( | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                    mContext, | 
					 | 
					 | 
					 | 
					                    context, | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                    ex.message, | 
					 | 
					 | 
					 | 
					                    ex.message, | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                    Toast.LENGTH_LONG | 
					 | 
					 | 
					 | 
					                    Toast.LENGTH_LONG | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                ).show() | 
					 | 
					 | 
					 | 
					                ).show() | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					 | 
					@ -141,7 +136,7 @@ class CrashHandler : Thread.UncaughtExceptionHandler { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            val timestamp = System.currentTimeMillis() | 
					 | 
					 | 
					 | 
					            val timestamp = System.currentTimeMillis() | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            val time = format.format(Date()) | 
					 | 
					 | 
					 | 
					            val time = format.format(Date()) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            val fileName = "crash-$time-$timestamp.log" | 
					 | 
					 | 
					 | 
					            val fileName = "crash-$time-$timestamp.log" | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            mContext?.externalCacheDir?.let { rootFile -> | 
					 | 
					 | 
					 | 
					            context.externalCacheDir?.let { rootFile -> | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                FileUtils.getFile(rootFile, "crash").listFiles()?.forEach { | 
					 | 
					 | 
					 | 
					                FileUtils.getFile(rootFile, "crash").listFiles()?.forEach { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                    if (it.lastModified() < System.currentTimeMillis() - TimeUnit.DAYS.toMillis(7)) { | 
					 | 
					 | 
					 | 
					                    if (it.lastModified() < System.currentTimeMillis() - TimeUnit.DAYS.toMillis(7)) { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                        it.delete() | 
					 | 
					 | 
					 | 
					                        it.delete() | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
					 | 
					
  |