Search in sources :

Example 16 with Device

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);
}
Also used : Device(com.microsoft.appcenter.ingestion.models.Device) Matchers.anyString(org.mockito.Matchers.anyString) TestUtils.generateString(com.microsoft.appcenter.test.TestUtils.generateString) File(java.io.File) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 17 with Device

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);
}
Also used : FilenameFilter(java.io.FilenameFilter) Device(com.microsoft.appcenter.ingestion.models.Device) Matchers.anyString(org.mockito.Matchers.anyString) TestUtils.generateString(com.microsoft.appcenter.test.TestUtils.generateString) File(java.io.File) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 18 with Device

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());
}
Also used : Context(android.content.Context) ErrorReport(com.microsoft.appcenter.crashes.model.ErrorReport) TestCrashException(com.microsoft.appcenter.crashes.model.TestCrashException) RunningAppProcessInfo(android.app.ActivityManager.RunningAppProcessInfo) ManagedErrorLog(com.microsoft.appcenter.crashes.ingestion.models.ManagedErrorLog) Device(com.microsoft.appcenter.ingestion.models.Device) Build(android.os.Build) Matchers.anyString(org.mockito.Matchers.anyString) TestUtils.generateString(com.microsoft.appcenter.test.TestUtils.generateString) ActivityManager(android.app.ActivityManager) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 19 with Device

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();
}
Also used : Context(android.content.Context) Device(com.microsoft.appcenter.ingestion.models.Device) FileWriter(java.io.FileWriter) IOException(java.io.IOException) File(java.io.File) BufferedWriter(java.io.BufferedWriter) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 20 with Device

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());
}
Also used : Device(com.microsoft.appcenter.ingestion.models.Device)

Aggregations

Device (com.microsoft.appcenter.ingestion.models.Device)46 Test (org.junit.Test)32 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)29 Context (android.content.Context)18 File (java.io.File)15 Date (java.util.Date)11 ManagedErrorLog (com.microsoft.appcenter.crashes.ingestion.models.ManagedErrorLog)10 Matchers.anyString (org.mockito.Matchers.anyString)10 TestCrashException (com.microsoft.appcenter.crashes.model.TestCrashException)9 IOException (java.io.IOException)9 ErrorReport (com.microsoft.appcenter.crashes.model.ErrorReport)8 Log (com.microsoft.appcenter.ingestion.models.Log)8 JSONException (org.json.JSONException)8 PackageInfo (android.content.pm.PackageInfo)7 PackageManager (android.content.pm.PackageManager)7 Build (android.os.Build)7 InvocationOnMock (org.mockito.invocation.InvocationOnMock)7 TelephonyManager (android.telephony.TelephonyManager)6 Log.getStackTraceString (android.util.Log.getStackTraceString)6 DefaultLogSerializer (com.microsoft.appcenter.ingestion.models.json.DefaultLogSerializer)6