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
46b51eb7
Commit
46b51eb7
authored
Dec 13, 2019
by
vince-bourgmayer
Browse files
Check in ServiceUEH if service is OMS and then disable OMS_IS_WORKING
parent
135708d1
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/foundation/e/drive/utils/ServiceExceptionHandler.java
View file @
46b51eb7
...
...
@@ -7,6 +7,7 @@
*/
package
foundation.e.drive.utils
;
import
android.app.Service
;
import
android.content.Context
;
import
android.os.Environment
;
import
android.util.Log
;
...
...
@@ -17,13 +18,14 @@ import java.io.PrintWriter;
import
java.io.StringWriter
;
import
java.lang.Thread.UncaughtExceptionHandler
;
import
foundation.e.drive.services.OperationManagerService
;
/**
* @author Vincent Bourgmayer
*/
public
class
ServiceExceptionHandler
implements
UncaughtExceptionHandler
{
private
UncaughtExceptionHandler
defaultUEH
;
private
final
static
String
TAG
=
ServiceExceptionHandler
.
class
.
getSimpleName
();
Service
service
;
...
...
@@ -42,6 +44,14 @@ public class ServiceExceptionHandler implements UncaughtExceptionHandler{
@Override
public
void
uncaughtException
(
Thread
t
,
Throwable
e
)
{
Log
.
d
(
TAG
,
"Service class: "
+
service
.
getClass
().
getSimpleName
());
//IF OMS is crashing, set settings that it runs to false;
if
(
service
.
getClass
().
getSimpleName
().
equals
(
OperationManagerService
.
class
.
getSimpleName
())){
service
.
getSharedPreferences
(
AppConstants
.
SHARED_PREFERENCE_NAME
,
Context
.
MODE_PRIVATE
)
.
edit
()
.
putBoolean
(
AppConstants
.
KEY_OMS_IS_WORKING
,
false
)
.
apply
();
}
if
(
isExternalStorageAvailable
()
&&
!
isExternalStorageReadOnly
()){
//Get TimeStamp
...
...
@@ -49,22 +59,26 @@ public class ServiceExceptionHandler implements UncaughtExceptionHandler{
//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
downloadDir
=
service
.
getApplication
().
getExternalFilesDir
(
"Logs"
);
File
logFile
=
new
File
(
downloadDir
,
fileName
);
try
{
FileOutputStream
fos
=
new
FileOutputStream
(
logFile
);
fos
.
write
(
service
.
getClass
().
getSimpleName
().
getBytes
());
fos
.
write
(
getStackTraceAsString
(
e
).
getBytes
());
fos
.
close
();
logFile
.
setReadable
(
true
,
false
);
}
catch
(
IOException
exception
)
{
exception
.
printStackTrace
();
}
}
//source: https://stackoverflow.com/questions/9050962/rethrow-uncaughtexceptionhandler-exception-after-logging-it/9050990#9050990
if
(
defaultUEH
!=
null
){
defaultUEH
.
uncaughtException
(
t
,
e
);
}
else
{
Log
.
d
(
"ServiceExceptionHandler"
,
"/e/ Drive has crashed and there is no ExceptionHandler"
);
Log
.
d
(
TAG
,
"/e/ Drive has crashed and there is no ExceptionHandler"
);
System
.
exit
(
1
);
//Kill /e/ Drive...
}
}
...
...
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