Skip to content

Commit b148ab2

Browse files
runningcodeclaude
andcommitted
feat(distribution): Move UpdateStatus and UpdateInfo to core sentry module
- Move UpdateStatus and UpdateInfo from distribution module to core sentry module - Update IDistributionApi to use proper types instead of Object - Add UpdateCallback interface for type-safe async callbacks - Rename UpdateStatus.Error to UpdateError to avoid java.lang.Error clash - Update DistributionIntegration to implement IDistributionApi with proper types - Remove duplicate classes from distribution module - Regenerate API files with proper type signatures This provides full type safety for the distribution API while keeping the types accessible to all modules that might need them. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent bf61b68 commit b148ab2

File tree

9 files changed

+159
-58
lines changed

9 files changed

+159
-58
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,9 @@ static void installDefaultIntegrations(
394394
options.setReplayController(replay);
395395
}
396396
if (isDistributionAvailable) {
397-
options.addIntegration(new DistributionIntegration(context));
397+
final DistributionIntegration distribution = new DistributionIntegration((context));
398+
options.setDistributionController(distribution);
399+
options.addIntegration(distribution);
398400
}
399401
options
400402
.getFeedbackOptions()

sentry-android-distribution/src/main/java/io/sentry/android/distribution/DistributionIntegration.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@ package io.sentry.android.distribution
33
import android.content.Context
44
import android.content.Intent
55
import android.net.Uri
6+
import io.sentry.IDistributionApi
67
import io.sentry.IScopes
78
import io.sentry.Integration
89
import io.sentry.SentryOptions
10+
import io.sentry.UpdateInfo
11+
import io.sentry.UpdateStatus
912

