ErrorLogHelper { @Nullable public static Device getStoredDeviceInfo(File logFolder) { File[] files = logFolder.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String filename) { return filename.equals(DEVICE_INFO_FILE); } }); if (files == null || files.length == 0) { AppCenterLog.warn(Crashes.LOG_TAG, "No stored deviceinfo file found in a minidump folder."); return null; } File deviceInfoFile = files[0]; String deviceInfoString = FileManager.read(deviceInfoFile); if (deviceInfoString == null) { AppCenterLog.error(Crashes.LOG_TAG, "Failed to read stored device info."); return null; } return parseDevice(deviceInfoString); }  @NonNull static ManagedErrorLog createErrorLog(@NonNull Context context, @NonNull final java.lang.Thread thread, @NonNull final Throwable throwable, @NonNull final Map<java.lang.Thread, StackTraceElement[]> allStackTraces, final long initializeTimestamp); @NonNull static ManagedErrorLog createErrorLog(@NonNull Context context, @NonNull final java.lang.Thread thread, @NonNull final Exception exception, @NonNull final Map<java.lang.Thread, StackTraceElement[]> allStackTraces, final long initializeTimestamp, boolean fatal); @NonNull static synchronized File getErrorStorageDirectory(); @NonNull static synchronized File getNewMinidumpDirectory(); @NonNull static synchronized File getNewMinidumpSubfolder(); @NonNull static synchronized File getNewMinidumpSubfolderWithContextData(Context context); @NonNull static synchronized File getPendingMinidumpDirectory(); @NonNull static File[] getStoredErrorLogFiles(); @NonNull static File[] getNewMinidumpFiles(); @Nullable static Device getStoredDeviceInfo(File logFolder); static void removeStaleMinidumpSubfolders(); static void removeMinidumpFolder(); @Nullable static File getLastErrorLogFile(); @Nullable static File getStoredThrowableFile(@NonNull UUID id); static void removeStoredThrowableFile(@NonNull UUID id); static void removeStoredErrorLogFile(@NonNull UUID id); @NonNull static ErrorReport getErrorReportFromErrorLog(@NonNull ManagedErrorLog log, String stackTrace); @NonNull static Exception getModelExceptionFromThrowable(@NonNull Throwable t); static Map<String, String> validateProperties(Map<String, String> properties, String logType); static void cleanPendingMinidumps(); @NonNull static UUID parseLogFolderUuid(File logFolder); @VisibleForTesting static void clearStaticState(); static final String DEVICE_INFO_FILE; static final String ERROR_LOG_FILE_EXTENSION; static final String THROWABLE_FILE_EXTENSION; @VisibleForTesting
    static final int FRAME_LIMIT; static final int MAX_PROPERTY_ITEM_LENGTH; static final String MINIDUMP_FILE_EXTENSION; }
@Test public void getStoredDeviceInfo() throws IOException { String deviceInfoString = "{\"sdkName\":\"appcenter.android\",\"sdkVersion\":\"2.5.4.2\",\"model\":\"Android SDK built for x86\",\"oemName\":\"Google\",\"osName\":\"Android\",\"osVersion\":\"9\",\"osBuild\":\"PSR1.180720.075\",\"osApiLevel\":28,\"locale\":\"en_US\",\"timeZoneOffset\":240,\"screenSize\":\"1080x1794\",\"appVersion\":\"2.5.4.2\",\"carrierName\":\"Android\",\"carrierCountry\":\"us\",\"appBuild\":\"59\",\"appNamespace\":\"com.microsoft.appcenter.sasquatch.project\"}"; File minidumpFolder = mTemporaryFolder.newFolder("minidump"); File deviceInfoFile = new File(minidumpFolder, ErrorLogHelper.DEVICE_INFO_FILE); assertTrue(deviceInfoFile.createNewFile()); mockStatic(FileManager.class); when(FileManager.read(eq(deviceInfoFile))).thenReturn(deviceInfoString); Device storedDeviceInfo = ErrorLogHelper.getStoredDeviceInfo(minidumpFolder); assertNotNull(storedDeviceInfo); }
@Test public void getStoredDeviceInfoNull() { File minidumpFolder = mock(File.class); when(minidumpFolder.listFiles(any(FilenameFilter.class))).thenReturn(null); Device storedDeviceInfo = ErrorLogHelper.getStoredDeviceInfo(minidumpFolder); assertNull(storedDeviceInfo); }
@Test public void getStoredDeviceInfoEmpty() throws IOException { File minidumpFolder = mTemporaryFolder.newFolder("minidump"); Device storedDeviceInfo = ErrorLogHelper.getStoredDeviceInfo(minidumpFolder); assertNull(storedDeviceInfo); }
@Test public void getStoredDeviceInfoCannotRead() throws IOException { File minidumpFolder = mTemporaryFolder.newFolder("minidump"); File deviceInfoFile = new File(minidumpFolder, ErrorLogHelper.DEVICE_INFO_FILE); assertTrue(deviceInfoFile.createNewFile()); mockStatic(FileManager.class); when(FileManager.read(eq(deviceInfoFile))).thenReturn(null); Device storedDeviceInfo3 = ErrorLogHelper.getStoredDeviceInfo(minidumpFolder); assertNull(storedDeviceInfo3); }