Example usage for java.lang Thread getDefaultUncaughtExceptionHandler

List of usage examples for java.lang Thread getDefaultUncaughtExceptionHandler

Introduction

In this page you can find the example usage for java.lang Thread getDefaultUncaughtExceptionHandler.

Prototype

public static UncaughtExceptionHandler getDefaultUncaughtExceptionHandler() 

Source Link

Document

Returns the default handler invoked when a thread abruptly terminates due to an uncaught exception.

Usage

From source file:uk.co.md87.android.common.ExceptionHandler.java

public ExceptionHandler(String appname, String url, String version, String imei) {
    this.appname = appname;
    this.url = url;
    this.version = version;
    this.imei = imei;
    this.defaultUEH = Thread.getDefaultUncaughtExceptionHandler();
}

From source file:com.moto.miletus.application.tabs.CommandsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_commands);

    if (!(Thread.getDefaultUncaughtExceptionHandler() instanceof CustomExceptionHandler)) {
        Thread.setDefaultUncaughtExceptionHandler(new CustomExceptionHandler(this));
    }//  w w  w . j a  va 2s.  c o  m

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);

    final Bundle state = savedInstanceState != null ? savedInstanceState : getIntent().getExtras();
    mComponent = state.getParcelable(Strings.EXTRA_KEY_DEVICE_COMPONENT);
    mDevice = state.getParcelable(Strings.EXTRA_KEY_DEVICE);
    if (mDevice == null || mComponent == null) {
        throw new IllegalArgumentException("Error in intent extra");
    }

    final ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayShowHomeEnabled(true);
        actionBar.setTitle(StringUtils.capitalize(
                mDevice.getDevice().getName().replace(com.moto.miletus.utils.Strings.mSearchName, "")));
        actionBar.setSubtitle(StringUtils.capitalize(getComponent().getTraitName().replace("_", "")));
    }
}

From source file:com.android.fastlibrary.AppException.java

private AppException() {
    this.mDefaultHandler = Thread.getDefaultUncaughtExceptionHandler();
}

From source file:co.bugjar.android.monitor.BugjarMonitor.java

/**
 * Get the Bugjar exception handler/*from  w w  w  .  j a va2 s .  c  om*/
 */
private ExceptionHandler exceptionHandler() {
    return new ExceptionHandler(filesDir, versionName, versionCode,
            Thread.getDefaultUncaughtExceptionHandler());
}

From source file:com.sir_m2x.messenger.utils.CustomExceptionHandler.java

public CustomExceptionHandler(final Context context, final String localPath, final String url) {
    this.context = context;
    this.localPath = localPath;
    this.url = url;
    this.defaultUEH = Thread.getDefaultUncaughtExceptionHandler();
}

From source file:com.atinternet.tracker.CrashDetectionHandlerTest.java

@Test
public void multiInstanceTest() {
    CrashDetectionHandler crashDetectionHandler = new CrashDetectionHandler(Robolectric.application,
            Thread.getDefaultUncaughtExceptionHandler());
    assertNotSame(this.crashDetectionHandler, crashDetectionHandler);
}

From source file:com.rukiasoft.androidapps.comunioelpuntal.crashlogs.ExceptionHandler.java

public static boolean register(Context _context) {
    Log.i(TAG, "Registering default exceptions handler");
    context = _context;//from w w w.j  a v a  2 s .  com
    // Get information about the Package
    PackageManager pm = context.getPackageManager();
    try {
        PackageInfo pi;
        // Version
        pi = pm.getPackageInfo(context.getPackageName(), 0);
        G.APP_VERSION = pi.versionName;
        // Package name
        G.APP_PACKAGE = pi.packageName;
        // Files dir for storing the stack traces
        G.FILES_PATH = context.getFilesDir().getAbsolutePath();
        // Device model
        G.PHONE_MODEL = android.os.Build.MODEL;
        // Android version
        G.ANDROID_VERSION = android.os.Build.VERSION.RELEASE;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }

    /*Log.d(TAG, "APP_VERSION: " + G.APP_VERSION);
      Log.d(TAG, "APP_PACKAGE: " + G.APP_PACKAGE);
    Log.d(TAG, "FILES_PATH: " + G.FILES_PATH);*/

    boolean stackTracesFound = false;
    // We'll return true if any stack traces were found
    if (searchForStackTraces().length > 0) {
        stackTracesFound = true;
    }

    new Thread() {
        @Override
        public void run() {
            // First of all transmit any stack traces that may be lying around
            submitStackTraces();
            UncaughtExceptionHandler currentHandler = Thread.getDefaultUncaughtExceptionHandler();
            if (currentHandler != null) {
                Log.d(TAG, "current handler class=" + currentHandler.getClass().getName());
            }
            // don't register again if already registered
            if (!(currentHandler instanceof DefaultExceptionHandler)) {
                Log.d(TAG, "Register default exceptions handler");
                Thread.setDefaultUncaughtExceptionHandler(new DefaultExceptionHandler(currentHandler));
            }
        }
    }.start();

    return stackTracesFound;
}