1013
/**
1114
* The public Android SDK for Sentry Build Distribution.
1215
*
1316
* Provides functionality to check for app updates and download new versions from Sentry's preprod
1417
* artifacts system.
1518
*/
16-
public class DistributionIntegration(context: Context) : Integration {
19+
public class DistributionIntegration(context: Context) : Integration, IDistributionApi {
1720

1821
private lateinit var scopes: IScopes
1922
private lateinit var sentryOptions: SentryOptions
@@ -62,33 +65,30 @@ public class DistributionIntegration(context: Context) : Integration {
6265
* thread while making the network request. Consider using checkForUpdate with callback for
6366
* non-blocking behavior.
6467
*
65-
* @param context Android context
6668
* @return UpdateStatus indicating if an update is available, up to date, or error
6769
*/
68-
public fun checkForUpdateBlocking(): UpdateStatus {
70+
public override fun checkForUpdateBlocking(): UpdateStatus {
6971
throw NotImplementedError()
7072
}
7173

7274
/**
73-
* Check for available updates asynchronously using a Kotlin lambda callback.
75+
* Check for available updates asynchronously using a callback.
7476
*
75-
* @param context Android context
76-
* @param onResult Lambda that will be called with the UpdateStatus result
77+
* @param onResult Callback that will be called with the UpdateStatus result
7778
*/
78-
public fun checkForUpdate(onResult: (UpdateStatus) -> Unit) {
79+
public override fun checkForUpdate(onResult: IDistributionApi.UpdateCallback) {
7980
// TODO implement this in a async way
8081
val result = checkForUpdateBlocking()
81-
onResult(result)
82+
onResult.onResult(result)
8283
}
8384

8485
/**
8586
* Download and install the provided update by opening the download URL in the default browser or
8687
* appropriate application.
8788
*
88-
* @param context Android context
8989
* @param info Information about the update to download
9090
*/
91-
public fun downloadUpdate(info: UpdateInfo) {
91+
public override fun downloadUpdate(info: UpdateInfo) {
9292
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(info.downloadUrl))
9393
browserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
9494

sentry-android-distribution/src/main/java/io/sentry/android/distribution/UpdateInfo.kt

Lines changed: 0 additions & 20 deletions
This file was deleted.

sentry-android-distribution/src/main/java/io/sentry/android/distribution/UpdateStatus.kt

Lines changed: 0 additions & 13 deletions
This file was deleted.

sentry/api/sentry.api

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -768,9 +768,13 @@ public abstract interface class io/sentry/IContinuousProfiler {
768768
}
769769

770770
public abstract interface class io/sentry/IDistributionApi {
771-
public abstract fun checkForUpdate (Ljava/lang/Object;)V
772-
public abstract fun checkForUpdateBlocking ()Ljava/lang/Object;
773-
public abstract fun downloadUpdate (Ljava/lang/Object;)V
771+
public abstract fun checkForUpdate (Lio/sentry/IDistributionApi$UpdateCallback;)V
772+
public abstract fun checkForUpdateBlocking ()Lio/sentry/UpdateStatus;
773+
public abstract fun downloadUpdate (Lio/sentry/UpdateInfo;)V
774+
}
775+
776+
public abstract interface class io/sentry/IDistributionApi$UpdateCallback {
777+
public abstract fun onResult (Lio/sentry/UpdateStatus;)V
774778
}
775779

776780
public abstract interface class io/sentry/IEnvelopeReader {
@@ -1476,9 +1480,9 @@ public final class io/sentry/NoOpContinuousProfiler : io/sentry/IContinuousProfi
14761480
}
14771481

14781482
public final class io/sentry/NoOpDistributionApi : io/sentry/IDistributionApi {
1479-
public fun checkForUpdate (Ljava/lang/Object;)V
1480-
public fun checkForUpdateBlocking ()Ljava/lang/Object;
1481-
public fun downloadUpdate (Ljava/lang/Object;)V
1483+
public fun checkForUpdate (Lio/sentry/IDistributionApi$UpdateCallback;)V
1484+
public fun checkForUpdateBlocking ()Lio/sentry/UpdateStatus;
1485+
public fun downloadUpdate (Lio/sentry/UpdateInfo;)V
14821486
public static fun getInstance ()Lio/sentry/NoOpDistributionApi;
14831487
}
14841488

@@ -4310,6 +4314,34 @@ public class io/sentry/UncaughtExceptionHandlerIntegration$UncaughtExceptionHint
43104314
public fun setFlushable (Lio/sentry/protocol/SentryId;)V
43114315
}
43124316

4317+
public final class io/sentry/UpdateInfo {
4318+
public fun <init> (Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
4319+
public fun getAppName ()Ljava/lang/String;
4320+
public fun getBuildNumber ()I
4321+
public fun getBuildVersion ()Ljava/lang/String;
4322+
public fun getCreatedDate ()Ljava/lang/String;
4323+
public fun getDownloadUrl ()Ljava/lang/String;
4324+
public fun getId ()Ljava/lang/String;
4325+
}
4326+
4327+
public abstract class io/sentry/UpdateStatus {
4328+
public fun <init> ()V
4329+
}
4330+
4331+
public final class io/sentry/UpdateStatus$NewRelease : io/sentry/UpdateStatus {
4332+
public fun <init> (Lio/sentry/UpdateInfo;)V
4333+
public fun getInfo ()Lio/sentry/UpdateInfo;
4334+
}
4335+
4336+
public final class io/sentry/UpdateStatus$UpToDate : io/sentry/UpdateStatus {
4337+
public static fun getInstance ()Lio/sentry/UpdateStatus$UpToDate;
4338+
}
4339+
4340+
public final class io/sentry/UpdateStatus$UpdateError : io/sentry/UpdateStatus {
4341+
public fun <init> (Ljava/lang/String;)V
4342+
public fun getMessage ()Ljava/lang/String;
4343+
}
4344+
43134345
public final class io/sentry/UserFeedback : io/sentry/JsonSerializable, io/sentry/JsonUnknown {
43144346
public fun <init> (Lio/sentry/protocol/SentryId;)V
43154347
public fun <init> (Lio/sentry/protocol/SentryId;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V

sentry/src/main/java/io/sentry/IDistributionApi.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,25 @@ public interface IDistributionApi {
1818
* @return UpdateStatus indicating if an update is available, up to date, or error
1919
*/
2020
@NotNull
21-
Object checkForUpdateBlocking();
21+
UpdateStatus checkForUpdateBlocking();
2222

2323
/**
2424
* Check for available updates asynchronously using a callback.
2525
*
2626
* @param onResult Callback that will be called with the UpdateStatus result
2727
*/
28-
void checkForUpdate(@NotNull Object onResult);
28+
void checkForUpdate(@NotNull UpdateCallback onResult);
2929

3030
/**
3131
* Download and install the provided update by opening the download URL in the default browser or
3232
* appropriate application.
3333
*
3434
* @param info Information about the update to download
3535
*/
36-
void downloadUpdate(@NotNull Object info);
36+
void downloadUpdate(@NotNull UpdateInfo info);
37+
38+
/** Callback interface for receiving async update check results. */
39+
interface UpdateCallback {
40+
void onResult(@NotNull UpdateStatus status);
41+
}
3742
}

sentry/src/main/java/io/sentry/NoOpDistributionApi.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,17 @@ public static NoOpDistributionApi getInstance() {
1414
}
1515

1616
@Override
17-
public @NotNull Object checkForUpdateBlocking() {
18-
// Return a no-op result - could be null or an error status
19-
return new Object(); // This will need to be properly typed when the actual types are available
17+
public @NotNull UpdateStatus checkForUpdateBlocking() {
18+
return UpdateStatus.UpToDate.getInstance();
2019
}
2120

2221
@Override
23-
public void checkForUpdate(@NotNull Object onResult) {
22+
public void checkForUpdate(@NotNull UpdateCallback onResult) {
2423
// No-op implementation - do nothing
2524
}
2625

2726
@Override
28-
public void downloadUpdate(@NotNull Object info) {
27+
public void downloadUpdate(@NotNull UpdateInfo info) {
2928
// No-op implementation - do nothing
3029
}
3130
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package io.sentry;
2+
3+
import org.jetbrains.annotations.NotNull;
4+
5+
/** Information about an available app update. */
6+
public final class UpdateInfo {
7+
private final @NotNull String id;
8+
private final @NotNull String buildVersion;
9+
private final int buildNumber;
10+
private final @NotNull String downloadUrl;
11+
private final @NotNull String appName;
12+
private final @NotNull String createdDate;
13+
14+
public UpdateInfo(
15+
final @NotNull String id,
16+
final @NotNull String buildVersion,
17+
final int buildNumber,
18+
final @NotNull String downloadUrl,
19+
final @NotNull String appName,
20+
final @NotNull String createdDate) {
21+
this.id = id;
22+
this.buildVersion = buildVersion;
23+
this.buildNumber = buildNumber;
24+
this.downloadUrl = downloadUrl;
25+
this.appName = appName;
26+
this.createdDate = createdDate;
27+
}
28+
29+
public @NotNull String getId() {
30+
return id;
31+
}
32+
33+
public @NotNull String getBuildVersion() {
34+
return buildVersion;
35+
}
36+
37+
public int getBuildNumber() {
38+
return buildNumber;
39+
}
40+
41+
public @NotNull String getDownloadUrl() {
42+
return downloadUrl;
43+
}
44+
45+
public @NotNull String getAppName() {
46+
return appName;
47+
}
48+
49+
public @NotNull String getCreatedDate() {
50+
return createdDate;
51+
}
52+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package io.sentry;
2+
3+
import org.jetbrains.annotations.NotNull;
4+
5+
/** Represents the result of checking for app updates. */
6+
public abstract class UpdateStatus {
7+
8+
/** Current app version is up to date, no update available. */
9+
public static final class UpToDate extends UpdateStatus {
10+
private static final UpToDate INSTANCE = new UpToDate();
11+
12+
private UpToDate() {}
13+
14+
public static UpToDate getInstance() {
15+
return INSTANCE;
16+
}
17+
}
18+
19+
/** A new release is available for download. */
20+
public static final class NewRelease extends UpdateStatus {
21+
private final @NotNull UpdateInfo info;
22+
23+
public NewRelease(final @NotNull UpdateInfo info) {
24+
this.info = info;
25+
}
26+
27+
public @NotNull UpdateInfo getInfo() {
28+
return info;
29+
}
30+
}
31+
32+
/** An error occurred during the update check. */
33+
public static final class UpdateError extends UpdateStatus {
34+
private final @NotNull String message;
35+
36+
public UpdateError(final @NotNull String message) {
37+
this.message = message;
38+
}
39+
40+
public @NotNull String getMessage() {
41+
return message;
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)