Skip to content

Commit bd0b45d

Browse files
authored
Merge pull request #76 from kiall/feature/acra
Switch from Firebase to ACRA crash reporting
2 parents 2b76d82 + 3b37ab2 commit bd0b45d

File tree

8 files changed

+116
-7
lines changed

8 files changed

+116
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.DS_Store
22
google-services.json
3+
acra.properties
34
/projectFilesBackup/
45

56
## From: https://github.com/github/gitignore/blob/master/Android.gitignore

app/build.gradle

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ android {
99
targetSdkVersion 24
1010
versionCode 48
1111
versionName '0.2.' + versionCode
12-
setProperty("archivesBaseName", "$applicationId.$versionName")
12+
setProperty("archivesBaseName", "${applicationId}_${versionName}")
13+
14+
buildConfigField "boolean", "ACRA_ENABLED", "false"
15+
buildConfigField "String", "ACRA_REPORT_URI", "\"\""
1316
}
1417

1518
buildTypes {
@@ -19,6 +22,13 @@ android {
1922
release {
2023
minifyEnabled false
2124
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
25+
26+
if (rootProject.file("acra.properties").exists()) {
27+
buildConfigField "boolean", "ACRA_ENABLED", "true"
28+
def acraProperties = new Properties()
29+
acraProperties.load(new FileInputStream(rootProject.file("acra.properties")))
30+
buildConfigField "String", "ACRA_REPORT_URI", "\"" + acraProperties.report_uri + "\""
31+
}
2232
}
2333
}
2434
productFlavors {
@@ -38,12 +48,7 @@ dependencies {
3848
compile 'com.android.support:support-v4:24.2.1'
3949
compile 'com.android.support:leanback-v17:24.2.1'
4050
compile 'com.android.support:preference-leanback-v17:24.2.1'
41-
compile 'com.google.firebase:firebase-core:9.8.0'
42-
compile 'com.google.firebase:firebase-crash:9.8.0'
4351
compile 'com.google.android.exoplayer:exoplayer:r1.5.9'
4452
compile 'de.mrmaffen:vlc-android-sdk:1.9.8'
45-
}
46-
47-
if (project.file('google-services.json').exists()) {
48-
apply plugin: 'com.google.gms.google-services'
53+
compile 'ch.acra:acra:4.9.0'
4954
}

app/src/debug/java/ie/macinnes/tvheadend/DevTestActivity.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import android.view.View;
2424
import android.widget.TextView;
2525

26+
import org.acra.ACRA;
2627
import org.json.JSONObject;
2728

2829
import ie.macinnes.tvheadend.account.AccountUtils;
@@ -118,6 +119,8 @@ public void deleteChannels(View view) {
118119
}
119120

120121
public void showPreferences(View view) {
122+
Exception e = new Exception("Tester 2");
123+
ACRA.getErrorReporter().handleException(e);
121124
startActivity(SettingsActivity.getPreferencesIntent(this));
122125
}
123126

@@ -127,4 +130,9 @@ public void restartEpgSyncService(View view) {
127130
context.stopService(i);
128131
context.startService(i);
129132
}
133+
134+
public void sendCrashReport(View view) {
135+
Exception e = new Exception("Test Crash Report");
136+
ACRA.getErrorReporter().handleException(e);
137+
}
130138
}

app/src/debug/res/layout/activity_dev_test.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ under the License.
7171
android:onClick="restartEpgSyncService"
7272
android:layout_gravity="center_horizontal"/>
7373

74+
<Button
75+
android:layout_width="fill_parent"
76+
android:layout_height="wrap_content"
77+
android:text="Send Fake Crash Report"
78+
android:nestedScrollingEnabled="true"
79+
android:onClick="sendCrashReport"
80+
android:layout_gravity="center_horizontal"/>
81+
7482
</LinearLayout>
7583

7684
<ScrollView

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ under the License.
5959
android:required="false"/>
6060

6161
<application
62+
android:name=".Application"
6263
android:allowBackup="true"
6364
android:banner="@drawable/banner"
6465
android:icon="@mipmap/ic_tv_service"
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) 2016 Kiall Mac Innes <kiall@macinnes.ie>
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
5+
* not use this file except in compliance with the License. You may obtain
6+
* a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations
14+
* under the License.
15+
*/
16+
17+
package ie.macinnes.tvheadend;
18+
19+
import android.content.Context;
20+
import android.util.Log;
21+
22+
import org.acra.ACRA;
23+
import org.acra.config.ACRAConfiguration;
24+
import org.acra.config.ACRAConfigurationException;
25+
import org.acra.config.ConfigurationBuilder;
26+
import org.acra.sender.HttpSender;
27+
28+
public class Application extends android.app.Application {
29+
private static final String TAG = Application.class.getName();
30+
31+
@Override
32+
protected void attachBaseContext(Context base) {
33+
super.attachBaseContext(base);
34+
35+
// Initialize ACRA crash reporting
36+
if (BuildConfig.ACRA_ENABLED) {
37+
Log.i(TAG, "Initializing ACRA");
38+
try {
39+
final ACRAConfiguration config = new ConfigurationBuilder(this)
40+
.setHttpMethod(HttpSender.Method.PUT)
41+
.setReportType(HttpSender.Type.JSON)
42+
.setFormUri(BuildConfig.ACRA_REPORT_URI)
43+
.setLogcatArguments("-t", "500", "-v", "time", "*:I")
44+
.setAdditionalSharedPreferences(Constants.PREFERENCE_TVHEADEND)
45+
.setSharedPreferenceName(Constants.PREFERENCE_TVHEADEND)
46+
.setSharedPreferenceMode(Context.MODE_PRIVATE)
47+
.setBuildConfigClass(BuildConfig.class)
48+
.build();
49+
ACRA.init(this, config);
50+
} catch (ACRAConfigurationException e) {
51+
Log.e(TAG, "Failed to init ACRA", e);
52+
}
53+
}
54+
}
55+
}

