Skip to content

Commit

Permalink
Get rid of unnecessary @VisibleForTest annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
bidetofevil committed Nov 16, 2023
1 parent 989dbf2 commit ba8e9b6
Show file tree
Hide file tree
Showing 35 changed files with 32 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import android.net.Uri
import android.os.Handler
import android.os.Looper
import android.widget.Toast
import androidx.annotation.VisibleForTesting
import io.embrace.android.embracesdk.logging.InternalStaticEmbraceLogger.Companion.logger
import io.embrace.android.embracesdk.samples.AutomaticVerificationChecker
import io.embrace.android.embracesdk.samples.VerificationActions
Expand Down Expand Up @@ -40,16 +39,12 @@ internal class EmbraceAutomaticVerification(

private var foregroundEventTriggered = false

@VisibleForTesting
internal lateinit var activityLifecycleTracker: ActivityTracker

@VisibleForTesting
internal lateinit var processStateService: ProcessStateService

@VisibleForTesting
var automaticVerificationChecker = AutomaticVerificationChecker()

@VisibleForTesting
var verificationActions = VerificationActions(Embrace.getInstance(), automaticVerificationChecker)

/**
Expand All @@ -72,7 +67,6 @@ internal class EmbraceAutomaticVerification(
instance.runVerifyIntegration()
}

@VisibleForTesting
fun setActivityListener() {
if (!::activityLifecycleTracker.isInitialized) {
activityLifecycleTracker = checkNotNull(Embrace.getImpl().activityLifecycleTracker)
Expand Down Expand Up @@ -101,7 +95,6 @@ internal class EmbraceAutomaticVerification(
}
}

@VisibleForTesting
fun startVerification() {
val activity = activityLifecycleTracker.foregroundActivity
if (activity != null) {
Expand Down Expand Up @@ -144,7 +137,6 @@ internal class EmbraceAutomaticVerification(
}
}

@VisibleForTesting
fun runEndSession() {
Embrace.getInstance().endSession()
logger.logInfo("$TAG End session manually")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.embrace.android.embracesdk.anr

import androidx.annotation.VisibleForTesting
import io.embrace.android.embracesdk.anr.detection.ThreadMonitoringState
import io.embrace.android.embracesdk.config.ConfigService
import io.embrace.android.embracesdk.internal.clock.Clock
Expand All @@ -24,7 +23,6 @@ internal class AnrStacktraceSampler(
private val anrExecutorService: ExecutorService
) : BlockedThreadListener, MemoryCleanerListener {

@VisibleForTesting
internal val anrIntervals = CopyOnWriteArrayList<AnrInterval>()
private val samples = mutableListOf<AnrSample>()
private var lastUnblockedMs: Long = 0
Expand Down Expand Up @@ -90,7 +88,7 @@ internal class AnrStacktraceSampler(
* intervals with samples has been reached & the SDK needs to discard samples. We attempt
* to pick the least valuable interval in this case.
*/
@VisibleForTesting

internal fun findLeastValuableIntervalWithSamples() =
findIntervalsWithSamples().minByOrNull(AnrInterval::duration)

Expand All @@ -101,7 +99,6 @@ internal class AnrStacktraceSampler(
}
}

