Skip to content

Commit 84172fb

Browse files
author
FunkyMuse
committed
removed unnecessary functions and updated kotlin to 1.4.30 and start-up to 1.0.0
1 parent 1ad1aac commit 84172fb

File tree

8 files changed

+119
-129
lines changed

8 files changed

+119
-129
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
### A small Android library written entirely in Kotlin to collect crash reports and save them to storage.
33

44
[![](https://jitpack.io/v/FunkyMuse/Crashy.svg)](https://jitpack.io/#FunkyMuse/Crashy)
5-
[![Kotlin](https://img.shields.io/badge/Kotlin-1.4.0-blue.svg)](https://kotlinlang.org) [![Platform](https://img.shields.io/badge/Platform-Android-green.svg)](https://developer.android.com/guide/)
5+
[![Kotlin](https://img.shields.io/badge/Kotlin-1.4.30-blue.svg)](https://kotlinlang.org) [![Platform](https://img.shields.io/badge/Platform-Android-green.svg)](https://developer.android.com/guide/)
66
![API](https://img.shields.io/badge/Min%20API-21-green)
77
![API](https://img.shields.io/badge/Compiled%20API-30-green)
88

@@ -25,7 +25,7 @@ allprojects {
2525
```gradle
2626
dependencies {
2727
// androidX startup for auto-init or find the latest version at the link above
28-
implementation "androidx.startup:startup-runtime:1.0.0-beta01"
28+
implementation "androidx.startup:startup-runtime:1.0.0"
2929
3030
//crashy
3131
implementation 'com.github.FunkyMuse:Crashy:$version'

app/build.gradle

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ android {
3939
dependencies {
4040
implementation fileTree(dir: "libs", include: ["*.jar"])
4141
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
42-
implementation 'androidx.core:core-ktx:1.5.0-alpha04'
42+
implementation 'androidx.core:core-ktx:1.5.0-beta01'
4343
implementation 'androidx.appcompat:appcompat:1.2.0'
44-
implementation 'androidx.constraintlayout:constraintlayout:2.0.2'
45-
testImplementation 'junit:junit:4.13.1'
44+
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
45+
46+
testImplementation "junit:junit:$junitVersion"
4647
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
4748
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
4849

build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
buildscript {
2-
ext.kotlin_version = "1.4.10"
2+
ext.kotlin_version = "1.4.30"
33
repositories {
44
google()
55
jcenter()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:4.1.0'
8+
classpath 'com.android.tools.build:gradle:4.1.2'
99
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1010
}
1111
}
@@ -23,12 +23,12 @@ task clean(type: Delete) {
2323

2424
ext {
2525
//tests
26-
junitVersion = '4.13.1'
26+
junitVersion = '4.13.2'
2727
hamcrestVersion = '1.3'
2828
androidXTestCoreVersion = '1.3.0'
2929
androidXTestExtKotlinRunnerVersion = '1.1.2'
3030
androidXTestRulesVersion = '1.2.0-beta01'
3131
robolectricVersion = '4.4'
3232
archTestingVersion = '2.1.0'
33-
startup = '1.0.0-rc01'
33+
startup = '1.0.0'
3434
}

crashyreporter/src/main/java/com/crazylegend/crashyreporter/extensions/ExtensionFunctions.kt

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ internal val Context.requestedPermissions get() = tryOrNull {
3636
packageManager.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS).requestedPermissions.toList()
3737
}
3838

39-
39+
internal const val NEW_ROW = "\n"
4040
internal val Context.getBatteryPercentage get() = batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY)
4141

4242
internal val Context.isBatteryCharging
@@ -163,16 +163,13 @@ internal fun Context.getExitReasons(pid: Int = 0, maxRes: Int = 1) =
163163
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
164164
activityManager.getHistoricalProcessExitReasons(packageName, pid, maxRes)
165165
.mapIndexed { index, it ->
166-
"~~~~~~~~~~~ Exit reason #${index + 1} ~~~~~~~~~~~\n" +
167-
"\n" +
168-
"Description: ${it.description}\n" +
169-
"Importance: ${buildImportance(it.importance)}\n" +
170-
"Reason: ${buildExitReason(it.reason)}\n" +
171-
"Timestamp: ${CrashyReporter.dateFormat.format(Date(it.timestamp))}\n" +
172-
"\n" +
173-
"~~~~~~~~~~~ END of exit reason #${index + 1} ~~~~~~~~~~~" +
174-
"\n" +
175-
"\n"
166+
"`` Exit reason #${index + 1} ``$NEW_ROW" +
167+
"Description: ${it.description}$NEW_ROW" +
168+
"Importance: ${buildImportance(it.importance)}$NEW_ROW" +
169+
"Reason: ${buildExitReason(it.reason)}$NEW_ROW" +
170+
"Timestamp: ${CrashyReporter.dateFormat.format(Date(it.timestamp))}$NEW_ROW" +
171+
"`` END of exit reason #${index + 1} ``" +
172+
NEW_ROW
176173
}
177174
} else {
178175
emptyList()
@@ -196,7 +193,7 @@ internal fun Context.getRunningProcesses() =
196193
activityManager.getRunningServices(Integer.MAX_VALUE).map {
197194
it.service.className
198195
}
199-
}.notAvailableIfNullNewLine().replace("[", "").replace("]", "").replace(",", "\n")
196+
}.notAvailableIfNullNewLine().replace("[", "").replace("]", "").replace(",", "$NEW_ROW")
200197

201198
internal fun buildImportance(importance: Int): String {
202199
return when (importance) {
@@ -218,7 +215,7 @@ internal const val notAvailableString = "N/A"
218215
internal fun String?.notAvailableIfNull() = if (this.isNullOrEmpty()) notAvailableString else this
219216

220217
internal fun <T> Collection<T>?.notAvailableIfNullNewLine(): String =
221-
if (this.isNullOrEmpty()) "N/A" else "\n${this}"
218+
if (this.isNullOrEmpty()) "N/A" else "$NEW_ROW${this}"
222219

223220
internal fun <T> Collection<T>?.notAvailableIfNull(): String =
224221
if (this.isNullOrEmpty()) "N/A" else "$this"
@@ -230,7 +227,7 @@ internal val Context.actualPackageName: String?
230227
internal val Context.flavor: String?
231228
get() = getBuildConfigValue(actualPackageName, "FLAVOR") as String?
232229

233-
internal val Context.appName: String?
230+
internal val Context.appName: String
234231
get() {
235232
val applicationInfo = applicationContext.applicationInfo
236233
val stringId = applicationInfo.labelRes
@@ -306,12 +303,6 @@ private val Context.currentSignatures: Array<String>
306303

307304
internal fun formatMillisToHoursMinutesSeconds(millis: Long) = String.format("%d hr %d min, %d sec", millis / (1000 * 60 * 60), (millis % (1000 * 60 * 60)) / (1000 * 60), ((millis % (1000 * 60 * 60)) % (1000 * 60)) / 1000)
308305

309-
internal fun <T> List<T>.mapWithNewLine() = mapIndexed { index, t -> if (index == lastIndex) t.toString() else "$t\n" }.toString().replace("[", "").replace("]", "")
310-
internal fun <T> Array<T>.mapWithNewLine() = mapIndexed { index, t -> if (index == lastIndex) t.toString() else "$t\n" }.toString().replace("[", "").replace("]", "")
311-
312-
internal fun <T> List<T>.mapWithoutNewLine() = map { it.toString() }.toString().replace("[", "").replace("]", "")
313-
internal fun <T> Array<T>.mapWithoutNewLine() = map { it.toString() }.toString().replace("[", "").replace("]", "")
314-
315-
internal val Context.systemFeatures get() = packageManager.systemAvailableFeatures.mapWithNewLine()
306+
internal val Context.systemFeatures get() = packageManager.systemAvailableFeatures.joinToString { it.toString() }
316307

317308
internal fun Context.isDebuggable(): Boolean = applicationContext.applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE != 0

crashyreporter/src/main/java/com/crazylegend/crashyreporter/utils/ApplicationUtils.kt

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,23 @@ import java.util.*
1313
internal object ApplicationUtils {
1414

1515
internal fun appendApplicationInfo(context: Context): String {
16-
return "*********** Application info ***********\n" +
17-
"\n" +
18-
"App name: ${context.appName.notAvailableIfNull()}\n" +
19-
"Version code: ${context.getVersionCodeCompat()}\n" +
20-
"Version name: ${context.getVersionName().notAvailableIfNull()}\n" +
21-
"Package name: ${context.applicationInfo.packageName.notAvailableIfNull()}\n" +
22-
"Short package name: ${context.shortAppName.notAvailableIfNull()}\n" +
23-
"Flavor: ${context.flavor.notAvailableIfNull()}\n" +
24-
"Signatures: ${context.apkSignatures.mapWithoutNewLine().notAvailableIfNull()}\n" +
25-
"Is debuggable: ${context.isDebuggable().asYesOrNo()}\n" +
26-
"First installed: ${CrashyReporter.dateFormat.format(Date(context.getFirstInstallTime))}\n" +
27-
"Last updated: ${CrashyReporter.dateFormat.format(Date(context.lastUpdateTime))}\n" +
28-
"Requested permissions: ${context.requestedPermissions?.mapWithoutNewLine().notAvailableIfNull()}\n" +
29-
"Default prefs: ${SharedPreferencesUtil.collect(context).notAvailableIfNull()}\n" +
30-
"Default prefs: ${SharedPreferencesUtil.collect(context).notAvailableIfNull()}\n" +
31-
"\n" +
32-
"*********** END of Application info ***********" +
33-
"\n" +
34-
"\n"
16+
return "`` Application info ``$NEW_ROW" +
17+
NEW_ROW +
18+
"App name: ${context.appName.notAvailableIfNull()}$NEW_ROW" +
19+
"Version code: ${context.getVersionCodeCompat()}$NEW_ROW" +
20+
"Version name: ${context.getVersionName().notAvailableIfNull()}$NEW_ROW" +
21+
"Package name: ${context.applicationInfo.packageName.notAvailableIfNull()}$NEW_ROW" +
22+
"Short package name: ${context.shortAppName.notAvailableIfNull()}$NEW_ROW" +
23+
"Flavor: ${context.flavor.notAvailableIfNull()}$NEW_ROW" +
24+
"Signatures: ${context.apkSignatures.joinToString { it }.notAvailableIfNull()}$NEW_ROW" +
25+
"Is debuggable: ${context.isDebuggable().asYesOrNo()}$NEW_ROW" +
26+
"First installed: ${CrashyReporter.dateFormat.format(Date(context.getFirstInstallTime))}$NEW_ROW" +
27+
"Last updated: ${CrashyReporter.dateFormat.format(Date(context.lastUpdateTime))}$NEW_ROW" +
28+
"Requested permissions: ${context.requestedPermissions?.joinToString { it.toString() }.notAvailableIfNull()}$NEW_ROW" +
29+
"Default prefs: ${SharedPreferencesUtil.collect(context).notAvailableIfNull()}$NEW_ROW" +
30+
"Default prefs: ${SharedPreferencesUtil.collect(context).notAvailableIfNull()}$NEW_ROW" +
31+
NEW_ROW +
32+
"`` END of Application info ``" +
33+
NEW_ROW + NEW_ROW
3534
}
3635
}

crashyreporter/src/main/java/com/crazylegend/crashyreporter/utils/DeviceUtils.kt

Lines changed: 60 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -23,61 +23,59 @@ internal object DeviceUtils {
2323

2424
fun getDeviceDetails(context: Context): String {
2525

26-
return "----------- Device info -----------\n" +
27-
"\n" +
26+
return "`` Device info ``$NEW_ROW" +
27+
NEW_ROW +
2828
"Report ID: ${UUID.randomUUID()}" +
29-
"\n" +
30-
"Device ID: ${getDeviceID(context)}\n" +
31-
"Application version: ${getAppVersion(context)}\n" +
32-
"Default launcher: ${getLaunchedFromApp(context)}\n" +
33-
"Timezone name: ${TimeZone.getDefault().displayName}\n" +
34-
"Timezone ID: ${TimeZone.getDefault().id}\n" +
35-
"Version release: ${Build.VERSION.RELEASE}\n" +
36-
"Version incremental : ${Build.VERSION.INCREMENTAL}\n" +
37-
"Version SDK: ${Build.VERSION.SDK_INT}\n" +
38-
"Board: ${Build.BOARD}\n" +
39-
"Bootloader: ${Build.BOOTLOADER}\n" +
40-
"Brand: ${Build.BRAND}\n" +
41-
"CPU_ABIS_32: ${Build.SUPPORTED_32_BIT_ABIS.map { it }.mapWithoutNewLine().notAvailableIfNull()}\n" +
42-
"CPU_ABIS_64: ${Build.SUPPORTED_64_BIT_ABIS.map { it }.mapWithoutNewLine().notAvailableIfNull()}\n" +
43-
"Supported ABIS: ${Build.SUPPORTED_ABIS.map { it }.mapWithoutNewLine().notAvailableIfNull()}\n" +
44-
"Device: ${Build.DEVICE}\n" +
45-
"Display: ${Build.DISPLAY}\n" +
46-
"Fingerprint: ${Build.FINGERPRINT}\n" +
47-
"Hardware: ${Build.HARDWARE}\n" +
48-
"Host: ${Build.HOST}\n" +
49-
"ID: ${Build.ID}\n" +
50-
"Manufacturer: ${Build.MANUFACTURER}\n" +
51-
"Product: ${Build.PRODUCT}\n" +
52-
"Build time: ${Build.TIME}\n" +
53-
"Build time formatted: ${CrashyReporter.dateFormat.format(Date(Build.TIME))}\n" +
54-
"Type: ${Build.TYPE}\n" +
55-
"Radio: ${getRadioVersion()}\n" +
56-
"Tags: ${Build.TAGS}\n" +
57-
"User: ${Build.USER}\n" +
58-
"User IDs: ${getUserPlayIDs(context).notAvailableIfNull()}\n" +
59-
"Is sustained performance mode supported: ${context.isSustainedPerformanceModeSupported}\n" +
60-
"Is in power save mode: ${context.isInPowerSaveMode}\n" +
61-
"Is in interactive state: ${context.isInInteractiveState}\n" +
62-
"Is ignoring battery optimizations: ${context.isIgnoringBatteryOptimization}\n" +
63-
"Thermal status: ${context.getThermalStatus}\n" +
64-
"Location power save mode: ${context.locationPowerSaveMode}\n" +
65-
"Is device idle: ${context.isDeviceIdle}\n" +
66-
"Battery percentage: ${context.getBatteryPercentage}\n" +
67-
"Battery remaining time: ${getChargeRemainingTime(context)}\n" +
68-
"Is battery charging: ${context.isBatteryCharging.asYesOrNo()}\n" +
69-
"Is device rooted: ${RootUtils.isDeviceRooted.asYesOrNo()}\n" +
70-
"CPU Model: ${CPUInfo.getCPUModel().notAvailableIfNull()}\n" +
71-
"# of CPU cores: ${CPUInfo.getNumberOfCores()}\n" +
72-
"Up time with sleep: ${upTimeWithSleep()}\n" +
73-
"Up time without sleep: ${upTimeWithoutSleep()}\n" +
74-
"\n" +
75-
"----------- END of Device info -----------" +
76-
"\n" +
77-
"\n" +
29+
NEW_ROW +
30+
"Device ID: ${getDeviceID(context)}$NEW_ROW" +
31+
"Application version: ${getAppVersion(context)}$NEW_ROW" +
32+
"Default launcher: ${getLaunchedFromApp(context)}$NEW_ROW" +
33+
"Timezone name: ${TimeZone.getDefault().displayName}$NEW_ROW" +
34+
"Timezone ID: ${TimeZone.getDefault().id}$NEW_ROW" +
35+
"Version release: ${Build.VERSION.RELEASE}$NEW_ROW" +
36+
"Version incremental : ${Build.VERSION.INCREMENTAL}$NEW_ROW" +
37+
"Version SDK: ${Build.VERSION.SDK_INT}$NEW_ROW" +
38+
"Board: ${Build.BOARD}$NEW_ROW" +
39+
"Bootloader: ${Build.BOOTLOADER}$NEW_ROW" +
40+
"Brand: ${Build.BRAND}$NEW_ROW" +
41+
"CPU ABIS 32: ${Build.SUPPORTED_32_BIT_ABIS.joinToString { it }.notAvailableIfNull()}$NEW_ROW" +
42+
"CPU ABIS 64: ${Build.SUPPORTED_64_BIT_ABIS.joinToString { it }.notAvailableIfNull()}$NEW_ROW" +
43+
"Supported ABIS: ${Build.SUPPORTED_ABIS.joinToString { it }.notAvailableIfNull()}$NEW_ROW" +
44+
"Device: ${Build.DEVICE}$NEW_ROW" +
45+
"Display: ${Build.DISPLAY}$NEW_ROW" +
46+
"Fingerprint: ${Build.FINGERPRINT}$NEW_ROW" +
47+
"Hardware: ${Build.HARDWARE}$NEW_ROW" +
48+
"Host: ${Build.HOST}$NEW_ROW" +
49+
"ID: ${Build.ID}$NEW_ROW" +
50+
"Manufacturer: ${Build.MANUFACTURER}$NEW_ROW" +
51+
"Product: ${Build.PRODUCT}$NEW_ROW" +
52+
"Build time: ${Build.TIME}$NEW_ROW" +
53+
"Build time formatted: ${CrashyReporter.dateFormat.format(Date(Build.TIME))}$NEW_ROW" +
54+
"Type: ${Build.TYPE}$NEW_ROW" +
55+
"Radio: ${getRadioVersion()}$NEW_ROW" +
56+
"Tags: ${Build.TAGS}$NEW_ROW" +
57+
"User: ${Build.USER}$NEW_ROW" +
58+
"User IDs: ${getUserPlayIDs(context).notAvailableIfNull()}$NEW_ROW" +
59+
"Is sustained performance mode supported: ${context.isSustainedPerformanceModeSupported}$NEW_ROW" +
60+
"Is in power save mode: ${context.isInPowerSaveMode}$NEW_ROW" +
61+
"Is in interactive state: ${context.isInInteractiveState}$NEW_ROW" +
62+
"Is ignoring battery optimizations: ${context.isIgnoringBatteryOptimization}$NEW_ROW" +
63+
"Thermal status: ${context.getThermalStatus}$NEW_ROW" +
64+
"Location power save mode: ${context.locationPowerSaveMode}$NEW_ROW" +
65+
"Is device idle: ${context.isDeviceIdle}$NEW_ROW" +
66+
"Battery percentage: ${context.getBatteryPercentage}$NEW_ROW" +
67+
"Battery remaining time: ${getChargeRemainingTime(context)}$NEW_ROW" +
68+
"Is battery charging: ${context.isBatteryCharging.asYesOrNo()}$NEW_ROW" +
69+
"Is device rooted: ${RootUtils.isDeviceRooted.asYesOrNo()}$NEW_ROW" +
70+
"CPU Model: ${CPUInfo.getCPUModel().notAvailableIfNull()}$NEW_ROW" +
71+
"Number of CPU cores: ${CPUInfo.getNumberOfCores()}$NEW_ROW" +
72+
"Up time with sleep: ${upTimeWithSleep()}$NEW_ROW" +
73+
"Up time without sleep: ${upTimeWithoutSleep()}$NEW_ROW" +
74+
NEW_ROW +
75+
"`` END of Device info ``" +
76+
NEW_ROW + NEW_ROW +
7877
appendExitReasons(context) +
79-
"\n" +
80-
"\n" +
78+
NEW_ROW + NEW_ROW +
8179
appendApplicationInfo(context)
8280
}
8381

@@ -96,9 +94,10 @@ internal object DeviceUtils {
9694

9795

9896
private fun appendExitReasons(context: Context): String {
99-
return "########### Exit reasons ###########\n" +
100-
"${context.getExitReasons(maxRes = 3).notAvailableIfNullNewLine().replace("[", "").replace("]", "").replace(",", "\n")}\n" +
101-
"########### END of exit reasons ###########"
97+
return "`` Exit reasons ``$NEW_ROW" + NEW_ROW +
98+
"${context.getExitReasons(maxRes = 3).notAvailableIfNullNewLine().replace("[", "").replace("]", "").replace(",", NEW_ROW)}$NEW_ROW" +
99+
NEW_ROW +
100+
"`` END of exit reasons ``"
102101
}
103102

104103

@@ -151,11 +150,11 @@ internal object DeviceUtils {
151150

152151

153152
fun getRunningProcesses(context: Context) =
154-
"^^^^^^^^^^^ Currently running foreground/background processes ^^^^^^^^^^^\n" +
155-
"\n" +
156-
"${context.getRunningProcesses()}\n" +
157-
"\n" +
158-
"^^^^^^^^^^^ END of running foreground/background processes info ^^^^^^^^^^^"
153+
"`` Currently running foreground/background processes ``$NEW_ROW" +
154+
NEW_ROW +
155+
"${context.getRunningProcesses()}$NEW_ROW" +
156+
NEW_ROW +
157+
"`` END of running foreground/background processes info ``"
159158

160159

161160
}

crashyreporter/src/main/java/com/crazylegend/crashyreporter/utils/SharedPreferencesUtil.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.crazylegend.crashyreporter.utils
22

33
import android.content.Context
44
import android.preference.PreferenceManager
5-
import com.crazylegend.crashyreporter.extensions.mapWithoutNewLine
65

76

87
/**
@@ -15,5 +14,5 @@ internal object SharedPreferencesUtil {
1514
val key = it.key
1615
val value = it.value
1716
"$key = $value"
18-
}.toList().mapWithoutNewLine()
17+
}.toList().joinToString()
1918
}

0 commit comments

Comments
 (0)