diff --git a/app/src/main/java/com/gh/gamecenter/MainActivity.java b/app/src/main/java/com/gh/gamecenter/MainActivity.java index e1870ff6e6..38dfedabcd 100644 --- a/app/src/main/java/com/gh/gamecenter/MainActivity.java +++ b/app/src/main/java/com/gh/gamecenter/MainActivity.java @@ -227,10 +227,10 @@ public class MainActivity extends BaseActivity { mPackageViewModel = ViewModelProviders.of(this, new PackageViewModel.Factory()).get(PackageViewModel.class); - final String message = com.gh.gamecenter.common.constant.Config.getExceptionMsg(); - if (!TextUtils.isEmpty(message)) { - com.gh.gamecenter.common.constant.Config.setExceptionMsg(null); - DataUtils.reportException(this, new Throwable(message)); + final boolean containsErrorMsg = com.gh.gamecenter.common.constant.Config.isContainsErrorMsg(); + if (containsErrorMsg) { + com.gh.gamecenter.common.constant.Config.updateContainsErrorMsg(false); + DataUtils.reportException(this, new Throwable(com.gh.gamecenter.common.constant.Config.getExceptionMsg())); // 被改过的包闪退时增加跳转到光环游戏详情并自动下载的方法 if (com.gh.gamecenter.common.constant.Config.DEFAULT_CHANNEL_FOR_RELEASE.equals(HaloApp.getInstance().getChannel())) { DialogHelper.showCenterWarningDialog(this, "发生闪退", "光环助手发生了闪退,建议安装到最新版本修复异常" diff --git a/app/src/main/java/com/gh/gamecenter/SuggestionActivity.java b/app/src/main/java/com/gh/gamecenter/SuggestionActivity.java index 5a2c290223..40fd8b524e 100644 --- a/app/src/main/java/com/gh/gamecenter/SuggestionActivity.java +++ b/app/src/main/java/com/gh/gamecenter/SuggestionActivity.java @@ -39,6 +39,7 @@ import com.gh.common.util.AdHelper; import com.gh.common.util.ApkActiveUtils; import com.gh.common.util.CheckLoginUtils; import com.gh.common.util.DirectUtils; +import com.gh.gamecenter.common.constant.Config; import com.gh.gamecenter.common.utils.NotificationHelper; import com.gh.common.util.PackageUtils; import com.gh.gamecenter.common.utils.ShareUtils; @@ -1265,7 +1266,9 @@ public class SuggestionActivity extends ToolBarActivity implements OnRequestCall } else { message = content; if (mSuggestType == SuggestType.crash) { - params.put("log", readFromFile()); + params.put("log", Config.getExceptionMsg()); + Config.setExceptionMsg(null); + Config.updateContainsErrorMsg(false); if (com.gh.gamecenter.common.BuildConfig.BUILD_TIME != 0) { message = message + " [此闪退基于" + com.gh.gamecenter.common.BuildConfig.BUILD_TIME + "测试包]"; } @@ -1307,12 +1310,6 @@ public class SuggestionActivity extends ToolBarActivity implements OnRequestCall postDialog.dismissAllowingStateLoss(); } setResult(SUGGEST_TYPE_REQUEST); - /*if (mHideHint.equals("APP闪退:")) { - showKefuReportDialog(); - } else { - toast("感谢您的反馈!"); - finish(); - }*/ toast("感谢您的反馈!"); finish(); AppExecutor.getUiExecutor().executeWithDelay(() -> NotificationHelper.showNotificationHintDialog(NotificationUgc.FEEDBACK, null), 1000); @@ -1401,41 +1398,6 @@ public class SuggestionActivity extends ToolBarActivity implements OnRequestCall }); } - public String readFromFile() { - - if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { - if (getExternalFilesDir(null) == null) return "SD Card error"; - File file = new File(getExternalFilesDir(null).getPath() + "/log"); - if (file.isFile()) return "检测log文件夹是文件"; - - File[] files = file.listFiles(); - if (files == null || files.length == 0) return "log文件夹为空" + file.getPath(); - File targetFile = files[files.length - 1]; - - try { - if (!targetFile.exists()) { - targetFile.createNewFile(); - return "No File error "; - } else { - try (InputStream in = new BufferedInputStream(new FileInputStream(targetFile)); - BufferedReader br = new BufferedReader(new InputStreamReader(in, "UTF-8"))) { - String tmp; - StringBuffer string = new StringBuffer(); - while ((tmp = br.readLine()) != null) { - string.append(tmp); - } - return string.toString(); - } - } - } catch (Exception e) { - return e.toString(); - } - } else { - return "SD Card error"; - } - } - - @Override public void onListClick(View view, int position, T data) { if (!mAgreePostPic && !NetworkUtils.isWifiConnected(this)) { @@ -1462,25 +1424,6 @@ public class SuggestionActivity extends ToolBarActivity implements OnRequestCall } } - private void showKefuReportDialog() { - // 只有是APP闪退反馈成功后弹出联系客服的弹窗 - String str = "您也可以联系客服进一步描述闪退的情况,如果您反馈的是新问题,即有机会获得红包奖励"; - DialogHelper.showWarningDialog(SuggestionActivity.this, "反馈成功", Html.fromHtml(str.substring(0, str.indexOf("红包奖励")) + "红包奖励"), "暂不", "联系客服", - () -> { - if (ShareUtils.isQQClientAvailable(this)) { - finish(); - DirectUtils.directToQqConversation(this, null); - } else { - toast("本机未安装QQ应用"); - } - return null; - }, - () -> { - finish(); - return null; - }); - } - @Override protected boolean handleBackPressed() { if (mSelectGameEntity != null && mCollectCancelPkgName.equals(mSelectGameEntity.getPackageName())) { diff --git a/module_common/src/main/java/com/gh/gamecenter/common/base/AppUncaughtHandler.java b/module_common/src/main/java/com/gh/gamecenter/common/base/AppUncaughtHandler.java index 89311d68c3..0ae6dc7f9e 100644 --- a/module_common/src/main/java/com/gh/gamecenter/common/base/AppUncaughtHandler.java +++ b/module_common/src/main/java/com/gh/gamecenter/common/base/AppUncaughtHandler.java @@ -13,19 +13,12 @@ import android.util.Log; import com.gh.gamecenter.common.constant.Config; import com.gh.gamecenter.core.HaloApp; -import com.lightgame.download.FileUtils; import com.lightgame.utils.AppManager; import com.lightgame.utils.Utils; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; import java.lang.Thread.UncaughtExceptionHandler; -import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.Date; import java.util.List; -import java.util.Locale; import java.util.concurrent.TimeoutException; import io.sentry.Sentry; @@ -64,7 +57,7 @@ public class AppUncaughtHandler implements UncaughtExceptionHandler { Utils.toast(mContext.getApplicationContext(), "\"光环助手\"发生错误"); Looper.loop(); }); - saveLocalLog(mContext, e); + saveCrashLogToSp(e); restart(mContext); Sentry.captureException(e); } @@ -117,32 +110,11 @@ public class AppUncaughtHandler implements UncaughtExceptionHandler { } - // 保存log到本地 - public static void saveLocalLog(Context context, Throwable ex) { + // 保存 crash log 到Sp + public static void saveCrashLogToSp(Throwable ex) { String errorMsg = Log.getStackTraceString(ex); Config.setExceptionMsg(errorMsg); - - // 保存到本地 - SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.getDefault()); - File file = new File(FileUtils.getLogPath(context.getApplicationContext(), - format.format(new Date()) + "_gh_assist" + ".log")); - FileWriter writer = null; - try { - file.createNewFile(); - writer = new FileWriter(file); - writer.write(errorMsg); - writer.flush(); - } catch (IOException e1) { - e1.printStackTrace(); - } finally { - if (writer != null) { - try { - writer.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - } + Config.updateContainsErrorMsg(true); } interface UncaughtExceptionListener { diff --git a/module_common/src/main/java/com/gh/gamecenter/common/constant/Config.kt b/module_common/src/main/java/com/gh/gamecenter/common/constant/Config.kt index f82ab8324f..9b823b63b3 100644 --- a/module_common/src/main/java/com/gh/gamecenter/common/constant/Config.kt +++ b/module_common/src/main/java/com/gh/gamecenter/common/constant/Config.kt @@ -21,6 +21,16 @@ object Config { setString(getPreferences(), "errMsg", errMsg) //先用apply(),保存不了再用commit() 9.0机型保存不了信息 } + @JvmStatic + fun updateContainsErrorMsg(containsCrashMsg: Boolean) { + setString(getPreferences(), "containsErrMsg", if (containsCrashMsg) "true" else "false") + } + + @JvmStatic + fun isContainsErrorMsg(): Boolean { + return "true" == getPreferences().getString("containsErrMsg", null) + } + fun getPreferences(): SharedPreferences { if (mDefaultSharedPreferences == null) { mDefaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(HaloApp.getInstance())