@@ -6,9 +6,12 @@ import android.net.Uri
6
6
import android.os.Build
7
7
import android.os.Bundle
8
8
import androidx.appcompat.app.AppCompatActivity
9
+ import com.yogeshpaliyal.common.data.UserSettings
10
+ import com.yogeshpaliyal.common.utils.getUserSettings
9
11
import com.yogeshpaliyal.keypass.BuildConfig
10
12
import com.yogeshpaliyal.keypass.databinding.ActivityCrashBinding
11
13
import dagger.hilt.android.AndroidEntryPoint
14
+ import kotlinx.coroutines.runBlocking
12
15
import java.lang.StringBuilder
13
16
14
17
@AndroidEntryPoint
@@ -31,35 +34,70 @@ class CrashActivity : AppCompatActivity() {
31
34
binding = ActivityCrashBinding .inflate(layoutInflater)
32
35
setContentView(binding.root)
33
36
34
- binding.txtCrash.text = intent.extras?.getString(ARG_DATA )
37
+ binding.txtCrash.text = getCrashWithMetaData( intent.extras?.getString(ARG_DATA ) )
35
38
36
39
binding.btnSendFeedback.setOnClickListener {
37
- val deviceInfo = StringBuilder ()
38
- deviceInfo.append(binding.txtCrash.text.toString())
39
- try {
40
- deviceInfo.append(" \n " )
41
- deviceInfo.append(" App Version: " + BuildConfig .VERSION_NAME )
42
- deviceInfo.append(" \n " )
43
- deviceInfo.append(" Brand Name: " + Build .BRAND )
44
- deviceInfo.append(" \n " )
45
- deviceInfo.append(" Manufacturer Name: " + Build .MANUFACTURER )
46
- deviceInfo.append(" \n " )
47
- deviceInfo.append(" Device Name: " + Build .MODEL )
48
- deviceInfo.append(" \n " )
49
- deviceInfo.append(" Device API Version: " + Build .VERSION .SDK_INT )
50
- deviceInfo.append(" \n " )
51
- } catch (e: Exception ) {
52
- e.printStackTrace()
53
- }
54
-
55
40
val intent = Intent (Intent .ACTION_SENDTO )
56
41
intent.data = Uri .parse(" mailto:" )
57
42
58
43
intent.putExtra(Intent .EXTRA_EMAIL , arrayOf(" yogeshpaliyal.foss+keypass@gmail.com" ))
59
44
intent.putExtra(Intent .EXTRA_SUBJECT , " Crash Report in KeyPass" )
60
- intent.putExtra(Intent .EXTRA_TEXT , deviceInfo .toString())
45
+ intent.putExtra(Intent .EXTRA_TEXT , binding.txtCrash.text .toString())
61
46
62
47
startActivity(Intent .createChooser(intent, " " ))
63
48
}
64
49
}
50
+
51
+ private fun getCrashWithMetaData (crashData : String? ): String {
52
+ var userSettings: UserSettings ? = null
53
+ var currentAppVersion = " Not able to fetch"
54
+ var lastAppVersion = " Not able to fetch"
55
+ runBlocking {
56
+ try {
57
+ userSettings = getUserSettings()
58
+ currentAppVersion = userSettings?.currentAppVersion.toString()
59
+ lastAppVersion = userSettings?.lastAppVersion.toString()
60
+ } catch (e: Exception ) {
61
+ currentAppVersion = e.message ? : " Not able to fetch"
62
+ lastAppVersion = e.message ? : " Not able to fetch"
63
+ e.printStackTrace()
64
+ }
65
+ }
66
+ val installerPackageName = getInstallerPackageName(this , BuildConfig .APPLICATION_ID )
67
+ val deviceInfo = StringBuilder ()
68
+ deviceInfo.append(crashData)
69
+ try {
70
+ deviceInfo.append(" \n " )
71
+ deviceInfo.append(" App Version from Build: " + BuildConfig .VERSION_NAME )
72
+ deviceInfo.append(" \n " )
73
+ deviceInfo.append(" Current App Version: $currentAppVersion " )
74
+ deviceInfo.append(" \n " )
75
+ deviceInfo.append(" Previous App Version: $lastAppVersion " )
76
+ deviceInfo.append(" \n " )
77
+ deviceInfo.append(" Installed from: $installerPackageName " )
78
+ deviceInfo.append(" \n " )
79
+ deviceInfo.append(" Brand Name: " + Build .BRAND )
80
+ deviceInfo.append(" \n " )
81
+ deviceInfo.append(" Manufacturer Name: " + Build .MANUFACTURER )
82
+ deviceInfo.append(" \n " )
83
+ deviceInfo.append(" Device Name: " + Build .MODEL )
84
+ deviceInfo.append(" \n " )
85
+ deviceInfo.append(" Device API Version: " + Build .VERSION .SDK_INT )
86
+ deviceInfo.append(" \n " )
87
+ } catch (e: Exception ) {
88
+ e.printStackTrace()
89
+ }
90
+ return deviceInfo.toString()
91
+ }
92
+
93
+ fun getInstallerPackageName (context : Context , packageName : String ): String? {
94
+ kotlin.runCatching {
95
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .R ) {
96
+ return context.packageManager.getInstallSourceInfo(packageName).installingPackageName
97
+ }
98
+ @Suppress(" DEPRECATION" )
99
+ return context.packageManager.getInstallerPackageName(packageName)
100
+ }
101
+ return null
102
+ }
65
103
}
0 commit comments