package com.tencent.bugly.agent;

 import android.app.Activity;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.os.Process;
import android.text.TextUtils;
import android.util.Log;
import java.lang.ref.WeakReference;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Locale; public class GameAgent
{
private static final String VERSION = "2.0";
private static final String LOG_TAG = "CrashReport-GameAgent";
private static final int GAME_TYPE_COCOS = 1;
private static final int GAME_TYPE_UNITY = 2;
private static final int LOG_LEVEL_VERBOSE = 0;
private static final int LOG_LEVEL_DEBUG = 1;
private static final int LOG_LEVEL_INFO = 2;
private static final int LOG_LEVEL_WARN = 3;
private static final int LOG_LEVEL_ERROR = 4;
private static final int TYPE_U3D_CRASH = 4;
private static final int TYPE_COCOS2DX_JS_CRASH = 5;
private static final int TYPE_COCOS2DX_LUA_CRASH = 6;
private static final String STRATEGY_CLASS_SUFFIX = "BuglyStrategy";
private static final String OLD_STRATEGY_CLASS_SUFFIX = "crashreport.CrashReport$UserStrategy";
private static final String CRASH_REPORT_CLASS_SUFFIX = "crashreport.CrashReport";
private static final String CLASS_UNITY_PLAYER = "com.unity3d.player.UnityPlayer";
private static final String CLASS_COCOS_ACTIVITY = "org.cocos2dx.lib.Cocos2dxActivity";
private static String sdkPackageName = "com.tencent.bugly";
private static Handler sHandler = null;
private static String sAppVersion = null;
private static String sAppChannel = null;
private static String sUserId = null;
private static boolean sIsDebug = false;
private static int sGameType = 0;
private static WeakReference<Activity> sContext = null; public static String getVersion()
{
return "2.0";
} public static void printLog(String paramString)
{
if (TextUtils.isEmpty(paramString)) {
return;
}
if (paramString.startsWith("<Log>"))
printLog(2, paramString);
else if (paramString.startsWith("<LogDebug>"))
printLog(1, paramString);
else if (paramString.startsWith("<LogInfo>"))
printLog(2, paramString);
else if (paramString.startsWith("<LogWarning>"))
printLog(3, paramString);
else if (paramString.startsWith("<LogAssert>"))
printLog(3, paramString);
else if (paramString.startsWith("<LogError>"))
printLog(4, paramString);
else if (paramString.startsWith("<LogException>"))
printLog(4, paramString);
else
printLog(0, paramString);
} private static void printLog(int paramInt, String paramString)
{
setLog(paramInt, "CrashReport-GameAgent", paramString);
} public static Activity getUnityActivity()
{
try
{
Object localObject = Reflection.getStaticField("com.unity3d.player.UnityPlayer", "currentActivity", null);
if ((localObject != null) && ((localObject instanceof Activity)))
return (Activity)localObject;
}
catch (Exception localException) {
Log.w("CrashReport-GameAgent", "Failed to get the current activity from UnityPlayer");
localException.printStackTrace();
} return null;
} public static Activity getCocosActivity()
{
try
{
Object localObject = Reflection.invokeStaticMethod("org.cocos2dx.lib.Cocos2dxActivity", "getContext", null, new Class[0]);
if ((localObject != null) && ((localObject instanceof Activity)))
return (Activity)localObject;
}
catch (Exception localException) {
Log.w("CrashReport-GameAgent", "Failed to get the current activity from UnityPlayer");
localException.printStackTrace();
} return null;
} private static Activity getActivity() {
Activity localActivity = null;
if ((sContext != null) && (sContext.get() != null)) {
return (Activity)sContext.get();
}
switch (sGameType) {
case 1:
localActivity = getCocosActivity();
break;
case 2:
localActivity = getUnityActivity();
break;
default:
Log.w("CrashReport-GameAgent", "Game type has not been set.");
} return localActivity;
} private static Context getApplicationContext() {
Activity localActivity = getActivity();
if (localActivity != null) {
return localActivity.getApplicationContext();
}
return null;
} private static void runTaskInUiThread(Runnable paramRunnable) {
Activity localActivity = getActivity();
if (localActivity != null)
localActivity.runOnUiThread(paramRunnable);
else
new Thread(paramRunnable).start();
} private static void exitApplication()
{
int i = Process.myPid();
printLog(3, String.format(Locale.US, "Exit application by kill process[%d]", new Object[] { Integer.valueOf(i) })); Process.killProcess(i);
} private static void delayExit(long paramLong)
{
paramLong = Math.max(0L, paramLong); if (sHandler != null) {
sHandler.postDelayed(new Runnable()
{
public void run() {
GameAgent.access$200();
}
}
, paramLong);
}
else
{
try
{
Thread.sleep(paramLong);
exitApplication();
} catch (InterruptedException localInterruptedException) {
localInterruptedException.printStackTrace();
}
}
} private static String convertToCanonicalName(String paramString)
{
StringBuilder localStringBuilder = new StringBuilder();
if (sdkPackageName == null) {
sdkPackageName = "com.tencent.bugly";
}
localStringBuilder.append(sdkPackageName);
localStringBuilder.append(".");
localStringBuilder.append(paramString);
return localStringBuilder.toString();
} public static void setSdkPackageName(String paramString)
{
if (TextUtils.isEmpty(paramString)) {
return;
}
sdkPackageName = paramString;
} public static void setGameType(int paramInt) {
sGameType = paramInt;
} public static void setLogEnable(boolean paramBoolean)
{
sIsDebug = paramBoolean;
} private static Object newStrategy(Context paramContext, String paramString1, String paramString2, long paramLong)
{
if ((paramContext == null) || ((TextUtils.isEmpty(paramString1)) && (TextUtils.isEmpty(paramString2)))) {
return null;
}
Object localObject = Reflection.newInstance(convertToCanonicalName("crashreport.CrashReport$UserStrategy"), new Object[] { paramContext }, new Class[] { Context.class }); if (localObject != null) {
try {
Class localClass = Class.forName(convertToCanonicalName("BuglyStrategy"));
Method localMethod1 = localClass.getDeclaredMethod("setAppChannel", new Class[] { String.class });
localMethod1.invoke(localObject, new Object[] { paramString1 }); Method localMethod2 = localClass.getDeclaredMethod("setAppVersion", new Class[] { String.class });
localMethod2.invoke(localObject, new Object[] { paramString2 }); Method localMethod3 = localClass.getDeclaredMethod("setAppReportDelay", new Class[] { Long.TYPE });
localMethod3.invoke(localObject, new Object[] { Long.valueOf(paramLong) }); return localObject;
} catch (NoSuchMethodException localNoSuchMethodException) {
localNoSuchMethodException.printStackTrace();
} catch (IllegalAccessException localIllegalAccessException) {
localIllegalAccessException.printStackTrace();
} catch (IllegalArgumentException localIllegalArgumentException) {
localIllegalArgumentException.printStackTrace();
} catch (InvocationTargetException localInvocationTargetException) {
localInvocationTargetException.printStackTrace();
} catch (Exception localException) {
localException.printStackTrace();
}
}
return null;
} public static void initCrashReport(String paramString, boolean paramBoolean) {
setLogEnable(paramBoolean);
initCrashReport(paramString, sAppChannel, sAppVersion, sUserId, 0L);
} private static void initCrashReport(final String paramString1, String paramString2, String paramString3, final String paramString4, long paramLong)
{
final Context localContext = getApplicationContext();
if (localContext == null) {
printLog(4, "Context is null. bugly initialize terminated.");
return;
}
if (TextUtils.isEmpty(paramString1)) {
printLog(4, "Please input appid when initCrashReport.");
return;
}
sHandler = new Handler(Looper.getMainLooper());
Object localObject = newStrategy(localContext, paramString2, paramString3, paramLong);
runTaskInUiThread(new Runnable()
{
public void run()
{
int i = 0;
boolean bool = GameAgent.sIsDebug;
if (this.val$strategy != null) {
Class localClass = null;
try {
localClass = Class.forName(GameAgent.convertToCanonicalName("crashreport.CrashReport$UserStrategy"));
} catch (ClassNotFoundException localClassNotFoundException) {
localClassNotFoundException.printStackTrace();
} catch (Exception localException) {
localException.printStackTrace();
}
if (localClass != null) {
GameAgent.Reflection.invokeStaticMethod(GameAgent.access$500("crashreport.CrashReport"), "initCrashReport", new Object[] { localContext, paramString1, Boolean.valueOf(bool), this.val$strategy }, new Class[] { Context.class, String.class, Boolean.TYPE, localClass }); i = 1;
}
} if (i == 0) {
GameAgent.Reflection.invokeStaticMethod(GameAgent.access$500("crashreport.CrashReport"), "initCrashReport", new Object[] { localContext, paramString1, Boolean.valueOf(bool) }, new Class[] { Context.class, String.class, Boolean.TYPE });
} GameAgent.setUserId(paramString4);
}
});
} public static void setAppVersion(String paramString)
{
if (TextUtils.isEmpty(paramString)) {
return;
}
sAppVersion = paramString;
runTaskInUiThread(new Runnable()
{
public void run() {
GameAgent.Reflection.invokeStaticMethod(GameAgent.access$500("crashreport.CrashReport"), "setAppVersion", new Object[] { GameAgent.access$600(), this.val$version }, new Class[] { Context.class, String.class });
}
});
} public static void setAppChannel(String paramString)
{
if (TextUtils.isEmpty(paramString)) {
return;
}
sAppChannel = paramString;
runTaskInUiThread(new Runnable()
{
public void run() {
GameAgent.Reflection.invokeStaticMethod(GameAgent.access$500("crashreport.CrashReport"), "setAppChannel", new Object[] { GameAgent.access$600(), this.val$channel }, new Class[] { Context.class, String.class });
}
});
} public static void setUserId(String paramString)
{
if (TextUtils.isEmpty(paramString)) {
return;
}
sUserId = paramString;
runTaskInUiThread(new Runnable()
{
public void run() {
GameAgent.Reflection.invokeStaticMethod(GameAgent.access$500("crashreport.CrashReport"), "setUserId", new Object[] { GameAgent.access$600(), this.val$userId }, new Class[] { Context.class, String.class });
}
});
} public static void setUserSceneTag(int paramInt)
{
runTaskInUiThread(new Runnable()
{
public void run() {
GameAgent.Reflection.invokeStaticMethod(GameAgent.access$500("crashreport.CrashReport"), "setUserSceneTag", new Object[] { GameAgent.access$600(), Integer.valueOf(this.val$sceneId) }, new Class[] { Context.class, Integer.TYPE });
}
});
} public static void putUserData(String paramString1, final String paramString2)
{
if ((TextUtils.isEmpty(paramString1)) || (TextUtils.isEmpty(paramString2))) {
return;
}
runTaskInUiThread(new Runnable()
{
public void run() {
GameAgent.Reflection.invokeStaticMethod(GameAgent.access$500("crashreport.CrashReport"), "putUserData", new Object[] { GameAgent.access$600(), this.val$key, paramString2 }, new Class[] { Context.class, String.class, String.class });
}
});
} public static void removeUserData(String paramString)
{
if (TextUtils.isEmpty(paramString)) {
return;
}
runTaskInUiThread(new Runnable()
{
public void run() {
GameAgent.Reflection.invokeStaticMethod(GameAgent.access$500("crashreport.CrashReport"), "removeUserData", new Object[] { GameAgent.access$600(), this.val$key }, new Class[] { Context.class, String.class });
}
});
} public static void setSdkConfig(String paramString1, final String paramString2)
{
if ((TextUtils.isEmpty(paramString1)) || (TextUtils.isEmpty(paramString2))) {
return;
}
runTaskInUiThread(new Runnable()
{
public void run() {
GameAgent.Reflection.invokeStaticMethod(GameAgent.access$500("crashreport.CrashReport"), "putSdkData", new Object[] { GameAgent.access$600(), "SDK_" + this.val$key, paramString2 }, new Class[] { Context.class, String.class, String.class });
}
});
} public static void setLog(int paramInt, final String paramString1, final String paramString2)
{
if (TextUtils.isEmpty(paramString1))
return;
String str;
switch (paramInt) {
case 0:
str = "v";
break;
case 1:
str = "d";
break;
case 2:
str = "i";
break;
case 3:
str = "w";
break;
case 4:
str = "e";
break;
default:
str = null;
} if (str != null)
runTaskInUiThread(new Runnable()
{
public void run() {
GameAgent.Reflection.invokeStaticMethod(GameAgent.access$500("crashreport.BuglyLog"), this.val$method, new Object[] { paramString1, paramString2 }, new Class[] { String.class, String.class });
}
});
} private static void postCocosException(int paramInt, String paramString1, final String paramString2, String paramString3, final boolean paramBoolean)
{
try
{
if (paramString3.startsWith("stack traceback")) {
paramString3 = paramString3.substring(paramString3.indexOf("\n") + 1, paramString3.length()).trim();
} int i = paramString3.indexOf("\n");
if (i > 0) {
paramString3 = paramString3.substring(i + 1, paramString3.length());
} i = paramString3.indexOf("\n");
str2 = paramString3;
if (i > 0) {
str2 = paramString3.substring(0, i);
} int j = str2.indexOf("]:");
if ((paramString1 == null) || (paramString1.length() == 0)) {
if (j != -1)
paramString1 = str2.substring(0, j + 1);
else
paramString1 = paramString2;
}
}
catch (Throwable localThrowable)
{
if ((paramString1 == null) || (paramString1.length() == 0)) {
paramString1 = paramString2;
}
}
final String str1 = paramString1;
final String str2 = paramString3;
runTaskInUiThread(new Runnable()
{
public void run() {
GameAgent.Reflection.invokeStaticMethod(GameAgent.access$500("crashreport.inner.InnerApi"), "postCocos2dxCrashAsync", new Object[] { Integer.valueOf(this.val$category), str1, paramString2, str2 }, new Class[] { Integer.TYPE, String.class, String.class, String.class }); if (paramBoolean)
GameAgent.delayExit(3000L);
}
});
} private static void postUnityException(String paramString1, final String paramString2, final String paramString3, final boolean paramBoolean)
{
runTaskInUiThread(new Runnable()
{
public void run() {
GameAgent.Reflection.invokeStaticMethod(GameAgent.access$500("crashreport.inner.InnerApi"), "postU3dCrashAsync", new Object[] { this.val$type, paramString2, paramString3 }, new Class[] { String.class, String.class, String.class }); if (paramBoolean)
GameAgent.delayExit(3000L);
}
});
} public static void postException(int paramInt, String paramString1, String paramString2, String paramString3, boolean paramBoolean)
{
switch (paramInt) {
case 5:
case 6:
postCocosException(paramInt, paramString1, paramString2, paramString3, paramBoolean);
break;
case 4:
postUnityException(paramString1, paramString2, paramString3, paramBoolean);
break;
default:
printLog(4, new StringBuilder().append("The category of exception posted is unknown: ").append(String.valueOf(paramInt)).toString());
}
} private static class Reflection
{
private static Object getStaticField(String paramString1, String paramString2, Object paramObject)
{
try
{
Class localClass = Class.forName(paramString1); Field localField = localClass.getDeclaredField(paramString2);
localField.setAccessible(true);
return localField.get(paramObject);
} catch (ClassNotFoundException localClassNotFoundException) {
localClassNotFoundException.printStackTrace();
} catch (NoSuchFieldException localNoSuchFieldException) {
localNoSuchFieldException.printStackTrace();
} catch (IllegalAccessException localIllegalAccessException) {
localIllegalAccessException.printStackTrace();
} return null;
} private static Object invokeStaticMethod(String paramString1, String paramString2, Object[] paramArrayOfObject, Class<?>[] paramArrayOfClass)
{
try
{
Class localClass = Class.forName(paramString1);
Method localMethod = localClass.getDeclaredMethod(paramString2, paramArrayOfClass);
localMethod.setAccessible(true);
return localMethod.invoke(null, paramArrayOfObject);
} catch (ClassNotFoundException localClassNotFoundException) {
localClassNotFoundException.printStackTrace();
} catch (NoSuchMethodException localNoSuchMethodException) {
localNoSuchMethodException.printStackTrace();
} catch (InvocationTargetException localInvocationTargetException) {
localInvocationTargetException.printStackTrace();
} catch (IllegalAccessException localIllegalAccessException) {
localIllegalAccessException.printStackTrace();
} catch (Exception localException) {
localException.printStackTrace();
}
return null;
} private static Object newInstance(String paramString, Object[] paramArrayOfObject, Class<?>[] paramArrayOfClass)
{
try
{
Class localClass = Class.forName(paramString);
if (paramArrayOfObject == null) {
return localClass.newInstance();
}
Constructor localConstructor = localClass.getConstructor(paramArrayOfClass);
return localConstructor.newInstance(paramArrayOfObject);
}
catch (ClassNotFoundException localClassNotFoundException) {
localClassNotFoundException.printStackTrace();
} catch (NoSuchMethodException localNoSuchMethodException) {
localNoSuchMethodException.printStackTrace();
} catch (InstantiationException localInstantiationException) {
localInstantiationException.printStackTrace();
} catch (IllegalAccessException localIllegalAccessException) {
localIllegalAccessException.printStackTrace();
} catch (InvocationTargetException localInvocationTargetException) {
localInvocationTargetException.printStackTrace();
} catch (Exception localException) {
localException.printStackTrace();
}
return null;
}
}
}
 private static readonly string GAME_AGENT_CLASS = "com.tencent.bugly.agent.GameAgent";
