Skip to content

Commit b7a5e0a

Browse files
committed
Spotless
1 parent d8402b6 commit b7a5e0a

8 files changed

Lines changed: 76 additions & 66 deletions

File tree

sentry-android-core/api/sentry-android-core.api

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,16 +167,29 @@ public final class io/sentry/android/core/AppLifecycleIntegration : io/sentry/In
167167
}
168168

169169
public final class io/sentry/android/core/AppState : java/io/Closeable {
170+
public fun addAppStateListener (Lio/sentry/android/core/AppState$AppStateListener;)V
170171
public fun close ()V
171172
public static fun getInstance ()Lio/sentry/android/core/AppState;
173+
public fun getLifecycleObserver ()Lio/sentry/android/core/AppState$LifecycleObserver;
172174
public fun isInBackground ()Ljava/lang/Boolean;
175+
public fun registerLifecycleObserver (Lio/sentry/SentryOptions;)V
176+
public fun removeAppStateListener (Lio/sentry/android/core/AppState$AppStateListener;)V
177+
public fun resetInstance ()V
178+
public fun unregisterLifecycleObserver ()V
173179
}
174180

175181
public abstract interface class io/sentry/android/core/AppState$AppStateListener {
176182
public abstract fun onBackground ()V
177183
public abstract fun onForeground ()V
178184
}
179185

