├── .gitignore
├── LICENSE
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── crazylegend
│ │ └── crashy
│ │ └── ExampleInstrumentedTest.kt
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── crazylegend
│ │ │ └── crashy
│ │ │ └── MainActivity.kt
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── crazylegend
│ └── crashy
│ └── ExampleUnitTest.kt
├── build.gradle
├── crashyreporter
├── .gitignore
├── build.gradle
├── consumer-rules.pro
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── crazylegend
│ │ └── crashyreporter
│ │ └── ExampleInstrumentedTest.kt
│ ├── main
│ ├── AndroidManifest.xml
│ └── java
│ │ └── com
│ │ └── crazylegend
│ │ └── crashyreporter
│ │ ├── CrashyReporter.kt
│ │ ├── extensions
│ │ └── ExtensionFunctions.kt
│ │ ├── handlers
│ │ ├── CrashyExceptionHandler.kt
│ │ └── CrashyNotInitializedException.kt
│ │ ├── initializer
│ │ └── CrashyInitializer.kt
│ │ └── utils
│ │ ├── ApplicationUtils.kt
│ │ ├── CPUInfo.kt
│ │ ├── DeviceUtils.kt
│ │ ├── RootUtils.kt
│ │ ├── SharedPreferencesUtil.kt
│ │ └── ThreadUtils.kt
│ └── test
│ └── java
│ └── com
│ └── crazylegend
│ └── crashyreporter
│ └── CrashyReporterTest.kt
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── jitpack.yml
├── screens
├── screen_1.png
├── screen_2.png
└── screen_3.png
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | .cxx
15 | /.idea/codeStyles/
16 | /.idea/
17 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Crashy
2 | ### A small Android library written entirely in Kotlin to collect crash reports and save them to storage.
3 |
4 | [](https://jitpack.io/#FunkyMuse/Crashy)
5 | [](https://kotlinlang.org) [](https://developer.android.com/guide/)
6 | 
7 | 
8 |
9 |
10 | ## Usage
11 | 1. Add JitPack to your project build.gradle
12 |
13 | ```gradle
14 | allprojects {
15 | repositories {
16 | ...
17 | maven { url 'https://jitpack.io' }
18 | }
19 | }
20 | ```
21 |
22 | 2. Add the dependency in the application build.gradle
23 |
24 | ```gradle
25 | dependencies {
26 | //crashy
27 | implementation 'com.github.FunkyMuse:Crashy:$version'
28 | }
29 | ```
30 |
31 | 3. In your application build.gradle add
32 |
33 | ```gradle
34 | compileOptions {
35 | sourceCompatibility = 11
36 | targetCompatibility = 11
37 | }
38 |
39 | kotlinOptions {
40 | jvmTarget = "11"
41 | }
42 | ```
43 | 4. Inside your AndroidManifest.xml file
44 | ```xml
45 |
50 |
53 |
54 | ```
55 |
56 | ## Screens of how the stack trace info looks like
57 |
58 |
59 |
60 |
61 | 5. How to use?
62 |
63 | Get logs
64 | ```kotlin
65 | //as a list of strings
66 | CrashyReporter.getLogsAsStrings()
67 |
68 | //as a list of files
69 | CrashyReporter.getLogFiles()
70 | ```
71 | Get all logs and purge them afterwards
72 | ```kotlin
73 | //as a list of strings
74 | CrashyReporter.getLogsAsStringsAndPurge()
75 |
76 | //as a list of files
77 | CrashyReporter.getLogFilesAndPurge()
78 | ```
79 | Manually log an exception
80 | ```kotlin
81 | CrashyReporter.logException(thread: Thread, throwable: Throwable)
82 |
83 | CrashyReporter.logException(exception: Throwable)
84 | ```
85 | Purge logs
86 | ```kotlin
87 | CrashyReporter.purgeLogs()
88 | ```
89 | Get dump folder
90 | ```kotlin
91 | val folder: File = CrashyReporter.dumpFolder
92 | ```
93 |
94 |
95 | ## Contributing
96 | Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
97 |
98 | ## License
99 | [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0)
100 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 |
4 | android {
5 | compileSdkVersion 30
6 |
7 | defaultConfig {
8 | applicationId "com.crazylegend.crashy"
9 | minSdkVersion 21
10 | targetSdkVersion 30
11 | versionCode 1
12 | versionName "1.0"
13 |
14 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
15 | }
16 |
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
21 | }
22 |
23 | debug {
24 | minifyEnabled true
25 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
26 | }
27 | }
28 |
29 | compileOptions {
30 | sourceCompatibility = 11
31 | targetCompatibility = 11
32 | }
33 |
34 | kotlinOptions {
35 | jvmTarget = "11"
36 | }
37 | }
38 |
39 | dependencies {
40 | implementation fileTree(dir: "libs", include: ["*.jar"])
41 | implementation 'androidx.core:core-ktx:1.7.0-alpha01'
42 | implementation 'androidx.appcompat:appcompat:1.3.1'
43 | implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
44 |
45 | testImplementation "junit:junit:$junitVersion"
46 | androidTestImplementation 'androidx.test.ext:junit:1.1.3'
47 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
48 |
49 | implementation project(path: ':crashyreporter')
50 |
51 | }
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FunkyMuse/Crashy/c522cd94ed31ff3dd54c968ca757a61a31d35c89/app/proguard-rules.pro
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/crazylegend/crashy/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.crazylegend.crashy
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.crazylegend.crashy", appContext.packageName)
23 | }
24 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
28 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/app/src/main/java/com/crazylegend/crashy/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.crazylegend.crashy
2 |
3 | import android.os.Bundle
4 | import android.text.method.ScrollingMovementMethod
5 | import android.util.Log
6 | import android.widget.TextView
7 | import androidx.appcompat.app.AppCompatActivity
8 | import androidx.appcompat.widget.AppCompatButton
9 | import androidx.constraintlayout.widget.ConstraintLayout
10 | import com.crazylegend.crashyreporter.CrashyReporter
11 |
12 | class MainActivity : AppCompatActivity() {
13 |
14 |
15 | override fun onCreate(savedInstanceState: Bundle?) {
16 | super.onCreate(savedInstanceState)
17 | setContentView(R.layout.activity_main)
18 |
19 |
20 |
21 | CrashyReporter.getLogsAsStrings()?.asSequence()?.forEach {
22 | Log.d("CRASHY", "WITH CRASH REASON: \n")
23 | findViewById(R.id.test).apply {
24 | text = it
25 | movementMethod = ScrollingMovementMethod()
26 | }
27 | println(it)
28 | }
29 |
30 | findViewById(R.id.crash).apply {
31 | setOnClickListener {
32 | CrashyReporter.purgeLogs()
33 |
34 | val array = arrayOf(1, 2)
35 | array[120]
36 | }
37 | }
38 | }
39 |
40 |
41 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
18 |
19 |
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FunkyMuse/Crashy/c522cd94ed31ff3dd54c968ca757a61a31d35c89/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FunkyMuse/Crashy/c522cd94ed31ff3dd54c968ca757a61a31d35c89/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FunkyMuse/Crashy/c522cd94ed31ff3dd54c968ca757a61a31d35c89/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FunkyMuse/Crashy/c522cd94ed31ff3dd54c968ca757a61a31d35c89/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FunkyMuse/Crashy/c522cd94ed31ff3dd54c968ca757a61a31d35c89/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FunkyMuse/Crashy/c522cd94ed31ff3dd54c968ca757a61a31d35c89/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FunkyMuse/Crashy/c522cd94ed31ff3dd54c968ca757a61a31d35c89/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FunkyMuse/Crashy/c522cd94ed31ff3dd54c968ca757a61a31d35c89/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FunkyMuse/Crashy/c522cd94ed31ff3dd54c968ca757a61a31d35c89/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FunkyMuse/Crashy/c522cd94ed31ff3dd54c968ca757a61a31d35c89/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #6200EE
4 | #3700B3
5 | #03DAC5
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Crashy
3 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/test/java/com/crazylegend/crashy/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.crazylegend.crashy
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | ext.kotlin_version = "1.5.21"
3 | repositories {
4 | google()
5 | mavenCentral()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:7.0.0'
9 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
10 | }
11 | }
12 |
13 | allprojects {
14 | repositories {
15 | google()
16 | mavenCentral()
17 | }
18 | }
19 |
20 | task clean(type: Delete) {
21 | delete rootProject.buildDir
22 | }
23 |
24 | ext {
25 | //tests
26 | junitVersion = '4.13.2'
27 | hamcrestVersion = '1.3'
28 | androidXTestCoreVersion = '1.4.0'
29 | androidXTestExtKotlinRunnerVersion = '1.1.3'
30 | androidXTestRulesVersion = '1.2.0-beta01'
31 | robolectricVersion = '4.6.1'
32 | archTestingVersion = '2.1.0'
33 | startup = '1.0.0'
34 | }
--------------------------------------------------------------------------------
/crashyreporter/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/crashyreporter/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'maven-publish'
4 |
5 | android {
6 | compileSdkVersion 30
7 |
8 | defaultConfig {
9 | minSdkVersion 21
10 | targetSdkVersion 30
11 |
12 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
13 | consumerProguardFiles "consumer-rules.pro"
14 | }
15 |
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 |
23 | testOptions.unitTests {
24 | includeAndroidResources = true
25 | }
26 |
27 | compileOptions {
28 | sourceCompatibility = 11
29 | targetCompatibility = 11
30 | }
31 |
32 | kotlinOptions {
33 | jvmTarget = "11"
34 | }
35 | }
36 |
37 | dependencies {
38 | implementation fileTree(dir: "libs", include: ["*.jar"])
39 |
40 | implementation 'androidx.core:core-ktx:1.6.0'
41 |
42 | androidTestImplementation 'androidx.test.ext:junit:1.1.3'
43 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
44 |
45 | api "androidx.startup:startup-runtime:$startup"
46 |
47 |
48 | // Dependencies for local unit tests
49 | testImplementation "junit:junit:$junitVersion"
50 | testImplementation "org.hamcrest:hamcrest-all:$hamcrestVersion"
51 | testImplementation "androidx.test.ext:junit-ktx:$androidXTestExtKotlinRunnerVersion"
52 | testImplementation "androidx.test:core-ktx:$androidXTestCoreVersion"
53 | testImplementation "org.robolectric:robolectric:$robolectricVersion"
54 | testImplementation "androidx.arch.core:core-testing:$archTestingVersion"
55 | }
56 |
57 | afterEvaluate {
58 | publishing {
59 | publications {
60 | release(MavenPublication) {
61 | from components.release
62 | }
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/crashyreporter/consumer-rules.pro:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FunkyMuse/Crashy/c522cd94ed31ff3dd54c968ca757a61a31d35c89/crashyreporter/consumer-rules.pro
--------------------------------------------------------------------------------
/crashyreporter/proguard-rules.pro:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FunkyMuse/Crashy/c522cd94ed31ff3dd54c968ca757a61a31d35c89/crashyreporter/proguard-rules.pro
--------------------------------------------------------------------------------
/crashyreporter/src/androidTest/java/com/crazylegend/crashyreporter/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.crazylegend.crashyreporter
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.crazylegend.crashyreporter.test", appContext.packageName)
23 | }
24 | }
--------------------------------------------------------------------------------
/crashyreporter/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
--------------------------------------------------------------------------------
/crashyreporter/src/main/java/com/crazylegend/crashyreporter/CrashyReporter.kt:
--------------------------------------------------------------------------------
1 | package com.crazylegend.crashyreporter
2 |
3 | import android.content.Context
4 | import com.crazylegend.crashyreporter.handlers.CrashyExceptionHandler
5 | import com.crazylegend.crashyreporter.handlers.CrashyNotInitializedException
6 | import com.crazylegend.crashyreporter.utils.DeviceUtils
7 | import com.crazylegend.crashyreporter.utils.ThreadUtils
8 | import com.crazylegend.crashyreporter.utils.ThreadUtils.getThreadInfo
9 | import java.io.File
10 | import java.io.PrintWriter
11 | import java.io.StringWriter
12 | import java.text.SimpleDateFormat
13 | import java.util.*
14 |
15 |
16 | /**
17 | * Created by crazy on 6/18/20 to long live and prosper !
18 | */
19 | object CrashyReporter {
20 |
21 | /**
22 | * Checks what time the library was initialized
23 | * -1 if not initialized
24 | */
25 | var initializeTime: Long = -1
26 | private set
27 |
28 | private lateinit var applicationContext: Context
29 |
30 | //paths
31 | private val pathToDump get() = applicationContext.filesDir.path + "/crashy/logs"
32 | val dumpFolder get() = File(pathToDump)
33 |
34 |
35 | //time
36 | internal val dateFormat get() = SimpleDateFormat("dd-MM-yyyy HH:mm:ss", Locale.getDefault())
37 | private val crashLogTime get() = dateFormat.format(Date())
38 |
39 | /**
40 | *
45 | *
48 | *
49 | */
50 | private const val NOT_REGISTERED_MESSAGE =
51 | "You must register the content provider in your AndroidManifest.xml" +
52 | "\n" +
57 | " \n" +
60 | " "
61 |
62 |
63 | //region public
64 | /**
65 | * Initializes the Crashy report
66 | * @param context Context
67 | */
68 | fun initialize(context: Context) {
69 | applicationContext = context
70 | setupExceptionHandler()
71 | initializeTime = System.currentTimeMillis()
72 | }
73 |
74 |
75 | /**
76 | * Deletes all the logs inside the [dumpFolder]
77 | * @throws CrashyNotInitializedException see [NOT_REGISTERED_MESSAGE]
78 | * @return Boolean whether deletion was a success
79 | */
80 | @Throws(CrashyNotInitializedException::class)
81 | fun purgeLogs() = dumpFolder.deleteRecursively()
82 |
83 | /**
84 | * You can use this for manually dumping log
85 | * @throws CrashyNotInitializedException see [NOT_REGISTERED_MESSAGE]
86 | * @param thread Thread
87 | * @param throwable Throwable
88 | */
89 | @Throws(CrashyNotInitializedException::class)
90 | fun logException(thread: Thread, throwable: Throwable) {
91 | setupHandlerAndDumpFolder()
92 | buildLog(thread, throwable)
93 | }
94 |
95 | /**
96 | * You can use this for manually dumping log it takes an [Exception] and uses [Thread.currentThread] as the thread of error
97 | * @throws CrashyNotInitializedException see [NOT_REGISTERED_MESSAGE]
98 | * @param exception Exception
99 | */
100 | @Throws(CrashyNotInitializedException::class)
101 | fun logException(exception: Throwable) {
102 | setupHandlerAndDumpFolder()
103 | buildLog(Thread.currentThread(), exception)
104 | }
105 |
106 | /**
107 | * Get all dumps as [List] of [String]
108 | * @throws CrashyNotInitializedException see [NOT_REGISTERED_MESSAGE]
109 | */
110 | @Throws(CrashyNotInitializedException::class)
111 | fun getLogsAsStrings() = dumpFolder.listFiles()?.map { it.readText() }
112 |
113 | /**
114 | * Get all dumps as [List] of [File]
115 | * @throws CrashyNotInitializedException see [NOT_REGISTERED_MESSAGE]
116 | */
117 | @Throws(CrashyNotInitializedException::class)
118 | fun getLogFiles() = dumpFolder.listFiles()?.toList()
119 |
120 |
121 | /**
122 | * Get all dumps as [List] of [String]
123 | * @throws CrashyNotInitializedException see [NOT_REGISTERED_MESSAGE]
124 | */
125 | @Throws(CrashyNotInitializedException::class)
126 | inline fun getLogsAsStringsAndPurge(purgeResult: (Boolean) -> Unit = {}) = dumpFolder.listFiles()?.map { it.readText() }.also { purgeResult(purgeLogs()) }
127 |
128 | /**
129 | * Get all dumps as [List] of [File]
130 | * @throws CrashyNotInitializedException see [NOT_REGISTERED_MESSAGE]
131 | */
132 | @Throws(CrashyNotInitializedException::class)
133 | inline fun getLogFilesAndPurge(purgeResult: (Boolean) -> Unit = {}) = dumpFolder.listFiles()?.toList().also { purgeResult(purgeLogs()) }
134 |
135 |
136 | /**
137 | * Get all dumps as [List] of [String]
138 | * @throws CrashyNotInitializedException see [NOT_REGISTERED_MESSAGE]
139 | */
140 | @Throws(CrashyNotInitializedException::class)
141 | inline fun getLogsAsStringsActionBeforePurge(purgeResult: (Boolean) -> Unit = {}, onStringsAction: (List?) -> Unit) =
142 | dumpFolder.listFiles()?.map { it.readText() }.also {
143 | onStringsAction(it)
144 | purgeResult(purgeLogs())
145 | }
146 |
147 | /**
148 | * Get all dumps as [List] of [File]
149 | * @throws CrashyNotInitializedException see [NOT_REGISTERED_MESSAGE]
150 | */
151 | @Throws(CrashyNotInitializedException::class)
152 | inline fun getLogFilesActionBeforePurge(purgeResult: (Boolean) -> Unit = {}, onFilesAction: (List?) -> Unit) = dumpFolder.listFiles()?.toList().also {
153 | onFilesAction(it)
154 | purgeResult(purgeLogs())
155 | }
156 |
157 | //endregion
158 |
159 |
160 | //region privates
161 | private fun setupExceptionHandler() {
162 | if (!::applicationContext.isInitialized) {
163 | throw CrashyNotInitializedException(NOT_REGISTERED_MESSAGE)
164 | }
165 |
166 | if (Thread.getDefaultUncaughtExceptionHandler() !is CrashyExceptionHandler) {
167 | Thread.setDefaultUncaughtExceptionHandler(CrashyExceptionHandler())
168 | }
169 | }
170 |
171 | private fun buildLog(thread: Thread, throwable: Throwable) = saveLog(getStackTrace(throwable), getThreadInfo(thread))
172 |
173 | private fun setupHandlerAndDumpFolder() {
174 | setupExceptionHandler()
175 | if (!dumpFolder.exists()) dumpFolder.mkdirs()
176 | }
177 |
178 | private fun getStackTrace(throwable: Throwable) =
179 | with(StringWriter()) {
180 | PrintWriter(this).also { printWriter -> printWriter.use { writer -> throwable.printStackTrace(writer) } }
181 | toString()
182 | }
183 |
184 |
185 | private fun saveLog(stackTrace: String, threadName: String) {
186 | val pathToWriteTo = File("$pathToDump/$crashLogTime.txt")
187 | pathToWriteTo.writeText(ThreadUtils.buildStackTraceString(stackTrace) + "\n" +
188 | threadName + "\n" + DeviceUtils.getDeviceDetails(applicationContext) + "\n" +
189 | DeviceUtils.getRunningProcesses(applicationContext))
190 | }
191 | //endregion
192 | }
--------------------------------------------------------------------------------
/crashyreporter/src/main/java/com/crazylegend/crashyreporter/extensions/ExtensionFunctions.kt:
--------------------------------------------------------------------------------
1 | @file:Suppress("DEPRECATION")
2 |
3 | package com.crazylegend.crashyreporter.extensions
4 |
5 | import android.app.ActivityManager
6 | import android.app.ActivityManager.RunningAppProcessInfo.*
7 | import android.app.ApplicationExitInfo
8 | import android.app.ApplicationExitInfo.*
9 | import android.content.Context
10 | import android.content.pm.ApplicationInfo
11 | import android.content.pm.PackageManager
12 | import android.content.pm.Signature
13 | import android.os.BatteryManager
14 | import android.os.Build
15 | import android.os.PowerManager
16 | import android.os.PowerManager.*
17 | import android.util.Base64.DEFAULT
18 | import android.util.Base64.encodeToString
19 | import androidx.annotation.RequiresApi
20 | import com.crazylegend.crashyreporter.CrashyReporter
21 | import java.security.MessageDigest
22 | import java.util.*
23 |
24 |
25 | /**
26 | * Created by crazy on 6/21/20 to long live and prosper !
27 | */
28 |
29 | private inline val Context.batteryManager
30 | @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
31 | get() = getSystemService(Context.BATTERY_SERVICE) as BatteryManager
32 |
33 | internal val Context.getFirstInstallTime get() = packageManager.getPackageInfo(packageName, 0).firstInstallTime
34 | internal val Context.lastUpdateTime get() = packageManager.getPackageInfo(packageName, 0).lastUpdateTime
35 | internal val Context.requestedPermissions get() = tryOrNull {
36 | packageManager.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS).requestedPermissions.toList()
37 | }
38 |
39 | internal const val NEW_ROW = "\n"
40 | internal val Context.getBatteryPercentage get() = batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY)
41 |
42 | internal val Context.isBatteryCharging
43 | get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
44 | batteryManager.isCharging
45 | } else {
46 | null
47 | }
48 |
49 | internal val Context.getChargeTimeRemaining
50 | get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
51 | batteryManager.computeChargeTimeRemaining()
52 | } else {
53 | null
54 | }
55 |
56 | private inline val Context.powerManager
57 | get() = getSystemService(Context.POWER_SERVICE) as PowerManager?
58 |
59 | private inline val Context.activityManager: ActivityManager
60 | get() = getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
61 |
62 | internal val Context.isSustainedPerformanceModeSupported
63 | get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
64 | powerManager?.isSustainedPerformanceModeSupported.asYesOrNo()
65 | } else {
66 | notAvailableString
67 | }
68 |
69 | internal val Context.isInPowerSaveMode
70 | get() = powerManager?.isPowerSaveMode.asYesOrNo()
71 |
72 | internal val Context.isInInteractiveState
73 | get() = powerManager?.isInteractive.asYesOrNo()
74 |
75 | internal val Context.isIgnoringBatteryOptimization
76 | get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
77 | powerManager?.isIgnoringBatteryOptimizations(packageName).asYesOrNo()
78 | } else {
79 | notAvailableString
80 | }
81 |
82 | internal fun Boolean?.asYesOrNo() =
83 | when (this) {
84 | true -> "Yes"
85 | false -> "No"
86 | null -> notAvailableString
87 | }
88 |
89 |
90 | /**
91 | * THERMAL_STATUS_NONE if device in not under thermal throttling. Value is
92 | * THERMAL_STATUS_NONE, THERMAL_STATUS_LIGHT,
93 | * THERMAL_STATUS_MODERATE, THERMAL_STATUS_SEVERE, THERMAL_STATUS_CRITICAL, THERMAL_STATUS_EMERGENCY, or THERMAL_STATUS_SHUTDOWN
94 | */
95 | internal val Context.getThermalStatus: String
96 | get() {
97 | return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
98 | when (powerManager?.currentThermalStatus) {
99 | THERMAL_STATUS_NONE -> "STATUS_NONE"
100 | THERMAL_STATUS_LIGHT -> "STATUS_LIGHT"
101 | THERMAL_STATUS_MODERATE -> "STATUS_MODERATE"
102 | THERMAL_STATUS_SEVERE -> "STATUS_SEVERE"
103 | THERMAL_STATUS_CRITICAL -> "STATUS_CRITICAL"
104 | THERMAL_STATUS_EMERGENCY -> "STATUS_EMERGENCY"
105 | THERMAL_STATUS_SHUTDOWN -> "STATUS_SHUTDOWN"
106 |
107 | else -> notAvailableString
108 | }
109 | } else {
110 | notAvailableString
111 | }
112 | }
113 |
114 | /**
115 | * Value is LOCATION_MODE_NO_CHANGE, LOCATION_MODE_GPS_DISABLED_WHEN_SCREEN_OFF,
116 | * LOCATION_MODE_ALL_DISABLED_WHEN_SCREEN_OFF,
117 | * LOCATION_MODE_FOREGROUND_ONLY, or LOCATION_MODE_THROTTLE_REQUESTS_WHEN_SCREEN_OFF
118 | */
119 | internal val Context.locationPowerSaveMode: String
120 | get() {
121 |
122 | return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
123 | when (powerManager?.locationPowerSaveMode) {
124 | LOCATION_MODE_NO_CHANGE -> "MODE_NO_CHANGE"
125 | LOCATION_MODE_GPS_DISABLED_WHEN_SCREEN_OFF -> "MODE_GPS_DISABLED_WHEN_SCREEN_OFF"
126 | LOCATION_MODE_ALL_DISABLED_WHEN_SCREEN_OFF -> "MODE_ALL_DISABLED_WHEN_SCREEN_OFF"
127 | LOCATION_MODE_FOREGROUND_ONLY -> "MODE_FOREGROUND_ONLY"
128 | LOCATION_MODE_THROTTLE_REQUESTS_WHEN_SCREEN_OFF -> "MODE_THROTTLE_REQUESTS_WHEN_SCREEN_OFF"
129 | else -> notAvailableString
130 | }
131 | } else {
132 | notAvailableString
133 | }
134 | }
135 |
136 | internal val Context.isDeviceIdle
137 | get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
138 | powerManager?.isDeviceIdleMode.asYesOrNo()
139 | } else {
140 | notAvailableString
141 | }
142 |
143 |
144 | private fun buildExitReason(reason: Int) = when (reason) {
145 | REASON_ANR -> "ANR"
146 | REASON_CRASH -> "CRASH"
147 | REASON_CRASH_NATIVE -> "CRASH_NATIVE"
148 | REASON_DEPENDENCY_DIED -> "DEPENDENCY_DIED"
149 | REASON_EXCESSIVE_RESOURCE_USAGE -> "EXCESSIVE_RESOURCE_USAGE"
150 | REASON_EXIT_SELF -> "EXIT_SELF"
151 | REASON_INITIALIZATION_FAILURE -> "INITIALIZATION_FAILURE"
152 | REASON_LOW_MEMORY -> "LOW_MEMORY"
153 | REASON_OTHER -> "OTHER"
154 | REASON_PERMISSION_CHANGE -> "PERMISSION_CHANGE"
155 | REASON_SIGNALED -> "SIGNALED"
156 | REASON_USER_REQUESTED -> "USER_REQUESTED"
157 | REASON_USER_STOPPED -> "USER_STOPPED"
158 | ApplicationExitInfo.REASON_UNKNOWN -> "UNKNOWN"
159 | else -> notAvailableString
160 | }
161 |
162 | internal fun Context.getExitReasons(pid: Int = 0, maxRes: Int = 1) =
163 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
164 | activityManager.getHistoricalProcessExitReasons(packageName, pid, maxRes)
165 | .mapIndexed { index, it ->
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
173 | }
174 | } else {
175 | emptyList()
176 | }
177 |
178 | internal inline fun tryOrNull(block: () -> T): T? = try {
179 | block()
180 | } catch (e: Exception) {
181 | null
182 | }
183 |
184 | internal inline fun tryOrIgnore(block: () -> T) {
185 | try {
186 | block()
187 | } catch (e: Exception) {
188 | }
189 | }
190 |
191 | internal fun Context.getRunningProcesses() =
192 | tryOrNull {
193 | activityManager.getRunningServices(Integer.MAX_VALUE).map {
194 | it.service.className
195 | }
196 | }.notAvailableIfNullNewLine().replace("[", "").replace("]", "").replace(",", "$NEW_ROW")
197 |
198 | internal fun buildImportance(importance: Int): String {
199 | return when (importance) {
200 | IMPORTANCE_FOREGROUND -> "FOREGROUND"
201 | IMPORTANCE_FOREGROUND_SERVICE -> "FOREGROUND_SERVICE"
202 | IMPORTANCE_TOP_SLEEPING -> "TOP_SLEEPING"
203 | IMPORTANCE_VISIBLE -> "VISIBLE"
204 | IMPORTANCE_PERCEPTIBLE -> "PERCEPTIBLE"
205 | IMPORTANCE_CANT_SAVE_STATE -> "CANT_SAVE_STATE"
206 | IMPORTANCE_SERVICE -> "SERVICE"
207 | IMPORTANCE_CACHED -> "CACHED"
208 | IMPORTANCE_GONE -> "GONE"
209 | else -> notAvailableString
210 | }
211 | }
212 |
213 | internal const val notAvailableString = "N/A"
214 |
215 | internal fun String?.notAvailableIfNull() = if (this.isNullOrEmpty()) notAvailableString else this
216 |
217 | internal fun Collection?.notAvailableIfNullNewLine(): String =
218 | if (this.isNullOrEmpty()) "N/A" else "$NEW_ROW${this}"
219 |
220 | internal fun Collection?.notAvailableIfNull(): String =
221 | if (this.isNullOrEmpty()) "N/A" else "$this"
222 |
223 |
224 | internal val Context.actualPackageName: String?
225 | get() = applicationContext.javaClass.`package`?.name
226 |
227 | internal val Context.flavor: String?
228 | get() = getBuildConfigValue(actualPackageName, "FLAVOR") as String?
229 |
230 | internal val Context.appName: String
231 | get() {
232 | val applicationInfo = applicationContext.applicationInfo
233 | val stringId = applicationInfo.labelRes
234 | return if (stringId == 0) {
235 | applicationInfo.nonLocalizedLabel.toString()
236 | } else {
237 | applicationContext.getString(stringId)
238 | }
239 | }
240 |
241 | internal fun Context.getVersionName(): String = packageManager.getPackageInfo(packageName, 0).versionName
242 |
243 |
244 | internal fun Context.getVersionCodeCompat(): Long = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
245 | packageManager.getPackageInfo(packageName, 0).longVersionCode
246 | } else {
247 | @Suppress("DEPRECATION")
248 | packageManager.getPackageInfo(packageName, 0).versionCode.toLong()
249 | }
250 |
251 | /**
252 | * Gets a field from the project's BuildConfig. This is useful when, for example, flavors
253 | * are used at the project level to set custom fields.
254 | * @param fieldName The name of the field-to-access
255 | * @return The value of the field, or `null` if the field is not found.
256 | */
257 | private fun getBuildConfigValue(packageName: String?, fieldName: String): Any? {
258 | val buildConfigClassName = "$packageName.BuildConfig"
259 | return try {
260 | val clazz = Class.forName(buildConfigClassName)
261 | val field = clazz.getField(fieldName)
262 | field.get(null)
263 | } catch (e: ClassNotFoundException) {
264 | null
265 | } catch (e: NoSuchFieldException) {
266 | null
267 | } catch (e: IllegalAccessException) {
268 | null
269 | }
270 | }
271 |
272 | internal val Context.shortAppName: String?
273 | get() = actualPackageName?.substringAfterLast('.')
274 |
275 |
276 | internal val Context.apkSignatures
277 | get() = currentSignatures.toList()
278 |
279 | @Suppress("DEPRECATION", "RemoveExplicitTypeArguments")
280 | private val Context.currentSignatures: Array
281 | get() {
282 | val actualSignatures = ArrayList()
283 | val signatures = try {
284 | val packageInfo = packageManager.getPackageInfo(packageName,
285 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
286 | PackageManager.GET_SIGNING_CERTIFICATES
287 | else PackageManager.GET_SIGNATURES)
288 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
289 | if (packageInfo.signingInfo.hasMultipleSigners())
290 | packageInfo.signingInfo.apkContentsSigners
291 | else packageInfo.signingInfo.signingCertificateHistory
292 | } else packageInfo.signatures
293 | } catch (e: Exception) {
294 | emptyArray()
295 | }
296 | signatures.forEach { signature ->
297 | val messageDigest = MessageDigest.getInstance("SHA")
298 | messageDigest.update(signature.toByteArray())
299 | tryOrIgnore { actualSignatures.add(encodeToString(messageDigest.digest(), DEFAULT).trim()) }
300 | }
301 | return actualSignatures.filter { it.isNotEmpty() && it.isNotBlank() }.toTypedArray()
302 | }
303 |
304 | 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)
305 |
306 | internal val Context.systemFeatures get() = packageManager.systemAvailableFeatures.joinToString { it.toString() }
307 |
308 | internal fun Context.isDebuggable(): Boolean = applicationContext.applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE != 0
309 |
--------------------------------------------------------------------------------
/crashyreporter/src/main/java/com/crazylegend/crashyreporter/handlers/CrashyExceptionHandler.kt:
--------------------------------------------------------------------------------
1 | package com.crazylegend.crashyreporter.handlers
2 |
3 | import com.crazylegend.crashyreporter.CrashyReporter
4 |
5 |
6 | /**
7 | * Created by crazy on 6/18/20 to long live and prosper !
8 | */
9 | internal class CrashyExceptionHandler : Thread.UncaughtExceptionHandler {
10 |
11 | private val exceptionHandler = Thread.getDefaultUncaughtExceptionHandler()
12 |
13 | override fun uncaughtException(thread: Thread, throwable: Throwable) {
14 | CrashyReporter.logException(thread, throwable)
15 | exceptionHandler?.uncaughtException(thread, throwable)
16 | }
17 | }
--------------------------------------------------------------------------------
/crashyreporter/src/main/java/com/crazylegend/crashyreporter/handlers/CrashyNotInitializedException.kt:
--------------------------------------------------------------------------------
1 | package com.crazylegend.crashyreporter.handlers
2 |
3 | internal class CrashyNotInitializedException(message: String) : RuntimeException(message)
4 |
--------------------------------------------------------------------------------
/crashyreporter/src/main/java/com/crazylegend/crashyreporter/initializer/CrashyInitializer.kt:
--------------------------------------------------------------------------------
1 | package com.crazylegend.crashyreporter.initializer
2 |
3 | import android.content.Context
4 | import androidx.startup.Initializer
5 | import com.crazylegend.crashyreporter.CrashyReporter
6 |
7 |
8 | /**
9 | * Created by crazy on 6/18/20 to long live and prosper !
10 | */
11 | internal class CrashyInitializer : Initializer {
12 |
13 | object CrashyToken
14 |
15 | override fun create(context: Context) = with(CrashyReporter.initialize(context)){ CrashyToken }
16 | override fun dependencies(): MutableList>> = mutableListOf()
17 | }
18 |
--------------------------------------------------------------------------------
/crashyreporter/src/main/java/com/crazylegend/crashyreporter/utils/ApplicationUtils.kt:
--------------------------------------------------------------------------------
1 | package com.crazylegend.crashyreporter.utils
2 |
3 | import android.content.Context
4 | import com.crazylegend.crashyreporter.CrashyReporter
5 | import com.crazylegend.crashyreporter.extensions.*
6 | import java.util.*
7 |
8 |
9 | /**
10 | * Created by crazy on 7/19/20 to long live and prosper !
11 | */
12 |
13 | internal object ApplicationUtils {
14 |
15 | internal fun appendApplicationInfo(context: Context): String {
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
34 | }
35 | }
--------------------------------------------------------------------------------
/crashyreporter/src/main/java/com/crazylegend/crashyreporter/utils/CPUInfo.kt:
--------------------------------------------------------------------------------
1 | @file:Suppress("SameParameterValue")
2 |
3 | package com.crazylegend.crashyreporter.utils
4 |
5 | import java.io.IOException
6 |
7 |
8 | /**
9 | * Created by crazy on 7/19/20 to long live and prosper !
10 | */
11 | internal object CPUInfo {
12 |
13 | fun getNumberOfCores() = Runtime.getRuntime().availableProcessors()
14 |
15 | fun getCPUModel(): String? {
16 | val processorInfoDump = getProcessText("cpuinfo") ?: return null
17 | return if (processorInfoDump.contains("Hardware\t: "))
18 | getProcessText("cpuinfo")?.substringAfter("Hardware\t: ")?.trim()
19 | else
20 | null
21 | }
22 |
23 | private fun getProcessText(procFolder: String): String? {
24 | val process = Runtime.getRuntime().exec("cat /proc/$procFolder")
25 | return try {
26 | process.inputStream.use {
27 | it.reader().readText()
28 | }
29 | } catch (e: IOException) {
30 | null
31 | } finally {
32 | process.destroy()
33 | }
34 | }
35 |
36 | }
--------------------------------------------------------------------------------
/crashyreporter/src/main/java/com/crazylegend/crashyreporter/utils/DeviceUtils.kt:
--------------------------------------------------------------------------------
1 | package com.crazylegend.crashyreporter.utils
2 |
3 | import android.Manifest
4 | import android.accounts.AccountManager
5 | import android.annotation.SuppressLint
6 | import android.content.Context
7 | import android.content.Intent
8 | import android.content.pm.PackageManager
9 | import android.os.Build
10 | import android.os.SystemClock
11 | import android.provider.Settings
12 | import androidx.core.app.ActivityCompat
13 | import com.crazylegend.crashyreporter.CrashyReporter
14 | import com.crazylegend.crashyreporter.extensions.*
15 | import com.crazylegend.crashyreporter.utils.ApplicationUtils.appendApplicationInfo
16 | import java.util.*
17 |
18 |
19 | /**
20 | * Created by crazy on 6/18/20 to long live and prosper !
21 | */
22 | internal object DeviceUtils {
23 |
24 | fun getDeviceDetails(context: Context): String {
25 |
26 | return "`` Device info ``$NEW_ROW" +
27 | NEW_ROW +
28 | "Report ID: ${UUID.randomUUID()}" +
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 +
77 | appendExitReasons(context) +
78 | NEW_ROW + NEW_ROW +
79 | appendApplicationInfo(context)
80 | }
81 |
82 | private fun getChargeRemainingTime(context: Context): String {
83 | val chargeRemainingTime = context.getChargeTimeRemaining
84 | return if (chargeRemainingTime != null) {
85 | if (chargeRemainingTime == -1L) {
86 | notAvailableString
87 | } else {
88 | CrashyReporter.dateFormat.format(Date(chargeRemainingTime)).notAvailableIfNull()
89 | }
90 | } else {
91 | notAvailableString
92 | }
93 | }
94 |
95 |
96 | private fun appendExitReasons(context: Context): String {
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 ``"
101 | }
102 |
103 |
104 | @SuppressLint("MissingPermission")
105 | private fun getUserPlayIDs(context: Context): List {
106 | return if (ActivityCompat.checkSelfPermission(context, Manifest.permission.GET_ACCOUNTS) == PackageManager.PERMISSION_GRANTED) {
107 | (context.getSystemService(Context.ACCOUNT_SERVICE) as AccountManager).accounts.map {
108 | if (it.type.equals("com.google", true)) {
109 | it.name
110 | } else {
111 | null
112 | }
113 | }
114 | } else {
115 | emptyList()
116 | }
117 | }
118 |
119 | private fun upTimeWithSleep() = formatMillisToHoursMinutesSeconds(SystemClock.elapsedRealtime())
120 | private fun upTimeWithoutSleep() = formatMillisToHoursMinutesSeconds(SystemClock.uptimeMillis())
121 |
122 | private fun getRadioVersion() = try {
123 | Build.getRadioVersion()
124 | } catch (e: java.lang.Exception) {
125 | null
126 | }
127 |
128 | @SuppressLint("HardwareIds")
129 | private fun getDeviceID(context: Context): String? = Settings.Secure.getString(context.contentResolver, Settings.Secure.ANDROID_ID)
130 | private fun getAppVersion(context: Context) = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
131 | context.packageManager.getPackageInfo(context.packageName, 0).longVersionCode
132 | } else {
133 | context.packageManager.getPackageInfo(context.packageName, 0).versionCode.toLong()
134 | }
135 |
136 | private fun getLaunchedFromApp(context: Context): String? {
137 | val packageName: String?
138 | val localPackageManager = context.packageManager
139 | val intent = with(Intent("android.intent.action.MAIN")) {
140 | addCategory("android.intent.category.HOME")
141 | this
142 | }
143 | packageName = try {
144 | localPackageManager.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY)?.activityInfo?.packageName
145 | } catch (e: Exception) {
146 | null
147 | }
148 | return packageName
149 | }
150 |
151 |
152 |
153 | fun getRunningProcesses(context: Context) =
154 | "`` Currently running foreground/background processes ``$NEW_ROW" +
155 | NEW_ROW +
156 | "${context.getRunningProcesses()}$NEW_ROW" +
157 | NEW_ROW +
158 | "`` END of running foreground/background processes info ``"
159 |
160 |
161 | }
162 |
163 |
164 |
165 |
--------------------------------------------------------------------------------
/crashyreporter/src/main/java/com/crazylegend/crashyreporter/utils/RootUtils.kt:
--------------------------------------------------------------------------------
1 | package com.crazylegend.crashyreporter.utils
2 |
3 | import java.io.BufferedReader
4 | import java.io.File
5 | import java.io.InputStreamReader
6 |
7 |
8 | /**
9 | * Created by crazy on 2/6/19 to long live and prosper !
10 | */
11 |
12 | internal object RootUtils {
13 |
14 | internal val isDeviceRooted: Boolean
15 | get() = checkRootMethod1() || checkRootMethod2() || checkRootMethod3()
16 |
17 | private fun checkRootMethod1(): Boolean {
18 | val buildTags = android.os.Build.TAGS
19 | return buildTags != null && buildTags.contains("test-keys")
20 | }
21 |
22 | private fun checkRootMethod2(): Boolean {
23 | val paths = arrayOf(
24 | "/system/app/Superuser.apk",
25 | "/sbin/su",
26 | "/system/bin/su",
27 | "/system/xbin/su",
28 | "/data/local/xbin/su",
29 | "/data/local/bin/su",
30 | "/system/sd/xbin/su",
31 | "/system/bin/failsafe/su",
32 | "/data/local/su",
33 | "/su/bin/su"
34 | )
35 | for (path in paths) {
36 | if (File(path).exists()) return true
37 | }
38 | return false
39 | }
40 |
41 | private fun checkRootMethod3(): Boolean {
42 | var process: Process? = null
43 | return try {
44 | process = Runtime.getRuntime().exec(arrayOf("/system/xbin/which", "su"))
45 | val bufferedReader = BufferedReader(InputStreamReader(process!!.inputStream))
46 | bufferedReader.readLine() != null
47 | } catch (t: Throwable) {
48 | false
49 | } finally {
50 | process?.destroy()
51 | }
52 | }
53 | }
--------------------------------------------------------------------------------
/crashyreporter/src/main/java/com/crazylegend/crashyreporter/utils/SharedPreferencesUtil.kt:
--------------------------------------------------------------------------------
1 | package com.crazylegend.crashyreporter.utils
2 |
3 | import android.content.Context
4 | import android.preference.PreferenceManager
5 |
6 |
7 | /**
8 | * Created by crazy on 7/20/20 to long live and prosper !
9 | */
10 | internal object SharedPreferencesUtil {
11 |
12 | fun collect(context: Context) =
13 | PreferenceManager.getDefaultSharedPreferences(context).all.iterator().asSequence().map {
14 | val key = it.key
15 | val value = it.value
16 | "$key = $value"
17 | }.toList().joinToString()
18 | }
--------------------------------------------------------------------------------
/crashyreporter/src/main/java/com/crazylegend/crashyreporter/utils/ThreadUtils.kt:
--------------------------------------------------------------------------------
1 | package com.crazylegend.crashyreporter.utils
2 |
3 | import android.os.SystemClock
4 | import com.crazylegend.crashyreporter.extensions.NEW_ROW
5 | import com.crazylegend.crashyreporter.extensions.formatMillisToHoursMinutesSeconds
6 |
7 |
8 | /**
9 | * Created by crazy on 6/18/20 to long live and prosper !
10 | */
11 | internal object ThreadUtils {
12 |
13 | fun getThreadInfo(thread: Thread) =
14 | "`` Thread info ``$NEW_ROW" +
15 | NEW_ROW +
16 | "Name: ${thread.name}$NEW_ROW" +
17 | "ID: ${thread.id}$NEW_ROW" +
18 | "State: ${thread.state.name}$NEW_ROW" +
19 | "Priority: ${thread.priority}$NEW_ROW" +
20 | "Thread group name: ${thread.threadGroup?.name}$NEW_ROW" +
21 | "Thread group parent: ${thread.threadGroup?.parent?.name}$NEW_ROW" +
22 | "Thread group active count: ${thread.threadGroup?.activeCount()}$NEW_ROW" +
23 | "Thread time: ${formatMillisToHoursMinutesSeconds(SystemClock.currentThreadTimeMillis())}$NEW_ROW" +
24 | NEW_ROW +
25 | "`` END of thread info ``$NEW_ROW"
26 |
27 |
28 | fun buildStackTraceString(stackTrace: String) =
29 | "`` Stacktrace ``$NEW_ROW" +
30 | NEW_ROW +
31 | "$stackTrace$NEW_ROW" +
32 | NEW_ROW +
33 | "`` END of stacktrace ``$NEW_ROW"
34 | }
--------------------------------------------------------------------------------
/crashyreporter/src/test/java/com/crazylegend/crashyreporter/CrashyReporterTest.kt:
--------------------------------------------------------------------------------
1 | package com.crazylegend.crashyreporter
2 |
3 | import android.content.Context
4 | import android.os.Build
5 | import androidx.arch.core.executor.testing.InstantTaskExecutorRule
6 | import androidx.test.core.app.ApplicationProvider
7 | import androidx.test.ext.junit.runners.AndroidJUnit4
8 | import org.hamcrest.CoreMatchers.`is`
9 | import org.junit.Assert.*
10 | import org.junit.Before
11 | import org.junit.Rule
12 | import org.junit.Test
13 | import org.junit.runner.RunWith
14 | import org.robolectric.annotation.Config
15 |
16 | /**
17 | * Created by crazy on 6/18/20 to long live and prosper !
18 | */
19 | @RunWith(AndroidJUnit4::class)
20 | @Config(sdk = [Build.VERSION_CODES.P])
21 | class CrashyReporterTest{
22 |
23 | @get:Rule
24 | var instantExecutorRule = InstantTaskExecutorRule()
25 |
26 | @Before
27 | fun setupReporter(){
28 | val context = ApplicationProvider.getApplicationContext()
29 | CrashyReporter.initialize(context)
30 | }
31 |
32 | @Test
33 | fun forceCrash_and_check_if_inserted(){
34 | CrashyReporter.purgeLogs()
35 | CrashyReporter.logException(ConcurrentModificationException())
36 | val list = CrashyReporter.getLogsAsStrings()
37 | val condition = !list.isNullOrEmpty()
38 | assertThat(condition, `is`(true))
39 | }
40 |
41 | @Test
42 | fun purgeLogs(){
43 | forceCrash_and_check_if_inserted()
44 | val purgatory = CrashyReporter.purgeLogs()
45 | assertThat(purgatory, `is`(true))
46 | }
47 |
48 | @Test
49 | fun forceCrash_and_check_if_inserted_with_thread(){
50 | CrashyReporter.purgeLogs()
51 | CrashyReporter.logException(thread = Thread.currentThread(), throwable = IndexOutOfBoundsException())
52 | val list = CrashyReporter.getLogsAsStrings()
53 | val condition = !list.isNullOrEmpty()
54 | assertThat(condition, `is`(true))
55 | }
56 |
57 | @Test
58 | fun getContentTest(){
59 | val list = CrashyReporter.getLogsAsStrings()
60 |
61 | if (list.isNullOrEmpty()){
62 | val first = list?.firstOrNull()
63 | assertNull(first)
64 | } else {
65 | val first = list.first().isNotBlank()
66 | assert(first)
67 | }
68 | }
69 |
70 | @Test
71 | fun getContentAndPurge(){
72 | forceCrash_and_check_if_inserted()
73 | val list = CrashyReporter.getLogsAsStringsAndPurge()
74 | assertNotNull(list)
75 | val condition = !list.isNullOrEmpty()
76 | assert(condition)
77 | }
78 |
79 |
80 |
81 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | org.gradle.jvmargs=-Xmx2048m
2 | org.gradle.parallel=true
3 | android.useAndroidX=true
4 | android.enableJetifier=true
5 | kotlin.code.style=obsolete
6 | org.gradle.caching=true
7 | kapt.use.worker.api=true
8 | org.gradle.unsafe.watch-fs=true
9 | org.gradle.configureondemand=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FunkyMuse/Crashy/c522cd94ed31ff3dd54c968ca757a61a31d35c89/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Oct 14 19:43:52 CEST 2020
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/jitpack.yml:
--------------------------------------------------------------------------------
1 | jdk:
2 | - openjdk11
3 | install:
4 | - ./gradlew publishToMavenLocal
5 | - find . -name "*.aar"
6 |
7 |
--------------------------------------------------------------------------------
/screens/screen_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FunkyMuse/Crashy/c522cd94ed31ff3dd54c968ca757a61a31d35c89/screens/screen_1.png
--------------------------------------------------------------------------------
/screens/screen_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FunkyMuse/Crashy/c522cd94ed31ff3dd54c968ca757a61a31d35c89/screens/screen_2.png
--------------------------------------------------------------------------------
/screens/screen_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FunkyMuse/Crashy/c522cd94ed31ff3dd54c968ca757a61a31d35c89/screens/screen_3.png
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':crashyreporter'
2 | include ':app'
3 | rootProject.name = "Crashy"
--------------------------------------------------------------------------------