// Path: dttv/dttv-samples/src/main/java/dttv/app/AppManager.java
// public class AppManager {
// 
//     //Activity 栈
//     private static Stack<Activity> activityStack;
//     //单例模式
//     private static AppManager instance;
// 
//     private AppManager(){}
// 
//     public static AppManager getInstance(){
//         synchronized (instance){
//             if (instance == null){
//                 instance = new AppManager();
//             }
//         }
//         return instance;
//     }
// 
//     /**
//      * 添加Activity到堆栈
//      * @param activity
//      */
//     public void addActivity(Activity activity){
//         if (activityStack == null){
//             activityStack = new Stack<Activity>();
//         }
//         activityStack.add(activity);
//     }
// 
//     /**
//      * 获取当前Activity
//      * @return
//      */
//     public Activity currentActivity(){
//         Activity activity = null;
//         if (activityStack != null){
//             activity = activityStack.lastElement();
//         }
//         return activity;
//     }
// 
//     /**
//      * 结束当前Activity（堆栈中最后一个压入的）
//      */
//     public void finishActivity(){
//         Activity activity = activityStack.lastElement();
//         finishCurrentActivity(activity);
//     }
// 
//     public void finishCurrentActivity(Activity activity){
//         if (activity != null){
//             activityStack.remove(activity);
//             activity.finish();
//             activity = null;
//         }
//     }
// 
//     public void finishAllActivity(){
//         for (int i = 0; i < activityStack.size(); i++){
//             if (null != activityStack.get(i)){
//                 activityStack.get(i).finish();
//             }
//         }
//         activityStack.clear();
//     }
// 
//     public void AppExit(Context context){
//         try {
//             finishAllActivity();
//             Process.killProcess(Process.myPid());
//             System.exit(0);
//         }catch (Exception e){}
//     }
// }


import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Environment;
import android.os.Looper;
import android.util.Log;
import android.widget.Toast;
import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.lang.reflect.Field;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import dttv.app.AppManager;
package dttv.app.exception;




/**
 * Created by shihuaxian on 2017/2/3.
 */

public class CrashHandler implements Thread.UncaughtExceptionHandler {

    private Thread.UncaughtExceptionHandler mDefaultHandler;

    private Context mContext;

    private Map<String,String> paramsMap = new HashMap<String, String>();

    /**
     * 格式化时间
     */
    private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
    private String TAG = this.getClass().getSimpleName();

    private static CrashHandler mInstance;

    private CrashHandler(){}

    public static synchronized CrashHandler getInstance(){
        if(mInstance == null){
            mInstance = new CrashHandler();
        }
        return mInstance;
    }

    public void init(Context context){
        mContext = context;
        mDefaultHandler = Thread.getDefaultUncaughtExceptionHandler();
        //设置该CrashHandler为系统默认的
        Thread.setDefaultUncaughtExceptionHandler(this);
    }


    @Override
    public void uncaughtException(Thread thread, Throwable throwable) {
        if (!handleException(throwable) && mDefaultHandler != null){//如果自己没有处理则交给系统处理
            mDefaultHandler.uncaughtException(thread,throwable);
        }else {//自己处理
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            //退出程序
// Path: dttv/dttv-samples/src/main/java/dttv/app/AppManager.java
// public class AppManager {
// 
//     //Activity 栈
//     private static Stack<Activity> activityStack;
//     //单例模式
//     private static AppManager instance;
// 
//     private AppManager(){}
// 
//     public static AppManager getInstance(){
//         synchronized (instance){
//             if (instance == null){
//                 instance = new AppManager();
//             }
//         }
//         return instance;
//     }
// 
//     /**
//      * 添加Activity到堆栈
//      * @param activity
//      */
//     public void addActivity(Activity activity){
//         if (activityStack == null){
//             activityStack = new Stack<Activity>();
//         }
//         activityStack.add(activity);
//     }
// 
//     /**
//      * 获取当前Activity
//      * @return
//      */
//     public Activity currentActivity(){
//         Activity activity = null;
//         if (activityStack != null){
//             activity = activityStack.lastElement();
//         }
//         return activity;
//     }
// 
//     /**
//      * 结束当前Activity（堆栈中最后一个压入的）
//      */
//     public void finishActivity(){
//         Activity activity = activityStack.lastElement();
//         finishCurrentActivity(activity);
//     }
// 
//     public void finishCurrentActivity(Activity activity){
//         if (activity != null){
//             activityStack.remove(activity);
//             activity.finish();
//             activity = null;
//         }
//     }
// 
//     public void finishAllActivity(){
//         for (int i = 0; i < activityStack.size(); i++){
//             if (null != activityStack.get(i)){
//                 activityStack.get(i).finish();
//             }
//         }
//         activityStack.clear();
//     }
// 
//     public void AppExit(Context context){
//         try {
//             finishAllActivity();
//             Process.killProcess(Process.myPid());
//             System.exit(0);
//         }catch (Exception e){}
//     }
// }


// Path: dttv/dttv-samples/src/main/java/dttv/app/exception/CrashHandler.java
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Environment;
import android.os.Looper;
import android.util.Log;
import android.widget.Toast;
import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.lang.reflect.Field;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import dttv.app.AppManager;

package dttv.app.exception;




/**
 * Created by shihuaxian on 2017/2/3.
 */

public class CrashHandler implements Thread.UncaughtExceptionHandler {

    private Thread.UncaughtExceptionHandler mDefaultHandler;

    private Context mContext;

    private Map<String,String> paramsMap = new HashMap<String, String>();

    /**
     * 格式化时间
     */
    private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
    private String TAG = this.getClass().getSimpleName();

    private static CrashHandler mInstance;

    private CrashHandler(){}

    public static synchronized CrashHandler getInstance(){
        if(mInstance == null){
            mInstance = new CrashHandler();
        }
        return mInstance;
    }

    public void init(Context context){
        mContext = context;
        mDefaultHandler = Thread.getDefaultUncaughtExceptionHandler();
        //设置该CrashHandler为系统默认的
        Thread.setDefaultUncaughtExceptionHandler(this);
    }


    @Override
    public void uncaughtException(Thread thread, Throwable throwable) {
        if (!handleException(throwable) && mDefaultHandler != null){//如果自己没有处理则交给系统处理
            mDefaultHandler.uncaughtException(thread,throwable);
        }else {//自己处理
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            //退出程序
            AppManager.getInstance().AppExit(mContext);