app/src/main/res/values/strings.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,15 @@ under the License.
1919
<string name="title_activity_authenticator">TVHeadend Authenticator</string>
2020
<string name="account_label">TVHeadend</string>
2121
<string name="title_activity_dev_test">TVH DevTest</string>
22+
23+
<string name="pref_disable_acra">Enable ACRA?</string>
24+
<string name="pref_acra_enabled">ACRA enabled</string>
25+
<string name="pref_acra_disabled">ACRA disabled</string>
26+
27+
<string name="pref_acra_syslog">Send system logs?</string>
28+
<string name="pref_acra_syslog_enabled">Sending system logs is enabled</string>
29+
<string name="pref_acra_syslog_disabled">Sending system logs is disabled</string>
30+
31+
<string name="pref_acra_user_email">Contact email address (optional)</string>
32+
<string name="pref_acra_user_email_summary">Sometimes, the developers may need to contact you for more info</string>
2233
</resources>

app/src/main/res/xml/preferences.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,24 @@
4646
android:dependency="vlc_deinterlace_enabled"/>
4747
</PreferenceScreen>
4848
</PreferenceCategory>
49+
50+
<PreferenceCategory android:title="Advanced Settings">
51+
<PreferenceScreen android:title="Crash Reporting Settings" android:key="crash_reporting_settings" android:persistent="false">
52+
<CheckBoxPreference android:key="acra.enable"
53+
android:title="@string/pref_disable_acra"
54+
android:summaryOn="@string/pref_acra_enabled"
55+
android:summaryOff="@string/pref_acra_disabled"
56+
android:defaultValue="true"/>
57+
<CheckBoxPreference android:key="acra.syslog.enable"
58+
android:summaryOn="@string/pref_acra_syslog_enabled"
59+
android:summaryOff="@string/pref_acra_syslog_disabled"
60+
android:title="@string/pref_acra_syslog"
61+
android:defaultValue="true"/>
62+
<EditTextPreference android:key="acra.user.email"
63+
android:title="@string/pref_acra_user_email"
64+
android:summary="@string/pref_acra_user_email_summary"/>
65+
66+
</PreferenceScreen>
67+
</PreferenceCategory>
68+
4969
</PreferenceScreen>

0 commit comments

Comments
 (0)