Commit bff139f6 authored by vince-bourgmayer's avatar vince-bourgmayer
Browse files

add method in CommonUtils to set the ServiceUncaughtExceptionHandler

parent 51884902
......@@ -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
......
......@@ -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();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment