Skip to content

Commit eb9622a

Browse files
authored
Bump Android API to 31 (#1775)
1 parent f9e7ace commit eb9622a

File tree

23 files changed

+58
-68
lines changed

23 files changed

+58
-68
lines changed

buildSrc/src/main/java/Config.kt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ object Config {
2323
}
2424

2525
object Android {
26-
private val sdkVersion = 30
26+
private val sdkVersion = 31
2727

2828
val minSdkVersion = 14
2929
val minSdkVersionOkHttp = 21
@@ -39,12 +39,15 @@ object Config {
3939
}
4040

4141
object Libs {
42+
val okHttpVersion = "4.9.2"
4243
val appCompat = "androidx.appcompat:appcompat:1.2.0"
4344
val timber = "com.jakewharton.timber:timber:4.7.1"
44-
val okhttpBom = "com.squareup.okhttp3:okhttp-bom:4.9.0"
45+
val okhttpBom = "com.squareup.okhttp3:okhttp-bom:$okHttpVersion"
4546
val okhttp = "com.squareup.okhttp3:okhttp"
4647
// only bump gson if https://github.com/google/gson/issues/1597 is fixed
47-
val gson = "com.google.code.gson:gson:2.8.5"
48+
private val gsonVersion = "2.8.5"
49+
val gsonDep = "com.google.code.gson:gson"
50+
val gson = "$gsonDep:$gsonVersion"
4851
val leakCanary = "com.squareup.leakcanary:leakcanary-android:2.7"
4952

5053
private val lifecycleVersion = "2.2.0"
@@ -103,22 +106,20 @@ object Config {
103106
}
104107

105108
object TestLibs {
106-
private val androidxTestVersion = "1.3.0"
109+
private val androidxTestVersion = "1.4.0-rc01"
107110

108111
val kotlinTestJunit = "org.jetbrains.kotlin:kotlin-test-junit:$kotlinVersion"
109112
val androidxCore = "androidx.test:core:$androidxTestVersion"
110113
val androidxRunner = "androidx.test:runner:$androidxTestVersion"
111-
val androidxJunit = "androidx.test.ext:junit:1.1.2"
112-
val androidxCoreKtx = "androidx.core:core-ktx:1.3.2"
113-
// bump to 4.6.1 breaks a few tests due to ShadowFileObserver
114-
val robolectric = "org.robolectric:robolectric:4.5.1"
114+
val androidxJunit = "androidx.test.ext:junit:1.1.3-rc01"
115+
val androidxCoreKtx = "androidx.core:core-ktx:1.7.0-rc01"
116+
val robolectric = "org.robolectric:robolectric:4.6.1"
115117
val mockitoKotlin = "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
116-
val mockitoInline = "org.mockito:mockito-inline:3.12.4"
118+
val mockitoInline = "org.mockito:mockito-inline:4.0.0"
117119
val awaitility = "org.awaitility:awaitility-kotlin:4.1.0"
118-
val mockWebserver = "com.squareup.okhttp3:mockwebserver:4.9.0"
120+
val mockWebserver = "com.squareup.okhttp3:mockwebserver:${Libs.okHttpVersion}"
119121
val mockWebserver3 = "com.squareup.okhttp3:mockwebserver:3.14.9"
120-
// bumping to 2.26.0 breaks tests
121-
val jsonUnit = "net.javacrumbs.json-unit:json-unit:2.11.1"
122+
val jsonUnit = "net.javacrumbs.json-unit:json-unit:2.28.0"
122123
}
123124

124125
object QualityPlugins {
@@ -162,7 +163,6 @@ object Config {
162163
val nopen = "com.jakewharton.nopen:nopen-annotations:$nopenVersion"
163164
val nopenChecker = "com.jakewharton.nopen:nopen-checker:$nopenVersion"
164165
val errorprone = "com.google.errorprone:error_prone_core:2.9.0"
165-
val errorProneJavac8 = "com.google.errorprone:javac:9+181-r4173-1"
166166
val errorProneNullAway = "com.uber.nullaway:nullaway:0.9.2"
167167
}
168168

sentry-android-core/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ dependencies {
8787
compileOnly(Config.CompileOnly.nopen)
8888
errorprone(Config.CompileOnly.nopenChecker)
8989
errorprone(Config.CompileOnly.errorprone)
90-
errorproneJavac(Config.CompileOnly.errorProneJavac8)
9190
errorprone(Config.CompileOnly.errorProneNullAway)
9291
compileOnly(Config.CompileOnly.jetbrainsAnnotations)
9392

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ final class EnvelopeFileObserver extends FileObserver {
3434
@NotNull ILogger logger,
3535
final long flushTimeoutMillis) {
3636
super(path);
37-
this.rootPath = Objects.requireNonNull(path, "File path is required.");
37+
this.rootPath = path;
3838
this.envelopeSender = Objects.requireNonNull(envelopeSender, "Envelope sender is required.");
3939
this.logger = Objects.requireNonNull(logger, "Logger is required.");
4040
this.flushTimeoutMillis = flushTimeoutMillis;

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,15 @@ public final void register(final @NotNull IHub hub, final @NotNull SentryOptions
4747

4848
observer =
4949
new EnvelopeFileObserver(path, outboxSender, logger, options.getFlushTimeoutMillis());
50-
observer.startWatching();
51-
52-
logger.log(SentryLevel.DEBUG, "EnvelopeFileObserverIntegration installed.");
50+
try {
51+
observer.startWatching();
52+
logger.log(SentryLevel.DEBUG, "EnvelopeFileObserverIntegration installed.");
53+
} catch (Exception e) {
54+
// it could throw eg NoSuchFileException or NullPointerException
55+
options
56+
.getLogger()
57+
.log(SentryLevel.ERROR, "Failed to initialize EnvelopeFileObserverIntegration.", e);
58+
}
5359
}
5460
}
5561

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

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

33
import static android.Manifest.permission.READ_PHONE_STATE;
4-
import static android.telephony.PhoneStateListener.LISTEN_CALL_STATE;
5-
import static android.telephony.PhoneStateListener.LISTEN_NONE;
64

75
import android.content.Context;
8-
import android.telephony.PhoneStateListener;
96
import android.telephony.TelephonyManager;
107
import androidx.annotation.Nullable;
118
import io.sentry.Breadcrumb;
@@ -31,6 +28,7 @@ public PhoneStateBreadcrumbsIntegration(final @NotNull Context context) {
3128
this.context = Objects.requireNonNull(context, "Context is required");
3229
}
3330

31+
@SuppressWarnings("deprecation")
3432
@Override
3533
public void register(final @NotNull IHub hub, final @NotNull SentryOptions options) {
3634
Objects.requireNonNull(hub, "Hub is required");
@@ -52,7 +50,7 @@ public void register(final @NotNull IHub hub, final @NotNull SentryOptions optio
5250
if (telephonyManager != null) {
5351
try {
5452
listener = new PhoneStateChangeListener(hub);
55-
telephonyManager.listen(listener, LISTEN_CALL_STATE);
53+
telephonyManager.listen(listener, android.telephony.PhoneStateListener.LISTEN_CALL_STATE);
5654

5755
options.getLogger().log(SentryLevel.DEBUG, "PhoneStateBreadcrumbsIntegration installed.");
5856
} catch (Exception e) {
@@ -66,10 +64,11 @@ public void register(final @NotNull IHub hub, final @NotNull SentryOptions optio
6664
}
6765
}
6866

67+
@SuppressWarnings("deprecation")
6968
@Override
7069
public void close() throws IOException {
7170
if (telephonyManager != null && listener != null) {
72-
telephonyManager.listen(listener, LISTEN_NONE);
71+
telephonyManager.listen(listener, android.telephony.PhoneStateListener.LISTEN_NONE);
7372
listener = null;
7473

7574
if (options != null) {
@@ -78,14 +77,16 @@ public void close() throws IOException {
7877
}
7978
}
8079

81-
static final class PhoneStateChangeListener extends PhoneStateListener {
80+
@SuppressWarnings("deprecation")
81+
static final class PhoneStateChangeListener extends android.telephony.PhoneStateListener {
8282

8383
private final @NotNull IHub hub;
8484

8585
PhoneStateChangeListener(final @NotNull IHub hub) {
8686
this.hub = hub;
8787
}
8888

89+
@SuppressWarnings("deprecation")
8990
@Override
9091
public void onCallStateChanged(int state, String incomingNumber) {
9192
// incomingNumber is never used and it's always empty if you don't have permission:

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,14 @@ import com.nhaarman.mockitokotlin2.eq
99
import com.nhaarman.mockitokotlin2.mock
1010
import com.nhaarman.mockitokotlin2.never
1111
import com.nhaarman.mockitokotlin2.verify
12-
import com.nhaarman.mockitokotlin2.verifyZeroInteractions
1312
import io.sentry.IEnvelopeSender
1413
import io.sentry.ILogger
15-
import io.sentry.SentryOptions
1614
import io.sentry.hints.ApplyScopeData
1715
import io.sentry.hints.Resettable
1816
import io.sentry.hints.Retryable
1917
import io.sentry.hints.SubmissionResult
2018
import java.io.File
2119
import kotlin.test.Test
22-
import kotlin.test.assertEquals
2320
import kotlin.test.assertFailsWith
2421
import kotlin.test.assertFalse
2522
import org.junit.runner.RunWith
@@ -32,10 +29,6 @@ class EnvelopeFileObserverTest {
3229
var path: String? = "."
3330
val envelopeSender = mock<IEnvelopeSender>()
3431
val logger = mock<ILogger>()
35-
val options = SentryOptions().apply {
36-
setDebug(true)
37-
setLogger(logger)
38-
}
3932

4033
fun getSut(flushTimeoutMillis: Long): EnvelopeFileObserver {
4134
return EnvelopeFileObserver(path, envelopeSender, logger, flushTimeoutMillis)
@@ -55,7 +48,7 @@ class EnvelopeFileObserverTest {
5548
fun `when event type is not close write, envelope sender is not called`() {
5649
triggerEvent(eventType = FileObserver.CLOSE_WRITE.inv())
5750

58-
verifyZeroInteractions(fixture.envelopeSender)
51+
verify(fixture.envelopeSender, never()).processEnvelopeFile(any(), anyOrNull())
5952
}
6053

6154
@Test
@@ -68,8 +61,10 @@ class EnvelopeFileObserverTest {
6861
@Test
6962
fun `when null is passed as a path, ctor throws`() {
7063
fixture.path = null
71-
val exception = assertFailsWith<Exception> { fixture.getSut(0) }
72-
assertEquals("File path is required.", exception.message)
64+
65+
// since EnvelopeFileObserver extends FileObserver and FileObserver requires a File(path),
66+
// it throws NullPointerException instead of our own IllegalArgumentException
67+
assertFailsWith<NullPointerException> { fixture.getSut(0) }
7368
}
7469

7570
@Test

sentry-apache-http-client-5/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ dependencies {
2626
compileOnly(Config.CompileOnly.nopen)
2727
errorprone(Config.CompileOnly.nopenChecker)
2828
errorprone(Config.CompileOnly.errorprone)
29-
errorproneJavac(Config.CompileOnly.errorProneJavac8)
3029
errorprone(Config.CompileOnly.errorProneNullAway)
3130
compileOnly(Config.CompileOnly.jetbrainsAnnotations)
3231

sentry-apollo/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ dependencies {
2929
errorprone(Config.CompileOnly.nopenChecker)
3030
errorprone(Config.CompileOnly.errorprone)
3131
errorprone(Config.CompileOnly.errorProneNullAway)
32-
errorproneJavac(Config.CompileOnly.errorProneJavac8)
3332
compileOnly(Config.CompileOnly.jetbrainsAnnotations)
3433

3534
// tests

sentry-jul/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ dependencies {
2727
errorprone(Config.CompileOnly.nopenChecker)
2828
errorprone(Config.CompileOnly.errorprone)
2929
errorprone(Config.CompileOnly.errorProneNullAway)
30-
errorproneJavac(Config.CompileOnly.errorProneJavac8)
3130
compileOnly(Config.CompileOnly.jetbrainsAnnotations)
3231

3332
// tests

sentry-kotlin-extensions/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ dependencies {
2727
compileOnly(Config.CompileOnly.nopen)
2828
errorprone(Config.CompileOnly.nopenChecker)
2929
errorprone(Config.CompileOnly.errorprone)
30-
errorproneJavac(Config.CompileOnly.errorProneJavac8)
3130
compileOnly(Config.CompileOnly.jetbrainsAnnotations)
3231

3332
// tests

0 commit comments

Comments
 (0)