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
bff139f6
Commit
bff139f6
authored
Dec 13, 2019
by
vince-bourgmayer
Browse files
add method in CommonUtils to set the ServiceUncaughtExceptionHandler
parent
51884902
Changes
2
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/foundation/e/drive/utils/CommonUtils.java
View file @
bff139f6
...
...
@@ -12,6 +12,7 @@ package foundation.e.drive.utils;
import
android.accounts.Account
;
import
android.accounts.AccountManager
;
import
android.app.Service
;
import
android.content.ContentResolver
;
import
android.content.Context
;
import
android.media.MediaScannerConnection
;
...
...
@@ -39,6 +40,21 @@ import static foundation.e.drive.utils.AppConstants.SETTINGSYNC_PROVIDER_AUTHORI
public
abstract
class
CommonUtils
{
final
private
static
String
TAG
=
CommonUtils
.
class
.
getSimpleName
();
/**
* Set ServiceUncaughtExceptionHandler to be the MainThread Exception Handler
* Or update the service which use it
* @param service current service
*/
public
static
void
setServiceUnCaughtExceptionHandler
(
Service
service
){
Thread
.
UncaughtExceptionHandler
defaultUEH
=
Thread
.
getDefaultUncaughtExceptionHandler
();
if
(
defaultUEH
.
getClass
().
getSimpleName
().
equals
(
ServiceExceptionHandler
.
class
.
getSimpleName
())){
Log
.
d
(
"ObserverService"
,
"ServiceExceptionHandler already set!"
);
((
ServiceExceptionHandler
)
defaultUEH
).
setService
(
service
);
}
else
{
Thread
.
setDefaultUncaughtExceptionHandler
(
new
ServiceExceptionHandler
(
service
));
}
}
/**
* Unregister from screeOffReceiver component
...
...
app/src/main/java/foundation/e/drive/utils/ServiceExceptionHandler.java
View file @
bff139f6
...
...
@@ -23,8 +23,18 @@ import java.lang.Thread.UncaughtExceptionHandler;
public
class
ServiceExceptionHandler
implements
UncaughtExceptionHandler
{
private
UncaughtExceptionHandler
defaultUEH
;
Service
service
;
/**
* Update the service which use this handler
* @param service current running service
*/
public
void
setService
(
Service
service
)
{
this
.
service
=
service
;
}
public
ServiceExceptionHandler
(
Service
service
)
{
this
.
service
=
service
;
defaultUEH
=
Thread
.
getDefaultUncaughtExceptionHandler
();
...
...
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