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. BA 认证

    IIBA-CBAP https://www.iiba.org/standards-and-resources/core-standard/ PMI-PBA https://www.pmi.org/ce ...

  2. CF581C Developing Skills 模拟

    Petya loves computer games. Finally a game that he's been waiting for so long came out! The main cha ...

  3. 记录下自己安装cuda以及cudnn

    之前已经装过一次了,不过没有做记录,现在又要翻一堆博客安装,长点记性,自己记录下. 环境 ubuntu16.04 python2.7 商家送过来时候已经装好了显卡驱动,所以省去了一大麻烦. 剩下的就是 ...

  4. C语言的存储类别和动态内存分配

    存储类别分三大类: 静态存储类别 自动存储类别 动态分配内存 变量.对象--->内存管理 内存考虑效率(时间更短.空间更小) 作用域 链接.---->空间 存储器   ----->时 ...

  5. tfs强行签入和删除工作区

    作者:为爱痴狂 原文:http://www.cnblogs.com/splyn/archive/2011/10/31/2230213.html 域用户被网络管理员重建,或者其他用户牵出文档,导致的TF ...

  6. 读经典——《CLR via C#》(Jeffrey Richter著) 笔记_.Net Framework 部署目标

    1.解决Windows性能不稳定: 2.降低Windows程序安装的复杂性: 3.解决Windows程序不安全性: 4.解决应用程序状态在硬盘上分散: 5.允许用户灵活地控制哪些东西能够安装,哪些东西 ...

  7. 批处理中setlocal enabledelayedexpansion的含义

    setlocal enabledelayedexpansion       延迟变量全称"延迟环境变量扩展",要理解这个东西,我们还得先理解一下什么叫扩展!       CMD在解 ...

  8. hdu1016 Prime Ring Problem(DFS)

    Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  9. IP地址概念

    1.1  IP地址概念 什么是IP地址:由32位二进制数组成,划分成4组,每组八位: 为了便于人类识别记忆,IP地址表现形式为 "点分十进制" 二进制数与十进制数的转换关系:00 ...

  10. github访问慢解决

    参考:https://github.com/chenxuhua/issues-blog/issues/3 hosts文件: # GitHub Start 192.30.253.112 github.c ...