use of com.microsoft.azure.mobile.crashes.ingestion.models.ManagedErrorLog in project mobile-center-sdk-android by Microsoft.
the class ErrorLogHelperTest method createErrorLogFailOver.
@Test
public void createErrorLogFailOver() throws DeviceInfoHelper.DeviceInfoException {
/* Mock base. */
Context mockContext = mock(Context.class);
when(SystemClock.elapsedRealtime()).thenReturn(1000L);
when(Process.myPid()).thenReturn(123);
/* Mock device. */
when(DeviceInfoHelper.getDeviceInfo(any(Context.class))).thenThrow(new DeviceInfoHelper.DeviceInfoException("mock", new PackageManager.NameNotFoundException()));
/* Mock architecture. */
Whitebox.setInternalState(Build.VERSION.class, "SDK_INT", 15);
Whitebox.setInternalState(Build.class, "CPU_ABI", "armeabi-v7a");
/* Test. */
ManagedErrorLog errorLog = ErrorLogHelper.createErrorLog(mockContext, java.lang.Thread.currentThread(), new java.lang.Exception(), java.lang.Thread.getAllStackTraces(), 900, true);
assertNotNull(errorLog);
assertNotNull(errorLog.getId());
assertTrue(System.currentTimeMillis() - errorLog.getToffset() <= 1000);
assertNull(errorLog.getDevice());
assertEquals(Integer.valueOf(123), errorLog.getProcessId());
assertNull(errorLog.getProcessName());
assertNull(errorLog.getParentProcessId());
assertNull(errorLog.getParentProcessName());
assertEquals("armeabi-v7a", errorLog.getArchitecture());
assertEquals((Long) java.lang.Thread.currentThread().getId(), errorLog.getErrorThreadId());
assertEquals(java.lang.Thread.currentThread().getName(), errorLog.getErrorThreadName());
assertEquals(Boolean.TRUE, errorLog.getFatal());
assertEquals(Long.valueOf(100), errorLog.getAppLaunchTOffset());
}
use of com.microsoft.azure.mobile.crashes.ingestion.models.ManagedErrorLog in project mobile-center-sdk-android by Microsoft.
the class Crashes method trackException.
/**
* Track an exception.
* TODO the backend does not support that service yet, will be public method later.
*
* @param exception An exception.
*/
synchronized void trackException(@NonNull com.microsoft.azure.mobile.crashes.ingestion.models.Exception exception) {
if (isInactive())
return;
ManagedErrorLog errorLog = ErrorLogHelper.createErrorLog(mContext, Thread.currentThread(), exception, Thread.getAllStackTraces(), getInitializeTimestamp(), false);
mChannel.enqueue(errorLog, ERROR_GROUP);
}
use of com.microsoft.azure.mobile.crashes.ingestion.models.ManagedErrorLog in project mobile-center-sdk-android by Microsoft.
the class Crashes method getChannelListener.
@Override
protected Channel.GroupListener getChannelListener() {
return new Channel.GroupListener() {
/** Process callback (template method) */
private void processCallback(Log log, final CallbackProcessor callbackProcessor) {
if (log instanceof ManagedErrorLog) {
ManagedErrorLog errorLog = (ManagedErrorLog) log;
if (errorLog.getFatal()) {
final ErrorReport report = buildErrorReport(errorLog);
UUID id = errorLog.getId();
if (report != null) {
/* Clean up before calling callbacks if requested. */
if (callbackProcessor.shouldDeleteThrowable()) {
removeStoredThrowable(id);
}
/* Call back. */
HandlerUtils.runOnUiThread(new Runnable() {
@Override
public void run() {
callbackProcessor.onCallBack(report);
}
});
} else
MobileCenterLog.warn(LOG_TAG, "Cannot find crash report for the error log: " + id);
}
} else {
if (!(log instanceof ErrorAttachmentLog))
MobileCenterLog.warn(LOG_TAG, "A different type of log comes to crashes: " + log.getClass().getName());
}
}
@Override
public void onBeforeSending(Log log) {
processCallback(log, new CallbackProcessor() {
@Override
public boolean shouldDeleteThrowable() {
return false;
}
@Override
public void onCallBack(ErrorReport report) {
mCrashesListener.onBeforeSending(report);
}
});
}
@Override
public void onSuccess(Log log) {
processCallback(log, new CallbackProcessor() {
@Override
public boolean shouldDeleteThrowable() {
return true;
}
@Override
public void onCallBack(ErrorReport report) {
mCrashesListener.onSendingSucceeded(report);
}
});
}
@Override
public void onFailure(Log log, final Exception e) {
processCallback(log, new CallbackProcessor() {
@Override
public boolean shouldDeleteThrowable() {
return true;
}
@Override
public void onCallBack(ErrorReport report) {
mCrashesListener.onSendingFailed(report, e);
}
});
}
};
}
use of com.microsoft.azure.mobile.crashes.ingestion.models.ManagedErrorLog in project mobile-center-sdk-android by Microsoft.
the class Crashes method processPendingErrors.
private void processPendingErrors() {
mHandler.post(new Runnable() {
@Override
public void run() {
for (File logFile : ErrorLogHelper.getStoredErrorLogFiles()) {
if (shouldStopProcessingPendingErrors())
return;
MobileCenterLog.debug(LOG_TAG, "Process pending error file: " + logFile);
String logfileContents = StorageHelper.InternalStorage.read(logFile);
if (logfileContents != null)
try {
ManagedErrorLog log = (ManagedErrorLog) mLogSerializer.deserializeLog(logfileContents);
UUID id = log.getId();
ErrorReport report = buildErrorReport(log);
if (report == null) {
removeAllStoredErrorLogFiles(id);
} else if (mCrashesListener.shouldProcess(report)) {
MobileCenterLog.debug(LOG_TAG, "CrashesListener.shouldProcess returned true, continue processing log: " + id.toString());
mUnprocessedErrorReports.put(id, mErrorReportCache.get(id));
} else {
MobileCenterLog.debug(LOG_TAG, "CrashesListener.shouldProcess returned false, clean up and ignore log: " + id.toString());
removeAllStoredErrorLogFiles(id);
}
} catch (JSONException e) {
MobileCenterLog.error(LOG_TAG, "Error parsing error log", e);
}
}
if (shouldStopProcessingPendingErrors())
return;
processUserConfirmation();
}
});
}
use of com.microsoft.azure.mobile.crashes.ingestion.models.ManagedErrorLog in project mobile-center-sdk-android by Microsoft.
the class Crashes method initialize.
private void initialize() {
boolean enabled = isInstanceEnabled();
mInitializeTimestamp = enabled ? SystemClock.elapsedRealtime() : -1;
if (!enabled) {
if (mUncaughtExceptionHandler != null) {
mUncaughtExceptionHandler.unregister();
mUncaughtExceptionHandler = null;
}
} else if (mContext != null && mUncaughtExceptionHandler == null) {
mUncaughtExceptionHandler = new UncaughtExceptionHandler();
mUncaughtExceptionHandler.register();
final File logFile = ErrorLogHelper.getLastErrorLogFile();
if (logFile != null) {
MobileCenterLog.debug(LOG_TAG, "Processing crash report for the last session.");
mCountDownLatch = new CountDownLatch(1);
mHandler.post(new Runnable() {
@Override
public void run() {
String logFileContents = StorageHelper.InternalStorage.read(logFile);
if (logFileContents == null)
MobileCenterLog.error(LOG_TAG, "Error reading last session error log.");
else {
try {
ManagedErrorLog log = (ManagedErrorLog) mLogSerializer.deserializeLog(logFileContents);
mLastSessionErrorReport = buildErrorReport(log);
MobileCenterLog.debug(LOG_TAG, "Processed crash report for the last session.");
} catch (JSONException e) {
MobileCenterLog.error(LOG_TAG, "Error parsing last session error log.", e);
}
}
mCountDownLatch.countDown();
HandlerUtils.runOnUiThread(new Runnable() {
@Override
public void run() {
/* Call callbacks for getInstanceLastSessionCrashReport(ResultCallback) . */
for (Iterator<ResultCallback<ErrorReport>> iterator = mLastCrashErrorReportCallbacks.iterator(); iterator.hasNext(); ) {
ResultCallback<ErrorReport> callback = iterator.next();
iterator.remove();
callback.onResult(mLastSessionErrorReport);
}
}
});
}
});
}
}
}
Aggregations