Skip to content

Commit

Permalink
Ref: Remove not needed interface abstractions on Android (#1953)
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto authored Mar 19, 2022
1 parent de7466e commit f710288
Show file tree
Hide file tree
Showing 20 changed files with 40 additions and 81 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

* Ref: Remove not needed interface abstractions on Android (#1953)

## 6.0.0-alpha.3

* Ref: Make hints Map<String, Object> instead of only Object (#1929)
Expand Down
9 changes: 2 additions & 7 deletions sentry-android-core/api/sentry-android-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public final class io/sentry/android/core/ActivityFramesTracker {
}

public final class io/sentry/android/core/ActivityLifecycleIntegration : android/app/Application$ActivityLifecycleCallbacks, io/sentry/Integration, java/io/Closeable {
public fun <init> (Landroid/app/Application;Lio/sentry/android/core/IBuildInfoProvider;Lio/sentry/android/core/ActivityFramesTracker;)V
public fun <init> (Landroid/app/Application;Lio/sentry/android/core/BuildInfoProvider;Lio/sentry/android/core/ActivityFramesTracker;)V
public fun close ()V
public fun onActivityCreated (Landroid/app/Activity;Landroid/os/Bundle;)V
public fun onActivityDestroyed (Landroid/app/Activity;)V
Expand Down Expand Up @@ -57,7 +57,7 @@ public final class io/sentry/android/core/BuildConfig {
public fun <init> ()V
}

public final class io/sentry/android/core/BuildInfoProvider : io/sentry/android/core/IBuildInfoProvider {
public final class io/sentry/android/core/BuildInfoProvider {
public fun <init> ()V
public fun getBuildTags ()Ljava/lang/String;
public fun getSdkInfoVersion ()I
Expand All @@ -70,11 +70,6 @@ public abstract class io/sentry/android/core/EnvelopeFileObserverIntegration : i
public final fun register (Lio/sentry/IHub;Lio/sentry/SentryOptions;)V
}

public abstract interface class io/sentry/android/core/IBuildInfoProvider {
public abstract fun getBuildTags ()Ljava/lang/String;
public abstract fun getSdkInfoVersion ()I
}

public abstract interface class io/sentry/android/core/IDebugImagesLoader {
public abstract fun clearDebugImages ()V
public abstract fun loadDebugImages ()Ljava/util/List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class ANRWatchDog extends Thread {

private final boolean reportInDebug;
private final ANRListener anrListener;
private final IHandler uiHandler;
private final MainLooperHandler uiHandler;
private final long timeoutIntervalMillis;
private final @NotNull ILogger logger;
private final AtomicLong tick = new AtomicLong(0);
Expand Down Expand Up @@ -51,7 +51,7 @@ final class ANRWatchDog extends Thread {
boolean reportInDebug,
@NotNull ANRListener listener,
@NotNull ILogger logger,
@NotNull IHandler uiHandler,
@NotNull MainLooperHandler uiHandler,
final @NotNull Context context) {
super();
this.reportInDebug = reportInDebug;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public final class ActivityLifecycleIntegration

public ActivityLifecycleIntegration(
final @NotNull Application application,
final @NotNull IBuildInfoProvider buildInfoProvider,
final @NotNull BuildInfoProvider buildInfoProvider,
final @NotNull ActivityFramesTracker activityFramesTracker) {
this.application = Objects.requireNonNull(application, "Application is required");
Objects.requireNonNull(buildInfoProvider, "BuildInfoProvider is required");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static void init(
final @NotNull SentryAndroidOptions options,
@NotNull Context context,
final @NotNull ILogger logger,
final @NotNull IBuildInfoProvider buildInfoProvider) {
final @NotNull BuildInfoProvider buildInfoProvider) {
init(options, context, logger, buildInfoProvider, new LoadClass());
}

Expand All @@ -89,7 +89,7 @@ static void init(
final @NotNull SentryAndroidOptions options,
@NotNull Context context,
final @NotNull ILogger logger,
final @NotNull IBuildInfoProvider buildInfoProvider,
final @NotNull BuildInfoProvider buildInfoProvider,
final @NotNull LoadClass loadClass) {
Objects.requireNonNull(context, "The context is required.");

Expand Down Expand Up @@ -122,7 +122,7 @@ static void init(
private static void installDefaultIntegrations(
final @NotNull Context context,
final @NotNull SentryOptions options,
final @NotNull IBuildInfoProvider buildInfoProvider,
final @NotNull BuildInfoProvider buildInfoProvider,
final @NotNull LoadClass loadClass,
final @NotNull ActivityFramesTracker activityFramesTracker) {

Expand Down Expand Up @@ -254,13 +254,13 @@ private static void initializeCacheDirs(
options.setCacheDirPath(cacheDir.getAbsolutePath());
}

private static boolean isNdkAvailable(final @NotNull IBuildInfoProvider buildInfoProvider) {
private static boolean isNdkAvailable(final @NotNull BuildInfoProvider buildInfoProvider) {
return buildInfoProvider.getSdkInfoVersion() >= Build.VERSION_CODES.JELLY_BEAN;
}

private static @Nullable Class<?> loadNdkIfAvailable(
final @NotNull SentryOptions options,
final @NotNull IBuildInfoProvider buildInfoProvider,
final @NotNull BuildInfoProvider buildInfoProvider,
final @NotNull LoadClass loadClass) {
if (isNdkAvailable(buildInfoProvider)) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ public final class AppLifecycleIntegration implements Integration, Closeable {

private @Nullable SentryAndroidOptions options;

private final @NotNull IHandler handler;
private final @NotNull MainLooperHandler handler;

public AppLifecycleIntegration() {
this(new MainLooperHandler());
}

AppLifecycleIntegration(final @NotNull IHandler handler) {
AppLifecycleIntegration(final @NotNull MainLooperHandler handler) {
this.handler = handler;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,17 @@

/** The Android Impl. of IBuildInfoProvider which returns the Build class info. */
@ApiStatus.Internal
public final class BuildInfoProvider implements IBuildInfoProvider {
public final class BuildInfoProvider {

/**
* Returns the Build.VERSION.SDK_INT
*
* @return the Build.VERSION.SDK_INT
*/
@Override
public int getSdkInfoVersion() {
return Build.VERSION.SDK_INT;
}

@Override
public @Nullable String getBuildTags() {
return Build.TAGS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,22 @@ final class DefaultAndroidEventProcessor implements EventProcessor {

@TestOnly final Future<Map<String, Object>> contextData;

private final @NotNull IBuildInfoProvider buildInfoProvider;
private final @NotNull BuildInfoProvider buildInfoProvider;
private final @NotNull RootChecker rootChecker;

private final @NotNull ILogger logger;

public DefaultAndroidEventProcessor(
final @NotNull Context context,
final @NotNull ILogger logger,
final @NotNull IBuildInfoProvider buildInfoProvider) {
final @NotNull BuildInfoProvider buildInfoProvider) {
this(context, logger, buildInfoProvider, new RootChecker(context, buildInfoProvider, logger));
}

DefaultAndroidEventProcessor(
final @NotNull Context context,
final @NotNull ILogger logger,
final @NotNull IBuildInfoProvider buildInfoProvider,
final @NotNull BuildInfoProvider buildInfoProvider,
final @NotNull RootChecker rootChecker) {
this.context = Objects.requireNonNull(context, "The application context is required.");
this.logger = Objects.requireNonNull(logger, "The Logger is required.");
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import android.os.Looper;
import org.jetbrains.annotations.NotNull;

final class MainLooperHandler implements IHandler {
final class MainLooperHandler {
private final @NotNull Handler handler;

MainLooperHandler() {
Expand All @@ -15,12 +15,10 @@ final class MainLooperHandler implements IHandler {
handler = new Handler(looper);
}

@Override
public void post(final @NotNull Runnable runnable) {
handler.post(runnable);
}

@Override
public @NotNull Thread getThread() {
return handler.getLooper().getThread();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import android.os.Build;
import io.sentry.ILogger;
import io.sentry.SentryLevel;
import io.sentry.android.core.IBuildInfoProvider;
import io.sentry.android.core.BuildInfoProvider;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -83,7 +83,7 @@ private ConnectivityChecker() {}
public static @Nullable String getConnectionType(
final @NotNull Context context,
final @NotNull ILogger logger,
final @NotNull IBuildInfoProvider buildInfoProvider) {
final @NotNull BuildInfoProvider buildInfoProvider) {
final ConnectivityManager connectivityManager = getConnectivityManager(context, logger);
if (connectivityManager == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import android.content.pm.PackageManager;
import io.sentry.ILogger;
import io.sentry.SentryLevel;
import io.sentry.android.core.IBuildInfoProvider;
import io.sentry.android.core.BuildInfoProvider;
import io.sentry.util.Objects;
import java.io.BufferedReader;
import java.io.File;
Expand All @@ -22,7 +22,7 @@ public final class RootChecker {
private static final Charset UTF_8 = Charset.forName("UTF-8");

private final @NotNull Context context;
private final @NotNull IBuildInfoProvider buildInfoProvider;
private final @NotNull BuildInfoProvider buildInfoProvider;
private final @NotNull ILogger logger;

private final @NotNull String[] rootFiles;
Expand All @@ -33,7 +33,7 @@ public final class RootChecker {

public RootChecker(
final @NotNull Context context,
final @NotNull IBuildInfoProvider buildInfoProvider,
final @NotNull BuildInfoProvider buildInfoProvider,
final @NotNull ILogger logger) {
this(
context,
Expand Down Expand Up @@ -66,7 +66,7 @@ public RootChecker(

RootChecker(
final @NotNull Context context,
final @NotNull IBuildInfoProvider buildInfoProvider,
final @NotNull BuildInfoProvider buildInfoProvider,
final @NotNull ILogger logger,
final @NotNull String[] rootFiles,
final @NotNull String[] rootPackages,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ANRWatchDogTest {
@Test
fun `when ANR is detected, callback is invoked with threads stacktrace`() {
var anr: ApplicationNotResponding? = null
val handler = mock<IHandler>()
val handler = mock<MainLooperHandler>()
val thread = mock<Thread>()
val expectedState = Thread.State.BLOCKED
val stacktrace = StackTraceElement("class", "method", "fileName", 10)
Expand Down Expand Up @@ -54,7 +54,7 @@ class ANRWatchDogTest {
@Test
fun `when ANR is not detected, callback is not invoked`() {
var anr: ApplicationNotResponding? = null
val handler = mock<IHandler>()
val handler = mock<MainLooperHandler>()
val thread = mock<Thread>()
var invoked = false
whenever(handler.post(any())).then { i ->
Expand Down Expand Up @@ -84,7 +84,7 @@ class ANRWatchDogTest {
@Test
fun `when ANR is detected and ActivityManager has ANR process, callback is invoked`() {
var anr: ApplicationNotResponding? = null
val handler = mock<IHandler>()
val handler = mock<MainLooperHandler>()
val thread = mock<Thread>()
val expectedState = Thread.State.BLOCKED
val stacktrace = StackTraceElement("class", "method", "fileName", 10)
Expand Down Expand Up @@ -125,7 +125,7 @@ class ANRWatchDogTest {
@Test
fun `when ANR is detected and ActivityManager has no ANR process, callback is not invoked`() {
var anr: ApplicationNotResponding? = null
val handler = mock<IHandler>()
val handler = mock<MainLooperHandler>()
val thread = mock<Thread>()
val expectedState = Thread.State.BLOCKED
val stacktrace = StackTraceElement("class", "method", "fileName", 10)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ActivityLifecycleIntegrationTest {
val activityFramesTracker = mock<ActivityFramesTracker>()
val transactionFinishedCallback = mock<TransactionFinishedCallback>()
val transaction = SentryTracer(context, hub, true, transactionFinishedCallback)
val buildInfo = mock<IBuildInfoProvider>()
val buildInfo = mock<BuildInfoProvider>()

fun getSut(apiVersion: Int = 29, importance: Int = RunningAppProcessInfo.IMPORTANCE_FOREGROUND): ActivityLifecycleIntegration {
whenever(hub.options).thenReturn(options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,8 @@ class AndroidOptionsInitializerTest {
}
}

private fun createBuildInfo(minApi: Int = 16): IBuildInfoProvider {
val buildInfo = mock<IBuildInfoProvider>()
private fun createBuildInfo(minApi: Int = 16): BuildInfoProvider {
val buildInfo = mock<BuildInfoProvider>()
whenever(buildInfo.sdkInfoVersion).thenReturn(minApi)
return buildInfo
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AppLifecycleIntegrationTest {

private class Fixture {
val hub = mock<IHub>()
val handler = mock<IHandler>()
val handler = mock<MainLooperHandler>()
val options = SentryAndroidOptions()

fun getSut(): AppLifecycleIntegration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ConnectivityCheckerTest {
private lateinit var contextMock: Context
private lateinit var connectivityManager: ConnectivityManager
private lateinit var networkInfo: NetworkInfo
private lateinit var buildInfo: IBuildInfoProvider
private lateinit var buildInfo: BuildInfoProvider
private lateinit var network: Network
private lateinit var networkCapabilities: NetworkCapabilities

Expand Down Expand Up @@ -100,7 +100,7 @@ class ConnectivityCheckerTest {

@Test
fun `When sdkInfoVersion is not min Marshmallow, return null for getConnectionType`() {
val buildInfo = mock<IBuildInfoProvider>()
val buildInfo = mock<BuildInfoProvider>()
whenever(buildInfo.sdkInfoVersion).thenReturn(Build.VERSION_CODES.ICE_CREAM_SANDWICH)

assertNull(ConnectivityChecker.getConnectionType(mock(), mock(), buildInfo))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ class DefaultAndroidEventProcessorTest {
private lateinit var context: Context

private val className = "io.sentry.android.core.DefaultAndroidEventProcessor"
private val ctorTypes = arrayOf(Context::class.java, ILogger::class.java, IBuildInfoProvider::class.java)
private val ctorTypes = arrayOf(Context::class.java, ILogger::class.java, BuildInfoProvider::class.java)

init {
Locale.setDefault(Locale.US)
}

private class Fixture {
val buildInfo = mock<IBuildInfoProvider>()
val buildInfo = mock<BuildInfoProvider>()
val options = SentryOptions().apply {
setDebug(true)
setLogger(mock())
Expand Down Expand Up @@ -98,7 +98,7 @@ class DefaultAndroidEventProcessorTest {
fun `when null buildInfo is provided, invalid argument is thrown`() {
val ctor = className.getCtor(ctorTypes)

val params = arrayOf(null, null, mock<IBuildInfoProvider>())
val params = arrayOf(null, null, mock<BuildInfoProvider>())
assertFailsWith<IllegalArgumentException> { ctor.newInstance(params) }
}

Expand Down
Loading

0 comments on commit f710288

Please sign in to comment.