Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
e
os
eDrive
Commits
4f395d94
Commit
4f395d94
authored
Nov 23, 2019
by
vince-bourgmayer
Browse files
add ServiceExceptionHandler
parent
f82b5293
Changes
2
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/foundation/e/drive/utils/AppConstants.java
View file @
4f395d94
...
@@ -27,7 +27,4 @@ public abstract class AppConstants {
...
@@ -27,7 +27,4 @@ public abstract class AppConstants {
public
static
final
String
[]
MEDIA_SYNCABLE_CATEGORIES
=
new
String
[]{
"Images"
,
"Movies"
,
"Music"
,
"Ringtones"
,
"Documents"
,
"Podcasts"
};
public
static
final
String
[]
MEDIA_SYNCABLE_CATEGORIES
=
new
String
[]{
"Images"
,
"Movies"
,
"Music"
,
"Ringtones"
,
"Documents"
,
"Podcasts"
};
public
static
final
String
[]
SETTINGS_SYNCABLE_CATEGORIES
=
new
String
[]
{
"Rom settings"
};
public
static
final
String
[]
SETTINGS_SYNCABLE_CATEGORIES
=
new
String
[]
{
"Rom settings"
};
}
}
app/src/main/java/foundation/e/drive/utils/ServiceExceptionHandler.java
0 → 100644
View file @
4f395d94
/*
* Copyright © Vincent Bourgmayer (/e/ foundation).
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*/
package
foundation.e.drive.utils
;
import
android.os.Environment
;
import
android.util.Log
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.PrintWriter
;
import
java.io.StringWriter
;
import
java.lang.Thread.UncaughtExceptionHandler
;
/**
* @author Vincent Bourgmayer
*/
public
class
ServiceExceptionHandler
implements
UncaughtExceptionHandler
{
@Override
public
void
uncaughtException
(
Thread
t
,
Throwable
e
)
{
e
.
printStackTrace
();
if
(
isExternalStorageAvailable
()
&&
!
isExternalStorageReadOnly
()){
//Get TimeStamp
Long
timestamp
=
System
.
currentTimeMillis
();
//Create a new file that user can sent to us
String
fileName
=
"eDrive-crash-"
+
timestamp
+
".log"
;
File
downloadDir
=
new
File
(
Environment
.
getExternalStoragePublicDirectory
(
Environment
.
DIRECTORY_DOWNLOADS
).
getPath
());
File
logFile
=
new
File
(
downloadDir
,
fileName
);
try
{
FileOutputStream
fos
=
new
FileOutputStream
(
logFile
);
fos
.
write
(
getStackTraceAsString
(
e
).
getBytes
());
fos
.
close
();
}
catch
(
IOException
exception
)
{
exception
.
printStackTrace
();
}
}
}
//source: https://www.journaldev.com/9400/android-external-storage-read-write-save-file
private
static
boolean
isExternalStorageAvailable
()
{
String
extStorageState
=
Environment
.
getExternalStorageState
();
if
(
Environment
.
MEDIA_MOUNTED
.
equals
(
extStorageState
))
{
return
true
;
}
return
false
;
}
//source: https://www.journaldev.com/9400/android-external-storage-read-write-save-file
private
static
boolean
isExternalStorageReadOnly
()
{
String
extStorageState
=
Environment
.
getExternalStorageState
();
if
(
Environment
.
MEDIA_MOUNTED_READ_ONLY
.
equals
(
extStorageState
))
{
return
true
;
}
return
false
;
}
/**
* Return the stackTrace of the exception as a String
* @param e the exception
* @return the Stacktrace as a string
*/
private
String
getStackTraceAsString
(
Throwable
e
){
StringWriter
sw
=
new
StringWriter
();
PrintWriter
pw
=
new
PrintWriter
(
sw
);
e
.
printStackTrace
(
pw
);
return
sw
.
toString
();
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment