diff --git a/app/build.gradle b/app/build.gradle index a2d20142c0..bf2a6d54b2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -298,6 +298,8 @@ dependencies { implementation "net.lingala.zip4j:zip4j:${zip4j}" + implementation "io.sentry:sentry-android:$sentry" + implementation("com.github.piasy:BigImageViewer:$bigImageViewer", { exclude group: 'com.squareup.okhttp3' exclude group: 'androidx.swiperefreshlayout' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 06ca15a85c..e1105b9d40 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -79,6 +79,10 @@ tools:replace="android:allowBackup" tools:targetApi="n"> + + + android:windowSoftInputMode="stateHidden" /> + android:theme="@style/TransparentStatusBarAndNavigationBar" /> - - - - - - + + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - - - - - - - - + + + + + + + + + + + + - - - + + + - - - - - - - - + + + + + + + + - - - + + + - - - + + + diff --git a/app/src/main/java/com/gh/base/AppUncaughtHandler.java b/app/src/main/java/com/gh/base/AppUncaughtHandler.java index df51f1c986..16dc54f472 100644 --- a/app/src/main/java/com/gh/base/AppUncaughtHandler.java +++ b/app/src/main/java/com/gh/base/AppUncaughtHandler.java @@ -26,6 +26,8 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; +import io.sentry.core.Sentry; + public class AppUncaughtHandler implements UncaughtExceptionHandler { private Context mContext; @@ -45,7 +47,9 @@ public class AppUncaughtHandler implements UncaughtExceptionHandler { Looper.loop(); } }); + saveLocalLog(mContext, ex); + Sentry.captureException(ex); restart(mContext); } diff --git a/app/src/main/java/com/gh/common/util/DataUtils.java b/app/src/main/java/com/gh/common/util/DataUtils.java index 019b504571..1a9e723f68 100644 --- a/app/src/main/java/com/gh/common/util/DataUtils.java +++ b/app/src/main/java/com/gh/common/util/DataUtils.java @@ -26,6 +26,8 @@ import java.util.HashMap; import java.util.Map; import java.util.Properties; +import io.sentry.android.core.SentryAndroid; + /** * Created by LGT on 2016/6/15. * 数据收集 工具类 (TalkingData、MTA) @@ -43,6 +45,27 @@ public class DataUtils { if (CommonDebug.IS_DEBUG) { return; } + + SentryAndroid.init(context, options -> { + if (BuildConfig.BUILD_TIME != 0L) { + options.setRelease("内测版" + BuildConfig.BUILD_TIME); + } else { + options.setRelease(channel); + } + options.setDebug(BuildConfig.DEBUG); + options.setEnableSessionTracking(true); + options.setEnvironment(BuildConfig.FLAVOR); + options.setDsn("https://6b1caf0d17c1408e8680f3f73ff80bd0@sentry.ghzs.com/22"); + + options.setBeforeSend((event, hint) -> { + if (BuildConfig.DEBUG) { + return null; + } else { + return event; + } + }); + }); + //TalkingData // try { // TCAgent.LOG_ON = false; diff --git a/app/src/main/java/com/gh/common/util/SentryHelper.kt b/app/src/main/java/com/gh/common/util/SentryHelper.kt new file mode 100644 index 0000000000..7a7b4a728b --- /dev/null +++ b/app/src/main/java/com/gh/common/util/SentryHelper.kt @@ -0,0 +1,47 @@ +package com.gh.common.util + +import android.text.TextUtils +import com.lightgame.utils.Utils +import io.sentry.core.Sentry +import io.sentry.core.SentryEvent +import io.sentry.core.SentryLevel +import io.sentry.core.protocol.Message + +object SentryHelper { + + /** + * 注意 tag-key 不支持中文 + */ + fun onEvent(eventId: String, vararg kv: String?) { + val sentryEvent = SentryEvent() + val message = Message() + message.message = eventId + sentryEvent.message = message + sentryEvent.level = SentryLevel.LOG + + for (i in kv.indices) { + if (i % 2 != 0) { + val key = kv[i - 1] + val value = kv[i] + if (!TextUtils.isEmpty(key) && !TextUtils.isEmpty(value)) { + sentryEvent.setTag(key, value) + debugOnly { + throwExceptionInDebug("tag-key 不支持中文", isContainChinese(key)) + } + } + } + } + + Utils.log("Sentry", "$eventId + [${kv.joinToString(" , ")}]") + Sentry.captureEvent(sentryEvent) + } + + // 判断一个字符串是否含有中文 + private fun isContainChinese(str: String?): Boolean { + if (str == null) return false + for (c in str.toCharArray()) { + if (c.toInt() in 0x4E00..0x9FA5) return true + } + return false + } +} diff --git a/app/src/main/java/com/halo/assistant/HaloApp.java b/app/src/main/java/com/halo/assistant/HaloApp.java index fef00e5e60..df36d8d394 100644 --- a/app/src/main/java/com/halo/assistant/HaloApp.java +++ b/app/src/main/java/com/halo/assistant/HaloApp.java @@ -8,6 +8,7 @@ import android.net.ConnectivityManager; import android.net.Uri; import android.preference.PreferenceManager; import android.text.TextUtils; + import androidx.collection.ArrayMap; import androidx.lifecycle.ProcessLifecycleOwner; @@ -47,6 +48,7 @@ import com.llew.huawei.verifier.LoadedApkHuaWei; import com.shuyu.gsyvideoplayer.cache.CacheFactory; import com.shuyu.gsyvideoplayer.player.PlayerFactory; import com.squareup.picasso.Picasso; + import io.reactivex.plugins.RxJavaPlugins; import tv.danmaku.ijk.media.exo2.Exo2PlayerManager; import tv.danmaku.ijk.media.exo2.ExoPlayerCacheManager; diff --git a/dependencies.gradle b/dependencies.gradle index eb0feb141b..c42493a39d 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -106,4 +106,6 @@ ext { chart = "3.1.0" zip4j = "2.6.1" whatTheStack = "0.1.0_rt" + + sentry = "2.3.2" // 不要更新到 3.X,3.X 需要后台版本支持 } \ No newline at end of file