private static readonly int TYPE_U3D_CRASH = ;
private static readonly int GAME_TYPE_UNITY = ;
private static bool hasSetGameType = false;
private static AndroidJavaClass _gameAgentClass = null; public static AndroidJavaClass GameAgent {
get {
if (_gameAgentClass == null) {
_gameAgentClass = new AndroidJavaClass(GAME_AGENT_CLASS);
// using (AndroidJavaClass clazz = new AndroidJavaClass(CLASS_UNITYAGENT)) {
// _gameAgentClass = clazz.CallStatic<AndroidJavaObject> ("getInstance");
// }
}
if (!hasSetGameType) {
// set game type: unity(2).
_gameAgentClass.CallStatic ("setGameType", GAME_TYPE_UNITY);
hasSetGameType = true;
}
return _gameAgentClass;
}
}

腾讯bugly 映射用法的更多相关文章

  1. 【腾讯Bugly干货分享】RecyclerView 必知必会

    本文来自于腾讯Bugly公众号(weixinBugly),未经作者同意,请勿转载,原文地址:http://mp.weixin.qq.com/s/CzrKotyupXbYY6EY2HP_dA 导语 Re ...

  2. 【腾讯Bugly干货分享】Android Linker 与 SO 加壳技术

    本文来自于腾讯bugly开发者社区,非经作者同意,请勿转载,原文地址:http://dev.qq.com/topic/57e3a3bc42eb88da6d4be143 作者:王赛 1. 前言 Andr ...

  3. 【腾讯Bugly干货分享】微信iOS SQLite源码优化实践

    本文来自于腾讯bugly开发者社区,非经作者同意,请勿转载,原文地址:http://dev.qq.com/topic/57b58022433221be01499480 作者:张三华 前言 随着微信iO ...

  4. 【腾讯Bugly干货分享】JSPatch 成长之路

    本文来自于腾讯bugly开发者社区,非经作者同意,请勿转载,原文地址:http://dev.qq.com/topic/579efa7083355a9a57a1ac5b Dev Club 是一个交流移动 ...

  5. 【腾讯bugly干货分享】微信Android热补丁实践演进之路

    本文来自于腾讯bugly开发者社区,非经作者同意,请勿转载,原文地址:http://bugly.qq.com/bbs/forum.php?mod=viewthread&tid=1264& ...

  6. 【腾讯Bugly干货分享】跨平台 ListView 性能优化

    本文来自于腾讯Bugly公众号(weixinBugly),未经作者同意,请勿转载,原文地址:https://mp.weixin.qq.com/s/FbiSLPxFdGqJ00WgpJ94yw 导语 精 ...

  7. 【腾讯Bugly干货分享】微信mars 的高性能日志模块 xlog

    本文来自于腾讯bugly开发者社区,未经作者同意,请勿转载,原文地址:http://dev.qq.com/topic/581c2c46bef1702a2db3ae53 Dev Club 是一个交流移动 ...

  8. 【腾讯Bugly干货分享】微信终端跨平台组件 mars 系列(一) - 高性能日志模块xlog

    本文来自于腾讯bugly开发者社区,非经作者同意,请勿转载,原文地址:http://dev.qq.com/topic/57ff5932cde42f1f03de29b1 本文来源: 微信客户端开发团队 ...

  9. 【腾讯Bugly干货分享】聊一聊微信“小程序”

    本文来自于腾讯bugly开发者社区,非经作者同意,请勿转载,原文地址:http://dev.qq.com/topic/57ecdf5ef03abecd43216fd0 Dev Club 是一个交流移动 ...