From source file:org.piwik.sdk.QuickTrackTest.java

@Test
public void testPiwikExceptionHandler() throws Exception {
    Tracker tracker = createTracker();/*from  w  w w  .java 2 s.  c o m*/
    assertFalse(Thread.getDefaultUncaughtExceptionHandler() instanceof PiwikExceptionHandler);
    QuickTrack.trackUncaughtExceptions(tracker);
    assertTrue(Thread.getDefaultUncaughtExceptionHandler() instanceof PiwikExceptionHandler);
    try {
        int i = 1 / 0;
        assertNotEquals(i, 0);
    } catch (Exception e) {
        (Thread.getDefaultUncaughtExceptionHandler()).uncaughtException(Thread.currentThread(), e);
    }
    QueryHashMap<String, String> queryParams = parseEventUrl(tracker.getLastEvent());
    validateDefaultQuery(queryParams);
    assertEquals(queryParams.get(QueryParams.EVENT_CATEGORY), "Exception");
    assertTrue(queryParams.get(QueryParams.EVENT_ACTION)
            .startsWith("org.piwik.sdk.QuickTrackTest/testPiwikExceptionHandler:"));
    assertEquals(queryParams.get(QueryParams.EVENT_NAME), "/ by zero");
    assertEquals(queryParams.get(QueryParams.EVENT_VALUE), "1");
}

From source file:com.moto.miletus.application.DeviceActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_device);

    if (!(Thread.getDefaultUncaughtExceptionHandler() instanceof CustomExceptionHandler)) {
        Thread.setDefaultUncaughtExceptionHandler(new CustomExceptionHandler(this));
    }/*w  w  w  .j a  v a 2s  .  c  o  m*/

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);

    final Bundle state = savedInstanceState != null ? savedInstanceState : getIntent().getExtras();
    mDevice = state.getParcelable(Strings.EXTRA_KEY_DEVICE);
    if (mDevice == null) {
        throw new IllegalArgumentException("No Device set in intent extra " + Strings.EXTRA_KEY_DEVICE);
    }

    final ActionBar actionBar = getSupportActionBar();
    if (actionBar == null) {
        return;
    }

    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayShowHomeEnabled(true);
    actionBar.setTitle(R.string.app_name);
    //actionBar.setSubtitle(mDevice.getName());

    SectionsPagerAdapter mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    mViewPager = (ViewPager) findViewById(R.id.container);
    if (mViewPager != null) {
        mViewPager.setAdapter(mSectionsPagerAdapter);
        mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
            @Override
            public void onPageSelected(int position) {
                actionBar.setSelectedNavigationItem(position);
            }
        });
    }

    for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
        actionBar
                .addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }
}

From source file:com.moto.miletus.application.utils.MqttSettingsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_mqtt);

    if (!(Thread.getDefaultUncaughtExceptionHandler() instanceof CustomExceptionHandler)) {
        Thread.setDefaultUncaughtExceptionHandler(new CustomExceptionHandler(this));
    }/*from   w w  w  .j ava2 s .c om*/

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);

    final Button saveSettings = (Button) findViewById(R.id.save_settings);

    if (saveSettings != null) {
        saveSettings.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                saveSettings();
                testConnect();
            }
        });
    }

    initialize();
}