Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
… after running much longer tests, it revealed that there was still another leak with the ExampleActivity which is now fixed NOJIRA - removing the silly copy sources task in favor of a source redirector (gradle build only) NOJIRA - adding Leak Canary and ACRA for leak testing and crash logging
- Loading branch information
1 parent
d436504
commit 3cadcd3
Showing
30 changed files
with
336 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
OpenStreetMapViewer/src/main/java/org/osmdroid/OsmApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
package org.osmdroid; | ||
|
||
import android.app.Application; | ||
import android.content.Context; | ||
import android.os.Environment; | ||
import android.util.Log; | ||
|
||
import com.squareup.leakcanary.LeakCanary; | ||
|
||
import org.acra.ACRA; | ||
import org.acra.annotation.ReportsCrashes; | ||
import org.acra.collector.CrashReportData; | ||
import org.acra.sender.ReportSender; | ||
import org.acra.sender.ReportSenderException; | ||
|
||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
import java.util.Locale; | ||
|
||
/** | ||
* This is the base application for the sample app. We only use to catch errors during development cycles | ||
* Created by alex on 7/4/16. | ||
*/ | ||
@ReportsCrashes( formUri = "") | ||
public class OsmApplication extends Application{ | ||
|
||
@Override | ||
public void onCreate(){ | ||
super.onCreate(); | ||
LeakCanary.install(this); | ||
Thread.currentThread().setUncaughtExceptionHandler(new OsmUncaughtExceptionHandler()); | ||
} | ||
|
||
@Override | ||
protected void attachBaseContext(Context base) { | ||
super.attachBaseContext(base); | ||
|
||
|
||
|
||
// Initialise ACRA | ||
ACRA.init(this); | ||
ACRA.getErrorReporter().setReportSender(new ErrorFileWriter()); | ||
|
||
|
||
|
||
} | ||
|
||
public static class OsmUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler { | ||
@Override | ||
public void uncaughtException(Thread thread, Throwable ex) { | ||
Log.e("UncaughtException", "Got an uncaught exception: "+ex.toString()); | ||
if(ex.getClass().equals(OutOfMemoryError.class)) | ||
{ | ||
writeHprof(); | ||
} | ||
ex.printStackTrace(); | ||
} | ||
} | ||
|
||
/** | ||
* writes the current heap to the file system at /sdcard/osmdroid/trace-{timestamp}.hprof | ||
*/ | ||
public static void writeHprof(){ | ||
try { | ||
android.os.Debug.dumpHprofData(Environment.getExternalStorageDirectory().getAbsolutePath() + "/osmdroid/trace-" + System.currentTimeMillis()+ ".hprof"); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Writes hard crash stack traces to a file on the SD card. | ||
*/ | ||
private static class ErrorFileWriter implements ReportSender { | ||
|
||
@Override | ||
public void send(Context context, CrashReportData crashReportData) throws ReportSenderException { | ||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss", | ||
Locale.US); | ||
String timeStamp = sdf.format(new Date()); | ||
String rootDirectory = Environment.getExternalStorageDirectory() | ||
.getAbsolutePath(); | ||
File f = new File(rootDirectory | ||
+ File.separatorChar | ||
+ "TCE" | ||
+ File.separatorChar | ||
+ "logs" | ||
+ File.separatorChar | ||
+ "crash" | ||
+ File.separatorChar); | ||
f.mkdirs(); | ||
f = new File(rootDirectory | ||
+ File.separatorChar | ||
+ "TCE" | ||
+ File.separatorChar | ||
+ "logs" | ||
+ File.separatorChar | ||
+ "crash" | ||
+ File.separatorChar | ||
+ "CRASH_" | ||
+ BuildConfig.APPLICATION_ID+ "_" | ||
+ timeStamp + ".log"); | ||
f.delete(); | ||
|
||
try { | ||
f.createNewFile(); | ||
PrintWriter pw = new PrintWriter(new FileWriter(f)); | ||
pw.println(crashReportData.toString()); | ||
pw.close(); | ||
} catch (Exception exc) { | ||
exc.printStackTrace(); | ||
} | ||
|
||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
OpenStreetMapViewer/src/main/java/org/osmdroid/samplefragments/SampleCustomTileSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.