mirror of
https://github.com/KitsunePie/AppErrorsTracking.git
synced 2025-09-01 08:45:16 +08:00
Added Microsoft App Center analytics
This commit is contained in:
@@ -27,6 +27,9 @@ android {
|
|||||||
versionName rootProject.ext.appVersionName
|
versionName rootProject.ext.appVersionName
|
||||||
|
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
|
||||||
|
/** 添加 App Center Secret 到 BuildConfig */
|
||||||
|
buildConfigField("String", "APP_CENTER_SECRET", "\"${getAppCenterSecret()}\"")
|
||||||
}
|
}
|
||||||
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
@@ -58,10 +61,23 @@ android {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取 App Center Secret
|
||||||
|
* @return [String]
|
||||||
|
*/
|
||||||
|
String getAppCenterSecret() {
|
||||||
|
def fileName = '../.secret/APP_CENTER_SECRET'
|
||||||
|
def content = ''
|
||||||
|
if (file(fileName).exists()) file(fileName).eachLine { content = it }
|
||||||
|
return content
|
||||||
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly 'de.robv.android.xposed:api:82'
|
compileOnly 'de.robv.android.xposed:api:82'
|
||||||
implementation 'com.highcapable.yukihookapi:api:1.1.4'
|
implementation 'com.highcapable.yukihookapi:api:1.1.4'
|
||||||
ksp 'com.highcapable.yukihookapi:ksp-xposed:1.1.4'
|
ksp 'com.highcapable.yukihookapi:ksp-xposed:1.1.4'
|
||||||
|
implementation "com.microsoft.appcenter:appcenter-analytics:4.4.5"
|
||||||
|
implementation "com.microsoft.appcenter:appcenter-crashes:4.4.5"
|
||||||
implementation 'com.google.code.gson:gson:2.9.0'
|
implementation 'com.google.code.gson:gson:2.9.0'
|
||||||
implementation 'com.github.duanhong169:drawabletoolbox:1.0.7'
|
implementation 'com.github.duanhong169:drawabletoolbox:1.0.7'
|
||||||
implementation "com.github.topjohnwu.libsu:core:3.1.2"
|
implementation "com.github.topjohnwu.libsu:core:3.1.2"
|
||||||
|
@@ -24,6 +24,7 @@ package com.fankes.apperrorstracking.application
|
|||||||
import androidx.appcompat.app.AppCompatDelegate
|
import androidx.appcompat.app.AppCompatDelegate
|
||||||
import com.fankes.apperrorstracking.data.ConfigData
|
import com.fankes.apperrorstracking.data.ConfigData
|
||||||
import com.fankes.apperrorstracking.locale.LocaleString
|
import com.fankes.apperrorstracking.locale.LocaleString
|
||||||
|
import com.fankes.apperrorstracking.utils.tool.AppAnalyticsTool
|
||||||
import com.highcapable.yukihookapi.hook.xposed.application.ModuleApplication
|
import com.highcapable.yukihookapi.hook.xposed.application.ModuleApplication
|
||||||
|
|
||||||
class AppErrorsApplication : ModuleApplication() {
|
class AppErrorsApplication : ModuleApplication() {
|
||||||
@@ -36,5 +37,7 @@ class AppErrorsApplication : ModuleApplication() {
|
|||||||
LocaleString.bind(instance = this)
|
LocaleString.bind(instance = this)
|
||||||
/** 装载存储控制类 */
|
/** 装载存储控制类 */
|
||||||
ConfigData.init(instance = this)
|
ConfigData.init(instance = this)
|
||||||
|
/** 装载 App Center */
|
||||||
|
AppAnalyticsTool.init(instance = this)
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -36,6 +36,7 @@ import com.fankes.apperrorstracking.ui.activity.debug.LoggerActivity
|
|||||||
import com.fankes.apperrorstracking.ui.activity.errors.AppErrorsMutedActivity
|
import com.fankes.apperrorstracking.ui.activity.errors.AppErrorsMutedActivity
|
||||||
import com.fankes.apperrorstracking.ui.activity.errors.AppErrorsRecordActivity
|
import com.fankes.apperrorstracking.ui.activity.errors.AppErrorsRecordActivity
|
||||||
import com.fankes.apperrorstracking.utils.factory.*
|
import com.fankes.apperrorstracking.utils.factory.*
|
||||||
|
import com.fankes.apperrorstracking.utils.tool.AppAnalyticsTool.bindAppAnalytics
|
||||||
import com.fankes.apperrorstracking.utils.tool.FrameworkTool
|
import com.fankes.apperrorstracking.utils.tool.FrameworkTool
|
||||||
import com.highcapable.yukihookapi.YukiHookAPI
|
import com.highcapable.yukihookapi.YukiHookAPI
|
||||||
|
|
||||||
@@ -66,6 +67,8 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
|||||||
if (btn.isPressed.not()) return@setOnCheckedChangeListener
|
if (btn.isPressed.not()) return@setOnCheckedChangeListener
|
||||||
hideOrShowLauncherIcon(b)
|
hideOrShowLauncherIcon(b)
|
||||||
}
|
}
|
||||||
|
/** 设置匿名统计 */
|
||||||
|
binding.enableAnonymousStatisticsSwitch.bindAppAnalytics()
|
||||||
/** 系统版本点击事件 */
|
/** 系统版本点击事件 */
|
||||||
binding.mainTextSystemVersion.setOnClickListener {
|
binding.mainTextSystemVersion.setOnClickListener {
|
||||||
showDialog {
|
showDialog {
|
||||||
|
@@ -0,0 +1,87 @@
|
|||||||
|
/*
|
||||||
|
* AppErrorsTracking - Added more features to app's crash dialog, fixed custom rom deleted dialog, the best experience to Android developer.
|
||||||
|
* Copyright (C) 2019-2022 Fankes Studio(qzmmcn@163.com)
|
||||||
|
* https://github.com/KitsunePie/AppErrorsTracking
|
||||||
|
*
|
||||||
|
* This software is non-free but opensource software: you can redistribute it
|
||||||
|
* and/or modify it under the terms of the GNU Affero General Public License
|
||||||
|
* as published by the Free Software Foundation; either
|
||||||
|
* version 3 of the License, or any later version.
|
||||||
|
*
|
||||||
|
* This software is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* and eula along with this software. If not, see
|
||||||
|
* <https://www.gnu.org/licenses/>
|
||||||
|
*
|
||||||
|
* This file is Created by fankes on 2022/10/5.
|
||||||
|
*/
|
||||||
|
@file:Suppress("unused")
|
||||||
|
|
||||||
|
package com.fankes.apperrorstracking.utils.tool
|
||||||
|
|
||||||
|
import android.app.Application
|
||||||
|
import android.widget.CompoundButton
|
||||||
|
import com.fankes.apperrorstracking.BuildConfig
|
||||||
|
import com.highcapable.yukihookapi.hook.factory.modulePrefs
|
||||||
|
import com.highcapable.yukihookapi.hook.xposed.prefs.data.PrefsData
|
||||||
|
import com.microsoft.appcenter.AppCenter
|
||||||
|
import com.microsoft.appcenter.analytics.Analytics
|
||||||
|
import com.microsoft.appcenter.crashes.Crashes
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Microsoft App Center 工具
|
||||||
|
*/
|
||||||
|
object AppAnalyticsTool {
|
||||||
|
|
||||||
|
/** App Secret */
|
||||||
|
private const val APP_CENTER_SECRET = BuildConfig.APP_CENTER_SECRET
|
||||||
|
|
||||||
|
/** 启用匿名统计收集使用情况功能 */
|
||||||
|
private val ENABLE_APP_CENTER_ANALYTICS = PrefsData("_enable_app_center_analytics", true)
|
||||||
|
|
||||||
|
/** 当前实例 */
|
||||||
|
private var instance: Application? = null
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否启用匿名统计收集使用情况功能
|
||||||
|
* @return [Boolean]
|
||||||
|
*/
|
||||||
|
private var isEnableAppCenterAnalytics
|
||||||
|
get() = instance?.modulePrefs?.get(ENABLE_APP_CENTER_ANALYTICS) ?: true
|
||||||
|
set(value) {
|
||||||
|
instance?.modulePrefs?.put(ENABLE_APP_CENTER_ANALYTICS, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 绑定到 [CompoundButton] 自动设置选中状态 */
|
||||||
|
fun CompoundButton.bindAppAnalytics() {
|
||||||
|
isChecked = isEnableAppCenterAnalytics
|
||||||
|
setOnCheckedChangeListener { button, isChecked ->
|
||||||
|
if (button.isPressed.not()) return@setOnCheckedChangeListener
|
||||||
|
isEnableAppCenterAnalytics = isChecked
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传分析日志
|
||||||
|
* @param name 事件名称
|
||||||
|
* @param data 事件详细内容 - 默认空
|
||||||
|
*/
|
||||||
|
fun trackEvent(name: String, data: HashMap<String, String>? = null) {
|
||||||
|
if (data != null) Analytics.trackEvent(name, data)
|
||||||
|
else Analytics.trackEvent(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化 App Center
|
||||||
|
* @param instance 实例
|
||||||
|
*/
|
||||||
|
fun init(instance: Application) {
|
||||||
|
this.instance = instance
|
||||||
|
if (isEnableAppCenterAnalytics && APP_CENTER_SECRET.isNotBlank())
|
||||||
|
AppCenter.start(instance, APP_CENTER_SECRET, Analytics::class.java, Crashes::class.java)
|
||||||
|
}
|
||||||
|
}
|
12
app/src/main/res/drawable/ic_appcenter.xml
Normal file
12
app/src/main/res/drawable/ic_appcenter.xml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="64"
|
||||||
|
android:viewportHeight="64">
|
||||||
|
<path
|
||||||
|
android:fillColor="#ffffff"
|
||||||
|
android:pathData="M44.5,49.92L57,51.79L44.5,57L7,44.5L44.5,49.92L44.5,7L57,12.21L57,51.79L44.5,49.92Z" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#ffffff"
|
||||||
|
android:pathData="M19.5,15.33L24.29,16.38L24.29,23.88L32,18.46L38.25,20.54L38.25,37.21L32,39.29L24.08,33.88L24.08,41.38L19.5,42.42L11.17,35.13L11.17,32L15.96,28.88L11.17,25.75L11.17,22.63L19.5,15.33ZM24.08,28.88L32,33.04L32,24.71L24.08,28.88ZM13.67,23.88L19.5,26.79L19.5,19.5L13.67,23.88ZM19.5,38.25L19.5,30.96L13.67,33.88L19.5,38.25Z" />
|
||||||
|
</vector>
|
@@ -581,6 +581,71 @@
|
|||||||
android:textSize="12sp" />
|
android:textSize="12sp" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="15dp"
|
||||||
|
android:layout_marginTop="15dp"
|
||||||
|
android:layout_marginRight="15dp"
|
||||||
|
android:background="@drawable/bg_permotion_round"
|
||||||
|
android:elevation="0dp"
|
||||||
|
android:gravity="center"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:paddingLeft="15dp"
|
||||||
|
android:paddingTop="15dp"
|
||||||
|
android:paddingRight="15dp">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center|start">
|
||||||
|
|
||||||
|
<androidx.cardview.widget.CardView
|
||||||
|
android:layout_width="15dp"
|
||||||
|
android:layout_height="15dp"
|
||||||
|
android:layout_marginEnd="10dp"
|
||||||
|
app:cardBackgroundColor="#FFCB2E62"
|
||||||
|
app:cardCornerRadius="50dp"
|
||||||
|
app:cardElevation="0dp">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:padding="2dp"
|
||||||
|
android:src="@drawable/ic_appcenter" />
|
||||||
|
</androidx.cardview.widget.CardView>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:alpha="0.85"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:text="@string/microsoft_app_center"
|
||||||
|
android:textColor="@color/colorTextGray"
|
||||||
|
android:textSize="12sp" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<com.fankes.apperrorstracking.ui.view.MaterialSwitch
|
||||||
|
android:id="@+id/enable_anonymous_statistics_switch"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/enable_anonymous_statistics"
|
||||||
|
android:textAllCaps="false"
|
||||||
|
android:textColor="@color/colorTextGray"
|
||||||
|
android:textSize="15sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="10dp"
|
||||||
|
android:alpha="0.6"
|
||||||
|
android:lineSpacingExtra="6dp"
|
||||||
|
android:text="@string/enable_anonymous_statistics_tip"
|
||||||
|
android:textColor="@color/colorTextDark"
|
||||||
|
android:textSize="12sp" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
Reference in New Issue
Block a user