Skip to content

Commit ea0c3cb

Browse files
committed
add a log file
1 parent 3e925bb commit ea0c3cb

4 files changed

Lines changed: 120 additions & 2 deletions

File tree

app/src/main/AndroidManifest.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@
88
<uses-permission android:name="android.permission.WAKE_LOCK" />
99
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
1010
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
11+
<!-- for gps -->
1112
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
1213
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
14+
<!-- for logging in a file -->
15+
<uses-permission android:name="android.permission.READ_LOGS" />
16+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
17+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
1318

1419
<application
1520
android:name=".ButlerCrashReporter"
@@ -39,4 +44,4 @@
3944
<activity android:name=".HelpActivity"></activity>
4045
</application>
4146

42-
</manifest>
47+
</manifest>

app/src/main/java/org/domogik/butler/ButlerCrashReporter.java

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
package org.domogik.butler;
22

33
import android.app.Application;
4+
import android.os.Environment;
45

56
import com.github.anrwatchdog.ANRWatchDog;
67

78
import org.acra.ACRA;
89
import org.acra.ReportingInteractionMode;
910
import org.acra.annotation.ReportsCrashes;
1011

12+
import java.io.File;
13+
import java.io.IOException;
14+
1115
import static org.acra.ReportField.ANDROID_VERSION;
1216
import static org.acra.ReportField.LOGCAT;
1317
import static org.acra.ReportField.PHONE_MODEL;
@@ -29,11 +33,67 @@ public class ButlerCrashReporter extends Application {
2933
@Override
3034
public void onCreate() {
3135
super.onCreate();
36+
37+
/******************************************************************
38+
Handle the crashes to send a report email with the logs
39+
******************************************************************/
3240
// The following line triggers the initialization of ACRA
3341
ACRA.init(this);
3442
ACRA.getErrorReporter().putCustomData("Release", getResources().getString(R.string.dummy_content));
3543
new ANRWatchDog().start();
3644

45+
/******************************************************************
46+
Log to a file
47+
******************************************************************/
48+
49+
if ( isExternalStorageWritable() ) {
50+
51+
File appDirectory = new File( Environment.getExternalStorageDirectory() + "/ButlerAndroid" );
52+
File logDirectory = new File( appDirectory + "/log" );
53+
File logFile = new File( logDirectory, "logcat" + System.currentTimeMillis() + ".txt" );
54+
55+
// create app folder
56+
if ( !appDirectory.exists() ) {
57+
appDirectory.mkdir();
58+
}
59+
60+
// create log folder
61+
if ( !logDirectory.exists() ) {
62+
logDirectory.mkdir();
63+
}
3764

65+
// clear the previous logcat and then write the new one to the file
66+
try {
67+
Process process = Runtime.getRuntime().exec( "logcat -c");
68+
process = Runtime.getRuntime().exec( "logcat -f " + logFile + " *:I ");
69+
} catch ( IOException e ) {
70+
e.printStackTrace();
71+
}
72+
73+
} else if ( isExternalStorageReadable() ) {
74+
// only readable
75+
} else {
76+
// not accessible
77+
}
78+
}
79+
80+
/* Checks if external storage is available for read and write */
81+
public boolean isExternalStorageWritable() {
82+
String state = Environment.getExternalStorageState();
83+
if ( Environment.MEDIA_MOUNTED.equals( state ) ) {
84+
return true;
85+
}
86+
return false;
3887
}
88+
89+
/* Checks if external storage is available to at least read */
90+
public boolean isExternalStorageReadable() {
91+
String state = Environment.getExternalStorageState();
92+
if ( Environment.MEDIA_MOUNTED.equals( state ) ||
93+
Environment.MEDIA_MOUNTED_READ_ONLY.equals( state ) ) {
94+
return true;
95+
}
96+
return false;
97+
}
98+
3999
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
4+
<string-array name="pref_keyspotting_lang">
5+
<item name="fr">fr</item>
6+
<item name="en">en</item>
7+
</string-array>
8+
<string-array name="pref_keyspotting_lang_values">
9+
<item name="fr">fr</item>
10+
<item name="en">en</item>
11+
</string-array>
12+
13+
<string-array name="pref_keyspotting_threshold">
14+
<item name="10">10</item>
15+
<item name="15">15</item>
16+
<item name="20">20</item>
17+
<item name="25">25</item>
18+
<item name="30">30</item>
19+
<item name="35">35</item>
20+
<item name="40">40</item>
21+
<item name="45">45</item>
22+
<item name="50">50</item>
23+
<item name="55">55</item>
24+
<item name="60">60</item>
25+
</string-array>
26+
<string-array name="pref_keyspotting_threshold_values">
27+
<item name="10">10</item>
28+
<item name="15">15</item>
29+
<item name="20">20</item>
30+
<item name="25">25</item>
31+
<item name="30">30</item>
32+
<item name="35">35</item>
33+
<item name="40">40</item>
34+
<item name="45">45</item>
35+
<item name="50">50</item>
36+
<item name="55">55</item>
37+
<item name="60">60</item>
38+
</string-array>
39+
40+
<!-- values in seconds -->
41+
<string-array name="pref_location_interval">
42+
<item name="60">1 minute</item>
43+
<item name="120">2 minutes</item>
44+
<item name="300">5 minutes</item>
45+
<item name="600">10 minutes</item>
46+
</string-array>
47+
<string-array name="pref_location_interval_values">
48+
<item name="60">60</item>
49+
<item name="120">120</item>
50+
<item name="300">300</item>
51+
<item name="600">600</item>
52+
</string-array>
53+
</resources>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<!-- release -->
55
<string name="dummy_content">~DEV beta4~</string> <!-- this one is displayed in the back of the main activity. Must be empty for a stable release -->
6-
<string name="release">0.1 beta4</string> <!-- this one is displayed in the about menu -->
6+
<string name="release">0.1 beta5</string> <!-- this one is displayed in the about menu -->
77

88
<!-- layout main -->
99
<string name="request_default">Click on the bottom button...</string>

0 commit comments

Comments
 (0)