Skip to content

Commit

Permalink
removing the client's own crash detection mechanism
Browse files Browse the repository at this point in the history
979b238c6a64e8ebbde7961cac8478b582e9dc2b
  • Loading branch information
alexklints committed Sep 9, 2024
1 parent 80fd70b commit 469ad7c
Show file tree
Hide file tree
Showing 24 changed files with 89 additions and 603 deletions.
6 changes: 0 additions & 6 deletions .mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -523,10 +523,8 @@
"analytics/src/main/java/io/appmetrica/analytics/impl/crash/CrashToFileWriter.java":"mobile/metrika/android/appmetrica/appmetrica-sdk/analytics/src/main/java/io/appmetrica/analytics/impl/crash/CrashToFileWriter.java",
"analytics/src/main/java/io/appmetrica/analytics/impl/crash/MetaInformation.java":"mobile/metrika/android/appmetrica/appmetrica-sdk/analytics/src/main/java/io/appmetrica/analytics/impl/crash/MetaInformation.java",
"analytics/src/main/java/io/appmetrica/analytics/impl/crash/PluginErrorDetailsConverter.kt":"mobile/metrika/android/appmetrica/appmetrica-sdk/analytics/src/main/java/io/appmetrica/analytics/impl/crash/PluginErrorDetailsConverter.kt",
"analytics/src/main/java/io/appmetrica/analytics/impl/crash/PushCrashProcessorCreator.kt":"mobile/metrika/android/appmetrica/appmetrica-sdk/analytics/src/main/java/io/appmetrica/analytics/impl/crash/PushCrashProcessorCreator.kt",
"analytics/src/main/java/io/appmetrica/analytics/impl/crash/ReadAndReportRunnable.java":"mobile/metrika/android/appmetrica/appmetrica-sdk/analytics/src/main/java/io/appmetrica/analytics/impl/crash/ReadAndReportRunnable.java",
"analytics/src/main/java/io/appmetrica/analytics/impl/crash/ReadOldCrashesRunnable.java":"mobile/metrika/android/appmetrica/appmetrica-sdk/analytics/src/main/java/io/appmetrica/analytics/impl/crash/ReadOldCrashesRunnable.java",
"analytics/src/main/java/io/appmetrica/analytics/impl/crash/SdkCrashProcessorCreator.kt":"mobile/metrika/android/appmetrica/appmetrica-sdk/analytics/src/main/java/io/appmetrica/analytics/impl/crash/SdkCrashProcessorCreator.kt",
"analytics/src/main/java/io/appmetrica/analytics/impl/crash/TechnicalCrashProcessorCreator.kt":"mobile/metrika/android/appmetrica/appmetrica-sdk/analytics/src/main/java/io/appmetrica/analytics/impl/crash/TechnicalCrashProcessorCreator.kt",
"analytics/src/main/java/io/appmetrica/analytics/impl/crash/UnhandledExceptionEventFormer.java":"mobile/metrika/android/appmetrica/appmetrica-sdk/analytics/src/main/java/io/appmetrica/analytics/impl/crash/UnhandledExceptionEventFormer.java",
"analytics/src/main/java/io/appmetrica/analytics/impl/crash/jvm/CrashDirectoryWatcher.java":"mobile/metrika/android/appmetrica/appmetrica-sdk/analytics/src/main/java/io/appmetrica/analytics/impl/crash/jvm/CrashDirectoryWatcher.java",
Expand All @@ -541,7 +539,6 @@
"analytics/src/main/java/io/appmetrica/analytics/impl/crash/jvm/client/CustomError.java":"mobile/metrika/android/appmetrica/appmetrica-sdk/analytics/src/main/java/io/appmetrica/analytics/impl/crash/jvm/client/CustomError.java",
"analytics/src/main/java/io/appmetrica/analytics/impl/crash/jvm/client/ICrashProcessor.java":"mobile/metrika/android/appmetrica/appmetrica-sdk/analytics/src/main/java/io/appmetrica/analytics/impl/crash/jvm/client/ICrashProcessor.java",
"analytics/src/main/java/io/appmetrica/analytics/impl/crash/jvm/client/JvmCrashClientController.kt":"mobile/metrika/android/appmetrica/appmetrica-sdk/analytics/src/main/java/io/appmetrica/analytics/impl/crash/jvm/client/JvmCrashClientController.kt",
"analytics/src/main/java/io/appmetrica/analytics/impl/crash/jvm/client/LibraryAnrDetector.java":"mobile/metrika/android/appmetrica/appmetrica-sdk/analytics/src/main/java/io/appmetrica/analytics/impl/crash/jvm/client/LibraryAnrDetector.java",
"analytics/src/main/java/io/appmetrica/analytics/impl/crash/jvm/client/LibraryAnrListener.kt":"mobile/metrika/android/appmetrica/appmetrica-sdk/analytics/src/main/java/io/appmetrica/analytics/impl/crash/jvm/client/LibraryAnrListener.kt",
"analytics/src/main/java/io/appmetrica/analytics/impl/crash/jvm/client/MainReporterAnrController.kt":"mobile/metrika/android/appmetrica/appmetrica-sdk/analytics/src/main/java/io/appmetrica/analytics/impl/crash/jvm/client/MainReporterAnrController.kt",
"analytics/src/main/java/io/appmetrica/analytics/impl/crash/jvm/client/RegularError.java":"mobile/metrika/android/appmetrica/appmetrica-sdk/analytics/src/main/java/io/appmetrica/analytics/impl/crash/jvm/client/RegularError.java",
Expand Down Expand Up @@ -1489,10 +1486,8 @@
"analytics/src/test/java/io/appmetrica/analytics/impl/crash/CrashToFileWriterTest.java":"mobile/metrika/android/appmetrica/appmetrica-sdk/analytics/src/test/java/io/appmetrica/analytics/impl/crash/CrashToFileWriterTest.java",
"analytics/src/test/java/io/appmetrica/analytics/impl/crash/MetaInformationTest.java":"mobile/metrika/android/appmetrica/appmetrica-sdk/analytics/src/test/java/io/appmetrica/analytics/impl/crash/MetaInformationTest.java",
"analytics/src/test/java/io/appmetrica/analytics/impl/crash/PluginErrorDetailsConverterTest.kt":"mobile/metrika/android/appmetrica/appmetrica-sdk/analytics/src/test/java/io/appmetrica/analytics/impl/crash/PluginErrorDetailsConverterTest.kt",
"analytics/src/test/java/io/appmetrica/analytics/impl/crash/PushCrashProcessorCreatorTest.kt":"mobile/metrika/android/appmetrica/appmetrica-sdk/analytics/src/test/java/io/appmetrica/analytics/impl/crash/PushCrashProcessorCreatorTest.kt",
"analytics/src/test/java/io/appmetrica/analytics/impl/crash/ReadAndReportRunnableTest.java":"mobile/metrika/android/appmetrica/appmetrica-sdk/analytics/src/test/java/io/appmetrica/analytics/impl/crash/ReadAndReportRunnableTest.java",
"analytics/src/test/java/io/appmetrica/analytics/impl/crash/ReadOldCrashesRunnableTest.java":"mobile/metrika/android/appmetrica/appmetrica-sdk/analytics/src/test/java/io/appmetrica/analytics/impl/crash/ReadOldCrashesRunnableTest.java",
"analytics/src/test/java/io/appmetrica/analytics/impl/crash/SdkCrashProcessorCreatorTest.kt":"mobile/metrika/android/appmetrica/appmetrica-sdk/analytics/src/test/java/io/appmetrica/analytics/impl/crash/SdkCrashProcessorCreatorTest.kt",
"analytics/src/test/java/io/appmetrica/analytics/impl/crash/TechnicalCrashProcessorFactoryTest.kt":"mobile/metrika/android/appmetrica/appmetrica-sdk/analytics/src/test/java/io/appmetrica/analytics/impl/crash/TechnicalCrashProcessorFactoryTest.kt",
"analytics/src/test/java/io/appmetrica/analytics/impl/crash/UnhandledExceptionEventFormerTest.java":"mobile/metrika/android/appmetrica/appmetrica-sdk/analytics/src/test/java/io/appmetrica/analytics/impl/crash/UnhandledExceptionEventFormerTest.java",
"analytics/src/test/java/io/appmetrica/analytics/impl/crash/jvm/CrashDirectoryWatcherTest.java":"mobile/metrika/android/appmetrica/appmetrica-sdk/analytics/src/test/java/io/appmetrica/analytics/impl/crash/jvm/CrashDirectoryWatcherTest.java",
Expand All @@ -1505,7 +1500,6 @@
"analytics/src/test/java/io/appmetrica/analytics/impl/crash/jvm/client/CrashProcessorCompositeTest.kt":"mobile/metrika/android/appmetrica/appmetrica-sdk/analytics/src/test/java/io/appmetrica/analytics/impl/crash/jvm/client/CrashProcessorCompositeTest.kt",
"analytics/src/test/java/io/appmetrica/analytics/impl/crash/jvm/client/CustomErrorTest.java":"mobile/metrika/android/appmetrica/appmetrica-sdk/analytics/src/test/java/io/appmetrica/analytics/impl/crash/jvm/client/CustomErrorTest.java",
"analytics/src/test/java/io/appmetrica/analytics/impl/crash/jvm/client/JvmCrashClientControllerTest.kt":"mobile/metrika/android/appmetrica/appmetrica-sdk/analytics/src/test/java/io/appmetrica/analytics/impl/crash/jvm/client/JvmCrashClientControllerTest.kt",
"analytics/src/test/java/io/appmetrica/analytics/impl/crash/jvm/client/LibraryAnrDetectorTest.java":"mobile/metrika/android/appmetrica/appmetrica-sdk/analytics/src/test/java/io/appmetrica/analytics/impl/crash/jvm/client/LibraryAnrDetectorTest.java",
"analytics/src/test/java/io/appmetrica/analytics/impl/crash/jvm/client/LibraryAnrListenerTest.kt":"mobile/metrika/android/appmetrica/appmetrica-sdk/analytics/src/test/java/io/appmetrica/analytics/impl/crash/jvm/client/LibraryAnrListenerTest.kt",
"analytics/src/test/java/io/appmetrica/analytics/impl/crash/jvm/client/MainReporterAnrControllerTest.kt":"mobile/metrika/android/appmetrica/appmetrica-sdk/analytics/src/test/java/io/appmetrica/analytics/impl/crash/jvm/client/MainReporterAnrControllerTest.kt",
"analytics/src/test/java/io/appmetrica/analytics/impl/crash/jvm/client/RegularErrorTest.java":"mobile/metrika/android/appmetrica/appmetrica-sdk/analytics/src/test/java/io/appmetrica/analytics/impl/crash/jvm/client/RegularErrorTest.java",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class AppMetricaFacade implements IReporterFactoryProvider {
@AnyThread
public AppMetricaFacade(@NonNull final Context context) {
mContext = context;
coreComponentsProvider = new AppMetricaCoreComponentsProvider();
coreComponentsProvider = ClientServiceLocator.getInstance().getAppMetricaCoreComponentsProvider();
mCore = coreComponentsProvider.getCore(
context,
ClientServiceLocator.getInstance().getClientExecutorProvider()
Expand Down Expand Up @@ -272,12 +272,12 @@ boolean isFullyInitialized() {
}

@VisibleForTesting(otherwise = VisibleForTesting.NONE)
public static void setInstance(@Nullable AppMetricaFacade instance) {
public static synchronized void setInstance(@Nullable AppMetricaFacade instance) {
sInstance = instance;
}

@VisibleForTesting(otherwise = VisibleForTesting.NONE)
public static void killInstance() {
public static synchronized void killInstance() {
sInstance = null;
sActivated = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.content.Context
import io.appmetrica.analytics.AppMetricaConfig
import io.appmetrica.analytics.impl.client.ProcessConfiguration
import io.appmetrica.analytics.impl.crash.PluginErrorDetailsConverter
import io.appmetrica.analytics.impl.crash.jvm.client.LibraryAnrDetector
import io.appmetrica.analytics.impl.crash.jvm.converter.AnrConverter
import io.appmetrica.analytics.impl.crash.jvm.converter.CustomErrorConverter
import io.appmetrica.analytics.impl.crash.jvm.converter.RegularErrorConverter
Expand All @@ -24,16 +23,6 @@ internal class MainReporterComponents(
val startupHelper: StartupHelper
) {

val selfSdkCrashReporterProvider = UnhandledSituationReporterProvider(
reporterFactoryProvider,
SdkData.SDK_API_KEY_UUID
)

val pushSdkCrashReporterProvider = UnhandledSituationReporterProvider(
reporterFactoryProvider,
SdkData.SDK_API_KEY_PUSH_SDK
)

val nativeCrashClient = NativeCrashClient(processConfiguration)

val extraMetaInfoRetriever = ExtraMetaInfoRetriever(context)
Expand All @@ -45,8 +34,6 @@ internal class MainReporterComponents(

val appStatusMonitor = AppStatusMonitor()

val libraryAnrDetector = LibraryAnrDetector()

val processDetector = ClientServiceLocator.getInstance().processDetector

val activityStateManager = ActivityStateManager()
Expand Down
19 changes: 0 additions & 19 deletions analytics/src/main/java/io/appmetrica/analytics/impl/SdkUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,16 @@

import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import io.appmetrica.analytics.AppMetrica;
import io.appmetrica.analytics.BuildConfig;
import io.appmetrica.analytics.coreutils.internal.StringUtils;
import io.appmetrica.analytics.logger.appmetrica.internal.ImportantLogger;
import java.util.regex.Pattern;

public class SdkUtils {

public static final String APPMETRICA_TAG = "AppMetrica";
public static final String APPMETRICA_ATTRIBUTION_TAG = "AppMetrica-Attribution";

private static final Pattern PUSH_PATTERN = Pattern.compile(".*at io\\.appmetrica\\.analytics\\.push\\.*");
private static final Pattern APPMETRICA_NOT_PUSH = Pattern.compile(".*at io\\.appmetrica\\.analytics\\.(?!push)");

// Logs sdk info.
static void logSdkInfo() {
final String logInfo = "Initializing of AppMetrica" +
Expand Down Expand Up @@ -45,20 +40,6 @@ public static void logStubUsage() {
);
}

public static boolean isExceptionFromMetrica(@Nullable Throwable exception) {
String stackTrace = Utils.getStackTrace(exception);

return !TextUtils.isEmpty(stackTrace)
&& APPMETRICA_NOT_PUSH.matcher(stackTrace).find();
}

public static boolean isExceptionFromPushSdk(@Nullable Throwable exception) {
String stackTrace = Utils.getStackTrace(exception);

return !TextUtils.isEmpty(stackTrace)
&& PUSH_PATTERN.matcher(stackTrace).find();
}

@NonNull
public static String formSdkBuildType() {
StringBuilder builder = new StringBuilder();
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ package io.appmetrica.analytics.impl.crash.jvm.client

import io.appmetrica.analytics.impl.ClientServiceLocator
import io.appmetrica.analytics.impl.IUnhandledSituationReporter
import io.appmetrica.analytics.impl.MainReporterComponents
import io.appmetrica.analytics.impl.crash.utils.ThreadsStateDumper
import io.appmetrica.analytics.logger.appmetrica.internal.DebugLogger

internal class LibraryAnrListener(
private val mainReporterComponents: MainReporterComponents,
private val mainReporterConsumer: IUnhandledSituationReporter
) : ANRMonitor.Listener {

Expand All @@ -17,15 +15,8 @@ internal class LibraryAnrListener(

override fun onAppNotResponding() {
val allThreads = threadsStateDumper.threadsDumpForAnr
val stacktrace = allThreads.affectedThread?.stacktrace ?: emptyList()
ClientServiceLocator.getInstance().clientExecutorProvider.defaultExecutor.execute {
mainReporterConsumer.reportAnr(allThreads)
if (mainReporterComponents.libraryAnrDetector.isAppmetricaAnr(stacktrace)) {
mainReporterComponents.selfSdkCrashReporterProvider.reporter.reportAnr(allThreads)
}
if (mainReporterComponents.libraryAnrDetector.isPushAnr(stacktrace)) {
mainReporterComponents.pushSdkCrashReporterProvider.reporter.reportAnr(allThreads)
}
DebugLogger.info(tag, "Detected ANR: $allThreads")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal class MainReporterAnrController(

private var anrMonitoringTimeout: Int = DefaultValues.DEFAULT_ANR_TICKS_COUNT

private val listener = LibraryAnrListener(mainReporterComponents, mainReporterConsumer)
private val listener = LibraryAnrListener(mainReporterConsumer)
private val anrMonitor = ANRMonitor(listener)

@Synchronized
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@ package io.appmetrica.analytics.impl.crash.jvm.client

import android.content.Context
import io.appmetrica.analytics.impl.IReporterFactoryProvider
import io.appmetrica.analytics.impl.crash.PushCrashProcessorCreator
import io.appmetrica.analytics.impl.crash.SdkCrashProcessorCreator
import io.appmetrica.analytics.impl.crash.TechnicalCrashProcessorCreator

internal class TechnicalCrashProcessorFactory {

private val crashProcessorCreators: MutableList<TechnicalCrashProcessorCreator> = mutableListOf(
SdkCrashProcessorCreator(),
PushCrashProcessorCreator(),
)
private val crashProcessorCreators: MutableList<TechnicalCrashProcessorCreator> = mutableListOf()

fun createCrashProcessors(
context: Context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.MockedConstruction;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
Expand Down Expand Up @@ -58,30 +57,20 @@ public class AppMetricaFacadeObjectTest extends CommonTest {
public final MockedConstructionRule<ClientMigrationManager> clientMigrationManagerMockedConstructionRule =
new MockedConstructionRule<>(ClientMigrationManager.class);

@Rule
public final MockedConstructionRule<AppMetricaCoreComponentsProvider> coreComponentsProviderConstructionRule =
new MockedConstructionRule<>(
AppMetricaCoreComponentsProvider.class,
new MockedConstruction.MockInitializer<AppMetricaCoreComponentsProvider>() {
@Override
public void prepare(AppMetricaCoreComponentsProvider mock,
MockedConstruction.Context context) throws Throwable {
when(mock.getImpl(mContext, mCore)).thenReturn(mImpl);
when(mock.getCore(mContext, clientExecutorProvider)).thenReturn(mCore);
}
}
);
private AppMetricaCoreComponentsProvider coreComponentsProvider;

@Before
public void setUp() throws Exception {
MockitoAnnotations.openMocks(this);
mContext = RuntimeEnvironment.getApplication();
when(ClientServiceLocator.getInstance().getAppMetricaCoreComponentsProvider().getCore(
mContext, clientExecutorProvider
)).thenReturn(mCore);
when(ClientServiceLocator.getInstance().getAppMetricaCoreComponentsProvider().getImpl(
mContext, mCore
)).thenReturn(mImpl);
when(ClientServiceLocator.getInstance().getClientExecutorProvider()).thenReturn(clientExecutorProvider);
when(clientExecutorProvider.getDefaultExecutor()).thenReturn(executor);
AppMetricaFacade.killInstance();
mFacade = new AppMetricaFacade(mContext);
coreComponentsProvider = coreComponentsProviderConstructionRule.getConstructionMock().constructed().get(0);
}

@Test
Expand Down
Loading

0 comments on commit 469ad7c

Please sign in to comment.