Skip to content

Commit

Permalink
Add getNativeCrashDir to StorageService.
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaslabari committed Jan 11, 2024
1 parent fc44bb0 commit 9c34cf7
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import io.embrace.android.embracesdk.payload.NativeSymbols
import io.embrace.android.embracesdk.session.lifecycle.ProcessStateListener
import io.embrace.android.embracesdk.session.lifecycle.ProcessStateService
import io.embrace.android.embracesdk.session.properties.EmbraceSessionProperties
import io.embrace.android.embracesdk.storage.NATIVE_CRASH_FILE_FOLDER
import io.embrace.android.embracesdk.storage.StorageService
import io.embrace.android.embracesdk.worker.BackgroundWorker
import java.io.BufferedReader
Expand Down Expand Up @@ -203,7 +204,7 @@ internal class EmbraceNdkService(
}

private fun createCrashReportDirectory() {
val directoryFile = storageService.getFile(NATIVE_CRASH_FILE_FOLDER, false)
val directoryFile = storageService.getNativeCrashDir()
if (directoryFile.exists()) {
return
}
Expand All @@ -213,8 +214,7 @@ internal class EmbraceNdkService(
}

private fun installSignals() {
val reportBasePath =
storageService.getFile(NATIVE_CRASH_FILE_FOLDER, false).absolutePath
val reportBasePath = storageService.getNativeCrashDir().absolutePath
val markerFilePath =
storageService.getFile(CrashFileMarker.CRASH_MARKER_FILE_NAME, false).absolutePath

Expand Down Expand Up @@ -637,7 +637,6 @@ internal class EmbraceNdkService(
private const val NATIVE_CRASH_FILE_SUFFIX = ".crash"
private const val NATIVE_CRASH_ERROR_FILE_SUFFIX = ".error"
private const val NATIVE_CRASH_MAP_FILE_SUFFIX = ".map"
private const val NATIVE_CRASH_FILE_FOLDER = "ndk"
private const val MAX_NATIVE_CRASH_FILES_ALLOWED = 4
private const val EMB_DEVICE_META_DATA_SIZE = 2048
private const val HANDLER_CHECK_DELAY_MS = 5000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package io.embrace.android.embracesdk.ndk

import io.embrace.android.embracesdk.logging.InternalEmbraceLogger
import io.embrace.android.embracesdk.payload.NativeCrashData
import io.embrace.android.embracesdk.storage.NATIVE_CRASH_FILE_FOLDER
import io.embrace.android.embracesdk.storage.StorageService
import java.io.File
import java.io.FilenameFilter

private const val NATIVE_CRASH_FILE_PREFIX = "emb_ndk"
private const val NATIVE_CRASH_FILE_SUFFIX = ".crash"
private const val NATIVE_CRASH_FILE_FOLDER = "ndk"
private const val NATIVE_CRASH_ERROR_FILE_SUFFIX = ".error"
private const val NATIVE_CRASH_MAP_FILE_SUFFIX = ".map"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ internal class EmbraceStorageService(
return File(cacheDirectory, EMBRACE_CONFIG_CACHE_DIRECTORY)
}

override fun getNativeCrashDir(): File {
return File(filesDirectory, NATIVE_CRASH_FILE_FOLDER)
}

override fun listFiles(filter: FilenameFilter): List<File> {
val filesDir = filesDirectory.listFiles(filter) ?: emptyArray()
val cacheDir = cacheDirectory.listFiles(filter) ?: emptyArray()
Expand Down Expand Up @@ -62,3 +66,8 @@ private const val EMBRACE_DIRECTORY = "embrace"
* Directory name for the config files that are stored in the cache directory.
*/
private const val EMBRACE_CONFIG_CACHE_DIRECTORY = "emb_config_cache"

/**
* Directory name for the native crash files that are stored in the files directory.
*/
internal const val NATIVE_CRASH_FILE_FOLDER = "ndk"
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ internal interface StorageService {
*/
fun getConfigCacheDir(): File

/**
* Returns a [File] instance referencing the directory where the native crash files are stored.
*/
fun getNativeCrashDir(): File

/**
* Returns a list of files from the files and cache directories that match the [filter].
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ internal class FakeStorageService : StorageService {
override fun getConfigCacheDir() =
File(cacheDirectory, "emb_config_cache")

override fun getNativeCrashDir() =
File(filesDirectory, "ndk")

override fun listFiles(filter: FilenameFilter): List<File> {
val filesDir = filesDirectory.listFiles(filter) ?: emptyArray()
val cacheDir = cacheDirectory.listFiles(filter) ?: emptyArray()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,11 @@ internal class EmbraceStorageServiceTest {
assertNotNull(storageDirForConfigCache)
assertEquals(cacheDir.absolutePath + "/emb_config_cache", storageDirForConfigCache.absolutePath)
}

@Test
fun `test getNativeCrashDir returns files dir`() {
val storageDirForNativeCrash = storageManager.getNativeCrashDir()
assertNotNull(storageDirForNativeCrash)
assertEquals("$embraceFilesDir/ndk", storageDirForNativeCrash.absolutePath)
}
}

0 comments on commit 9c34cf7

Please sign in to comment.