use of com.microsoft.appcenter.ingestion.models.Device in project mobile-center-sdk-android by Microsoft.
the class ErrorLogHelperTest method getStoredDeviceInfoAndUserIdEmpty.
@Test
public void getStoredDeviceInfoAndUserIdEmpty() throws IOException {
File minidumpFolder = mTemporaryFolder.newFolder("minidump");
Device storedDeviceInfo = ErrorLogHelper.getStoredDeviceInfo(minidumpFolder);
String storedUserId = ErrorLogHelper.getStoredUserInfo(minidumpFolder);
assertNull(storedDeviceInfo);
assertNull(storedUserId);
}
use of com.microsoft.appcenter.ingestion.models.Device in project mobile-center-sdk-android by Microsoft.
the class ErrorLogHelperTest method getStoredDeviceInfoAndUserIdNull.
@Test
public void getStoredDeviceInfoAndUserIdNull() {
File minidumpFolder = mock(File.class);
when(minidumpFolder.listFiles(any(FilenameFilter.class))).thenReturn(null);
Device storedDeviceInfo = ErrorLogHelper.getStoredDeviceInfo(minidumpFolder);
String storedUserId = ErrorLogHelper.getStoredUserInfo(minidumpFolder);
assertNull(storedDeviceInfo);
assertNull(storedUserId);
}
use of com.microsoft.appcenter.ingestion.models.Device in project mobile-center-sdk-android by Microsoft.
the class ErrorLogHelperTest method getErrorReportFromErrorLog.
@Test
public void getErrorReportFromErrorLog() throws java.lang.Exception {
/* Mock base. */
Context mockContext = mock(Context.class);
when(Process.myPid()).thenReturn(123);
/* Mock device. */
Device mockDevice = mock(Device.class);
when(DeviceInfoHelper.getDeviceInfo(any(Context.class))).thenReturn(mockDevice);
/* Mock process name. */
ActivityManager activityManager = mock(ActivityManager.class);
RunningAppProcessInfo runningAppProcessInfo = new RunningAppProcessInfo(null, 0, null);
runningAppProcessInfo.pid = 123;
runningAppProcessInfo.processName = "right.process";
when(mockContext.getSystemService(Context.ACTIVITY_SERVICE)).thenReturn(activityManager);
when(activityManager.getRunningAppProcesses()).thenReturn(Arrays.asList(mock(RunningAppProcessInfo.class), runningAppProcessInfo));
/* Mock architecture. */
TestUtils.setInternalState(Build.VERSION.class, "SDK_INT", 23);
TestUtils.setInternalState(Build.class, "SUPPORTED_ABIS", new String[] { "armeabi-v7a", "arm" });
/* Create an error log. */
ManagedErrorLog errorLog = ErrorLogHelper.createErrorLog(mockContext, java.lang.Thread.currentThread(), new RuntimeException(new TestCrashException()), java.lang.Thread.getAllStackTraces(), 900);
assertNotNull(errorLog);
/* Test. */
String stackTrace = "Sample stack trace";
ErrorReport report = ErrorLogHelper.getErrorReportFromErrorLog(errorLog, stackTrace);
assertNotNull(report);
assertEquals(errorLog.getId().toString(), report.getId());
assertEquals(errorLog.getErrorThreadName(), report.getThreadName());
assertEquals(stackTrace, report.getStackTrace());
assertEquals(errorLog.getAppLaunchTimestamp(), report.getAppStartTime());
assertEquals(errorLog.getTimestamp(), report.getAppErrorTime());
assertEquals(errorLog.getDevice(), report.getDevice());
}
use of com.microsoft.appcenter.ingestion.models.Device in project mobile-center-sdk-android by Microsoft.
the class ErrorLogHelperTest method throwIOExceptionWhenGetMinidumpSubfolderWithDeviceInfo.
@Test
public void throwIOExceptionWhenGetMinidumpSubfolderWithDeviceInfo() throws java.lang.Exception {
/* Prepare data. */
BufferedWriter mockBufferedWriter = mock(BufferedWriter.class);
FileWriter mockFileWriter = mock(FileWriter.class);
whenNew(BufferedWriter.class).withAnyArguments().thenReturn(mockBufferedWriter);
whenNew(FileWriter.class).withAnyArguments().thenReturn(mockFileWriter);
doThrow(new IOException()).when(mockBufferedWriter).write(anyString());
mockStatic(TextUtils.class);
when(TextUtils.isEmpty(anyString())).thenReturn(false);
when(TextUtils.getTrimmedLength(anyString())).thenReturn(1);
Device mockDevice = mock(Device.class);
mockStatic(DeviceInfoHelper.class);
when(DeviceInfoHelper.getDeviceInfo(any(Context.class))).thenReturn(mockDevice);
Context mockContext = mock(Context.class);
File mockFile = mock(File.class);
whenNew(File.class).withAnyArguments().thenReturn(mockFile);
/* Verify. */
ErrorLogHelper.getNewMinidumpSubfolderWithContextData(mockContext);
verify(mockFile).delete();
}
use of com.microsoft.appcenter.ingestion.models.Device in project mobile-center-sdk-android by Microsoft.
the class PartAUtils method addPartAFromLog.
/**
* Adds part A extension to common schema log from device object in Log.
*
* @param src source log.
* @param dest destination common schema log.
* @param transmissionTarget transmission target to use.
*/
public static void addPartAFromLog(Log src, CommonSchemaLog dest, String transmissionTarget) {
/* TODO: We should cache the extension. */
Device device = src.getDevice();
/* Add top level part A fields. */
dest.setVer("3.0");
dest.setTimestamp(src.getTimestamp());
/* TODO: We should cache the ikey for transmission target */
dest.setIKey("o" + COMMON_SCHEMA_PREFIX_SEPARATOR + getTargetKey(transmissionTarget));
/* Copy target token also in the set. */
dest.addTransmissionTarget(transmissionTarget);
/* Add extension. */
if (dest.getExt() == null) {
dest.setExt(new Extensions());
}
/* Add protocol extension. */
dest.getExt().setProtocol(new ProtocolExtension());
dest.getExt().getProtocol().setDevModel(device.getModel());
dest.getExt().getProtocol().setDevMake(device.getOemName());
/* Add user extension. */
dest.getExt().setUser(new UserExtension());
dest.getExt().getUser().setLocalId(UserIdContext.getPrefixedUserId(src.getUserId()));
dest.getExt().getUser().setLocale(device.getLocale().replace("_", "-"));
/* Add OS extension. */
dest.getExt().setOs(new OsExtension());
dest.getExt().getOs().setName(device.getOsName());
dest.getExt().getOs().setVer(device.getOsVersion() + "-" + device.getOsBuild() + "-" + device.getOsApiLevel());
/* TODO: Add app locale. */
/* Add app extension. */
dest.getExt().setApp(new AppExtension());
dest.getExt().getApp().setVer(device.getAppVersion());
dest.getExt().getApp().setId("a" + COMMON_SCHEMA_PREFIX_SEPARATOR + device.getAppNamespace());
/* TODO: Add network type. */
/* Add net extension. */
dest.getExt().setNet(new NetExtension());
dest.getExt().getNet().setProvider(device.getCarrierName());
/* Add SDK extension. */
dest.getExt().setSdk(new SdkExtension());
dest.getExt().getSdk().setLibVer(device.getSdkName() + "-" + device.getSdkVersion());
/* Add loc extension. */
dest.getExt().setLoc(new LocExtension());
String timezoneOffset = String.format(Locale.US, "%s%02d:%02d", device.getTimeZoneOffset() >= 0 ? "+" : "-", Math.abs(device.getTimeZoneOffset() / 60), Math.abs(device.getTimeZoneOffset() % 60));
dest.getExt().getLoc().setTz(timezoneOffset);
/* Add device extension. */
dest.getExt().setDevice(new DeviceExtension());
}
Aggregations