Search in sources :

Example 1 with CrashManagerListener

use of net.hockeyapp.android.CrashManagerListener in project android-oss by kickstarter.

the class KSApplication method checkForCrashes.

private void checkForCrashes() {
    final String appId = Build.isExternal() ? Secrets.HockeyAppId.EXTERNAL : Secrets.HockeyAppId.INTERNAL;
    CrashManager.register(this, appId, new CrashManagerListener() {

        public boolean shouldAutoUploadCrashes() {
            return true;
        }
    });
}
Also used : CrashManagerListener(net.hockeyapp.android.CrashManagerListener)

Example 2 with CrashManagerListener

use of net.hockeyapp.android.CrashManagerListener in project wire-android by wireapp.

the class ZTimeFormatter method getSeparatorTime.

private static String getSeparatorTime(@Nullable Context context, LocalDateTime now, LocalDateTime then, boolean is24HourFormat, ZoneId timeZone, boolean epocIsJustNow, boolean showWeekday, boolean defaultLocale) {
    if (context == null) {
        return "";
    }
    Resources res;
    if (defaultLocale) {
        res = getEnglishResources(context);
    } else {
        res = context.getResources();
    }
    final boolean isLastTwoMins = now.minusMinutes(2).isBefore(then) || (epocIsJustNow && then.atZone(timeZone).toInstant().toEpochMilli() == 0);
    final boolean isLastSixtyMins = now.minusMinutes(60).isBefore(then);
    if (isLastTwoMins) {
        return res.getString(R.string.timestamp__just_now);
    } else if (isLastSixtyMins) {
        int minutes = (int) Duration.between(then, now).toMinutes();
        return res.getQuantityString(R.plurals.timestamp__x_minutes_ago, minutes, minutes);
    }
    final String time = is24HourFormat ? res.getString(R.string.timestamp_pattern__24h_format) : res.getString(R.string.timestamp_pattern__12h_format);
    final boolean isSameDay = now.toLocalDate().atStartOfDay().isBefore(then);
    final boolean isThisYear = now.getYear() == then.getYear();
    final String pattern;
    if (isSameDay) {
        pattern = time;
    } else if (isThisYear) {
        if (showWeekday) {
            pattern = res.getString(R.string.timestamp_pattern__date_and_time__no_year, time);
        } else {
            pattern = res.getString(R.string.timestamp_pattern__date_and_time__no_year_no_weekday, time);
        }
    } else {
        if (showWeekday) {
            pattern = res.getString(R.string.timestamp_pattern__date_and_time__with_year, time);
        } else {
            pattern = res.getString(R.string.timestamp_pattern__date_and_time__with_year_no_weekday, time);
        }
    }
    try {
        return DateTimeFormatter.ofPattern(pattern).format(then.atZone(timeZone));
    } catch (Exception e) {
        ExceptionHandler.saveException(e, Thread.currentThread(), new CrashManagerListener() {

            @Override
            public String getDescription() {
                return pattern;
            }
        });
        if (!defaultLocale) {
            return getSeparatorTime(context, now, then, is24HourFormat, timeZone, epocIsJustNow, showWeekday, true);
        } else {
            return "";
        }
    }
}
Also used : Resources(android.content.res.Resources) CrashManagerListener(net.hockeyapp.android.CrashManagerListener)

Example 3 with CrashManagerListener

use of net.hockeyapp.android.CrashManagerListener in project wire-android by wireapp.

the class ZTimeFormatter method getSingleMessageTime.

private static String getSingleMessageTime(Context context, Date date, boolean defaultLocale) {
    boolean is24HourFormat = DateFormat.is24HourFormat(context);
    Resources resources = defaultLocale ? getEnglishResources(context) : context.getResources();
    final String pattern = is24HourFormat ? resources.getString(R.string.timestamp_pattern__24h_format) : resources.getString(R.string.timestamp_pattern__12h_format);
    try {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
        return formatter.format(DateConvertUtils.asLocalDateTime(date).atZone(ZoneId.systemDefault()));
    } catch (Exception e) {
        ExceptionHandler.saveException(e, Thread.currentThread(), new CrashManagerListener() {

            @Override
            public String getDescription() {
                return pattern;
            }
        });
        if (!defaultLocale) {
            return getSingleMessageTime(context, date, true);
        } else {
            return "";
        }
    }
}
Also used : Resources(android.content.res.Resources) DateTimeFormatter(org.threeten.bp.format.DateTimeFormatter) CrashManagerListener(net.hockeyapp.android.CrashManagerListener)

Example 4 with CrashManagerListener

use of net.hockeyapp.android.CrashManagerListener in project wire-android by wireapp.

the class HockeyCrashReporting method checkForCrashes.

public static void checkForCrashes(final Context context, final String deviceId, GlobalTrackingController trackingController) {
    Timber.v("checkForCrashes - registering...");
    final CrashManagerListener listener = new CrashManagerListener() {

        @Override
        public boolean shouldAutoUploadCrashes() {
            return true;
        }

        @Override
        public String getUserID() {
            return deviceId;
        }
    };
    CrashManager.initialize(context, Util.getAppIdentifier(context), listener);
    boolean nativeCrashFound = NativeCrashManager.loggedDumpFiles(Util.getAppIdentifier(context));
    if (nativeCrashFound) {
        StringBuffer details = new StringBuffer(Constants.PHONE_MANUFACTURER).append("/").append(Constants.PHONE_MODEL);
        trackingController.tagEvent(ExceptionEvent.exception("NDK", details.toString()));
    }
    // execute crash manager in background, it does IO and can take some time
    // XXX: this works because we use auto upload (and app context), so hockey doesn't try to show a dialog
    Threading.IO().execute(new Runnable() {

        @Override
        public void run() {
            // check number of crash reports, will drop them if there is too many
            String[] traces = new File(Constants.FILES_PATH).list(new FilenameFilter() {

                @Override
                public boolean accept(File dir, String filename) {
                    return filename.endsWith(".stacktrace");
                }
            });
            if (traces != null && traces.length > 256) {
                Timber.v("checkForCrashes - found too many crash reports: %d, will drop them", traces.length);
                CrashManager.deleteStackTraces(new WeakReference<>(context));
            }
            CrashManager.execute(context, listener);
        }
    });
}
Also used : FilenameFilter(java.io.FilenameFilter) WeakReference(java.lang.ref.WeakReference) File(java.io.File) CrashManagerListener(net.hockeyapp.android.CrashManagerListener)

Aggregations

CrashManagerListener (net.hockeyapp.android.CrashManagerListener)4 Resources (android.content.res.Resources)2 File (java.io.File)1 FilenameFilter (java.io.FilenameFilter)1 WeakReference (java.lang.ref.WeakReference)1 DateTimeFormatter (org.threeten.bp.format.DateTimeFormatter)1