@VisibleForTesting
internal fun reachedAnrStacktraceCaptureLimit(): Boolean {
val limit = configService.anrBehavior.getMaxAnrIntervalsPerSession()
val count = findIntervalsWithSamples().size
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ internal class EmbraceAnrService(
private val sigquitDetectionService: SigquitDetectionService
private val targetThreadHeartbeatScheduler: LivenessCheckScheduler

@VisibleForTesting
val listeners = CopyOnWriteArrayList<BlockedThreadListener>()

init {
Expand Down Expand Up @@ -151,7 +150,6 @@ internal class EmbraceAnrService(
}
}

@VisibleForTesting
internal fun processAnrTick(timestamp: Long) {
// Check if ANR capture is enabled
if (!configService.anrBehavior.isAnrCaptureEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.embrace.android.embracesdk.anr

import androidx.annotation.VisibleForTesting
import io.embrace.android.embracesdk.config.ConfigService
import io.embrace.android.embracesdk.payload.ThreadInfo
import java.util.regex.Pattern
Expand Down Expand Up @@ -43,7 +42,7 @@ internal class ThreadInfoCollector(
*
* @return filtered threads
*/
@VisibleForTesting

internal fun getAllowedThreads(configService: ConfigService): Set<ThreadInfo> {
val allowed: MutableSet<ThreadInfo> = HashSet()
val anrBehavior = configService.anrBehavior
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package io.embrace.android.embracesdk.anr.detection

import android.app.ActivityManager
import android.os.Process
import androidx.annotation.VisibleForTesting
import io.embrace.android.embracesdk.anr.BlockedThreadListener
import io.embrace.android.embracesdk.config.ConfigService
import io.embrace.android.embracesdk.internal.clock.Clock
Expand Down Expand Up @@ -35,14 +34,12 @@ internal class AnrProcessErrorSampler(

private var intervalMs: Long = configService.anrBehavior.getAnrProcessErrorsIntervalMs()

@VisibleForTesting
var scheduledFuture: ScheduledFuture<*>? = null

@VisibleForTesting
var anrProcessErrors: NavigableMap<Long, AnrProcessErrorStateInfo> = ConcurrentSkipListMap()

// timestamp when the thread has been unblocked
@VisibleForTesting

var threadUnblockedMs: Long? = null

override fun onThreadBlocked(thread: Thread, timestamp: Long) {
Expand Down Expand Up @@ -95,7 +92,7 @@ internal class AnrProcessErrorSampler(
*
* @param threadBlockedTimestamp timestamp of when the thread has been blocked
*/
@VisibleForTesting

internal fun onSearchForProcessErrors(threadBlockedTimestamp: Long) {
val shouldStopScheduler = !isSchedulerAllowedToRun()
if (shouldStopScheduler) {
Expand Down Expand Up @@ -139,7 +136,7 @@ internal class AnrProcessErrorSampler(
* Basically, once the thread has been unblocked, we still have [schedulerExtraTimeAllowance]
* ms for the scheduler to keep running.
*/
@VisibleForTesting

internal fun isSchedulerAllowedToRun(): Boolean {
return when (val ms = threadUnblockedMs) {
null -> true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.embrace.android.embracesdk.anr.detection

import android.os.Debug
import androidx.annotation.VisibleForTesting
import io.embrace.android.embracesdk.anr.BlockedThreadListener
import io.embrace.android.embracesdk.config.ConfigService
import io.embrace.android.embracesdk.internal.clock.Clock
Expand Down Expand Up @@ -105,7 +104,7 @@ internal class BlockedThreadDetector constructor(
* To avoid useless samples grouped within a few ms of each other, this function will return
* false & thus avoid sampling if less than half of the interval MS has passed.
*/
@VisibleForTesting

internal fun shouldAttemptAnrSample(timestamp: Long): Boolean {
val lastMonitorThreadResponseMs = state.lastMonitorThreadResponseMs
val delta = timestamp - lastMonitorThreadResponseMs // time since last check
Expand All @@ -118,7 +117,7 @@ internal class BlockedThreadDetector constructor(
*
* This defaults to the main thread not having processed a message within 1s.
*/
@VisibleForTesting

internal fun isAnrDurationThresholdExceeded(timestamp: Long): Boolean {
enforceThread(anrMonitorThread)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.embrace.android.embracesdk.anr.detection

import android.os.Message
import androidx.annotation.VisibleForTesting
import io.embrace.android.embracesdk.anr.detection.TargetThreadHandler.Companion.HEARTBEAT_REQUEST
import io.embrace.android.embracesdk.config.ConfigService
import io.embrace.android.embracesdk.internal.clock.Clock
Expand Down Expand Up @@ -107,7 +106,7 @@ internal class LivenessCheckScheduler internal constructor(
* Called at regular intervals on the monitor thread. This function posts a message to the
* main thread that is used to check whether it is live or not.
*/
@VisibleForTesting

internal fun onMonitorThreadHeartbeat() {
enforceThread(anrMonitorThread)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.os.Handler
import android.os.Looper
import android.os.Message
import android.os.MessageQueue
import androidx.annotation.VisibleForTesting
import io.embrace.android.embracesdk.config.ConfigService
import io.embrace.android.embracesdk.internal.clock.Clock
import io.embrace.android.embracesdk.internal.enforceThread
Expand Down Expand Up @@ -49,7 +48,6 @@ internal class TargetThreadHandler(
}
}

@VisibleForTesting
internal fun onIdleThread(): Boolean {
onMainThreadUnblocked()
return true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.embrace.android.embracesdk.anr.ndk

import androidx.annotation.VisibleForTesting
import io.embrace.android.embracesdk.config.ConfigService
import io.embrace.android.embracesdk.config.behavior.AnrBehavior
import io.embrace.android.embracesdk.internal.DeviceArchitecture
Expand Down Expand Up @@ -40,22 +39,16 @@ internal class EmbraceNativeThreadSamplerService @JvmOverloads constructor(
fun finishSampling(): List<NativeThreadAnrSample>?
}

@VisibleForTesting
internal var ignored = true

@VisibleForTesting
internal var sampling = false

@VisibleForTesting
internal var count = -1

@VisibleForTesting
internal var factor = -1

@VisibleForTesting
internal var intervals: MutableList<NativeThreadAnrInterval> = mutableListOf()

@VisibleForTesting
internal val currentInterval: NativeThreadAnrInterval?
get() = intervals.lastOrNull()

Expand Down Expand Up @@ -239,7 +232,7 @@ internal class EmbraceNativeThreadSamplerService @JvmOverloads constructor(
* Determines whether or not we should sample the target thread based on the thread stacktrace
* and the ANR config.
*/
@VisibleForTesting

internal fun containsAllowedStackframes(
anrBehavior: AnrBehavior,
stacktrace: Array<StackTraceElement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package io.embrace.android.embracesdk.anr.ndk

import android.os.Handler
import android.os.Looper
import androidx.annotation.VisibleForTesting
import io.embrace.android.embracesdk.anr.AnrService
import io.embrace.android.embracesdk.config.ConfigService
import io.embrace.android.embracesdk.logging.InternalEmbraceLogger
Expand All @@ -24,7 +23,6 @@ internal class NativeThreadSamplerInstaller(
private val isMonitoring = AtomicBoolean(false)
private var targetHandler: Handler? = null

@VisibleForTesting
internal var currentThread: Thread? = null

private fun prepareTargetHandler() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.embrace.android.embracesdk.anr.sigquit

import androidx.annotation.VisibleForTesting
import io.embrace.android.embracesdk.config.ConfigService
import io.embrace.android.embracesdk.internal.SharedObjectLoader
import io.embrace.android.embracesdk.logging.InternalEmbraceLogger
Expand Down Expand Up @@ -56,7 +55,6 @@ internal class SigquitDetectionService(
}
}

@VisibleForTesting
fun setupGoogleAnrHandler() {
logger.logDeveloper("EmbraceAnrService", "Setting up Google ANR Handler")
// TODO: split up the ANR tracking and NDK crash reporter libs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.app.ActivityManager
import android.app.ApplicationExitInfo
import android.os.Build.VERSION_CODES
import androidx.annotation.RequiresApi
import androidx.annotation.VisibleForTesting
import io.embrace.android.embracesdk.capture.metadata.MetadataService
import io.embrace.android.embracesdk.capture.user.UserService
import io.embrace.android.embracesdk.comms.delivery.DeliveryService
Expand Down Expand Up @@ -42,7 +41,6 @@ internal class EmbraceApplicationExitInfoService constructor(
private const val SDK_AEI_SEND_LIMIT = 32
}

@VisibleForTesting
@Volatile
var backgroundExecution: Future<*>? = null

Expand Down Expand Up @@ -146,7 +144,6 @@ internal class EmbraceApplicationExitInfoService constructor(
return unsentAeiObjects
}

@VisibleForTesting
fun buildSessionAppExitInfoData(
appExitInfo: ApplicationExitInfo,
trace: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package io.embrace.android.embracesdk.capture.crumbs
import android.app.Activity
import android.text.TextUtils
import android.util.Pair
import androidx.annotation.VisibleForTesting
import io.embrace.android.embracesdk.config.ConfigService
import io.embrace.android.embracesdk.internal.ApkToolsConfig
import io.embrace.android.embracesdk.internal.CacheableValue
Expand Down Expand Up @@ -60,7 +59,6 @@ internal class EmbraceBreadcrumbService(
private val viewBreadcrumbs = LinkedBlockingDeque<ViewBreadcrumb?>()
private val tapBreadcrumbs = LinkedBlockingDeque<TapBreadcrumb?>()

@VisibleForTesting
val customBreadcrumbs = LinkedBlockingDeque<CustomBreadcrumb?>()
private val rnActionBreadcrumbs = LinkedBlockingDeque<RnActionBreadcrumb?>()
val webViewBreadcrumbs = LinkedBlockingDeque<WebViewBreadcrumb?>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package io.embrace.android.embracesdk.capture.crumbs

import android.app.Activity
import android.os.Bundle
import androidx.annotation.VisibleForTesting
import io.embrace.android.embracesdk.logging.InternalEmbraceLogger
import io.embrace.android.embracesdk.payload.PushNotificationBreadcrumb.NotificationType
import io.embrace.android.embracesdk.session.lifecycle.ActivityLifecycleListener
Expand All @@ -15,7 +14,6 @@ internal class PushNotificationCaptureService(
private val logger: InternalEmbraceLogger
) : ActivityLifecycleListener {

@VisibleForTesting
companion object Utils {

enum class PRIORITY(val priority: Int) {
Expand All @@ -39,15 +37,14 @@ internal class PushNotificationCaptureService(
* this, or adding com.google.firebase:firebase-messaging as a dependency on the sdk and
* add some more complex code.
*/
@VisibleForTesting

fun getMessagePriority(priority: String?) =
when (priority) {
"high" -> PRIORITY.PRIORITY_HIGH.priority
"normal" -> PRIORITY.PRIORITY_NORMAL.priority
else -> PRIORITY.PRIORITY_UNKNOWN.priority
}

@VisibleForTesting
fun extractDeveloperDefinedPayload(bundle: Bundle): Map<String, String> {
val keySet = bundle.keySet() ?: return emptyMap()
return keySet.filter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import android.os.Build
import android.os.Environment
import android.os.StatFs
import android.view.WindowManager
import androidx.annotation.VisibleForTesting
import io.embrace.android.embracesdk.BuildConfig
import io.embrace.android.embracesdk.Embrace.AppFramework
import io.embrace.android.embracesdk.capture.cpu.CpuInfoDelegate
Expand Down Expand Up @@ -227,7 +226,6 @@ internal class EmbraceMetadataService private constructor(
)
}

@VisibleForTesting
fun asyncRetrieveDiskUsage(isAndroid26OrAbove: Boolean) {
metadataRetrieveExecutorService.submit(
Callable<Any?> {
Expand All @@ -251,7 +249,6 @@ internal class EmbraceMetadataService private constructor(
)
}

@VisibleForTesting
fun getReactNativeBundleId(): String? = reactNativeBundleId.value

override fun getDeviceId(): String = deviceId.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.os.Build
import android.os.StrictMode
import android.os.strictmode.Violation
import androidx.annotation.RequiresApi
import androidx.annotation.VisibleForTesting
import io.embrace.android.embracesdk.config.ConfigService
import io.embrace.android.embracesdk.internal.clock.Clock
import io.embrace.android.embracesdk.payload.ExceptionInfo
Expand All @@ -25,7 +24,6 @@ internal class EmbraceStrictModeService(
addStrictModeListener(executorService, StrictMode.OnThreadViolationListener(::addViolation))
}

@VisibleForTesting
internal fun addViolation(violation: Violation) {
if (violations.size < configService.anrBehavior.getStrictModeViolationLimit()) {
val exceptionInfo = ExceptionInfo.ofThrowable(violation)
Expand Down
Loading

0 comments on commit ba8e9b6

Please sign in to comment.