随机推荐

  1. C++基础学习4:引用

    C++引用(Reference) 引用(Reference)是C++语言相对于C语言的又一个扩充,是C++常用的一个重要内容之一.类似于指针,只是在声明的时候用"&"取代了 ...

  2. Solr学习笔记(1) —— Solr概述&Solr的安装

    一.概述 使用Solr实现电商网站中商品信息搜索功能,可以根据关键字.分类.价格搜索商品信息,也可以根据价格进行排序. 1.1 实现方法 在一些大型门户网站.电子商务网站等都需要站内搜索功能,使用传统 ...

  3. 奇妙的 clip-path 几何图形

    CSS 新属性 clip-path,意味裁剪路径的意思,让我们可以很便捷的生成各种几何图形. clip-path 通过定义特殊的路径,实现我们想要的图形.而这个路径,正是 SVG 中的 path . ...

  4. 读经典——《CLR via C#》(Jeffrey Richter著) 笔记_类型的各种成员

    [Class中,可能包含的成员] 常量, 字段, 实例构造器, 类型构造器, 方法, 操作符重载, 转换操作符, 属性, 事件, 类型(Class)

  5. 华东交通大学2015年ACM“双基”程序设计竞赛1002

    Problem B Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other) Total Sub ...

  6. bash 中 trim 字符串(去除首尾空格) - grep 去空行

    在 bash 下如何去除一个字符串首尾的空格(也就是 trim)呢?其实有一个简单的办法: $ echo $STR 注 意 $STR 不要带引号.因为 $STR 展开后,会作为 echo 的参数.那么 ...

  7. day35 数据库的初步认识

    一.    数据库的由来分类 1.   数据库的概念 百度定义: 数据库,简而言之可视为电子化的文件柜——存储电子文件的处所,用户可以对文件中的数据运行新增.截取.更新.删除等操作. 所谓“数据库”系 ...

  8. GM MDI Tech 3 VS GM tech 2

    Many customers ask for this question: what is the difference between GM tech 2 and GM MDI Tech 3 sca ...

  9. 信息领域热词分析系统--python切词

    利用python将标题切割成词语 import jieba #读取文件 f=open(r"F:\大数据\大作业\爬取到的数据\data1_xinxi.txt",'r') s=f.r ...

  10. Pycharm 查看一个类的继承关系图

    Pycharm 查看一个类的继承关系图 在我们开发过程中: 无论是使用的开发框架自带的类, 还是我们自定义的类都特别多; 并且类之间单继承和多继承频繁使用, 这个继承,不仅仅是一级的继承关系,包括好几 ...