186+
public final class io/sentry/android/core/AppState$LifecycleObserver : androidx/lifecycle/DefaultLifecycleObserver {
187+
public fun <init> (Lio/sentry/android/core/AppState;)V
188+
public fun getListeners ()Ljava/util/List;
189+
public fun onStart (Landroidx/lifecycle/LifecycleOwner;)V
190+
public fun onStop (Landroidx/lifecycle/LifecycleOwner;)V
191+
}
192+
180193
public final class io/sentry/android/core/BuildConfig {
181194
public static final field BUILD_TYPE Ljava/lang/String;
182195
public static final field DEBUG Z

sentry-android-core/src/main/java/io/sentry/android/core/AppState.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.sentry.android.core;
22

3-
import android.util.Log;
43
import androidx.annotation.NonNull;
54
import androidx.lifecycle.DefaultLifecycleObserver;
65
import androidx.lifecycle.LifecycleOwner;

sentry-android-core/src/main/java/io/sentry/android/core/ContextUtils.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import io.sentry.SentryOptions;
2222
import io.sentry.android.core.util.AndroidLazyEvaluator;
2323
import io.sentry.protocol.App;
24-
import io.sentry.util.LazyEvaluator;
2524
import java.io.BufferedReader;
2625
import java.io.File;
2726
import java.io.FileReader;

sentry-android-core/src/main/java/io/sentry/android/core/SystemEventsBreadcrumbsIntegration.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import android.content.Intent;
2626
import android.content.IntentFilter;
2727
import android.os.Bundle;
28-
import android.util.Log;
2928
import io.sentry.Breadcrumb;
3029
import io.sentry.Hint;
3130
import io.sentry.IScopes;
@@ -110,8 +109,7 @@ public void register(final @NotNull IScopes scopes, final @NotNull SentryOptions
110109
}
111110

112111
private void registerReceiver(
113-
final @NotNull IScopes scopes,
114-
final @NotNull SentryAndroidOptions options) {
112+
final @NotNull IScopes scopes, final @NotNull SentryAndroidOptions options) {
115113

116114
if (!options.isEnableSystemEventBreadcrumbs()) {
117115
return;

sentry-android-core/src/main/java/io/sentry/android/core/internal/util/AndroidConnectionStatusProvider.java

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
* details
3636
*/
3737
@ApiStatus.Internal
38-
public final class AndroidConnectionStatusProvider implements IConnectionStatusProvider,
39-
AppState.AppStateListener {
38+
public final class AndroidConnectionStatusProvider
39+
implements IConnectionStatusProvider, AppState.AppStateListener {
4040

4141
private final @NotNull Context context;
4242
private final @NotNull SentryOptions options;
@@ -67,7 +67,7 @@ public final class AndroidConnectionStatusProvider implements IConnectionStatusP
6767
private volatile long lastCacheUpdateTime = 0;
6868
private static final long CACHE_TTL_MS = 2 * 60 * 1000L; // 2 minutes
6969
private final @NotNull AtomicBoolean isConnected = new AtomicBoolean(false);
70-
70+
7171
@SuppressLint("InlinedApi")
7272
public AndroidConnectionStatusProvider(
7373
@NotNull Context context,
@@ -172,7 +172,8 @@ private void ensureNetworkCallbackRegistered() {
172172
public void onAvailable(final @NotNull Network network) {
173173
currentNetwork = network;
174174

175-
// have to only dispatch this on first registration + when the connection got re-established
175+
// have to only dispatch this on first registration + when the connection got
176+
// re-established
176177
// otherwise it would've been dispatched on every foreground
177178
if (!isConnected.getAndSet(true)) {
178179
try (final @NotNull ISentryLifecycleToken ignored = childCallbacksLock.acquire()) {
@@ -452,12 +453,11 @@ private void unregisterNetworkCallback(final boolean clearObservers) {
452453
public void close() {
453454
submitSafe(
454455
() -> {
455-
unregisterNetworkCallback(/* clearObservers = */true);
456+
unregisterNetworkCallback(/* clearObservers= */ true);
456457
try (final @NotNull ISentryLifecycleToken ignored = childCallbacksLock.acquire()) {
457458
childCallbacks.clear();
458459
}
459-
try (final @NotNull ISentryLifecycleToken ignored =
460-
connectivityManagerLock.acquire()) {
460+
try (final @NotNull ISentryLifecycleToken ignored = connectivityManagerLock.acquire()) {
461461
connectivityManager = null;
462462
}
463463
AppState.getInstance().removeAppStateListener(this);
@@ -470,30 +470,32 @@ public void onForeground() {
470470
return;
471471
}
472472

473-
submitSafe(() -> {
474-
// proactively update cache and notify observers on foreground to ensure connectivity state is not stale
475-
updateCache(null);
476-
477-
final @NotNull ConnectionStatus status = getConnectionStatusFromCache();
478-
if (status == ConnectionStatus.DISCONNECTED) {
479-
// onLost is not called retroactively when we registerNetworkCallback (as opposed to onAvailable), so we have to do it manually for the DISCONNECTED case
480-
isConnected.set(false);
481-
try (final @NotNull ISentryLifecycleToken ignored = childCallbacksLock.acquire()) {
482-
for (final @NotNull NetworkCallback cb : childCallbacks) {
483-
//noinspection DataFlowIssue
484-
cb.onLost(null);
473+
submitSafe(
474+
() -> {
475+
// proactively update cache and notify observers on foreground to ensure connectivity
476+
// state is not stale
477+
updateCache(null);
478+
479+
final @NotNull ConnectionStatus status = getConnectionStatusFromCache();
480+
if (status == ConnectionStatus.DISCONNECTED) {
481+
// onLost is not called retroactively when we registerNetworkCallback (as opposed to
482+
// onAvailable), so we have to do it manually for the DISCONNECTED case
483+
isConnected.set(false);
484+
try (final @NotNull ISentryLifecycleToken ignored = childCallbacksLock.acquire()) {
485+
for (final @NotNull NetworkCallback cb : childCallbacks) {
486+
//noinspection DataFlowIssue
487+
cb.onLost(null);
488+
}
489+
}
490+
}
491+
try (final @NotNull ISentryLifecycleToken ignored = lock.acquire()) {
492+
for (final @NotNull IConnectionStatusObserver observer : connectionStatusObservers) {
493+
observer.onConnectionStatusChanged(status);
494+
}
485495
}
486-
}
487-
}
488-
try (final @NotNull ISentryLifecycleToken ignored = lock.acquire()) {
489-
for (final @NotNull IConnectionStatusObserver observer :
490-
connectionStatusObservers) {
491-
observer.onConnectionStatusChanged(status);
492-
}
493-
}
494496

495-
ensureNetworkCallbackRegistered();
496-
});
497+
ensureNetworkCallbackRegistered();
498+
});
497499
}
498500

499501
@Override
@@ -502,10 +504,11 @@ public void onBackground() {
502504
return;
503505
}
504506

505-
submitSafe(() -> {
506-
//noinspection Convert2MethodRef
507-
unregisterNetworkCallback(/* clearObservers = */false);
508-
});
507+
submitSafe(
508+
() -> {
509+
//noinspection Convert2MethodRef
510+
unregisterNetworkCallback(/* clearObservers= */ false);
511+
});
509512
}
510513

511514
/**
@@ -796,7 +799,8 @@ private void submitSafe(@NotNull Runnable r) {
796799
try {
797800
options.getExecutorService().submit(r);
798801
} catch (Throwable e) {
799-
options.getLogger()
802+
options
803+
.getLogger()
800804
.log(SentryLevel.ERROR, "AndroidConnectionStatusProvider submit failed", e);
801805
}
802806
}

sentry-android-core/src/test/java/io/sentry/android/core/SystemEventsBreadcrumbsIntegrationTest.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ class SystemEventsBreadcrumbsIntegrationTest {
7272
AppState.getInstance().resetInstance()
7373
AppState.getInstance().registerLifecycleObserver(fixture.options)
7474
ShadowBuild.reset()
75-
val activityManager = ApplicationProvider.getApplicationContext<Context>().getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager?
75+
val activityManager =
76+
ApplicationProvider.getApplicationContext<Context>()
77+
.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager?
7678
fixture.shadowActivityManager = Shadow.extract(activityManager)
7779
}
7880

@@ -514,7 +516,8 @@ class SystemEventsBreadcrumbsIntegrationTest {
514516

515517
@Test
516518
fun `when integration is registered in background, receiver is registered`() {
517-
val process = RunningAppProcessInfo().apply { this.importance = RunningAppProcessInfo.IMPORTANCE_CACHED }
519+
val process =
520+
RunningAppProcessInfo().apply { this.importance = RunningAppProcessInfo.IMPORTANCE_CACHED }
518521
val processes = mutableListOf(process)
519522
fixture.shadowActivityManager.setProcesses(processes)
520523

sentry-android-core/src/test/java/io/sentry/android/core/internal/util/AndroidConnectionStatusProviderTest.kt

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import io.sentry.android.core.ContextUtils
2525
import io.sentry.android.core.SystemEventsBreadcrumbsIntegration
2626
import io.sentry.test.ImmediateExecutorService
2727
import io.sentry.transport.ICurrentDateProvider
28-
import org.junit.runner.RunWith
2928
import kotlin.test.AfterTest
3029
import kotlin.test.BeforeTest
3130
import kotlin.test.Test
@@ -34,15 +33,14 @@ import kotlin.test.assertFalse
3433
import kotlin.test.assertNotNull
3534
import kotlin.test.assertNull
3635
import kotlin.test.assertTrue
36+
import org.junit.runner.RunWith
3737
import org.mockito.MockedStatic
3838
import org.mockito.Mockito.mockStatic
3939
import org.mockito.kotlin.any
4040
import org.mockito.kotlin.anyOrNull
4141
import org.mockito.kotlin.argumentCaptor
4242
import org.mockito.kotlin.clearInvocations
43-
import org.mockito.kotlin.doAnswer
4443
import org.mockito.kotlin.eq
45-
import org.mockito.kotlin.isNull
4644
import org.mockito.kotlin.mock
4745
import org.mockito.kotlin.mockingDetails
4846
import org.mockito.kotlin.times
@@ -51,7 +49,6 @@ import org.mockito.kotlin.verifyNoInteractions
5149
import org.mockito.kotlin.verifyNoMoreInteractions
5250
import org.mockito.kotlin.whenever
5351
import org.robolectric.annotation.Config
54-
import java.util.concurrent.ExecutorService
5552

5653
@RunWith(AndroidJUnit4::class)
5754
@Config(sdk = [Build.VERSION_CODES.P])
@@ -109,9 +106,11 @@ class AndroidConnectionStatusProviderTest {
109106

110107
// Mock ContextUtils to return foreground importance
111108
contextUtilsStaticMock = mockStatic(ContextUtils::class.java)
112-
contextUtilsStaticMock.`when`<Boolean> { ContextUtils.isForegroundImportance() }
109+
contextUtilsStaticMock
110+
.`when`<Boolean> { ContextUtils.isForegroundImportance() }
113111
.thenReturn(true)
114-
contextUtilsStaticMock.`when`<Context> { ContextUtils.getApplicationContext(any()) }
112+
contextUtilsStaticMock
113+
.`when`<Context> { ContextUtils.getApplicationContext(any()) }
115114
.thenReturn(contextMock)
116115

117116
AppState.getInstance().resetInstance()
@@ -187,13 +186,8 @@ class AndroidConnectionStatusProviderTest {
187186
.thenReturn(PERMISSION_GRANTED)
188187

189188
// Need to mock ContextUtils for the new provider as well
190-
contextUtilsStaticMock.`when`<Context> {
191-
ContextUtils.getApplicationContext(
192-
eq(
193-
nullConnectivityContext
194-
)
195-
)
196-
}
189+
contextUtilsStaticMock
190+
.`when`<Context> { ContextUtils.getApplicationContext(eq(nullConnectivityContext)) }
197191
.thenReturn(nullConnectivityContext)
198192

199193
// Create a new provider with the null connectivity manager
@@ -674,7 +668,7 @@ class AndroidConnectionStatusProviderTest {
674668
contextMock,
675669
logger,
676670
buildInfo,
677-
childCallback
671+
childCallback,
678672
)
679673
connectionStatusProvider.onBackground()
680674

@@ -748,7 +742,8 @@ class AndroidConnectionStatusProviderTest {
748742
// Then change capabilities
749743
newCallback.onCapabilitiesChanged(network, newCaps)
750744

751-
// Verify observer was notified (once for onForeground status update, once for capabilities change)
745+
// Verify observer was notified (once for onForeground status update, once for capabilities
746+
// change)
752747
verify(observer, times(2)).onConnectionStatusChanged(any())
753748
}
754749

sentry-samples/sentry-samples-android/src/main/java/io/sentry/samples/android/DummyService.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ public int onStartCommand(Intent intent, int flags, int startId) {
2727

2828
Notification notification = null;
2929
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
30-
notification = new Notification.Builder(this, CHANNEL_ID)
31-
.setContentTitle("Dummy Service Running")
32-
.setContentText("Used for background broadcast testing.")
33-
.setSmallIcon(android.R.drawable.ic_menu_info_details)
34-
.build();
30+
notification =
31+
new Notification.Builder(this, CHANNEL_ID)
32+
.setContentTitle("Dummy Service Running")
33+
.setContentText("Used for background broadcast testing.")
34+
.setSmallIcon(android.R.drawable.ic_menu_info_details)
35+
.build();
3536
}
3637

3738
if (notification != null) {
@@ -57,11 +58,9 @@ public IBinder onBind(Intent intent) {
5758

5859
private void createNotificationChannel() {
5960
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
60-
NotificationChannel channel = new NotificationChannel(
61-
CHANNEL_ID,
62-
"Dummy Service Channel",
63-
NotificationManager.IMPORTANCE_LOW
64-
);
61+
NotificationChannel channel =
62+
new NotificationChannel(
63+
CHANNEL_ID, "Dummy Service Channel", NotificationManager.IMPORTANCE_LOW);
6564
NotificationManager manager = getSystemService(NotificationManager.class);
6665
manager.createNotificationChannel(channel);
6766
}

0 commit comments

Comments
 (0)